Search in sources :

Example 11 with DraftData

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);
}
Also used : HashMap(java.util.HashMap) DraftData(org.motechproject.mds.dto.DraftData) Test(org.junit.Test)

Example 12 with 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"));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) HashMap(java.util.HashMap) LookupDto(org.motechproject.mds.dto.LookupDto) DraftData(org.motechproject.mds.dto.DraftData) EntityDraft(org.motechproject.mds.domain.EntityDraft) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 13 with DraftData

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()));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) HashMap(java.util.HashMap) DraftData(org.motechproject.mds.dto.DraftData) Test(org.junit.Test)

Example 14 with DraftData

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;
}
Also used : HashMap(java.util.HashMap) DraftData(org.motechproject.mds.dto.DraftData)

Example 15 with 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;
}
Also used : HashMap(java.util.HashMap) DraftData(org.motechproject.mds.dto.DraftData)

Aggregations

DraftData (org.motechproject.mds.dto.DraftData)16 Test (org.junit.Test)11 HashMap (java.util.HashMap)6 EntityDto (org.motechproject.mds.dto.EntityDto)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 EntityDraft (org.motechproject.mds.domain.EntityDraft)3 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)2 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Field (org.motechproject.mds.domain.Field)1 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)1 FieldSetting (org.motechproject.mds.domain.FieldSetting)1 Lookup (org.motechproject.mds.domain.Lookup)1