use of org.motechproject.mds.dto.UserPreferencesDto 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.dto.UserPreferencesDto in project motech by motech.
the class EntityServiceImpl method addEntityUserPreferences.
private void addEntityUserPreferences(AdvancedSettingsDto advancedSettingsDto, Entity entity) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
UserPreferencesDto userPreferencesDto = userPreferencesService.getUserPreferences(entity.getId(), SecurityContextHolder.getContext().getAuthentication().getName());
advancedSettingsDto.setUserPreferences(userPreferencesDto);
}
}
use of org.motechproject.mds.dto.UserPreferencesDto 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.dto.UserPreferencesDto in project motech by motech.
the class MdsBundleIT method testUserPreferences.
@Test
public void testUserPreferences() {
EntityDto entityDto = createEntityForPreferencesTest();
// first retrieve - should create default user preferences for entity
UserPreferencesDto userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(new Integer(50), userPreferencesDto.getGridRowsNumber());
assertEquals(3, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("someBoolean"));
assertTrue(userPreferencesDto.getVisibleFields().contains("someString"));
assertTrue(userPreferencesDto.getVisibleFields().contains("someInteger"));
assertEquals(0, userPreferencesDto.getSelectedFields().size());
assertEquals(0, userPreferencesDto.getUnselectedFields().size());
userPreferencesService.updateGridSize(entityDto.getId(), USERNAME, 100);
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(new Integer(100), userPreferencesDto.getGridRowsNumber());
// if null then default value from settings will be used
userPreferencesService.updateGridSize(entityDto.getId(), USERNAME, null);
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(new Integer(50), userPreferencesDto.getGridRowsNumber());
userPreferencesService.unselectField(entityDto.getId(), USERNAME, "someString");
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(2, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("someBoolean"));
assertTrue(userPreferencesDto.getVisibleFields().contains("someInteger"));
assertEquals(0, userPreferencesDto.getSelectedFields().size());
assertEquals(1, userPreferencesDto.getUnselectedFields().size());
assertTrue(userPreferencesDto.getUnselectedFields().contains("someString"));
userPreferencesService.selectField(entityDto.getId(), USERNAME, "otherInteger");
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(3, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("someBoolean"));
assertTrue(userPreferencesDto.getVisibleFields().contains("someInteger"));
assertTrue(userPreferencesDto.getVisibleFields().contains("otherInteger"));
assertEquals(1, userPreferencesDto.getSelectedFields().size());
assertTrue(userPreferencesDto.getSelectedFields().contains("otherInteger"));
assertEquals(1, userPreferencesDto.getUnselectedFields().size());
assertTrue(userPreferencesDto.getUnselectedFields().contains("someString"));
userPreferencesService.selectField(entityDto.getId(), USERNAME, "someString");
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(4, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("someBoolean"));
assertTrue(userPreferencesDto.getVisibleFields().contains("otherInteger"));
assertTrue(userPreferencesDto.getVisibleFields().contains("otherInteger"));
assertTrue(userPreferencesDto.getVisibleFields().contains("someString"));
assertEquals(2, userPreferencesDto.getSelectedFields().size());
assertTrue(userPreferencesDto.getSelectedFields().contains("otherInteger"));
assertTrue(userPreferencesDto.getSelectedFields().contains("someString"));
assertEquals(0, userPreferencesDto.getUnselectedFields().size());
userPreferencesService.unselectFields(entityDto.getId(), USERNAME);
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(0, userPreferencesDto.getVisibleFields().size());
assertEquals(0, userPreferencesDto.getSelectedFields().size());
assertEquals(10, userPreferencesDto.getUnselectedFields().size());
userPreferencesService.selectFields(entityDto.getId(), USERNAME);
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(10, userPreferencesDto.getVisibleFields().size());
assertEquals(10, userPreferencesDto.getSelectedFields().size());
assertEquals(0, userPreferencesDto.getUnselectedFields().size());
// if field will be removed from entity then it should be removed also from preferences (CASCADE)
EntityDraft draft = entityService.getEntityDraft(entityDto.getId());
List<FieldDto> fields1 = entityService.getEntityFields(draft.getId());
Long someIntegerId = getFieldIdByName(fields1, "someInteger");
DraftData draftData = DraftBuilder.forFieldRemoval(someIntegerId);
entityService.saveDraftEntityChanges(entityDto.getId(), draftData);
entityService.commitChanges(entityDto.getId());
userPreferencesDto = userPreferencesService.getUserPreferences(entityDto.getId(), USERNAME);
assertEquals(9, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getSelectedFields().contains("someBoolean"));
assertTrue(userPreferencesDto.getSelectedFields().contains("someString"));
assertFalse(userPreferencesDto.getSelectedFields().contains("someInteger"));
}
use of org.motechproject.mds.dto.UserPreferencesDto in project motech by motech.
the class EntityServiceContextIT method shouldUpdateUserPreferencesAfterCommit.
@Test
public void shouldUpdateUserPreferencesAfterCommit() {
EntityDto entityDto = new EntityDto();
entityDto.setName("UserPrefTest");
entityDto = entityService.createEntity(entityDto);
final Long entityId = entityDto.getId();
entityService.saveDraftEntityChanges(entityId, DraftBuilder.forNewField("disp", "f1name", Long.class.getName()));
List<FieldDto> fields = entityService.getFields(entityId);
assertNotNull(fields);
assertEquals(asList("id", "creator", "owner", "modifiedBy", "creationDate", "modificationDate", "f1name"), extract(fields, on(FieldDto.class).getBasic().getName()));
entityService.commitChanges(entityId);
List<Field> draftFields = entityService.getEntityDraft(entityId).getFields();
Field field = selectFirst(draftFields, having(on(Field.class).getName(), equalTo("f1name")));
entityService.saveDraftEntityChanges(entityDto.getId(), DraftBuilder.forFieldEdit(field.getId(), "basic.name", "newName"));
userPreferencesService.selectFields(entityId, "motech");
userPreferencesService.unselectField(entityId, "motech", "id");
userPreferencesService.unselectField(entityId, "motech", "owner");
UserPreferencesDto userPreferencesDto = userPreferencesService.getUserPreferences(entityId, "motech");
assertEquals(5, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("f1name"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creator"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modifiedBy"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creationDate"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modificationDate"));
entityService.commitChanges(entityId);
userPreferencesDto = userPreferencesService.getUserPreferences(entityId, "motech");
assertEquals(5, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("newName"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creator"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modifiedBy"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creationDate"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modificationDate"));
assertEquals(2, userPreferencesDto.getUnselectedFields().size());
assertTrue(userPreferencesDto.getUnselectedFields().contains("id"));
assertTrue(userPreferencesDto.getUnselectedFields().contains("owner"));
}
Aggregations