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

Commit

Permalink
copy previous targets as fuzzy when modified text flow source content…
Browse files Browse the repository at this point in the history
… is pushed
  • Loading branch information
davidmason committed Sep 7, 2011
1 parent 09c620a commit fd19c43
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
Expand Up @@ -26,6 +26,7 @@
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
import org.zanata.common.ContentState;
import org.zanata.common.ResourceType;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
Expand Down Expand Up @@ -96,9 +97,18 @@ boolean transferFromTextFlows(List<TextFlow> from, HDocument to, Set<String> ena
textFlow.setObsolete(false);
// avoid changing revision when resurrecting an unchanged TF
if (transferFromTextFlow(tf, textFlow, enabledExtensions))
{
{// content has changed
textFlow.setRevision(nextDocRev);
changed = true;
for (HTextFlowTarget targ : textFlow.getTargets().values())
{
// if (targ.getState() != ContentState.New)
if (targ.getState() == ContentState.Approved)
{
targ.setState(ContentState.NeedReview);
targ.setVersionNum(targ.getVersionNum() + 1);
}
}
log.debug("TextFlow with id {0} has changed", tf.getId());
}
}
Expand Down
Expand Up @@ -9,15 +9,20 @@
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.zanata.common.ContentState;
import org.zanata.common.LocaleId;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
import org.zanata.model.HPerson;
import org.zanata.model.HSimpleComment;
import org.zanata.model.HTextFlow;
import org.zanata.model.HTextFlowTarget;
import org.zanata.model.po.HPoTargetHeader;
import org.zanata.rest.dto.extensions.gettext.PoTargetHeader;
Expand All @@ -30,12 +35,18 @@ public class ResourceUtilsTest

private static ResourceUtils resourceUtils = new ResourceUtils();

@Test
public void mergeNoTextFlows()
@BeforeClass
public static void logMemoryForTests()
{
// FIXME why is this here?
Runtime runtime = Runtime.getRuntime();
log.info("total memory :" + runtime.totalMemory());
log.info("unit tests free memory :" + runtime.freeMemory());
}

@Test
public void mergeNoTextFlows()
{
List<TextFlow> from = new ArrayList<TextFlow>();
HDocument to = new HDocument();
boolean changed = resourceUtils.transferFromTextFlows(from, to, new HashSet<String>(), 1);
Expand All @@ -52,11 +63,82 @@ public void mergeTextFlowWithOneFromChange()
from.add(tf1);

HDocument to = new HDocument();

boolean changed = resourceUtils.transferFromTextFlows(from, to, new HashSet<String>(), 1);

assertThat(changed, is(true));
}

@Test
public void mergeChangedTextFlow()
{
// set up HDocument with a text flow
HDocument to = new HDocument();
int originalTFRevision = 1;
to.setRevision(originalTFRevision);
HTextFlow originalTF = new HTextFlow(to, "id", "original text");
originalTF.setRevision(originalTFRevision);

// target locales that will have new, fuzzy and approved targets
HLocale newLoc, fuzzyLoc, apprLoc;
newLoc = new HLocale(LocaleId.DE);
fuzzyLoc = new HLocale(LocaleId.FR);
apprLoc = new HLocale(LocaleId.ES);

HTextFlowTarget newTarg, fuzzyTarg, apprTarg;
newTarg = new HTextFlowTarget(originalTF, newLoc);
fuzzyTarg = new HTextFlowTarget(originalTF, fuzzyLoc);
apprTarg = new HTextFlowTarget(originalTF, apprLoc);

int newTargVersionBefore = 1;
int fuzzyTargVersionBefore = 1;
int apprTargVersionBefore = 1;

newTarg.setVersionNum(newTargVersionBefore);
fuzzyTarg.setVersionNum(fuzzyTargVersionBefore);
apprTarg.setVersionNum(apprTargVersionBefore);

newTarg.setState(ContentState.New);
fuzzyTarg.setState(ContentState.NeedReview);
apprTarg.setState(ContentState.Approved);

originalTF.getTargets().put(newLoc, newTarg);
originalTF.getTargets().put(fuzzyLoc, fuzzyTarg);
originalTF.getTargets().put(apprLoc, apprTarg);

to.getAllTextFlows().put("id", originalTF);

// set up a textflow with the same id and different content
TextFlow changedTF = new TextFlow(originalTF.getResId(), LocaleId.EN, "changed text");
List<TextFlow> from = new ArrayList<TextFlow>();
from.add(changedTF);

int newTFRevision = 2;

boolean changed = resourceUtils.transferFromTextFlows(from, to, new HashSet<String>(), newTFRevision);


Map<HLocale, HTextFlowTarget> targets = to.getAllTextFlows().get("id").getTargets();
newTarg = targets.get(newLoc);
assertThat(newTarg.getState(), is(ContentState.New));
assertThat(newTarg.getVersionNum(), is(newTargVersionBefore));
assertThat(newTarg.getTextFlowRevision(), is(originalTFRevision));

fuzzyTarg = targets.get(fuzzyLoc);
assertThat(fuzzyTarg.getState(), is(ContentState.NeedReview));
assertThat(fuzzyTarg.getVersionNum(), is(fuzzyTargVersionBefore));
assertThat(fuzzyTarg.getTextFlowRevision(), is(originalTFRevision));

apprTarg = targets.get(apprLoc);
assertThat("approved targets should be set to fuzzy when source content changes", apprTarg.getState(), is(ContentState.NeedReview));
assertThat(apprTarg.getVersionNum(), is(apprTargVersionBefore + 1));
// Note: TFTRevision should be updated when target content or state is
// changed in editor, not here.
assertThat(apprTarg.getTextFlowRevision(), is(originalTFRevision));

assertThat(changed, is(true));
}

@Test
public void pushCommentInitialImport()
{
Expand Down

0 comments on commit fd19c43

Please sign in to comment.