use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class SchemaComparatorTest method shouldCompareLookupsWithDifferentFields.
@Test
public void shouldCompareLookupsWithDifferentFields() {
LookupDto lookupDto = new LookupDto("lookupName", true, true, new ArrayList<LookupFieldDto>(), true, "methodName", new ArrayList<String>());
LookupFieldDto lookupFieldDto = new LookupFieldDto(1L, "name", LookupFieldType.RANGE, "customOperator", true, "relatedName");
lookupDto.setLookupFields(asList(lookupFieldDto));
LookupDto lookupDto2 = new LookupDto("lookupName", true, true, new ArrayList<LookupFieldDto>(), true, "methodName", new ArrayList<String>());
LookupFieldDto lookupFieldDto2 = new LookupFieldDto(1L, "name", LookupFieldType.RANGE, "customOperator", true, "differentRelatedName");
lookupDto2.setLookupFields(asList(lookupFieldDto2));
entityLookups = asList(lookupDto);
newLookups = asList(lookupDto2);
when(entityService.getEntityLookups(ENTITY_ID)).thenReturn(entityLookups);
boolean lookupsDiffer = schemaComparator.lookupsDiffer(ENTITY_ID, newLookups);
assertTrue(lookupsDiffer);
}
use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class SchemaComparatorTest method shouldCompareTheSameLookups.
@Test
public void shouldCompareTheSameLookups() {
LookupDto lookupDto = new LookupDto("lookupName", true, true, new ArrayList<LookupFieldDto>(), true, "methodName", new ArrayList<String>());
entityLookups = asList(lookupDto);
newLookups = asList(lookupDto);
when(entityService.getEntityLookups(ENTITY_ID)).thenReturn(entityLookups);
boolean lookupsDiffer = schemaComparator.lookupsDiffer(ENTITY_ID, newLookups);
assertFalse(lookupsDiffer);
}
use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class SchemaComparatorTest method shouldCompareOnlyReadOnlyLookups.
@Test
public void shouldCompareOnlyReadOnlyLookups() {
LookupDto lookupDto = new LookupDto("lookupName", true, true, new ArrayList<LookupFieldDto>(), true, "methodName", new ArrayList<String>());
LookupDto lookupDto2 = new LookupDto();
lookupDto2.setReadOnly(false);
entityLookups = asList(lookupDto, lookupDto2);
newLookups = asList(lookupDto);
when(entityService.getEntityLookups(ENTITY_ID)).thenReturn(entityLookups);
boolean lookupsDiffer = schemaComparator.lookupsDiffer(ENTITY_ID, newLookups);
assertFalse(lookupsDiffer);
}
use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class LookupProcessorTest method shouldProcessMethodWithRangeParam.
@Test
public void shouldProcessMethodWithRangeParam() throws NoSuchMethodException {
FieldDto arg0Field = new FieldDto("arg0Field", "Arg 0 Field", TypeDto.BOOLEAN);
FieldDto rangeField = new FieldDto("rangeField", "Range Field", TypeDto.STRING);
FieldDto regularFieldField = new FieldDto("regularField", "Regular Field", TypeDto.BOOLEAN);
FieldDto rangeFieldField = new FieldDto("rangeFieldDouble", "Range Field Double", TypeDto.DOUBLE);
EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg0Field, rangeField, regularFieldField, rangeFieldField));
lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
LookupFieldDto[][] expectedFields = { { lookupFieldDto("arg0"), lookupFieldDto("range", RANGE) }, { lookupFieldDto("regularField"), lookupFieldDto("rangeField", RANGE) } };
String[][] expectedFieldsOrder = { { "arg0", "range" }, { "regularField", "rangeField" } };
// test two methods, one with @LookupField annotations, second without
for (int i = 0; i < 2; i++) {
Method method = getTestMethodWithRangeParam(i);
when(paranamer.lookupParameterNames(method)).thenReturn(new String[] { "arg0", "range" });
LookupDto expectedLookup = new LookupDto("Test Method With Range Param " + i, false, false, asList(expectedFields[i]), true, "testMethodWithRangeParam" + i, asList(expectedFieldsOrder[i]), true);
lookupProcessor.process(method);
Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
assertTrue(elements.containsKey(TEST_CLASS_NAME));
List<LookupDto> list = elements.get(TEST_CLASS_NAME);
assertEquals(1, list.size());
assertEquals(expectedLookup, list.get(0));
assertEquals(asList(VALUE, RANGE), extract(list.get(0).getLookupFields(), on(LookupFieldDto.class).getType()));
lookupProcessor.clear();
}
}
use of org.motechproject.mds.dto.LookupFieldDto in project motech by motech.
the class LookupBuilder method body.
private String body() {
StringBuilder body = new StringBuilder();
body.append("java.util.List properties = new java.util.ArrayList();");
Map<String, String> jdoQueryVariables = new HashMap<>();
for (String lookupFieldName : lookup.getFieldsOrder()) {
boolean appendJdoVariableName = false;
FieldDto field = getLookupField(lookupFieldName);
// don't use lookupFieldName for fetching fields, as it can contain dots, etc.
LookupFieldDto lookupField = lookup.getLookupField(field.getBasic().getName());
FieldDto relationField = null;
if (lookupFieldName.contains(".")) {
EntityDto relatedEntity = schemaHolder.getEntityByClassName(new RelationshipHolder(field).getRelatedClass());
relationField = schemaHolder.getFieldByName(relatedEntity, LookupName.getRelatedFieldName(lookupFieldName));
}
TypeDto type = field.getType();
String typeClassName = resolveClassName(type, relationField);
body.append("properties.add(");
if (type.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
typeClassName = holder.getUnderlyingType();
body.append(resolvePropertyForCombobox(holder, type));
} else if (relationField != null && relationField.getType().isCombobox()) {
RelationshipHolder relationshipHolder = new RelationshipHolder(field);
EntityDto relatedEntity = schemaHolder.getEntityByClassName(relationshipHolder.getRelatedClass());
ComboboxHolder holder = new ComboboxHolder(relatedEntity, relationField);
typeClassName = holder.getUnderlyingType();
body.append(resolvePropertyForCombobox(holder, type));
addJdoVariableName(jdoQueryVariables, lookupFieldName);
appendJdoVariableName = needsJdoVariable(type);
} else if (relationField != null && (type.getTypeClass().equals(TypeDto.MANY_TO_MANY_RELATIONSHIP.getTypeClass()) || type.getTypeClass().equals(TypeDto.ONE_TO_MANY_RELATIONSHIP.getTypeClass()))) {
// related class collection
body.append(PropertyBuilder.class.getName());
body.append(".createRelationProperty");
addJdoVariableName(jdoQueryVariables, lookupFieldName);
appendJdoVariableName = true;
} else {
body.append(PropertyBuilder.class.getName());
body.append(".create");
}
body.append(buildPropertyParameters(appendJdoVariableName, lookupFieldName, lookupField, typeClassName, jdoQueryVariables));
}
body.append(buildReturn());
return body.toString();
}
Aggregations