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

Commit

Permalink
Merge branch 'integration/master' of github.com:zanata/zanata into in…
Browse files Browse the repository at this point in the history
…tegration/master
  • Loading branch information
Alex Eng committed May 17, 2012
2 parents bee5438 + 556d8f6 commit 5bbea9f
Show file tree
Hide file tree
Showing 20 changed files with 652 additions and 377 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -19,9 +19,9 @@
</scm>

<properties>
<zanata.api.version>1.6.0-alpha-2</zanata.api.version>
<zanata.api.version>1.6.0-alpha-3-SNAPSHOT</zanata.api.version>
<zanata.client.version>1.6.0-alpha-2</zanata.client.version>
<zanata.common.version>1.6.0-alpha-2</zanata.common.version>
<zanata.common.version>1.6.0-alpha-3-SNAPSHOT</zanata.common.version>

<!--delombok properties-->
<lombok.source.dir>${project.build.sourceDirectory}/org/zanata</lombok.source.dir>
Expand Down
Expand Up @@ -32,13 +32,13 @@
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
* @author camunoz@redhat.com
*
Expand Down
Expand Up @@ -67,7 +67,6 @@ private List<String> getContentsToIndex()
* As of release 1.6, replaced by {@link #getContents()}
* @return
*/
@Override
@Deprecated
@Transient
public String getContent()
Expand Down
3 changes: 2 additions & 1 deletion zanata-model/src/main/java/org/zanata/model/HTextFlow.java
Expand Up @@ -63,6 +63,7 @@
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.zanata.common.HasContents;
import org.zanata.common.LocaleId;
import org.zanata.hibernate.search.ContainingWorkspaceBridge;
import org.zanata.hibernate.search.IdFilterFactory;
Expand Down Expand Up @@ -105,7 +106,7 @@
@NoArgsConstructor
@ToString(of = {"resId", "revision", "contents", "comment", "obsolete"})
@Slf4j
public class HTextFlow extends HTextContainer implements Serializable, ITextFlowHistory, HasSimpleComment
public class HTextFlow extends HTextContainer implements Serializable, ITextFlowHistory, HasSimpleComment, HasContents
{
private static final long serialVersionUID = 3023080107971905435L;

Expand Down
11 changes: 5 additions & 6 deletions zanata-model/src/main/java/org/zanata/model/HTextFlowTarget.java
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -46,6 +47,9 @@
import javax.persistence.PreUpdate;
import javax.persistence.Transient;

import lombok.NoArgsConstructor;
import lombok.Setter;

import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
Expand All @@ -71,10 +75,6 @@

import com.google.common.base.Objects;

import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
* Represents a flow of translated text that should be processed as a
* stand-alone structural unit.
Expand Down Expand Up @@ -117,7 +117,7 @@ public class HTextFlowTarget extends ModelEntityBase implements HasContents, Has

private HSimpleComment comment;

public Map<Integer, HTextFlowTargetHistory> history;
private Map<Integer, HTextFlowTargetHistory> history;

// Only for internal use (persistence transient)
private Integer oldVersionNum;
Expand Down Expand Up @@ -199,7 +199,6 @@ public HTextFlow getTextFlow()
*
* @return
*/
@Override
@Deprecated
@Transient
public String getContent()
Expand Down
38 changes: 38 additions & 0 deletions zanata-war/pom.xml
Expand Up @@ -474,6 +474,44 @@
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<versionRange>
[1.7,)
</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.4,)
</versionRange>
<goals>
<goal>properties</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
Expand Down
Expand Up @@ -20,12 +20,16 @@
*/
package org.zanata.action;

import java.io.InputStream;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.common.MergeType;
Expand All @@ -41,19 +45,12 @@
import org.zanata.rest.StringSet;
import org.zanata.rest.dto.extensions.ExtensionType;
import org.zanata.rest.dto.resource.Resource;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.DocumentService;
import org.zanata.service.TranslationFileService;
import org.zanata.service.TranslationService;

import java.io.InputStream;
import java.util.Collection;
import java.util.List;

import static org.jboss.seam.international.StatusMessage.Severity;

@Name("projectIterationFilesAction")
@Scope(ScopeType.PAGE)
public class ProjectIterationFilesAction
Expand Down Expand Up @@ -138,21 +135,21 @@ public void uploadTranslationFile()
this.translationFileUpload.getFileName());

// translate it
Collection<TextFlowTarget> resourcesNotFound =
List<String> warnings =
this.translationServiceImpl.translateAllInDoc(this.projectSlug, this.iterationSlug, this.translationFileUpload.getDocId(),
new LocaleId(this.localeId), transRes, new StringSet(ExtensionType.GetText.toString()),
this.translationFileUpload.getMergeTranslations() ? MergeType.AUTO : MergeType.IMPORT);

StringBuilder facesInfoMssg = new StringBuilder("File {0} uploaded.");
if( resourcesNotFound.size() > 0 )
if (!warnings.isEmpty())
{
facesInfoMssg.append(" There were some warnings, see below.");
}

FacesMessages.instance().add(Severity.INFO, facesInfoMssg.toString(), this.translationFileUpload.getFileName());
for( TextFlowTarget nf : resourcesNotFound )
for (String warning : warnings)
{
FacesMessages.instance().add(Severity.WARN, "Could not find text flow for message: {0}", nf.getContents());
FacesMessages.instance().add(Severity.WARN, warning);
}
}
catch (ZanataServiceException zex)
Expand Down
7 changes: 7 additions & 0 deletions zanata-war/src/main/java/org/zanata/dao/TextFlowDAO.java
Expand Up @@ -59,6 +59,13 @@
public class TextFlowDAO extends AbstractDAOImpl<HTextFlow, Long>
{
private static final Version LUCENE_VERSION = Version.LUCENE_29;
private static final String CONTENT_FIELDS[] = new String[6];
{
for (int i = 0; i < 6; i++)
{
CONTENT_FIELDS[i] = IndexFieldLabels.CONTENT_CASE_FOLDED + i;
}
}

@In
private FullTextEntityManager entityManager;
Expand Down
Expand Up @@ -98,8 +98,9 @@ public class ResourceUtils
private static final String CONTENT_TYPE_HDR = HeaderFields.KEY_ContentType;
private static final String PLURAL_FORMS_HDR = "Plural-Forms";

private final static Pattern NPLURALS_TAG_PATTERN = Pattern.compile("nplurals=");
private final static Pattern NPLURALS_PATTERN = Pattern.compile("nplurals=[0-9]+");
private static final Pattern NPLURALS_TAG_PATTERN = Pattern.compile("nplurals=");
private static final Pattern NPLURALS_PATTERN = Pattern.compile("nplurals=[0-9]+");
private static final String PLURALS_FILE = "pluralforms.properties";

private static final Log log = Logging.getLog(ResourceUtils.class);

Expand All @@ -115,7 +116,7 @@ public void create()
if (pluralForms == null)
{
pluralForms = new Properties();
pluralForms.load(this.getClass().getClassLoader().getResourceAsStream("pluralforms.properties"));
pluralForms.load(this.getClass().getClassLoader().getResourceAsStream(PLURALS_FILE));
}
}
catch (IOException e)
Expand Down Expand Up @@ -278,10 +279,6 @@ public boolean transferFromTextFlowTarget(TextFlowTarget from, HTextFlowTarget t
to.setState(from.getState());
changed = true;
}
if (changed)
{
to.setVersionNum(to.getVersionNum() + 1);
}
return changed;
}

Expand Down Expand Up @@ -1074,7 +1071,11 @@ private int getNPluralForms(String entries, HLocale targetLocale)
{
pluralForms = getPluralForms(targetLocale);
}

if (pluralForms == null)
{
log.error("No plural forms for locale {0} found in {1}", targetLocale, PLURALS_FILE);
throw new RuntimeException("No plural forms found; contact admin. Locale: " + targetLocale);
}
Matcher nPluralsMatcher = NPLURALS_PATTERN.matcher(pluralForms);
String nPluralsString = "";
while (nPluralsMatcher.find())
Expand Down
Expand Up @@ -20,7 +20,33 @@
*/
package org.zanata.rest.service;

import com.google.common.base.Function;
import static org.zanata.rest.service.SourceDocResource.RESOURCE_SLUG_TEMPLATE;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.codehaus.enunciate.jaxrs.TypeHint;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand All @@ -44,41 +70,11 @@
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.NoSuchEntityException;
import org.zanata.rest.ReadOnlyEntityException;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.CopyTransService;
import org.zanata.service.LocaleService;
import org.zanata.service.TranslationService;
import org.zanata.util.StringUtil;

import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.zanata.rest.service.SourceDocResource.RESOURCE_SLUG_TEMPLATE;

@Name("translatedDocResourceService")
@Path(TranslatedDocResourceService.SERVICE_PATH)
Expand Down Expand Up @@ -355,34 +351,21 @@ public Response putTranslations(@PathParam("id") String idNoSlash, @PathParam("l
}

// Translate
Collection<TextFlowTarget> unknownResIds =
List<String> warnings =
this.translationServiceImpl.translateAllInDoc(projectSlug, iterationSlug, id, locale, messageBody, extensions, mergeType);


// Regenerate etag in case it has changed
// TODO create valid etag
etag = eTagUtils.generateETagForDocument(hProjectIteration, id, new HashSet<String>(0));

log.debug("successful put translation");
// TODO lastChanged
if (unknownResIds.isEmpty())
{
return Response.ok().tag(etag).build();
}
else
StringBuilder sb = new StringBuilder();
for (String warning : warnings)
{
String resIdStr = StringUtil.concat(unknownResIds, ',',
new Function<TextFlowTarget, String>()
{
@Override
public String apply(@Nullable TextFlowTarget from)
{
return from.getResId();
}
}
);
return Response.ok("warning: unknown resIds: " + unknownResIds).tag(etag).build();
sb.append("warning: ").append(warning).append('\n');
}
return Response.ok(sb.toString()).tag(etag).build();
}

private HProjectIteration retrieveAndCheckIteration(boolean writeOperation)
Expand Down

0 comments on commit 5bbea9f

Please sign in to comment.