use of org.alien4cloud.tosca.editor.exception.EditionConcurrencyException in project alien4cloud by alien4cloud.
the class EditorService method checkSynchronization.
/**
* Ensure that the request is synchronized with the current state of the edition.
*
* @param operation, The operation under evaluation.
*/
private synchronized void checkSynchronization(AbstractEditorOperation operation) {
// there is an operation being processed so just fail (nobody could get the notification)
if (EditionContextManager.get().getCurrentOperation() != null) {
throw new EditionConcurrencyException();
}
List<AbstractEditorOperation> operations = EditionContextManager.get().getOperations();
// if someone performed some operations we have to ensure that the new operation is performed on top of a synchronized topology
if (EditionContextManager.get().getLastOperationIndex() == -1) {
if (operation.getPreviousOperationId() != null) {
throw new EditionConcurrencyException();
}
} else if (!operations.get(EditionContextManager.get().getLastOperationIndex()).getId().equals(operation.getPreviousOperationId())) {
throw new EditionConcurrencyException();
}
operation.setId(UUID.randomUUID().toString());
EditionContextManager.get().setCurrentOperation(operation);
}
Aggregations