Search in sources :

Example 6 with UserPreferencesDto

use of org.motechproject.mds.dto.UserPreferencesDto 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)

Example 7 with UserPreferencesDto

use of org.motechproject.mds.dto.UserPreferencesDto in project motech by motech.

the class UserPreferencesServiceImpl method getEntityPreferences.

@Override
public List<UserPreferencesDto> getEntityPreferences(Long id) {
    Entity entity = getEntity(id);
    List<UserPreferences> userPreferences = allUserPreferences.retrieveByClassName(entity.getClassName());
    List<UserPreferencesDto> dtos = new ArrayList<>();
    Set<String> displayableFields = getDisplayableFields(entity);
    if (userPreferences != null) {
        Integer defaultGridSize = settingsService.getGridSize();
        for (UserPreferences preferences : userPreferences) {
            UserPreferencesDto dto = preferences.toDto(displayableFields);
            if (dto.getGridRowsNumber() == null) {
                dto.setGridRowsNumber(defaultGridSize);
            }
            dtos.add(dto);
        }
    }
    return dtos;
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) ArrayList(java.util.ArrayList) UserPreferencesDto(org.motechproject.mds.dto.UserPreferencesDto)

Example 8 with UserPreferencesDto

use of org.motechproject.mds.dto.UserPreferencesDto in project motech by motech.

the class UserPreferencesServiceImpl method getUserPreferences.

@Override
@Transactional
public UserPreferencesDto getUserPreferences(Long id, String username) {
    Entity entity = getEntity(id);
    UserPreferences userPreferences = allUserPreferences.retrieveByClassNameAndUsername(entity.getClassName(), username);
    userPreferences = checkPreferences(userPreferences, entity, username);
    if (userPreferences != null) {
        UserPreferencesDto dto = userPreferences.toDto(getDisplayableFields(entity));
        if (dto.getGridRowsNumber() == null) {
            dto.setGridRowsNumber(settingsService.getGridSize());
        }
        return dto;
    }
    return null;
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) UserPreferencesDto(org.motechproject.mds.dto.UserPreferencesDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserPreferencesDto (org.motechproject.mds.dto.UserPreferencesDto)8 UserPreferences (org.motechproject.mds.domain.UserPreferences)4 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)4 Test (org.junit.Test)3 Entity (org.motechproject.mds.domain.Entity)3 ArrayList (java.util.ArrayList)2 EntityDraft (org.motechproject.mds.domain.EntityDraft)2 Field (org.motechproject.mds.domain.Field)2 EntityDto (org.motechproject.mds.dto.EntityDto)2 FieldDto (org.motechproject.mds.dto.FieldDto)2 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 MdsEntity (org.motechproject.mds.domain.MdsEntity)1 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)1 DraftData (org.motechproject.mds.dto.DraftData)1 EntityChangedException (org.motechproject.mds.exception.entity.EntityChangedException)1 Authentication (org.springframework.security.core.Authentication)1