Search in sources :

Example 6 with ResourceGroup

use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.

the class EnunciateJaxrsContext method getResourceGroupsByAnnotation.

public List<ResourceGroup> getResourceGroupsByAnnotation(ApiRegistrationContext registrationContext) {
    Map<String, AnnotationBasedResourceGroupImpl> resourcesByAnnotation = new HashMap<String, AnnotationBasedResourceGroupImpl>();
    FacetFilter facetFilter = registrationContext.getFacetFilter();
    for (RootResource rootResource : rootResources) {
        if (!facetFilter.accept(rootResource)) {
            continue;
        }
        for (ResourceMethod method : rootResource.getResourceMethods(true)) {
            if (facetFilter.accept(method)) {
                com.webcohesion.enunciate.metadata.rs.ResourceGroup annotation = AnnotationUtils.getResourceGroup(method);
                com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = method.getParent();
                while (annotation == null && resource != null) {
                    annotation = AnnotationUtils.getResourceGroup(resource);
                    resource = resource.getParent();
                }
                com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = method.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
                resource = method.getParent();
                while (context == null && resource != null) {
                    context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
                    resource = resource.getParent();
                }
                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) {
                    String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
                    resourceGroup = new AnnotationBasedResourceGroupImpl(contextPath, 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 : RootResource(com.webcohesion.enunciate.modules.jaxrs.model.RootResource) AnnotationBasedResourceGroupImpl(com.webcohesion.enunciate.modules.jaxrs.api.impl.AnnotationBasedResourceGroupImpl) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup) ResourceImpl(com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceImpl) ResourceMethod(com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod)

Example 7 with ResourceGroup

use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.

the class EnunciateSpringWebContext method getResourceGroupsByClass.

public List<ResourceGroup> getResourceGroupsByClass(ApiRegistrationContext registrationContext) {
    List<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>();
    Set<String> slugs = new TreeSet<String>();
    FacetFilter facetFilter = registrationContext.getFacetFilter();
    for (SpringController springController : controllers) {
        if (!facetFilter.accept(springController)) {
            continue;
        }
        String slug = springController.getSimpleName().toString();
        if (slugs.contains(slug)) {
            slug = "";
            String[] qualifiedNameTokens = springController.getQualifiedName().toString().split("\\.");
            for (int i = qualifiedNameTokens.length - 1; i >= 0; i--) {
                slug = slug.isEmpty() ? qualifiedNameTokens[i] : slug + "_" + qualifiedNameTokens[i];
                if (!slugs.contains(slug)) {
                    break;
                }
            }
        }
        slugs.add(slug);
        ResourceGroup group = new ResourceClassResourceGroupImpl(springController, slug, relativeContextPath, registrationContext);
        if (!group.getResources().isEmpty()) {
            resourceGroups.add(group);
        }
    }
    Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
    return resourceGroups;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ResourceClassResourceGroupImpl(com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceClassResourceGroupImpl) SpringController(com.webcohesion.enunciate.modules.spring_web.model.SpringController) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Aggregations

ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)7 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)6 RootResource (com.webcohesion.enunciate.modules.jaxrs.model.RootResource)3 SpringController (com.webcohesion.enunciate.modules.spring_web.model.SpringController)3 ResourceImpl (com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceImpl)2 ResourceMethod (com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod)2 ResourceImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceImpl)2 RequestMapping (com.webcohesion.enunciate.modules.spring_web.model.RequestMapping)2 DataType (com.webcohesion.enunciate.api.datatype.DataType)1 Property (com.webcohesion.enunciate.api.datatype.Property)1 Syntax (com.webcohesion.enunciate.api.datatype.Syntax)1 Value (com.webcohesion.enunciate.api.datatype.Value)1 Method (com.webcohesion.enunciate.api.resources.Method)1 ResourceApi (com.webcohesion.enunciate.api.resources.ResourceApi)1 Operation (com.webcohesion.enunciate.api.services.Operation)1 Service (com.webcohesion.enunciate.api.services.Service)1 ServiceApi (com.webcohesion.enunciate.api.services.ServiceApi)1 DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)1 DecoratedPackageElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedPackageElement)1 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)1