Search in sources :

Example 1 with MetadataDto

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

the class InstanceServiceTest method mockAnotherEntityFields.

private void mockAnotherEntityFields() {
    FieldDto relatedField = FieldTestHelper.fieldDto(2L, "testClasses", OneToManyRelationship.class.getName(), "Test Classes", null);
    relatedField.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, TestClass.class.getName()));
    when(entityService.getEntityFieldsForUI(ANOTHER_ENTITY_ID)).thenReturn(asList(FieldTestHelper.fieldDto(1L, "id", Long.class.getName(), "Id", null), relatedField));
}
Also used : OneToManyRelationship(org.motechproject.mds.domain.OneToManyRelationship) Matchers.anyLong(org.mockito.Matchers.anyLong) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 2 with MetadataDto

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

the class RelationshipDisplayUtilTest method prepareFieldDefinitionsForManufacturer.

private List<FieldDto> prepareFieldDefinitionsForManufacturer() {
    List<FieldDto> fields = new ArrayList<>();
    FieldDto name = new FieldDto("name", "Name", null);
    FieldDto factories = new FieldDto("factories", "Factories", null);
    factories.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, "Factory"));
    FieldDto safetyPolicy = new FieldDto("safetyPolicy", "Safety policy", null);
    safetyPolicy.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, "SafetyPolicy"));
    fields.add(name);
    fields.add(factories);
    fields.add(safetyPolicy);
    return fields;
}
Also used : ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 3 with MetadataDto

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

the class RelationshipDisplayUtilTest method prepareFieldDefinitionsForFactory.

private List<FieldDto> prepareFieldDefinitionsForFactory() {
    List<FieldDto> fields = new ArrayList<>();
    FieldDto name = new FieldDto("name", "Name", null);
    FieldDto location = new FieldDto("location", "Location", null);
    location.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, "Location"));
    fields.add(name);
    fields.add(location);
    return fields;
}
Also used : ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 4 with MetadataDto

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

the class EntityDefaultFieldsHelper method defaultFields.

public static List<FieldDto> defaultFields(SchemaHolder schemaHolder) {
    TypeDto longType = schemaHolder.getType(Long.class);
    TypeDto stringType = schemaHolder.getType(String.class);
    TypeDto dateTimeType = schemaHolder.getType(DateTime.class);
    FieldDto idField = new FieldDto(Constants.Util.ID_FIELD_NAME, Constants.Util.ID_DISPLAY_FIELD_NAME, longType, true, true);
    idField.setReadOnly(true);
    idField.setMetadata(Collections.singletonList(new MetadataDto(AUTO_GENERATED, TRUE)));
    FieldDto creatorField = new FieldDto(Constants.Util.CREATOR_FIELD_NAME, Constants.Util.CREATOR_DISPLAY_FIELD_NAME, stringType, true, false);
    creatorField.setReadOnly(true);
    creatorField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
    FieldDto ownerField = new FieldDto(Constants.Util.OWNER_FIELD_NAME, Constants.Util.OWNER_DISPLAY_FIELD_NAME, stringType, false, false);
    ownerField.setReadOnly(true);
    ownerField.addMetadata(new MetadataDto(AUTO_GENERATED_EDITABLE, TRUE));
    FieldDto modifiedByField = new FieldDto(Constants.Util.MODIFIED_BY_FIELD_NAME, Constants.Util.MODIFIED_BY_DISPLAY_FIELD_NAME, stringType, true, false);
    modifiedByField.setReadOnly(true);
    modifiedByField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
    FieldDto modificationDateField = new FieldDto(Constants.Util.MODIFICATION_DATE_FIELD_NAME, Constants.Util.MODIFICATION_DATE_DISPLAY_FIELD_NAME, dateTimeType, true, false);
    modificationDateField.setReadOnly(true);
    modificationDateField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
    FieldDto creationDateField = new FieldDto(Constants.Util.CREATION_DATE_FIELD_NAME, Constants.Util.CREATION_DATE_DISPLAY_FIELD_NAME, dateTimeType, true, false);
    creationDateField.setReadOnly(true);
    creationDateField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
    return Arrays.asList(idField, creatorField, ownerField, modifiedByField, modificationDateField, creationDateField);
}
Also used : TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 5 with MetadataDto

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

the class Field method updateMetadata.

private void updateMetadata(List<MetadataDto> metadataList) {
    Iterator<FieldMetadata> it = getMetadata().iterator();
    while (it.hasNext()) {
        FieldMetadata meta = it.next();
        boolean inNewList = false;
        for (MetadataDto metadataDto : metadataList) {
            if (StringUtils.equals(metadataDto.getKey(), meta.getKey())) {
                inNewList = true;
                break;
            }
        }
        if (!inNewList) {
            it.remove();
        }
    }
    for (MetadataDto metadataDto : metadataList) {
        FieldMetadata meta = getMetadata(metadataDto.getKey());
        if (null == meta) {
            FieldMetadata newMetadata = new FieldMetadata(metadataDto);
            addMetadata(newMetadata);
        } else {
            meta.update(metadataDto);
        }
    }
}
Also used : MetadataDto(org.motechproject.mds.dto.MetadataDto)

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