private boolean lookupPermitted(boolean childLookup, ControllerMethod cm) { ChildrenOf anno = (ChildrenOf) cm.anno; if (childLookup) { return anno.allowChildLookups(); } return true; }
public Set<AnnoResource> execute(AnnoCollectionResource parent, boolean isChildLookup) throws NotAuthorizedException, BadRequestException, NotFoundException, Exception { Set<AnnoResource> result = new HashSet<AnnoResource>(); List<ControllerMethod> candidateMethods = getMethods(parent.source.getClass()); // Find any override methods Set<Class> overrideSourceTypes = new HashSet<Class>(); for (ControllerMethod cm : candidateMethods) { ChildrenOf anno = (ChildrenOf) cm.anno; if (anno.override()) { overrideSourceTypes.add(cm.sourceType); } } // If we have override methods, then remove any methods targeting base classes of the override // source types if (overrideSourceTypes.size() > 0) { Iterator<ControllerMethod> it = candidateMethods.iterator(); while (it.hasNext()) { Class sourceType = it.next().sourceType; for (Class overrideClass : overrideSourceTypes) { if (overrideClass != sourceType && sourceType.isAssignableFrom(overrideClass)) { it.remove(); break; } } } } for (ControllerMethod cm : candidateMethods) { try { if (lookupPermitted(isChildLookup, cm)) { Object o = invoke(cm, parent); annoResourceFactory.createAndAppend(result, o, parent, cm); } } catch (NotAuthorizedException e) { throw e; } catch (BadRequestException e) { throw e; } catch (NotFoundException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } } return result; }