Search in sources :

Example 1 with EntityChangedException

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;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityChangedException(org.motechproject.mds.exception.entity.EntityChangedException) ArrayList(java.util.ArrayList) UserPreferencesDto(org.motechproject.mds.dto.UserPreferencesDto) EntityDraft(org.motechproject.mds.domain.EntityDraft) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ArrayList (java.util.ArrayList)1 Entity (org.motechproject.mds.domain.Entity)1 EntityDraft (org.motechproject.mds.domain.EntityDraft)1 MdsEntity (org.motechproject.mds.domain.MdsEntity)1 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)1 UserPreferencesDto (org.motechproject.mds.dto.UserPreferencesDto)1 EntityChangedException (org.motechproject.mds.exception.entity.EntityChangedException)1 Transactional (org.springframework.transaction.annotation.Transactional)1