Search in sources :

Example 6 with UserPreferences

use of org.motechproject.mds.domain.UserPreferences 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 7 with UserPreferences

use of org.motechproject.mds.domain.UserPreferences in project motech by motech.

the class UserPreferencesServiceImpl method unselectFields.

@Override
@Transactional
public void unselectFields(Long id, String username) {
    Entity entity = getEntity(id);
    UserPreferences userPreferences = allUserPreferences.retrieveByClassNameAndUsername(entity.getClassName(), username);
    userPreferences = checkPreferences(userPreferences, entity, username);
    Set<Field> fields = new HashSet<>();
    fields.addAll(entity.getFields());
    userPreferences.setUnselectedFields(fields);
    userPreferences.setSelectedFields(new HashSet<Field>());
    allUserPreferences.update(userPreferences);
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with UserPreferences

use of org.motechproject.mds.domain.UserPreferences in project motech by motech.

the class UserPreferencesServiceImpl method selectFields.

@Override
@Transactional
public void selectFields(Long id, String username) {
    Entity entity = getEntity(id);
    UserPreferences userPreferences = allUserPreferences.retrieveByClassNameAndUsername(entity.getClassName(), username);
    userPreferences = checkPreferences(userPreferences, entity, username);
    Set<Field> fields = new HashSet<>();
    fields.addAll(entity.getFields());
    userPreferences.setSelectedFields(fields);
    userPreferences.setUnselectedFields(new HashSet<Field>());
    allUserPreferences.update(userPreferences);
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with UserPreferences

use of org.motechproject.mds.domain.UserPreferences 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)

Example 10 with UserPreferences

use of org.motechproject.mds.domain.UserPreferences in project motech by motech.

the class UserPreferencesServiceImpl method selectField.

@Override
@Transactional
public void selectField(Long id, String username, String fieldName) {
    Entity entity = getEntity(id);
    UserPreferences userPreferences = allUserPreferences.retrieveByClassNameAndUsername(entity.getClassName(), username);
    userPreferences = checkPreferences(userPreferences, entity, username);
    Field field = entity.getField(fieldName);
    assertField(field, entity.getClassName(), fieldName);
    userPreferences.selectField(field);
    allUserPreferences.update(userPreferences);
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserPreferences (org.motechproject.mds.domain.UserPreferences)11 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)11 Entity (org.motechproject.mds.domain.Entity)8 Transactional (org.springframework.transaction.annotation.Transactional)7 Field (org.motechproject.mds.domain.Field)5 UserPreferencesDto (org.motechproject.mds.dto.UserPreferencesDto)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1