use of org.eclipse.emfcloud.modelserver.emf.common.ModelServerEditingDomain in project emfcloud-modelserver by eclipse-emfcloud.
the class JsonPatchHelper method getJsonPatch.
public JsonNode getJsonPatch(final EObject root, final CCommandExecutionResult result) throws EncodingException {
// TODO Support multiple resource patches.
// See issue https://github.com/eclipse-emfcloud/emfcloud-modelserver/issues/159
JsonNode newModel = getCurrentModel(root);
ChangeDescription cd = (ChangeDescription) result.getChangeDescription();
ModelServerEditingDomain editingDomain = modelManager.getEditingDomain(root.eResource().getResourceSet());
JsonNode oldModel = null;
try {
// Compute the old model by reverting the current change. We need to do that in a write-transaction.
// Note: we could also apply it on a read-only copy of the model, but this could potentially modify
// the IDs (which are part of the Resource; not of the EObjects), causing unexpected patch changes.
InternalTransaction transaction = editingDomain.startTransaction(false, null);
try {
cd.applyAndReverse();
oldModel = getCurrentModel(root);
cd.applyAndReverse();
transaction.commit();
} catch (RollbackException e) {
LOG.error("Failed to generate JsonPatch", e);
return null;
} finally {
if (transaction != null && transaction.isActive()) {
rollback(transaction, editingDomain);
}
}
} catch (InterruptedException e) {
LOG.error("Failed to generate JsonPatch", e);
return null;
}
return diffModel(oldModel, newModel);
}
Aggregations