entitiesUpdateAction.setEntity(entity);
entitiesUpdateAction.setUpdateEntity(updateEntity);
try {
if (entity == updateEntity) {
String error = "The before update entity and the after update entity cannot be the same object.";
throw new ActionException(error, entitiesUpdateAction);
}
T retrievedEntity = this.retrieveByOid(entity.getOid());
if (retrievedEntity == null) {
String error = "No before update entity.";
throw new ActionException(error, entitiesUpdateAction);
} else {
if (retrievedEntity != entity) {
String error = "Wrong before update entity.";
throw new ActionException(error, entitiesUpdateAction);
}
}
if (!preUpdate(entity, updateEntity)) {
return false;
}
boolean updated = false;
T backupBeforeEntity = (T) entity.copy();
updated = entity.update(updateEntity);
if (updated) {
if (postUpdate(backupBeforeEntity, entity)) {
IDomainModel domainModel = getDomainModel();
if (domainModel != null && !domainModel.isSession()
&& domainModel.isInitialized()) {
ModelMeta modelMeta = domainModel.getModelMeta();
modelMeta.setParents(updateEntity, this);
domainModel.notifyObservers(entitiesUpdateAction);
}
return true;
} else {
if (entity.update(backupBeforeEntity)) {
return false;
} else {
String error = "Cannot undo an update that has a not valid postcondition.";
throw new ActionException(error, entitiesUpdateAction);
}
}
}
} catch (Exception e) {
log.error("Error in Entities.update: " + e.getMessage());
throw new ActionException(e.getMessage(), entitiesUpdateAction);
}
return false;
}