Search in sources :

Example 91 with FieldDto

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

the class ExampleData method findFieldByName.

public FieldDto findFieldByName(Long entityId, String name) {
    List<FieldDto> fields = getFields(entityId);
    FieldDto found = null;
    for (FieldDto field : fields) {
        if (equalsIgnoreCase(field.getBasic().getName(), name)) {
            found = field;
            break;
        }
    }
    if (null != found && fieldsHistory.containsKey(found.getEntityId()) && fieldsHistory.get(found.getEntityId()).containsKey(found.getId())) {
        found = fieldsHistory.get(found.getEntityId()).get(found.getId());
    }
    return found;
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto)

Example 92 with FieldDto

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

Example 93 with FieldDto

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

the class RestIgnoreProcessor method afterExecution.

@Override
protected void afterExecution() {
    Collection<String> ignoredFieldNames = getElements();
    List<String> fieldNames = new ArrayList<>();
    for (FieldDto field : fields) {
        if (!ignoredFieldNames.contains(field.getBasic().getName())) {
            fieldNames.add(field.getBasic().getName());
        }
    }
    restOptions.setFieldNames(fieldNames);
}
Also used : ArrayList(java.util.ArrayList) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 94 with FieldDto

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

the class LookupProcessor method setUseGenericParam.

private void setUseGenericParam(EntityDto entity, Class<?> methodParameterType, LookupFieldDto lookupField) {
    FieldDto field = findEntityFieldByName(entity.getClassName(), lookupField.getName());
    TypeDto fieldType = field.getType();
    EntityDto relatedEntity = null;
    if (fieldType.isRelationship()) {
        relatedEntity = findEntityByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
        field = findEntityFieldByName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue(), lookupField.getRelatedName());
    }
    if (fieldType.isCombobox()) {
        ComboboxHolder holder = new ComboboxHolder(relatedEntity == null ? entity : relatedEntity, field);
        boolean isCollection = holder.isCollection();
        boolean isCollectionParam = Collection.class.isAssignableFrom(methodParameterType);
        lookupField.setUseGenericParam(isCollection && !isCollectionParam);
    }
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 95 with FieldDto

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

the class EntityInfrastructureBuilderTest method shouldCreateCodeForClassWithLookups.

@Test
public void shouldCreateCodeForClassWithLookups() throws Exception {
    MDSClassLoader mdsClassLoaderImpl = MDSClassLoader.getStandaloneInstance(getClass().getClassLoader());
    EntityDto entity = new EntityDto(SampleWithLookups.class.getName());
    entity.setMaxFetchDepth(-1);
    LookupDto lookup = new LookupDto();
    lookup.setLookupName("testLookup");
    lookup.setMethodName("testLookupMethod");
    FieldDto testField = fieldDto("TestField", "testDispName", String.class);
    FieldDto testField2 = fieldDto("TestField2", "DisplayName with space", String.class);
    FieldDto dateField = fieldDto("dateField", "Display names should not affect methods", DateTime.class);
    FieldDto timeField = fieldDto("timeField", Time.class);
    when(schemaHolder.getFieldByName(SampleWithLookups.class.getName(), "TestField")).thenReturn(testField);
    when(schemaHolder.getFieldByName(SampleWithLookups.class.getName(), "TestField2")).thenReturn(testField2);
    when(schemaHolder.getFieldByName(SampleWithLookups.class.getName(), "dateField")).thenReturn(dateField);
    when(schemaHolder.getFieldByName(SampleWithLookups.class.getName(), "timeField")).thenReturn(timeField);
    lookup.setFieldsOrder(asList("TestField", "TestField2", "dateField", "timeField"));
    lookup.setSingleObjectReturn(true);
    when(schemaHolder.getLookups(entity)).thenReturn(singletonList(lookup));
    List<LookupFieldDto> lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto("TestField", LookupFieldType.VALUE));
    lookupFields.add(new LookupFieldDto("TestField2", LookupFieldType.VALUE));
    lookupFields.add(new LookupFieldDto("dateField", LookupFieldType.RANGE));
    lookupFields.add(new LookupFieldDto("timeField", LookupFieldType.SET));
    lookup.setLookupFields(lookupFields);
    List<ClassData> data = entityInfrastructureBuilder.buildInfrastructure(entity, schemaHolder);
    for (ClassData classData : data) {
        mdsClassLoaderImpl.safeDefineClass(classData.getClassName(), classData.getBytecode());
    }
    verifySingleLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_SERVICE));
    verifySingleLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_INTERFACE));
    verifyCountLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_SERVICE));
    verifyCountLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_INTERFACE));
    // lookup with multiple return
    lookup.setSingleObjectReturn(false);
    mdsClassLoaderImpl = MDSClassLoader.getStandaloneInstance(getClass().getClassLoader());
    data = entityInfrastructureBuilder.buildInfrastructure(entity, schemaHolder);
    for (ClassData classData : data) {
        mdsClassLoaderImpl.safeDefineClass(classData.getClassName(), classData.getBytecode());
    }
    verifyMultiReturnLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_SERVICE));
    verifyMultiReturnLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_INTERFACE));
    verifyCountLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_SERVICE));
    verifyCountLookup(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_INTERFACE));
    verifyFetchDepthInRepository(mdsClassLoaderImpl.loadClass(SAMPLE_WITH_LOOKUPS_REPOSITORY), -1);
}
Also used : MDSClassLoader(org.motechproject.mds.util.MDSClassLoader) EntityDto(org.motechproject.mds.dto.EntityDto) ClassData(org.motechproject.mds.domain.ClassData) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) SampleWithLookups(org.motechproject.mds.builder.SampleWithLookups) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FieldDto (org.motechproject.mds.dto.FieldDto)158 Test (org.junit.Test)61 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)60 EntityDto (org.motechproject.mds.dto.EntityDto)53 ArrayList (java.util.ArrayList)47 LookupDto (org.motechproject.mds.dto.LookupDto)29 List (java.util.List)23 MetadataDto (org.motechproject.mds.dto.MetadataDto)22 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)19 TypeDto (org.motechproject.mds.dto.TypeDto)17 Method (java.lang.reflect.Method)14 MotechDataService (org.motechproject.mds.service.MotechDataService)14 HashMap (java.util.HashMap)12 Field (org.motechproject.mds.domain.Field)12 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)12 Arrays.asList (java.util.Arrays.asList)11 SettingDto (org.motechproject.mds.dto.SettingDto)11 Before (org.junit.Before)7 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)7