use of org.motechproject.mds.dto.DraftData in project motech by motech.
the class EntityServiceContextIT method shouldNotSaveDraftWhenEntityIsUnavailable.
@Test(expected = EntityNotFoundException.class)
public void shouldNotSaveDraftWhenEntityIsUnavailable() throws IOException {
Map<String, Object> values = new HashMap<>();
values.put("path", DraftData.ADD_NEW_INDEX);
values.put("advanced", true);
DraftData draftData = new DraftData();
draftData.setEdit(true);
draftData.setValues(values);
entityService.saveDraftEntityChanges(123L, draftData);
}
use of org.motechproject.mds.dto.DraftData 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.dto.DraftData in project motech by motech.
the class EntityServiceContextIT method shouldSaveEntityWithGivenLookups.
@Test
public void shouldSaveEntityWithGivenLookups() throws IOException {
EntityDto entityDto = new EntityDto();
entityDto.setName("myEntity");
Map<String, Object> values = new HashMap<>();
values.put("path", DraftData.ADD_NEW_INDEX);
values.put("advanced", true);
values.put("value", asList("Lookup 1"));
DraftData draftData = new DraftData();
draftData.setEdit(true);
draftData.setValues(values);
entityDto = entityService.createEntity(entityDto);
entityService.saveDraftEntityChanges(entityDto.getId(), draftData);
entityService.commitChanges(entityDto.getId());
assertTrue(containsLookup("Lookup 1", entityDto.getId()));
}
use of org.motechproject.mds.dto.DraftData in project motech by motech.
the class DraftBuilder method forNewField.
public static DraftData forNewField(String displayName, String name, String typeClass) {
Map<String, Object> values = new HashMap<>();
values.put(DraftData.TYPE_CLASS, typeClass);
values.put(DraftData.DISPLAY_NAME, displayName);
values.put(DraftData.NAME, name);
DraftData draftData = new DraftData();
draftData.setValues(values);
draftData.setCreate(true);
return draftData;
}
use of org.motechproject.mds.dto.DraftData in project motech by motech.
the class DraftBuilder method forFieldEdit.
public static DraftData forFieldEdit(Long fieldId, String path, Object value) {
Map<String, Object> values = new HashMap<>();
values.put(DraftData.FIELD_ID, fieldId);
values.put(DraftData.PATH, path);
values.put(DraftData.VALUE, Arrays.asList(value));
DraftData draftData = new DraftData();
draftData.setValues(values);
draftData.setEdit(true);
return draftData;
}
Aggregations