Search in sources :

Example 1 with AnnotationBasedResourceGroupImpl

use of com.webcohesion.enunciate.modules.spring_web.api.impl.AnnotationBasedResourceGroupImpl in project enunciate by stoicflame.

the class EnunciateSpringWebContext method getResourceGroupsByAnnotation.

public List<ResourceGroup> getResourceGroupsByAnnotation(ApiRegistrationContext registrationContext) {
    Map<String, AnnotationBasedResourceGroupImpl> resourcesByAnnotation = new HashMap<String, AnnotationBasedResourceGroupImpl>();
    FacetFilter facetFilter = registrationContext.getFacetFilter();
    for (SpringController springController : controllers) {
        if (!facetFilter.accept(springController)) {
            continue;
        }
        com.webcohesion.enunciate.metadata.rs.ResourceGroup controllerAnnotation = null;
        boolean controllerAnnotationEvaluated = false;
        for (RequestMapping method : springController.getRequestMappings()) {
            if (facetFilter.accept(method)) {
                com.webcohesion.enunciate.metadata.rs.ResourceGroup annotation = AnnotationUtils.getResourceGroup(method);
                if (annotation == null) {
                    if (!controllerAnnotationEvaluated) {
                        controllerAnnotation = AnnotationUtils.getResourceGroup(springController);
                        controllerAnnotationEvaluated = true;
                    }
                    annotation = controllerAnnotation;
                }
                String label = annotation == null ? "Other" : annotation.value();
                String description = annotation == null ? null : annotation.description();
                if ("##default".equals(description)) {
                    description = null;
                }
                AnnotationBasedResourceGroupImpl resourceGroup = resourcesByAnnotation.get(label);
                if (resourceGroup == null) {
                    resourceGroup = new AnnotationBasedResourceGroupImpl(relativeContextPath, label, new SortedList<Resource>(new ResourceComparator(this.pathSortStrategy)), this.pathSortStrategy);
                    resourcesByAnnotation.put(label, resourceGroup);
                }
                resourceGroup.setDescriptionIfNull(description);
                resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
            }
        }
    }
    ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByAnnotation.values());
    Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
    return resourceGroups;
}
Also used : AnnotationBasedResourceGroupImpl(com.webcohesion.enunciate.modules.spring_web.api.impl.AnnotationBasedResourceGroupImpl) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) RequestMapping(com.webcohesion.enunciate.modules.spring_web.model.RequestMapping) ResourceImpl(com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceImpl) SpringController(com.webcohesion.enunciate.modules.spring_web.model.SpringController) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Aggregations

ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)1 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 AnnotationBasedResourceGroupImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.AnnotationBasedResourceGroupImpl)1 ResourceImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceImpl)1 RequestMapping (com.webcohesion.enunciate.modules.spring_web.model.RequestMapping)1 SpringController (com.webcohesion.enunciate.modules.spring_web.model.SpringController)1