return results;
}
// single locale check - assumes update requests are all from the same
// project-iteration
HTextFlow sampleHTextFlow =
entityManager.find(HTextFlow.class, translationRequests.get(0)
.getTransUnitId().getValue());
HProjectIteration projectIteration =
sampleHTextFlow.getDocument().getProjectIteration();
HLocale hLocale = validateLocale(localeId, projectIteration);
// single permission check - assumes update requests are all from same
// project
validateReviewPermissionIfApplicable(translationRequests,
projectIteration, hLocale);
for (TransUnitUpdateRequest request : translationRequests) {
HTextFlow hTextFlow =
entityManager.find(HTextFlow.class, request
.getTransUnitId().getValue());
TranslationResultImpl result = new TranslationResultImpl();
if (runValidation) {
String validationMessage =
validateTranslations(request.getNewContentState(),
projectIteration, request.getTransUnitId()
.toString(), hTextFlow.getContents(),
request.getNewContents());
if (!StringUtils.isEmpty(validationMessage)) {
log.warn(validationMessage);
result.isSuccess = false;
result.errorMessage = validationMessage;
continue;
}
}
HTextFlowTarget hTextFlowTarget =
textFlowTargetDAO.getOrCreateTarget(hTextFlow, hLocale);
// if hTextFlowTarget is created, any further hibernate fetch will
// trigger an implicit flush
// (which will save this target even if it's not fully ready!!!)
if (request.hasTargetComment()) {
// FIXME this creates orphan comments, and replaces identical
// comments with copies
hTextFlowTarget.setComment(new HSimpleComment(request
.getTargetComment()));
}
result.baseVersion = hTextFlowTarget.getVersionNum();
result.baseContentState = hTextFlowTarget.getState();
if (request.getBaseTranslationVersion() == hTextFlowTarget
.getVersionNum()) {
try {
int nPlurals = getNumPlurals(hLocale, hTextFlow);
result.targetChanged =
translate(hTextFlowTarget,
request.getNewContents(),
request.getNewContentState(), nPlurals,
projectIteration
.getRequireTranslationReview());
result.isSuccess = true;
} catch (HibernateException e) {
result.isSuccess = false;
log.warn("HibernateException while translating");
}
} else {
// concurrent edits not allowed
String errorMessage =
"translation failed for textflow " + hTextFlow.getId()
+ ": base versionNum + "
+ request.getBaseTranslationVersion()
+ " does not match current versionNum "
+ hTextFlowTarget.getVersionNum();