use of org.motechproject.mds.exception.entity.EntityChangedException in project motech by motech.
the class EntityServiceImpl method commitChanges.
@Override
@Transactional
public List<String> commitChanges(Long entityId, String changesOwner) {
List<String> modulesToRefresh = new ArrayList<>();
EntityDraft draft = getEntityDraft(entityId, changesOwner);
if (draft.isOutdated()) {
throw new EntityChangedException();
}
entityValidator.validateEntity(draft);
Entity parent = draft.getParentEntity();
String username = draft.getDraftOwnerUsername();
mdsConstructor.removeFields(parent, draft.getFieldsToRemove());
mdsConstructor.updateFields(parent, draft.getFieldNameChanges());
mdsConstructor.removeUniqueIndexes(parent, draft.getUniqueIndexesToDrop());
mdsConstructor.updateRequired(parent, draft.getFieldNameRequired());
comboboxDataMigrationHelper.migrateComboboxDataIfNecessary(parent, draft);
List<UserPreferencesDto> oldEntityPreferences = userPreferencesService.getEntityPreferences(parent.getId());
configureRelatedFields(parent, draft, modulesToRefresh);
parent.updateFromDraft(draft);
updateUserPreferences(parent, draft, oldEntityPreferences);
if (username != null) {
allEntityAudits.createAudit(parent, username);
}
allEntityDrafts.delete(draft);
addModuleToRefresh(parent, modulesToRefresh);
return modulesToRefresh;
}
Aggregations