use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class EntityServiceImpl method addNonPersistentDataForLookupFields.
private void addNonPersistentDataForLookupFields(Collection<LookupDto> lookupDtos, Entity entity) {
for (LookupDto lookup : lookupDtos) {
for (LookupFieldDto lookupField : lookup.getLookupFields()) {
Field field = entity.getField(lookupField.getName());
if (StringUtils.isNotBlank(lookupField.getRelatedName())) {
Entity relatedEntity = allEntities.retrieveByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
Field relatedField = relatedEntity.getField(lookupField.getRelatedName());
addNonPersistentDataForLookupField(relatedField, lookupField, field.getDisplayName(), relatedField.getDisplayName());
} else {
addNonPersistentDataForLookupField(field, lookupField, field.getDisplayName(), null);
}
}
}
}
use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class MdsBundleIT method prepareTestEntities.
private void prepareTestEntities() throws IOException {
getLogger().info("Preparing entities for testing");
EntityDto entityDto = new EntityDto(9999L, FOO);
entityDto = entityService.createEntity(entityDto);
SchemaHolder schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder);
List<FieldDto> fields = new ArrayList<>();
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BOOLEAN, new FieldBasicDto("Some Boolean", "someBoolean"), false, null));
// this field is unique
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString", false, true), false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
// test with capitalized name
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Capital Name", "CapitalName"), false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
fields.add(new FieldDto(null, entityDto.getId(), COLLECTION, new FieldBasicDto("Some List", "someList"), false, null, null, asList(new SettingDto(Constants.Settings.COMBOBOX_VALUES, new LinkedList<>(), COLLECTION, REQUIRE), new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, true, BOOLEAN), new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, true, BOOLEAN)), null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATETIME, new FieldBasicDto("dateTime", "someDateTime"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATETIME8, new FieldBasicDto("someJavaDateTime", "someJavaDateTime"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.MAP, new FieldBasicDto("someMap", "someMap"), false, Arrays.asList(new MetadataDto(MAP_KEY_TYPE, String.class.getName()), new MetadataDto(MAP_VALUE_TYPE, TestClass.class.getName())), null, null, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.PERIOD, new FieldBasicDto("somePeriod", "somePeriod"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BLOB, new FieldBasicDto("someBlob", "someBlob"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.LOCAL_DATE, new FieldBasicDto("someLocalDate", "someLocalDate"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.LOCAL_DATE8, new FieldBasicDto("someJavaDate", "someJavaDate"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATE, new FieldBasicDto("someDate", "someDate"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.TIME, new FieldBasicDto("someTime", "someTime"), false, null));
List<SettingDto> decimalSettings = asList(new SettingDto("mds.form.label.precision", 10), new SettingDto("mds.form.label.scale", 5));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DOUBLE, new FieldBasicDto("Some Decimal", "someDecimal"), false, null, null, decimalSettings, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("someInteger", "someInt"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.COLLECTION, new FieldBasicDto("Some Enum", "someEnum"), false, null, null, asList(new SettingDto(Constants.Settings.COMBOBOX_VALUES, asList("one", "two", "three"), COLLECTION, REQUIRE), new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, false, BOOLEAN), new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, false, BOOLEAN)), null));
entityService.addFields(entityDto, fields);
List<LookupDto> lookups = new ArrayList<>();
List<LookupFieldDto> lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someBoolean", LookupFieldType.VALUE));
lookups.add(new LookupDto("By boolean", false, false, lookupFields, true, "byBool", asList("someBoolean")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE));
lookups.add(new LookupDto("By unique String", true, false, lookupFields, true, "byUniqueString", asList("someString")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someBoolean", LookupFieldType.VALUE));
lookupFields.add(new LookupFieldDto(null, "someDateTime", LookupFieldType.RANGE));
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.SET));
lookupFields.add(new LookupFieldDto(null, "someList", LookupFieldType.VALUE));
lookups.add(new LookupDto("Combined", false, false, lookupFields, true));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someInt", LookupFieldType.VALUE, "<="));
lookups.add(new LookupDto("With custom operator", false, false, lookupFields, true, "customOperator", asList("someInt")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE, "matches()"));
lookups.add(new LookupDto("With matches", false, false, lookupFields, true, "matchesOperator", asList("someString")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE, Constants.Operators.MATCHES_CASE_INSENSITIVE));
lookups.add(new LookupDto("With matches case insensitive", false, false, lookupFields, true, "matchesOperatorCI", singletonList("someString")));
entityService.addLookups(entityDto.getId(), lookups);
schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder);
getLogger().info("Entities ready for testing");
}
use of org.motechproject.mds.dto.LookupFieldDto 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.LookupFieldDto in project motech by motech.
the class EntityServiceContextIT method shouldAddLookups.
@Test
public void shouldAddLookups() throws IOException {
EntityDto entityDto = new EntityDto();
entityDto.setName("LookupTestEnt");
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");
lookupFieldDtos.get(1).setType(RANGE);
lookupFieldDtos.get(2).setType(SET);
LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
entityService.addLookups(entityDto.getId(), asList(lookup));
LookupDto lookupFromDb = entityService.getLookupByName(entityDto.getId(), "lookup");
assertNotNull(lookupFromDb);
assertEquals("lookup", lookupFromDb.getLookupName());
assertEquals("lookup", lookupFromDb.getMethodName());
assertEquals(asList("boolField", "dtField", "strField"), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getName()));
assertEquals(asList(VALUE, RANGE, SET), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getType()));
assertEquals(asList("boolField", "dtField", "strField"), lookupFromDb.getFieldsOrder());
}
use of org.motechproject.mds.dto.LookupFieldDto 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());
}
Aggregations