use of org.motechproject.mds.domain.EntityDraft in project motech by motech.
the class AllEntityDraftsContextIT method shouldCreateAndDeleteDrafts.
@Test
public void shouldCreateAndDeleteDrafts() {
EntityDto dto = new EntityDto();
dto.setClassName("DraftCls");
Entity entity = allEntities.create(dto);
allEntityDrafts.create(entity, USERNAME);
allEntityDrafts.create(entity, USERNAME_2);
EntityDraft draft = allEntityDrafts.retrieve(entity, USERNAME);
assertNotNull(draft);
assertEquals("DraftCls", draft.getClassName());
assertEquals(USERNAME, draft.getDraftOwnerUsername());
draft = allEntityDrafts.retrieve(entity, USERNAME_2);
assertNotNull(draft);
assertEquals("DraftCls", draft.getClassName());
assertEquals(USERNAME_2, draft.getDraftOwnerUsername());
assertNull(allEntityDrafts.retrieve(entity, "otherUser"));
allEntityDrafts.deleteAll(entity);
assertTrue(allEntityDrafts.retrieveAll(entity).isEmpty());
assertNull(allEntityDrafts.retrieve(entity, USERNAME));
assertNull(allEntityDrafts.retrieve(entity, USERNAME_2));
}
use of org.motechproject.mds.domain.EntityDraft in project motech by motech.
the class EntityServiceContextIT method shouldAddNewFieldForLookupAndSaveEntity.
@Test
public void shouldAddNewFieldForLookupAndSaveEntity() throws IOException {
EntityDto entityDto = new EntityDto();
entityDto.setName("myEntity");
entityDto = entityService.createEntity(entityDto);
// add a new field to draft
EntityDraft entityDraft = entityService.getEntityDraft(entityDto.getId());
entityService.saveDraftEntityChanges(entityDraft.getId(), DraftBuilder.forNewField("disp", "testFieldName", Long.class.getName()));
FieldDto field = selectFirst(entityService.getFields(entityDraft.getId()), having(on(FieldDto.class).getBasic().getName(), equalTo("testFieldName")));
LookupDto lookup = new LookupDto("lookup", false, false, null, true);
entityService.addLookups(entityDraft.getId(), Collections.singletonList(lookup));
Map<String, Object> values = new HashMap<>();
values.put("path", "indexes.0.$addField");
values.put("advanced", true);
values.put("value", Collections.singletonList(field.getId()));
DraftData draftData = new DraftData();
draftData.setEdit(true);
draftData.setValues(values);
entityService.saveDraftEntityChanges(entityDraft.getId(), draftData);
entityService.commitChanges(entityDto.getId());
assertNotNull(entityService.getLookupByName(entityDto.getId(), "lookup").getLookupField("testFieldName"));
}
use of org.motechproject.mds.domain.EntityDraft 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;
}
use of org.motechproject.mds.domain.EntityDraft in project motech by motech.
the class EntityServiceImpl method updateDraft.
@Override
@Transactional
public EntityDto updateDraft(Long entityId) {
Entity entity = allEntities.retrieveById(entityId);
EntityDraft draft = getEntityDraft(entityId);
allEntityDrafts.setProperties(draft, entity);
draft.setChangesMade(false);
return draft.toDto();
}
Aggregations