Search in sources :

Example 1 with FieldBasicDto

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

the class MdsDummyDataGeneratorImpl method prepareDummyEntity.

private void prepareDummyEntity(int number, int fieldsPerEntity, int lookupsPerEntity) throws IOException {
    EntityDto entityDto = new EntityDto(Long.valueOf(number), entityPrefix.concat(String.valueOf(number)));
    entityDto = entityService.createEntity(entityDto);
    List<FieldDto> fields = new ArrayList<>();
    for (int i = 0; i < fieldsPerEntity; i++) {
        TypeDto type = pickRandomFieldType();
        fields.add(new FieldDto(null, entityDto.getId(), type, new FieldBasicDto(fieldPrefix.concat(String.valueOf(i)), fieldPrefix.concat(String.valueOf(i))), false, null, null, settingsFor(type), null));
    }
    entityService.addFields(entityDto, fields);
    List<LookupDto> lookups = new ArrayList<>();
    for (int i = 0; i < lookupsPerEntity; i++) {
        List<LookupFieldDto> lookupFields = new ArrayList<>();
        List<FieldDto> entityFields = entityService.getFields(entityDto.getId());
        int amountOfFields = RAND.nextInt(entityFields.size());
        for (int j = 0; j < amountOfFields; j++) {
            lookupFields.add(new LookupFieldDto(null, entityFields.get(j).getBasic().getName(), LookupFieldType.VALUE));
        }
        lookups.add(new LookupDto(lookupPrefix.concat(String.valueOf(i)), RAND.nextBoolean(), RAND.nextBoolean(), lookupFields, false));
    }
    entityService.addLookups(entityDto.getId(), lookups);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 2 with FieldBasicDto

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

the class Field method toDto.

public FieldDto toDto() {
    FieldBasicDto basic = new FieldBasicDto(displayName, name, required, unique, parseDefaultValue(), tooltip, placeholder);
    TypeDto typeDto = null;
    List<MetadataDto> metaDto = new ArrayList<>();
    for (FieldMetadata meta : metadata) {
        metaDto.add(meta.toDto());
    }
    FieldValidationDto validationDto = null;
    if (CollectionUtils.isNotEmpty(validations)) {
        validationDto = new FieldValidationDto();
        for (FieldValidation validation : validations) {
            validationDto.addCriterion(validation.toDto());
        }
    }
    List<SettingDto> settingsDto = new ArrayList<>();
    for (FieldSetting setting : settings) {
        settingsDto.add(setting.toDto());
    }
    List<LookupDto> lookupDtos = new ArrayList<>();
    for (Lookup lookup : getLookups()) {
        lookupDtos.add(lookup.toDto());
    }
    if (typeDto == null && type != null) {
        typeDto = type.toDto();
    }
    return new FieldDto(id, entity == null ? null : entity.getId(), typeDto, basic, readOnly, nonEditable, nonDisplayable, uiFilterable, uiChanged, metaDto, validationDto, settingsDto, lookupDtos);
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) SettingDto(org.motechproject.mds.dto.SettingDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 3 with FieldBasicDto

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

the class MdsBundleIT method createEntityForPreferencesTest.

private EntityDto createEntityForPreferencesTest() {
    EntityDto entityDto = new EntityDto(null, 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, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString"), false, false, false, false, false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Some Integer", "someInteger"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Other Integer", "otherInteger"), false, false, false, false, false, null, null, null, null));
    entityService.addFields(entityDto, fields);
    Map<String, Long> displayedFields = new HashMap<>();
    displayedFields.put("someInteger", 1L);
    displayedFields.put("someBoolean", 2L);
    displayedFields.put("someString", 3L);
    entityService.addDisplayedFields(entityDto, displayedFields);
    schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    return entityDto;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) SettingDto(org.motechproject.mds.dto.SettingDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 4 with FieldBasicDto

use of org.motechproject.mds.dto.FieldBasicDto 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");
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) MetadataDto(org.motechproject.mds.dto.MetadataDto) LinkedList(java.util.LinkedList) EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) SettingDto(org.motechproject.mds.dto.SettingDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 5 with FieldBasicDto

use of org.motechproject.mds.dto.FieldBasicDto 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)

Aggregations

FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)20 FieldDto (org.motechproject.mds.dto.FieldDto)19 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)11 EntityDto (org.motechproject.mds.dto.EntityDto)9 TypeDto (org.motechproject.mds.dto.TypeDto)9 MetadataDto (org.motechproject.mds.dto.MetadataDto)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 LookupDto (org.motechproject.mds.dto.LookupDto)5 LinkedList (java.util.LinkedList)4 SettingDto (org.motechproject.mds.dto.SettingDto)4 Field (org.motechproject.mds.domain.Field)3 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 Type (org.motechproject.mds.domain.Type)2 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)2 ValidationCriterionDto (org.motechproject.mds.dto.ValidationCriterionDto)2 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)2 ResultActions (org.springframework.test.web.server.ResultActions)2