Response.status(Status.BAD_REQUEST)
.entity("encountered TextFlow with duplicate ID "
+ tf.getId()).build();
throw new WebApplicationException(response);
}
HTextFlow textFlow;
if (previousIds.contains(tf.getId())) {
previousIds.remove(tf.getId());
textFlow = to.getAllTextFlows().get(tf.getId());
textFlow.setObsolete(false);
to.getTextFlows().add(textFlow);
// 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().isTranslated()) {
targ.setState(ContentState.NeedReview);
targ.setVersionNum(targ.getVersionNum() + 1);
}
}
log.debug("TextFlow with id {} has changed", tf.getId());
}
} else {
textFlow = new HTextFlow();
textFlow.setDocument(to);
textFlow.setResId(tf.getId());
textFlow.setRevision(nextDocRev);
transferFromTextFlow(tf, textFlow, enabledExtensions);
changed = true;
to.getAllTextFlows().put(textFlow.getResId(), textFlow);
to.getTextFlows().add(textFlow);
entityManager.persist(textFlow);
log.debug("TextFlow with id {} is new", tf.getId());
}
count++;
if (count % 100 == 0) {
entityManager.flush();
}
// FIXME we can't clear entityManager here. See
// org.zanata.feature.rest.CopyTransTest.testPushTranslationAndCopyTrans.
// If you clear, last copyTran REST call will trigger exception on
// the server (hDocument.getTextFlows() will contain null entries -
// corrupted collection.
// see https://github.com/zanata/zanata-server/pull/571#issuecomment-55547577)
/*
if (count % 500 == 0) {
// this in some cases seem to slow down overall performance
entityManager.clear();
to = entityManager.find(HDocument.class, to.getId());
}
*/
}
// set remaining textflows to obsolete.
for (String id : previousIds) {
HTextFlow textFlow = to.getAllTextFlows().get(id);
if (!textFlow.isObsolete()) {
changed = true;
log.debug("TextFlow with id {} is now obsolete", id);
textFlow.setRevision(to.getRevision());
textFlow.setObsolete(true);
}
}
if (changed)
to.setRevision(nextDocRev);
return changed;