Search in sources :

Example 1 with UserPreferences

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

the class UserPreferencesServiceTest method shouldMergeFieldsInformation.

@Test
public void shouldMergeFieldsInformation() {
    Set<Field> selectedFields = new HashSet<>();
    selectedFields.add(getField3());
    Set<Field> unselectedFields = new HashSet<>();
    unselectedFields.add(getField2());
    UserPreferences preferences = new UserPreferences(USERNAME, CLASS_NAME, 20, selectedFields, unselectedFields);
    when(allUserPreferences.retrieveByClassNameAndUsername(CLASS_NAME, USERNAME)).thenReturn(preferences);
    UserPreferencesDto userPreferencesDto = userPreferencesService.getUserPreferences(15l, USERNAME);
    assertNotNull(userPreferencesDto);
    assertEquals(1, userPreferencesDto.getSelectedFields().size());
    assertEquals(1, userPreferencesDto.getUnselectedFields().size());
    assertEquals(2, userPreferencesDto.getVisibleFields().size());
    assertTrue(userPreferencesDto.getSelectedFields().contains("sampleField3"));
    assertTrue(userPreferencesDto.getUnselectedFields().contains("sampleField2"));
    assertTrue(userPreferencesDto.getVisibleFields().contains("sampleField1"));
    assertTrue(userPreferencesDto.getVisibleFields().contains("sampleField3"));
}
Also used : AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) UserPreferences(org.motechproject.mds.domain.UserPreferences) Field(org.motechproject.mds.domain.Field) UserPreferencesDto(org.motechproject.mds.dto.UserPreferencesDto) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with UserPreferences

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

the class UserPreferencesServiceTest method shouldCreateDefaultPreferences.

@Test
public void shouldCreateDefaultPreferences() {
    when(allUserPreferences.retrieveByClassNameAndUsername(CLASS_NAME, USERNAME)).thenReturn(null);
    userPreferencesService.getUserPreferences(15l, USERNAME);
    verify(allUserPreferences).create(userPreferencesCaptor.capture());
    UserPreferences capturedPreferences = userPreferencesCaptor.getValue();
    assertEquals(USERNAME, capturedPreferences.getUsername());
    assertEquals(CLASS_NAME, capturedPreferences.getClassName());
    assertNotNull(capturedPreferences.getSelectedFields().size());
    assertEquals(0, capturedPreferences.getSelectedFields().size());
    assertEquals(0, capturedPreferences.getUnselectedFields().size());
}
Also used : AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) UserPreferences(org.motechproject.mds.domain.UserPreferences) Test(org.junit.Test)

Example 3 with UserPreferences

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

the class EntityServiceImpl method updateUserPreferences.

private void updateUserPreferences(Entity parent, EntityDraft draft, List<UserPreferencesDto> userPreferencesDtos) {
    for (UserPreferencesDto preferencesDto : userPreferencesDtos) {
        UserPreferences preferences = allUserPreferences.retrieveByClassNameAndUsername(preferencesDto.getClassName(), preferencesDto.getUsername());
        preferences.setSelectedFields(getFieldsForPreferences(parent, draft, preferencesDto.getSelectedFields()));
        preferences.setUnselectedFields(getFieldsForPreferences(parent, draft, preferencesDto.getUnselectedFields()));
        allUserPreferences.update(preferences);
    }
}
Also used : AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) UserPreferences(org.motechproject.mds.domain.UserPreferences) UserPreferencesDto(org.motechproject.mds.dto.UserPreferencesDto)

Example 4 with UserPreferences

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

the class UserPreferencesServiceImpl method unselectField.

@Override
@Transactional
public void unselectField(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.unselectField(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)

Example 5 with UserPreferences

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

the class UserPreferencesServiceImpl method updateGridSize.

@Override
@Transactional
public void updateGridSize(Long id, String username, Integer newSize) {
    Entity entity = getEntity(id);
    UserPreferences userPreferences = allUserPreferences.retrieveByClassNameAndUsername(entity.getClassName(), username);
    userPreferences = checkPreferences(userPreferences, entity, username);
    if (userPreferences.getGridRowsNumber() != newSize) {
        userPreferences.setGridRowsNumber(newSize == null ? settingsService.getGridSize() : newSize);
        allUserPreferences.update(userPreferences);
    }
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) 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