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

Commit

Permalink
Merge pull request #149 from zanata/rhbz1000237
Browse files Browse the repository at this point in the history
rhbz1000237 - Make sure unwanted copy trans results are discarded.
  • Loading branch information
seanf committed Aug 30, 2013
2 parents 6640b7c + dace028 commit 52a8f9b
Showing 1 changed file with 41 additions and 5 deletions.
Expand Up @@ -26,6 +26,7 @@

import java.util.List;

import javax.annotation.Nullable;
import javax.persistence.EntityManager;

import org.hibernate.HibernateException;
Expand Down Expand Up @@ -289,22 +290,53 @@ private int copyTransPass( HDocument document, HLocale locale, boolean checkCont
return copyCount;
}

private ContentState determineContentState(boolean contextMatches, boolean projectMatches, boolean docIdMatches,
HCopyTransOptions options, boolean requireTranslationReview, ContentState matchingTargetState)
/**
* Determines the content state a copied translation should have.
*
* @param contextMatches Whether the copied TextFlow's context matches the target TextFlow's context or not.
* @param projectMatches Whether the copied TextFlow's project matches the target TextFlow's context or not.
* @param docIdMatches Whether the copied TextFlow's docId matches the target TextFlow's context or not.
* @param options The copy trans options being used.
* @param requireTranslationReview Whether the project being copied to requires review or not.
* @param matchingTargetState The state of the match found by copy trans.
* @return The content state that the copied translation should have. May return null if the translation should not
* be copied at all.
*/
private @Nullable
ContentState determineContentState(boolean contextMatches, boolean projectMatches, boolean docIdMatches,
HCopyTransOptions options, boolean requireTranslationReview, ContentState matchingTargetState)
{
// Everything matches, and requires approval
if (requireTranslationReview && matchingTargetState.isApproved() && projectMatches && contextMatches && docIdMatches)
{
return Approved;
}
// Everything matches, and does not require approval
else if( matchingTargetState.isApproved() && projectMatches && contextMatches && docIdMatches )
{
return Translated;
}
// Everything else
ContentState state = Translated;
state = getExpectedContentState(contextMatches, options.getContextMismatchAction(), state);
state = getExpectedContentState(projectMatches, options.getProjectMismatchAction(), state);
state = getExpectedContentState(docIdMatches, options.getDocIdMismatchAction(), state);
return state;
}

public ContentState getExpectedContentState( boolean match, HCopyTransOptions.ConditionRuleAction action,
ContentState currentState )
/**
* Gets the content state that is expected for a translation when evaluated against a single copy trans
* condition.
* Copy Trans conditions are of the form: Is it the same project? Is it the same documentId? ... etc.
*
* @param match Whether the condition holds or not (is there a match?)
* @param action The action to take when the condition matches.
* @param currentState The current state of the translation.
* @return The content state that is expected the copied translation to have.
*/
public @Nullable
ContentState getExpectedContentState( boolean match, HCopyTransOptions.ConditionRuleAction action,
ContentState currentState )
{
if( currentState == null )
{
Expand Down Expand Up @@ -429,7 +461,11 @@ private void copyTransForLocale(HDocument document, HLocale locale, HCopyTransOp
*/
private static boolean shouldOverwrite(HTextFlowTarget currentlyStored, ContentState matchState)
{
if( currentlyStored != null )
if( matchState == null )
{
return false;
}
else if( currentlyStored != null )
{
if( currentlyStored.getState().isRejectedOrFuzzy() && matchState.isTranslated())
{
Expand Down

0 comments on commit 52a8f9b

Please sign in to comment.