Search in sources :

Example 6 with AdvancedSettingsDto

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

the class EntityServiceImpl method getSchema.

@Override
@Transactional
public SchemaHolder getSchema() {
    StopWatch stopWatch = new StopWatch();
    SchemaHolder entitiesHolder = new SchemaHolder();
    LOGGER.debug("Retrieving entities for processing");
    stopWatch.start();
    List<Entity> entities = allEntities.getActualEntities();
    stopWatch.stop();
    LOGGER.debug("{} entities retrieved in {} ms", entities.size(), stopWatch.getTime());
    StopWatchHelper.restart(stopWatch);
    for (Entity entity : entities) {
        LOGGER.debug("Preparing entity: {}", entity.getClassName());
        StopWatchHelper.restart(stopWatch);
        EntityDto entityDto = entity.toDto();
        stopWatch.stop();
        LOGGER.debug("Entity dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        AdvancedSettingsDto advSettingsDto = entity.advancedSettingsDto();
        stopWatch.stop();
        LOGGER.debug("Advanced settings dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        List<FieldDto> fieldDtos = entity.getFieldDtos();
        stopWatch.stop();
        LOGGER.debug("Field dtos created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        entitiesHolder.addEntity(entityDto, advSettingsDto, fieldDtos);
        stopWatch.stop();
        LOGGER.debug("Result stored in {} ms", stopWatch.getTime());
    }
    LOGGER.debug("Retrieving types for processing");
    List<Type> types = allTypes.retrieveAll();
    for (Type type : types) {
        TypeDto typeDto = type.toDto();
        entitiesHolder.addType(typeDto);
        entitiesHolder.addTypeValidation(typeDto, type.getTypeValidationDtos());
    }
    LOGGER.debug("Entities holder ready");
    return entitiesHolder;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDto(org.motechproject.mds.dto.EntityDto) Type(org.motechproject.mds.domain.Type) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TypeDto(org.motechproject.mds.dto.TypeDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) StopWatch(org.apache.commons.lang.time.StopWatch) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with AdvancedSettingsDto

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

the class MdsDataProviderBuilderImplTest method shouldGenerateJson.

@Test
public void shouldGenerateJson() {
    String json = "{\n" + "    \"name\": \"data-services\",\n" + "    \"objects\": [         {\n" + "            \"displayName\": \"TestEntity\",\n" + "            \"type\": \"org.motechproject.TestEntity\",\n" + "            \"lookupFields\": [                 {\n" + "                    \"displayName\": \"TestLookupName\",\n" + "                    \"fields\": [\n" + "                         \"TestFieldName\"                      ]\n" + "                },                {\n" + "                    \"displayName\": \"mds.dataprovider.byinstanceid\",\n" + "                    \"fields\": [\n" + "                        \"mds.dataprovider.instanceid\"\n" + "                    ]\n" + "                }\n" + "            ],\n" + "            \"fields\": [\n" + "                                {\n" + "                    \"displayName\": \"TestFieldDisplayName\",\n" + "                    \"fieldKey\": \"TestFieldName\"\n" + "                }              ]\n" + "        }      ]\n" + "}\n";
    EntityDto entity = new EntityDto();
    entity.setId(Long.valueOf("1"));
    entity.setName("TestEntity");
    entity.setClassName("org.motechproject.TestEntity");
    FieldDto field = new FieldDto();
    FieldBasicDto fieldBasicDto = new FieldBasicDto();
    fieldBasicDto.setName("TestFieldName");
    fieldBasicDto.setDisplayName("TestFieldDisplayName");
    field.setBasic(fieldBasicDto);
    fieldList.add(field);
    LookupDto lookup = new LookupDto();
    lookup.setLookupName("TestLookupName");
    List<LookupFieldDto> lookupFields = new LinkedList<>();
    lookupFields.add(FieldTestHelper.lookupFieldDto("TestFieldName"));
    lookup.setLookupFields(lookupFields);
    lookupList.add(lookup);
    AdvancedSettingsDto advancedSettings = new AdvancedSettingsDto();
    advancedSettings.setIndexes(lookupList);
    SchemaHolder schema = new SchemaHolder();
    schema.addEntity(entity, advancedSettings, fieldList);
    String generatedJson = mdsDataProviderBuilder.generateDataProvider(schema);
    assertEquals(json, generatedJson.replace("\r\n", "\n"));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupDto(org.motechproject.mds.dto.LookupDto) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) LinkedList(java.util.LinkedList) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 8 with AdvancedSettingsDto

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

the class EntityServiceContextIT method shouldUpdateRestOptions.

@Test
public void shouldUpdateRestOptions() throws IOException {
    // given
    EntityDto entityDto = new EntityDto();
    entityDto.setName("RestTestEnt");
    entityDto = entityService.createEntity(entityDto);
    FieldDto boolField = FieldTestHelper.fieldDto("boolField", Boolean.class);
    FieldDto dtField = FieldTestHelper.fieldDto("dtField", DateTime.class);
    FieldDto strField = FieldTestHelper.fieldDto("strField", String.class);
    entityService.addFields(entityDto, asList(boolField, dtField, strField));
    List<LookupFieldDto> lookupFieldDtos = lookupFieldsFromNames("boolField", "dtField", "strField");
    LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
    List<LookupFieldDto> strLookupFieldDtos = lookupFieldsFromNames("strField");
    LookupDto strLookup = new LookupDto("strLookup", false, false, strLookupFieldDtos, true);
    entityService.addLookups(entityDto.getId(), asList(lookup, strLookup));
    RestOptionsDto restOptionsDto = new RestOptionsDto(true, false, true, false, false);
    restOptionsDto.addField("boolField");
    restOptionsDto.addField("strField");
    restOptionsDto.addLookup("strLookup");
    // when
    entityService.updateRestOptions(entityDto.getId(), restOptionsDto);
    // then
    AdvancedSettingsDto advancedSettingsDto = entityService.getAdvancedSettings(entityDto.getId(), true);
    RestOptionsDto fromDb = advancedSettingsDto.getRestOptions();
    assertTrue(fromDb.isCreate());
    assertFalse(fromDb.isRead());
    assertTrue(fromDb.isUpdate());
    assertFalse(fromDb.isDelete());
    assertEquals(asList("strLookup"), fromDb.getLookupNames());
    assertEquals(asList("boolField", "strField"), fromDb.getFieldNames());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 9 with AdvancedSettingsDto

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

the class FieldHelperTest method advancedSettingsDto.

private AdvancedSettingsDto advancedSettingsDto() {
    AdvancedSettingsDto advancedSettings = new AdvancedSettingsDto();
    advancedSettings.setEntityId(100L);
    LookupDto lookup = new LookupDto(1L, "look1Name", true, true, null, false, "look1", new ArrayList<String>());
    LookupDto lookup2 = new LookupDto(2L, "look2Name", false, false, null, false, "look2", new ArrayList<String>());
    advancedSettings.setIndexes(new ArrayList<>((asList(lookup, lookup2))));
    return advancedSettings;
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto)

Example 10 with AdvancedSettingsDto

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

the class FieldHelperTest method shouldAddAndRemoveLookups.

@Test
public void shouldAddAndRemoveLookups() {
    AdvancedSettingsDto advancedSettings = advancedSettingsDto();
    FieldHelper.setField(advancedSettings, "$addNewIndex", asList("Lookup 1"));
    assertEquals(3, advancedSettings.getIndexes().size());
    FieldHelper.setField(advancedSettings, "$removeIndex", asList(1));
    assertEquals(2, advancedSettings.getIndexes().size());
}
Also used : AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) Test(org.junit.Test)

Aggregations

AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)17 Test (org.junit.Test)7 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)7 ArrayList (java.util.ArrayList)5 LookupDto (org.motechproject.mds.dto.LookupDto)5 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)5 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)4 TrackingDto (org.motechproject.mds.dto.TrackingDto)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AnotherSample (org.motechproject.mds.annotations.internal.samples.AnotherSample)2 ReadAccessSample (org.motechproject.mds.annotations.internal.samples.ReadAccessSample)2 MdsEntity (org.motechproject.mds.domain.MdsEntity)2 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)2 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)2 EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)2 FileOutputStream (java.io.FileOutputStream)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1