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;
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations