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

Commit

Permalink
Merge branch 'release' into integration/master
Browse files Browse the repository at this point in the history
Conflicts:
	zanata-war/src/test/java/org/zanata/service/impl/CopyTransServiceImplTest.java
  • Loading branch information
Carlos A. Munoz committed Aug 29, 2013
2 parents 055a8c0 + 6640b7c commit 686584c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
13 changes: 9 additions & 4 deletions zanata-war/src/main/java/org/zanata/dao/TextFlowTargetDAO.java
Expand Up @@ -15,6 +15,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.zanata.common.ContentState;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
Expand Down Expand Up @@ -184,9 +185,8 @@ public List<HTextFlowTarget> findTranslations(HDocument document, HLocale locale
public ScrollableResults findMatchingTranslations(HDocument document, HLocale locale, boolean checkContext, boolean checkDocument, boolean checkProject, boolean requireTranslationReview)
{
StringBuilder queryStr = new StringBuilder(
"select textFlow, max(match.id) " +
"select textFlow, max(match.id) " +
"from HTextFlowTarget match, HTextFlow textFlow " +
// "join fetch match.textFlow " +
"where " +
"textFlow.document = :document " +
"and textFlow.contentHash = match.textFlow.contentHash " +
Expand All @@ -197,7 +197,11 @@ public ScrollableResults findMatchingTranslations(HDocument document, HLocale lo
"and (match.locale not in indices(textFlow.targets) " +
"or :finalState != (select t.state from HTextFlowTarget t where t.textFlow = textFlow and t.locale = :locale) ) " +
// Do not reuse its own translations
"and match.textFlow != textFlow "
"and match.textFlow != textFlow " +
// Do not reuse matches from obsolete entities (document, iteration, project)
"and match.textFlow.document.obsolete = false " +
"and match.textFlow.document.projectIteration.status != :obsoleteEntityStatus " +
"and match.textFlow.document.projectIteration.project.status != :obsoleteEntityStatus "
);
if( checkContext )
{
Expand All @@ -218,7 +222,8 @@ public ScrollableResults findMatchingTranslations(HDocument document, HLocale lo
q.setParameter("document", document)
.setParameter("locale", locale)
.setParameter("approvedState", ContentState.Approved)
.setParameter("translatedState", ContentState.Translated);
.setParameter("translatedState", ContentState.Translated)
.setParameter("obsoleteEntityStatus", EntityStatus.OBSOLETE);
if (requireTranslationReview)
{
q.setParameter("finalState", ContentState.Approved);
Expand Down
Expand Up @@ -34,12 +34,16 @@
import org.zanata.async.tasks.CopyTransTask;
import org.zanata.common.ContentState;
import org.zanata.common.ContentType;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.dao.AccountDAO;
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.LocaleDAO;
import org.zanata.dao.ProjectDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.model.HCopyTransOptions;
import org.zanata.model.HDocument;
import org.zanata.model.HProject;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HTextFlow;
import org.zanata.model.HTextFlowTarget;
Expand All @@ -54,8 +58,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.zanata.async.tasks.CopyTransTask.CopyTransTaskHandle;
import static org.zanata.common.ContentState.*;
import static org.zanata.common.ContentState.Approved;
import static org.zanata.common.ContentState.NeedReview;
import static org.zanata.common.ContentState.Translated;
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction;
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction.DOWNGRADE_TO_FUZZY;
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction.IGNORE;
Expand Down Expand Up @@ -247,6 +252,58 @@ else if( !Arrays.equals( execution.getExpectedContents(), target.getContents().t
}
}

@Test
public void ignoreTranslationsFromObsoleteProjectAndVersion() throws Exception
{
ProjectIterationDAO projectIterationDAO = seam.autowire(ProjectIterationDAO.class);
ProjectDAO projectDAO = seam.autowire(ProjectDAO.class);

// Make versions and projects obsolete
HProjectIteration version = projectIterationDAO.getBySlug("same-project", "same-version");
version.setStatus(EntityStatus.OBSOLETE);
projectIterationDAO.makePersistent(version);

HProject project = projectDAO.getBySlug("different-project");
project.setStatus(EntityStatus.OBSOLETE);
projectDAO.makePersistent(project);

// Run the copy trans scenario (very liberal, but nothing should be translated)
CopyTransExecution execution = new CopyTransExecution(IGNORE, IGNORE, IGNORE, true, true, true, true)
.expectUntranslated();
testCopyTrans(execution);
}

@Test
public void ignoreTranslationsFromObsoleteDocuments() throws Exception
{
ProjectIterationDAO projectIterationDAO = seam.autowire(ProjectIterationDAO.class);
DocumentDAO documentDAO = seam.autowire(DocumentDAO.class);

// Make all documents obsolete
HProjectIteration version = projectIterationDAO.getBySlug("same-project", "same-version");
for( HDocument doc : version.getDocuments().values() )
{
doc.setObsolete(true);
documentDAO.makePersistent(doc);
}

ProjectDAO projectDAO = seam.autowire(ProjectDAO.class);
HProject project = projectDAO.getBySlug("different-project");
for( HProjectIteration it : project.getProjectIterations() )
{
for( HDocument doc : it.getDocuments().values() )
{
doc.setObsolete(true);
documentDAO.makePersistent(doc);
}
}

// Run the copy trans scenario (very liberal, but nothing should be translated)
CopyTransExecution execution = new CopyTransExecution(IGNORE, IGNORE, IGNORE, true, true, true, true)
.expectUntranslated();
testCopyTrans(execution);
}

private ContentState getExpectedContentState( CopyTransExecution execution )
{
ContentState expectedContentState = Translated;
Expand Down

0 comments on commit 686584c

Please sign in to comment.