Search in sources :

Example 1 with Lookup

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);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) Collection(java.util.Collection) Lookup(org.motechproject.mds.annotations.Lookup) Method(java.lang.reflect.Method) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Aggregations

Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 Lookup (org.motechproject.mds.annotations.Lookup)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 LookupDto (org.motechproject.mds.dto.LookupDto)1 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)1