use of org.motechproject.mds.annotations.Lookup in project motech by motech.
the class LookupProcessor method process.
@Override
protected void process(AnnotatedElement annotatedElement) {
Method method = (Method) annotatedElement;
Class returnType = method.getReturnType();
String returnClassName = returnType.getName();
boolean singleObjectReturn = true;
if (returnType.isArray() || Collection.class.isAssignableFrom(returnType)) {
singleObjectReturn = false;
returnClassName = determineGenericClass(method.getGenericReturnType().toString());
}
EntityDto entity = findEntityByClassName(returnClassName);
if (entity == null) {
LOGGER.error("There's no matching entity for the resolved return type of the lookup" + "method: {}; Resolved return type: {}", method.getName(), returnClassName);
return;
}
LOGGER.debug("Found entity class by the return type of lookup method: {}", entity.getName());
Lookup annotation = ReflectionsUtil.findAnnotation(method, Lookup.class);
String lookupName = generateLookupName(annotation.name(), method.getName());
List<LookupFieldDto> lookupFields = findLookupFields(method, entity);
boolean restExposed = processRestExposed(method);
boolean indexRequired = annotation.indexRequired();
verifyLookupParameters(method, returnClassName, lookupName, lookupFields, method.getParameterTypes());
LookupDto lookup = new LookupDto();
lookup.setSingleObjectReturn(singleObjectReturn);
lookup.setLookupName(lookupName);
lookup.setLookupFields(lookupFields);
lookup.setReadOnly(true);
lookup.setMethodName(method.getName());
lookup.setIndexRequired(indexRequired);
if (!restOptionsModifiedByUser(entity)) {
lookup.setExposedViaRest(restExposed);
}
if (!getElements().containsKey(returnClassName)) {
put(returnClassName, new ArrayList<>());
}
getElement(returnClassName).add(lookup);
}
Aggregations