Search in sources :

Example 1 with ResourceClassResourceGroupImpl

use of com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceClassResourceGroupImpl in project enunciate by stoicflame.

the class EnunciateJaxrsContext 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 (RootResource rootResource : rootResources) {
        if (!facetFilter.accept(rootResource)) {
            continue;
        }
        String slug = rootResource.getSimpleName().toString();
        if (slugs.contains(slug)) {
            slug = "";
            String[] qualifiedNameTokens = rootResource.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);
        com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = rootResource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
        com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = rootResource.getParent();
        while (context == null && resource != null) {
            context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
            resource = resource.getParent();
        }
        String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
        ResourceGroup group = new ResourceClassResourceGroupImpl(rootResource, slug, contextPath, registrationContext);
        if (!group.getResources().isEmpty()) {
            resourceGroups.add(group);
        }
    }
    Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
    return resourceGroups;
}
Also used : RootResource(com.webcohesion.enunciate.modules.jaxrs.model.RootResource) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ResourceClassResourceGroupImpl(com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceClassResourceGroupImpl) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Aggregations

ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)1 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 ResourceClassResourceGroupImpl (com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceClassResourceGroupImpl)1 RootResource (com.webcohesion.enunciate.modules.jaxrs.model.RootResource)1