Search in sources :

Example 11 with FieldBasicDto

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

the class FieldTestHelper method fieldInfo.

public static FieldInfo fieldInfo(String name, Class typeClass, boolean required, boolean restExposed, boolean autoGenerated) {
    FieldInfo field = new FieldInfo();
    FieldDto fieldDto = new FieldDto();
    fieldDto.setBasic(new FieldBasicDto());
    fieldDto.getBasic().setName(name);
    fieldDto.getBasic().setDisplayName(name + " disp");
    fieldDto.getBasic().setRequired(required);
    TypeDto type = new TypeDto();
    type.setTypeClass(typeClass.getName());
    fieldDto.setType(type);
    field.setRestExposed(restExposed);
    if (autoGenerated) {
        fieldDto.addMetadata(new MetadataDto(Constants.Util.AUTO_GENERATED, Constants.Util.TRUE));
    }
    field.setField(fieldDto);
    field.getTypeInfo().setType(typeClass.getName());
    return field;
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 12 with FieldBasicDto

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

the class FieldTestHelper method fieldDto.

public static FieldDto fieldDto(Long id, String name, String className, String displayName, Object defValue) {
    FieldDto fieldDto = new FieldDto();
    fieldDto.setType(new TypeDto(className, "", "", className));
    fieldDto.setBasic(new FieldBasicDto(displayName, name));
    fieldDto.getBasic().setDefaultValue(defValue);
    fieldDto.setId(id);
    return fieldDto;
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 13 with FieldBasicDto

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

the class EntityServiceImpl method addField.

private void addField(Entity entity, FieldDto fieldDto) {
    FieldBasicDto basic = fieldDto.getBasic();
    String typeClass = fieldDto.getType().getTypeClass();
    Type type = allTypes.retrieveByClassName(typeClass);
    Field field = new Field(entity, basic.getName(), basic.getDisplayName(), basic.isRequired(), basic.isUnique(), fieldDto.isReadOnly(), fieldDto.isNonEditable(), fieldDto.isNonDisplayable(), (String) basic.getDefaultValue(), basic.getTooltip(), basic.getPlaceholder(), null);
    field.setType(type);
    if (type.hasSettings()) {
        for (TypeSetting setting : type.getSettings()) {
            SettingDto settingDto = fieldDto.getSetting(setting.getName());
            FieldSetting fieldSetting = new FieldSetting(field, setting);
            if (null != settingDto) {
                fieldSetting.setValue(settingDto.getValueAsString());
            }
            field.addSetting(fieldSetting);
        }
    }
    if (type.hasValidation()) {
        for (TypeValidation validation : type.getValidations()) {
            FieldValidation fieldValidation = new FieldValidation(field, validation);
            FieldValidationDto validationDto = fieldDto.getValidation();
            if (null != validationDto) {
                ValidationCriterionDto criterion = validationDto.getCriterion(validation.getDisplayName());
                if (null != criterion) {
                    fieldValidation.setValue(criterion.valueAsString());
                    fieldValidation.setEnabled(criterion.isEnabled());
                }
            }
            field.addValidation(fieldValidation);
        }
    }
    for (MetadataDto metadata : fieldDto.getMetadata()) {
        field.addMetadata(new FieldMetadata(metadata));
    }
    entity.addField(field);
}
Also used : FieldMetadata(org.motechproject.mds.domain.FieldMetadata) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldSetting(org.motechproject.mds.domain.FieldSetting) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) TypeValidation(org.motechproject.mds.domain.TypeValidation) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) TypeSetting(org.motechproject.mds.domain.TypeSetting) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) SettingDto(org.motechproject.mds.dto.SettingDto) FieldValidation(org.motechproject.mds.domain.FieldValidation)

Example 14 with FieldBasicDto

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

the class RestIgnoreProcessorTest method mockEntityFields.

private List<FieldDto> mockEntityFields() {
    List<FieldDto> fields = new ArrayList<>();
    List<String> fieldNames = new ArrayList<>(Arrays.asList(Constants.Util.GENERATED_FIELD_NAMES));
    fieldNames.addAll(Arrays.asList("anotherInt", "anotherString", "restIgnoredBoolean"));
    long i = 0;
    for (String fieldName : fieldNames) {
        long fieldId = i++;
        FieldDto fieldDto = mock(FieldDto.class);
        FieldBasicDto fieldBasicDto = mock(FieldBasicDto.class);
        when(fieldDto.getId()).thenReturn(fieldId);
        when(fieldDto.getBasic()).thenReturn(fieldBasicDto);
        when(fieldBasicDto.getName()).thenReturn(fieldName);
        fields.add(fieldDto);
    }
    return fields;
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ArrayList(java.util.ArrayList) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 15 with FieldBasicDto

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

the class EntityMetadataBuilderTest method shouldMarkEudeFieldsAsUnique.

@Test
public void shouldMarkEudeFieldsAsUnique() {
    when(entity.getName()).thenReturn(ENTITY_NAME);
    when(jdoMetadata.newPackageMetadata(anyString())).thenReturn(packageMetadata);
    when(packageMetadata.newClassMetadata(anyString())).thenReturn(classMetadata);
    FieldDto eudeField = mock(FieldDto.class);
    FieldBasicDto eudeBasic = mock(FieldBasicDto.class);
    when(eudeField.getBasic()).thenReturn(eudeBasic);
    when(eudeBasic.getName()).thenReturn("uniqueField");
    when(eudeField.isReadOnly()).thenReturn(false);
    when(eudeBasic.isUnique()).thenReturn(true);
    when(eudeField.getType()).thenReturn(TypeDto.STRING);
    FieldDto ddeField = mock(FieldDto.class);
    FieldBasicDto ddeBasic = mock(FieldBasicDto.class);
    when(ddeField.getBasic()).thenReturn(ddeBasic);
    when(ddeBasic.getName()).thenReturn("uniqueField2");
    when(ddeField.isReadOnly()).thenReturn(true);
    when(ddeBasic.isUnique()).thenReturn(true);
    when(ddeField.getType()).thenReturn(TypeDto.STRING);
    when(schemaHolder.getFields(entity)).thenReturn(asList(ddeField, eudeField));
    FieldMetadata fmdEude = mock(FieldMetadata.class);
    when(fmdEude.getName()).thenReturn("uniqueField");
    when(classMetadata.newFieldMetadata("uniqueField")).thenReturn(fmdEude);
    FieldMetadata fmdDde = mock(FieldMetadata.class);
    when(fmdDde.getName()).thenReturn("uniqueField2");
    when(classMetadata.newFieldMetadata("uniqueField2")).thenReturn(fmdDde);
    UniqueMetadata umd = mock(UniqueMetadata.class);
    when(fmdEude.newUniqueMetadata()).thenReturn(umd);
    entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
    verify(fmdDde, never()).newUniqueMetadata();
    verify(fmdDde, never()).setUnique(anyBoolean());
    verify(fmdEude).newUniqueMetadata();
    verify(umd).setName("unq_Sample_uniqueField");
}
Also used : FieldMetadata(javax.jdo.metadata.FieldMetadata) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) UniqueMetadata(javax.jdo.metadata.UniqueMetadata) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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