Search in sources :

Example 6 with MetadataDto

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

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

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

the class FieldProcessorTest method assertRelationshipField.

private void assertRelationshipField(FieldDto field, Class<?> relatedClass, Class<?> relationshipType, String relatedFieldName, ExpectedCascadeSettings expectedCascadeSettings, Class collectionType) {
    assertEquals(relationshipType.getName(), field.getType().getTypeClass());
    MetadataDto md = field.getMetadata(Constants.MetadataKeys.RELATED_CLASS);
    assertNotNull(md);
    assertEquals(relatedClass.getName(), md.getValue());
    if (relatedFieldName != null) {
        md = field.getMetadata(Constants.MetadataKeys.RELATED_FIELD);
        assertNotNull(md);
        assertEquals(relatedFieldName, md.getValue());
    } else {
        assertNull(field.getMetadata(Constants.MetadataKeys.RELATED_FIELD));
    }
    if (expectedCascadeSettings != null) {
        assertEquals(expectedCascadeSettings.isPersist(), getCascadeSetting(field, Constants.Settings.CASCADE_PERSIST));
        assertEquals(expectedCascadeSettings.isUpdate(), getCascadeSetting(field, Constants.Settings.CASCADE_UPDATE));
        assertEquals(expectedCascadeSettings.isDelete(), getCascadeSetting(field, Constants.Settings.CASCADE_DELETE));
    }
    if (collectionType != null) {
        md = field.getMetadata(Constants.MetadataKeys.RELATIONSHIP_COLLECTION_TYPE);
        assertNotNull(md);
        assertEquals(collectionType.getName(), md.getValue());
    }
}
Also used : MetadataDto(org.motechproject.mds.dto.MetadataDto)

Example 9 with MetadataDto

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

the class EntitySorterTest method setUpEntities.

@Before
public void setUpEntities() {
    book = new EntityDto("Book");
    author = new EntityDto("Author");
    authorFieldInBook = fieldDto("author", ManyToManyRelationship.class);
    authorFieldInBook.addMetadata(new MetadataDto(RELATED_CLASS, "Author"));
    FieldDto bookFieldInAuthor = fieldDto("book", ManyToManyRelationship.class);
    bookFieldInAuthor.addMetadata(new MetadataDto(RELATED_CLASS, "Book"));
    when(schemaHolder.getFields(book)).thenReturn(singletonList(authorFieldInBook));
    when(schemaHolder.getFields(author)).thenReturn(singletonList(bookFieldInAuthor));
    entity1 = new EntityDto("Entity1");
    entity2 = new EntityDto("Entity2");
    entity3 = new EntityDto("Entity3");
    FieldDto entity1Field = fieldDto("entity1", OneToOneRelationship.class);
    entity1Field.addMetadata(new MetadataDto(RELATED_CLASS, "Entity2"));
    FieldDto entity2Field = fieldDto("entity2", OneToOneRelationship.class);
    entity2Field.addMetadata(new MetadataDto(RELATED_CLASS, "Entity3"));
    when(schemaHolder.getFields(entity1)).thenReturn(singletonList(entity1Field));
    when(schemaHolder.getFields(entity2)).thenReturn(singletonList(entity2Field));
    parentEntity = new EntityDto("Parent");
    childEntity = new EntityDto("Child");
    childEntity.setSuperClass("Parent");
    binaryTree = new EntityDto("Binary tree");
    FieldDto leftChild = fieldDto("leftChild", "Left child", OneToOneRelationship.class);
    leftChild.addMetadata(new MetadataDto(RELATED_CLASS, "Binary tree"));
    FieldDto rightChild = fieldDto("rightChild", "Right child", OneToOneRelationship.class);
    rightChild.addMetadata(new MetadataDto(RELATED_CLASS, "Binary tree"));
    when(schemaHolder.getFields(binaryTree)).thenReturn(asList(leftChild, rightChild));
    entity1.setRecordHistory(true);
    entity2.setRecordHistory(true);
    entity3.setRecordHistory(true);
    book.setRecordHistory(true);
    author.setRecordHistory(true);
    parentEntity.setRecordHistory(true);
    childEntity.setRecordHistory(true);
    binaryTree.setRecordHistory(true);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ManyToManyRelationship(org.motechproject.mds.domain.ManyToManyRelationship) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto) Before(org.junit.Before)

Example 10 with MetadataDto

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

the class FieldHelperTest method fieldDto.

private FieldDto fieldDto() {
    TypeDto type = new TypeDto("typeDispName", "typeDesc", "typeDefaultName", "typeClass");
    FieldBasicDto basic = new FieldBasicDto("fieldDispName", "fieldName", true, false, "defVal", "tooltip", "placeholder");
    MetadataDto metadata = new MetadataDto("key", "val");
    ValidationCriterionDto criterion = new ValidationCriterionDto("criterionDispName", type);
    FieldValidationDto validation = new FieldValidationDto(criterion);
    return new FieldDto(1L, 100L, type, basic, false, new ArrayList<>(asList(metadata)), validation, null, null);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

MetadataDto (org.motechproject.mds.dto.MetadataDto)28 FieldDto (org.motechproject.mds.dto.FieldDto)22 Test (org.junit.Test)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)8 TypeDto (org.motechproject.mds.dto.TypeDto)7 ArrayList (java.util.ArrayList)6 SettingDto (org.motechproject.mds.dto.SettingDto)6 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)5 LinkedList (java.util.LinkedList)3 FieldMetadata (javax.jdo.metadata.FieldMetadata)3 EntityDto (org.motechproject.mds.dto.EntityDto)3 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)3 LookupDto (org.motechproject.mds.dto.LookupDto)3 Method (java.lang.reflect.Method)2 List (java.util.List)2 ForeignKeyMetadata (javax.jdo.metadata.ForeignKeyMetadata)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 ClassData (org.motechproject.mds.domain.ClassData)2 ValidationCriterionDto (org.motechproject.mds.dto.ValidationCriterionDto)2 ResultActions (org.springframework.test.web.server.ResultActions)2