Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Server-side file conversion and REST service
Browse files Browse the repository at this point in the history
https://bugzilla.redhat.com/show_bug.cgi?id=1186972

Squashed commit of the following:

commit 328c9cd
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 12 11:17:23 2015 +1000

    Fix unit test

commit 0109910
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 12 10:45:14 2015 +1000

    Remove banned dependency

commit 033f30f
Merge: c4446f3 4a04970
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 12 10:41:24 2015 +1000

    Merge branch 'integration/master' into rhbz1186972

commit c4446f3
Author: Alex Eng <aeng@redhat.com>
Date:   Mon May 11 08:18:09 2015 +1000

    Add check for invalid char in locale id for File-project type

commit b200c95
Merge: 069bfea a5b7b9e
Author: Alex Eng <aeng@redhat.com>
Date:   Thu May 7 15:56:27 2015 +1000

    Merge branch 'integration/master' into rhbz1186972

    Conflicts:
    	pom.xml
    	zanata-war/pom.xml
    	zanata-war/src/main/java/org/zanata/rest/service/FileService.java
    	zanata-war/src/main/webapp/WEB-INF/layout/version/upload_translation_modal.xhtml

commit 069bfea
Author: Alex Eng <aeng@redhat.com>
Date:   Thu May 7 11:23:18 2015 +1000

    Update release notes

commit 5ba88b1
Author: Alex Eng <aeng@redhat.com>
Date:   Thu May 7 09:56:09 2015 +1000

    Format 'if(' with spacing

commit f7a5266
Author: Alex Eng <aeng@redhat.com>
Date:   Wed May 6 15:55:56 2015 +1000

    Remove duplicate get file extension method, update styling for 'if'

commit d8286f6
Author: Alex Eng <aeng@redhat.com>
Date:   Wed May 6 14:40:17 2015 +1000

    fix multi file upload accepted file descriptions

commit cc8dcbc
Author: Alex Eng <aeng@redhat.com>
Date:   Wed May 6 13:50:16 2015 +1000

    Add @nonnull annotation for required param in FileFormatAdapter

commit a649908
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 5 10:14:28 2015 +1000

    Allow custom file extension to upload from client

commit 1fa6e2d
Author: Alex Eng <aeng@redhat.com>
Date:   Fri May 1 11:52:36 2015 +1000

    Refactor properties adapter file

commit 89fd494
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Apr 27 08:00:49 2015 +1000

    Fix download file option from UI

commit a4df408
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Apr 24 14:03:26 2015 +1000

    Implement gettext adapter for file project type

commit 7fbbc0c
Author: Alex Eng <aeng@redhat.com>
Date:   Wed Apr 22 14:24:57 2015 +1000

    WIP: gettext adapter

commit a0028f7
Author: Alex Eng <aeng@redhat.com>
Date:   Tue Apr 21 11:15:54 2015 +1000

    Add xliff type in server side conversion

commit e7bebe6
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Apr 20 13:12:34 2015 +1000

    Change default value of document type to null

commit 4c45fe6
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Apr 13 10:24:01 2015 +1000

    Clear adapter selection when cancel upload trans-file

commit 27c6aa1
Author: Alex Eng <aeng@redhat.com>
Date:   Sun Apr 12 19:24:03 2015 +1000

    Remove GWT upload file dialog

commit c1ff245
Author: Alex Eng <aeng@redhat.com>
Date:   Thu Apr 9 15:56:30 2015 +1000

    Add propertiesUTF8 support for upload documents

commit 9f5183f
Author: Alex Eng <aeng@redhat.com>
Date:   Wed Apr 8 16:34:01 2015 +1000

    Update zanata-commin version, implement PropertiesAdapter

commit 111eb98
Merge: 1e20372 307b890
Author: Alex Eng <aeng@redhat.com>
Date:   Tue Apr 7 08:51:05 2015 +1000

    Merge branch 'integration/master' into rhbz1186972

commit 1e20372
Author: Alex Eng <aeng@redhat.com>
Date:   Wed Apr 1 15:40:58 2015 +1000

    WIP: creating PropertiesAdapter and GettextAdapter

commit 99d50df
Author: Alex Eng <aeng@redhat.com>
Date:   Wed Apr 1 15:40:49 2015 +1000

    WIP: creating PropertiesAdapter and GettextAdapter
  • Loading branch information
Alex Eng committed May 12, 2015
1 parent 4a04970 commit 847501d
Show file tree
Hide file tree
Showing 44 changed files with 1,640 additions and 1,052 deletions.
3 changes: 3 additions & 0 deletions docs/release-notes.md
Expand Up @@ -37,6 +37,9 @@ Example usage in html file: `<link rel="shortcut icon" href="#{assets['img/logo/

<h5>New Features</h5>
* [1133989](https://bugzilla.redhat.com/show_bug.cgi?id=1133989) - Copy translations from existing version.
* [1186972](https://bugzilla.redhat.com/show_bug.cgi?id=1186972) - Server-side file conversion and REST service.
* File project type now supports XLIFF, PROPERTIES, PROPERTIES_UTF8, and GETTEXT
* [1204982](https://bugzilla.redhat.com/show_bug.cgi?id=1204982) - Documentation update for zanata.org/help + readthedocs
*

## 3.6.3
Expand Down
18 changes: 17 additions & 1 deletion pom.xml
Expand Up @@ -48,7 +48,7 @@
<!-- This should always be the previous version of the used api version above (but only 3.0.1 or later will work) -->
<zanata.api.compat.version>3.4.1</zanata.api.compat.version>
<zanata.client.version>3.7.0-SNAPSHOT</zanata.client.version>
<zanata.common.version>3.6.0</zanata.common.version>
<zanata.common.version>3.6.1-SNAPSHOT</zanata.common.version>

<richfaces.version>4.5.4.Final</richfaces.version>

Expand Down Expand Up @@ -448,6 +448,22 @@
<artifactId>zanata-adapter-glossary</artifactId>
<version>${zanata.common.version}</version>
</dependency>
<dependency>
<groupId>org.zanata</groupId>
<artifactId>zanata-adapter-properties</artifactId>
<version>${zanata.common.version}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.zanata</groupId>
<artifactId>zanata-adapter-xliff</artifactId>
<version>${zanata.common.version}</version>
</dependency>

<!-- zanata client -->
<dependency>
Expand Down
10 changes: 10 additions & 0 deletions zanata-war/pom.xml
Expand Up @@ -1313,6 +1313,16 @@
<artifactId>zanata-adapter-glossary</artifactId>
</dependency>

<dependency>
<groupId>org.zanata</groupId>
<artifactId>zanata-adapter-properties</artifactId>
</dependency>

<dependency>
<groupId>org.zanata</groupId>
<artifactId>zanata-adapter-xliff</artifactId>
</dependency>

<!-- Compatibility Dependencies -->

<dependency>
Expand Down
32 changes: 28 additions & 4 deletions zanata-war/src/main/java/org/zanata/action/VersionHome.java
Expand Up @@ -43,6 +43,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.international.StatusMessage;
import org.zanata.common.DocumentType;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.common.ProjectType;
Expand All @@ -59,6 +60,7 @@
import org.zanata.service.SlugEntityService;
import org.zanata.service.ValidationService;
import org.zanata.service.impl.LocaleServiceImpl;
import org.zanata.transformer.Transformer;
import org.zanata.ui.faces.FacesMessages;
import org.zanata.util.ComparatorUtil;
import org.zanata.util.Event;
Expand All @@ -67,9 +69,11 @@
import org.zanata.webtrans.shared.model.ValidationId;
import org.zanata.webtrans.shared.validation.ValidationFactory;

import javax.annotation.Nullable;
import javax.faces.application.FacesMessage;
import javax.faces.event.ValueChangeEvent;
import javax.persistence.EntityNotFoundException;
import javax.swing.text.Document;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -449,10 +453,30 @@ public void copyProjectTypeFromProject() {
* @return comma-separated list of accepted file extensions. May be an empty
* string
*/
public String getAcceptedSourceFileTypes() {
return Joiner
.on(", ")
.join(ProjectType.getSupportedSourceFileTypes(getProjectType()));
public String getAcceptedSourceFileExtensions() {
List<String> supportedTypes = Lists.transform(ProjectType
.getSupportedSourceFileTypes(getProjectType()),
new Function<DocumentType, String>() {
@Override
public String apply(DocumentType docType) {
return Joiner.on(",").join(
docType.getSourceExtensions());
}
});
return Joiner.on(", ").join(supportedTypes);
}

public String getAcceptedSourceFile() {
List<String> supportedTypes = Lists.transform(ProjectType
.getSupportedSourceFileTypes(getProjectType()),
new Function<DocumentType, String>() {
@Override
public String apply(DocumentType docType) {
return docType.name() + "[" + Joiner.on(",").join(
docType.getSourceExtensions()) + "]";
}
});
return Joiner.on(", ").join(supportedTypes);
}

private void updateProjectType() {
Expand Down
92 changes: 71 additions & 21 deletions zanata-war/src/main/java/org/zanata/action/VersionHomeAction.java
Expand Up @@ -36,6 +36,7 @@
import javax.faces.application.FacesMessage;
import javax.validation.ConstraintViolationException;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
Expand Down Expand Up @@ -82,6 +83,7 @@
import org.zanata.ui.InMemoryListFilter;
import org.zanata.ui.model.statistic.WordStatistic;
import org.zanata.util.DateUtil;
import org.zanata.util.FileUtil;
import org.zanata.util.ServiceLocator;
import org.zanata.util.StatisticsUtil;
import org.zanata.util.UrlUtil;
Expand Down Expand Up @@ -695,17 +697,34 @@ public boolean isFileUploadAllowed(HLocale hLocale) {
.getProject(), hLocale);
}

private DocumentType getDocumentType(Optional<String> docType) {
DocumentType type;
if (!docType.isPresent()) {
// if docType null, only 1 document type available for selected file extensions
type = translationFileServiceImpl
.getDocumentTypes(sourceFileUpload.getFileName())
.iterator().next();
} else {
// if docType not null, adapter is selected by user from drop down
type = DocumentType.getByName(docType.get());
}
return type;
}

public void uploadSourceFile() {
identity.checkPermission("import-template", getVersion());

if (sourceFileUpload.getFileName().endsWith(".pot")) {
uploadPotFile();
} else {
DocumentType type =
translationFileServiceImpl.getDocumentType(sourceFileUpload
.getFileName());
if (translationFileServiceImpl.hasAdapterFor(type)) {
uploadAdapterFile();

Optional<String> docType =
Optional.fromNullable(sourceFileUpload.documentType);

DocumentType documentType = getDocumentType(docType);

if (translationFileServiceImpl.hasAdapterFor(documentType)) {
uploadAdapterFile(documentType);
} else {
conversationScopeMessages.setMessage(
FacesMessage.SEVERITY_INFO,
Expand All @@ -721,10 +740,17 @@ public boolean isPoDocument(String docId) {
versionSlug, docId);
}

public String extensionOf(String docPath, String docName) {
public String sourceExtensionOf(String docPath, String docName) {
return "."
+ translationFileServiceImpl.getFileExtension(projectSlug,
versionSlug, docPath, docName);
+ translationFileServiceImpl.getSourceFileExtension(projectSlug,
versionSlug, docPath, docName);
}

public String translationExtensionOf(String docPath, String docName) {
return "."
+ translationFileServiceImpl.getTranslationFileExtension(
projectSlug,
versionSlug, docPath, docName);
}

public boolean hasOriginal(String docPath, String docName) {
Expand Down Expand Up @@ -754,7 +780,7 @@ private void uploadPotFile() {
String docId = sourceFileUpload.getDocId();
if (docId == null) {
docId =
translationFileServiceImpl.generateDocId(
FileUtil.generateDocId(
sourceFileUpload.getDocumentPath(),
sourceFileUpload.getFileName());
}
Expand Down Expand Up @@ -788,7 +814,7 @@ private void uploadPotFile() {

private Optional<String> getOptionalParams() {
return Optional.fromNullable(Strings.emptyToNull(sourceFileUpload
.getAdapterParams()));
.getAdapterParams()));
}

public void setSelectedLocaleId(String localeId) {
Expand All @@ -805,7 +831,7 @@ public void setSelectedDocumentId(String projectSlug, String versionSlug,

// TODO add logging for disk writing errors
// TODO damason: unify this with Source/TranslationDocumentUpload
private void uploadAdapterFile() {
private void uploadAdapterFile(DocumentType docType) {
String fileName = sourceFileUpload.getFileName();
String docId = sourceFileUpload.getDocId();
String documentPath = "";
Expand Down Expand Up @@ -845,17 +871,16 @@ private void uploadAdapterFile() {
HDocument document = null;
try {
Resource doc;

if (docId == null) {
doc =
translationFileServiceImpl.parseAdapterDocumentFile(
doc = translationFileServiceImpl.parseAdapterDocumentFile(
tempFile.toURI(), documentPath, fileName,
getOptionalParams());
getOptionalParams(), Optional.of(docType.name()));
} else {
doc =
translationFileServiceImpl
doc = translationFileServiceImpl
.parseUpdatedAdapterDocumentFile(
tempFile.toURI(), docId, fileName,
getOptionalParams());
getOptionalParams(), Optional.of(docType.name()));
}
doc.setLang(new LocaleId(sourceFileUpload.getSourceLang()));
Set<String> extensions = Collections.<String> emptySet();
Expand All @@ -879,8 +904,7 @@ private void uploadAdapterFile() {
HRawDocument rawDocument = new HRawDocument();
rawDocument.setDocument(document);
rawDocument.setContentHash(new String(Hex.encodeHex(md5hash)));
rawDocument.setType(DocumentType.typeFor(translationFileServiceImpl
.extractExtension(fileName)));
rawDocument.setType(docType);
rawDocument.setUploadedBy(identity.getCredentials().getUsername());

Optional<String> params = getOptionalParams();
Expand All @@ -899,7 +923,7 @@ private void uploadAdapterFile() {
"uploaded file did not pass virus scan");
}
filePersistService.persistRawDocumentContentFromFile(rawDocument,
tempFile);
tempFile, FilenameUtils.getExtension(fileName));
documentDAO.addRawDocument(document, rawDocument);
documentDAO.flush();
}
Expand All @@ -925,17 +949,39 @@ public boolean isCopyActionsRunning() {
copyTransManager.isCopyTransRunning(getVersion());
}

public boolean needDocumentTypeSelection(String fileName) {
return translationFileServiceImpl.hasMultipleDocumentTypes(fileName);
}

public List<DocumentType> getDocumentTypes(String fileName) {
return Lists.newArrayList(
translationFileServiceImpl.getDocumentTypes(fileName));
}

public void setDefaultTranslationDocType(String fileName) {
translationFileUpload.setDocumentType(null);
}

public void uploadTranslationFile(HLocale hLocale) {
identity.checkPermission("modify-translation", hLocale, getVersion()
.getProject());
try {
// process the file
String fileName = translationFileUpload.fileName;
if (!needDocumentTypeSelection(fileName)) {
//Get documentType for this file name
DocumentType documentType = getDocumentTypes(fileName).get(0);
translationFileUpload.setDocumentType(documentType.name());
}

Optional<String> docType =
Optional.fromNullable(translationFileUpload.documentType);
TranslationsResource transRes =
translationFileServiceImpl.parseTranslationFile(
translationFileUpload.getFileContents(),
translationFileUpload.getFileName(), hLocale
.getLocaleId().getId(), projectSlug,
versionSlug, translationFileUpload.docId);
versionSlug, translationFileUpload.docId, docType);

// translate it
Set<String> extensions;
Expand Down Expand Up @@ -1145,6 +1191,8 @@ public static class SourceFileUploadHelper implements Serializable {
private String sourceLang = "en-US"; // en-US by default

private String adapterParams = "";

private String documentType;
}

/**
Expand All @@ -1164,5 +1212,7 @@ public static class TranslationFileUploadHelper implements Serializable {
private boolean mergeTranslations = true; // Merge by default

private boolean assignCreditToUploader = false;

private String documentType;
}
}

0 comments on commit 847501d

Please sign in to comment.