private void mergeTextFlowTarget(HTextFlowTarget sourceTft, HTextFlowTarget targetTft) { targetTft.setContents(sourceTft.getContents()); targetTft.setState(sourceTft.getState()); targetTft.setLastChanged(sourceTft.getLastChanged()); targetTft.setLastModifiedBy(sourceTft.getLastModifiedBy()); targetTft.setTranslator(sourceTft.getTranslator()); if (sourceTft.getComment() == null) { targetTft.setComment(null); } else { HSimpleComment hComment = targetTft.getComment(); if (hComment == null) { hComment = new HSimpleComment(); targetTft.setComment(hComment); } hComment.setComment(sourceTft.getComment().getComment()); } targetTft.setRevisionComment(TranslationUtil.getMergeTranslationMessage(sourceTft)); targetTft.setSourceType(TranslationSourceType.MERGE_VERSION); TranslationUtil.copyEntity(sourceTft, targetTft); }
private void saveCopyTransMatch( Long actorId, final HTextFlowTarget matchingTarget, final HTextFlow originalTf, final HCopyTransOptions options, final boolean requireTranslationReview) { final HProjectIteration matchingTargetProjectIteration = matchingTarget.getTextFlow().getDocument().getProjectIteration(); // lazy evaluation of some conditions Supplier<Boolean> contextMatches = new Supplier<Boolean>() { @Override public Boolean get() { return originalTf.getResId().equals(matchingTarget.getTextFlow().getResId()); } }; Supplier<Boolean> projectMatches = new Supplier<Boolean>() { public Boolean get() { return originalTf .getDocument() .getProjectIteration() .getProject() .getId() .equals(matchingTargetProjectIteration.getProject().getId()); } }; Supplier<Boolean> docIdMatches = new Supplier<Boolean>() { @Override public Boolean get() { return originalTf .getDocument() .getDocId() .equals(matchingTarget.getTextFlow().getDocument().getDocId()); } }; final ContentState copyState = determineContentState( contextMatches, projectMatches, docIdMatches, options, requireTranslationReview, matchingTarget.getState()); boolean hasValidationError = validationTranslations( copyState, matchingTargetProjectIteration, originalTf.getContents(), matchingTarget.getContents()); if (hasValidationError) { return; } HTextFlowTarget hTarget = textFlowTargetDAO.getOrCreateTarget(originalTf, matchingTarget.getLocale()); ContentState prevState = hTarget.getId() == null ? ContentState.New : hTarget.getState(); if (shouldOverwrite(hTarget, copyState)) { // NB we don't touch creationDate hTarget.setTextFlowRevision(originalTf.getRevision()); hTarget.setLastChanged(matchingTarget.getLastChanged()); hTarget.setLastModifiedBy(matchingTarget.getLastModifiedBy()); hTarget.setTranslator(matchingTarget.getTranslator()); // TODO rhbz953734 - will need a new copyTran option for // review state if (copyState == ContentState.Approved) { hTarget.setReviewer(matchingTarget.getReviewer()); } hTarget.setContents(matchingTarget.getContents()); hTarget.setState(copyState); if (matchingTarget.getComment() == null) { hTarget.setComment(null); } else { HSimpleComment hComment = hTarget.getComment(); if (hComment == null) { hComment = new HSimpleComment(); hTarget.setComment(hComment); } hComment.setComment(matchingTarget.getComment().getComment()); } hTarget.setRevisionComment(TranslationUtil.getCopyTransMessage(matchingTarget)); hTarget.setSourceType(TranslationSourceType.COPY_TRANS); TranslationUtil.copyEntity(matchingTarget, hTarget); // TODO Maybe we should think about registering a Hibernate // integrator for these updates signalCopiedTranslation(hTarget, prevState, originalTf.getWordCount()); } }