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;
}
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"));
}
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());
}
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;
}
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());
}
Aggregations