Search in sources :

Example 96 with EntityDto

use of org.motechproject.mds.dto.EntityDto 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 97 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class MdsLookupServiceTest method setUp.

@Before
public void setUp() {
    MotechClassPool.registerServiceInterface(Record.class.getName(), TestDataService.class.getName());
    EntityDto entity = new EntityDto(ENTITY_ID, ENTITY_CLASS_NAME);
    FieldDto strField = FieldTestHelper.fieldDto(STR_FIELD_ID, STR_PARAM, String.class.getName(), "strDisp", null);
    FieldDto intField = FieldTestHelper.fieldDto(INT_FIELD_ID, INT_PARAM, Integer.class.getName(), "strDisp", null);
    LookupFieldDto strLookupField = new LookupFieldDto(STR_FIELD_ID, STR_PARAM, LookupFieldType.VALUE);
    LookupFieldDto intLookupField = new LookupFieldDto(INT_FIELD_ID, INT_PARAM, LookupFieldType.VALUE);
    LookupDto firstLookup = new LookupDto(FIRST_LOOKUP_NAME, true, false, asList(strLookupField, intLookupField), false);
    LookupDto secondLookup = new LookupDto(SECOND_LOOKUP_NAME, false, false, asList(strLookupField, intLookupField), false);
    when(entityService.getEntityByClassName(ENTITY_CLASS_NAME)).thenReturn(entity);
    when(entityService.getEntityFields(ENTITY_ID)).thenReturn(asList(intField, strField));
    when(entityService.getLookupByName(ENTITY_ID, FIRST_LOOKUP_NAME)).thenReturn(firstLookup);
    when(entityService.getLookupByName(ENTITY_ID, SECOND_LOOKUP_NAME)).thenReturn(secondLookup);
    Map<String, FieldDto> mapping = new HashMap<>();
    mapping.put(STR_PARAM, strField);
    mapping.put(INT_PARAM, intField);
    when(entityService.getLookupFieldsMapping(ENTITY_ID, FIRST_LOOKUP_NAME)).thenReturn(mapping);
    when(entityService.getLookupFieldsMapping(ENTITY_ID, SECOND_LOOKUP_NAME)).thenReturn(mapping);
    when(bundleContext.getServiceReference(TestDataService.class.getName())).thenReturn(serviceReference);
    when(bundleContext.getService(serviceReference)).thenReturn(dataService);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) HashMap(java.util.HashMap) LookupDto(org.motechproject.mds.dto.LookupDto) Record(org.motechproject.mds.testutil.records.Record) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Before(org.junit.Before)

Example 98 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class JarGeneratorServiceContextIT method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    MotechClassPool.clearEnhancedData();
    EntityDto entitySAMPLE = new EntityDto(null, SAMPLE);
    entitySAMPLE.setRecordHistory(true);
    EntityDto entityEXAMPLE = new EntityDto(null, EXAMPLE);
    entityEXAMPLE.setRecordHistory(true);
    EntityDto entityFOO = new EntityDto(null, FOO);
    entityFOO.setRecordHistory(true);
    // Entity without history
    EntityDto entityBAR = new EntityDto(null, BAR);
    entityBAR.setRecordHistory(false);
    entityService.createEntity(entitySAMPLE);
    entityService.createEntity(entityEXAMPLE);
    entityService.createEntity(entityFOO);
    entityService.createEntity(entityBAR);
    bundleHeaders = new BundleHeaders(bundleContext);
    Path path = Paths.get(monitor.bundleLocation());
    Files.deleteIfExists(path);
    setProperty(monitor, "bundleStarted", true);
    setProperty(monitor, "bundleInstalled", true);
    setProperty(monitor, "contextInitialized", true);
    SchemaHolder schemaHolder = entityService.getSchema();
    constructor.constructEntities(schemaHolder);
}
Also used : Path(java.nio.file.Path) EntityDto(org.motechproject.mds.dto.EntityDto) BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) Before(org.junit.Before)

Example 99 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EditableLookupsLoaderTest method prepareEntityDto.

private EntityDto prepareEntityDto() {
    EntityDto entity = new EntityDto();
    entity.setClassName(CLASS_NAME);
    return entity;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto)

Example 100 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class MdsDummyDataGeneratorImpl method makeInstances.

private void makeInstances(MotechDataService service, Long entityId, int numberOfInstances, int numberOfHistoricalRevisions, int numberOfTrashInstances) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    EntityDto entityDto = entityService.getEntity(entityId);
    for (int i = 0; i < numberOfInstances; i++) {
        Object obj = makeDummyInstance(entityDto.getId());
        service.create(obj);
        for (int j = 0; j < numberOfHistoricalRevisions; j++) {
            service.update(obj);
        }
    }
    for (int i = 0; i < numberOfTrashInstances; i++) {
        Object obj = makeDummyInstance(entityDto.getId());
        obj = service.create(obj);
        service.delete(obj);
    }
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6