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"));
}
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());
}
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);
}
}
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);
}
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);
}
}
Aggregations