private static void addSectionsForResource(CollectInfo collectInfo, Resource resource) { for (String section : resource.getSections()) { if (collectInfo.getSection(section) == null) { collectInfo.addSection(new Section(section)); } } }
private static Resource getResource( CollectInfo collectInfo, Object restlet, String basePath, ChallengeScheme scheme) { Resource resource = new Resource(); resource.setResourcePath(basePath); if (restlet instanceof Directory) { Directory directory = (Directory) restlet; resource.setName(directory.getName()); resource.setDescription(directory.getDescription()); } if (restlet instanceof ServerResource) { ServerResource serverResource = (ServerResource) restlet; resource.setName(serverResource.getName()); resource.setDescription(serverResource.getDescription()); } if (restlet instanceof DocumentedResource) { DocumentedResource documentedServerResource = (DocumentedResource) restlet; resource.setSections(documentedServerResource.getSections()); } else if (collectInfo.isUseSectionNamingPackageStrategy()) { String sectionName = restlet.getClass().getPackage().getName(); resource.getSections().add(sectionName); } if (StringUtils.isNullOrEmpty(resource.getName())) { String name = restlet.getClass().getSimpleName(); if (name.endsWith(SUFFIX_SERVER_RESOURCE) && name.length() > SUFFIX_SERVER_RESOURCE.length()) { name = name.substring(0, name.length() - SUFFIX_SERVER_RESOURCE.length()); } if (name.endsWith(SUFFIX_RESOURCE) && name.length() > SUFFIX_RESOURCE.length()) { name = name.substring(0, name.length() - SUFFIX_RESOURCE.length()); } resource.setName(name); } Template template = new Template(basePath); for (String variable : template.getVariableNames()) { PathVariable pathVariable = new PathVariable(); pathVariable.setName(variable); resource.getPathVariables().add(pathVariable); } if (scheme != null) { resource.setAuthenticationProtocol(scheme.getName()); } return resource; }
public static void collectResource( CollectInfo collectInfo, Directory directory, String basePath, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { Resource resource = getResource(collectInfo, directory, basePath, scheme); // add operations ArrayList<Operation> operations = new ArrayList<>(); operations.add(getOperationFromMethod(Method.GET)); if (directory.isModifiable()) { operations.add(getOperationFromMethod(Method.DELETE)); operations.add(getOperationFromMethod(Method.PUT)); } resource.setOperations(operations); for (IntrospectionHelper helper : introspectionHelper) { helper.processResource(resource, directory.getClass()); } addSectionsForResource(collectInfo, resource); collectInfo.addResource(resource); }
public static void collectResource( CollectInfo collectInfo, ServerResource sr, String basePath, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { Resource resource = getResource(collectInfo, sr, basePath, scheme); // add operations ArrayList<Operation> operations = new ArrayList<>(); List<AnnotationInfo> annotations = sr.isAnnotated() ? AnnotationUtils.getInstance().getAnnotations(sr.getClass()) : null; if (annotations != null) { for (AnnotationInfo annotationInfo : annotations) { if (annotationInfo instanceof MethodAnnotationInfo) { MethodAnnotationInfo methodAnnotationInfo = (MethodAnnotationInfo) annotationInfo; Method method = methodAnnotationInfo.getRestletMethod(); Operation operation = getOperationFromMethod(method); if (StringUtils.isNullOrEmpty(operation.getName())) { operation.setName(methodAnnotationInfo.getJavaMethod().getName()); } completeOperation(collectInfo, operation, methodAnnotationInfo, sr, introspectionHelper); for (IntrospectionHelper helper : introspectionHelper) { List<Class<?>> representationClasses = helper.processOperation( resource, operation, sr.getClass(), methodAnnotationInfo.getJavaMethod()); if (representationClasses != null && !representationClasses.isEmpty()) { for (Class<?> representationClazz : representationClasses) { TypeInfo typeInfo; try { typeInfo = Types.getTypeInfo(representationClazz, null); } catch (UnsupportedTypeException e) { LOGGER.warning( "Could not add representation class " + representationClazz.getName() + ". " + e.getMessage()); continue; } RepresentationCollector.addRepresentation( collectInfo, typeInfo, introspectionHelper); } } } operations.add(operation); } } if (!operations.isEmpty()) { sortOperationsByMethod(operations); resource.setOperations(operations); addSectionsForResource(collectInfo, resource); collectInfo.addResource(resource); } else { LOGGER.warning("Resource " + resource.getName() + " has no methods."); } } else { LOGGER.warning("Resource " + resource.getName() + " has no methods."); } for (IntrospectionHelper helper : introspectionHelper) { helper.processResource(resource, sr.getClass()); } }