Search in sources :

Example 1 with ResourceMethod

use of com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod in project enunciate by stoicflame.

the class EnunciateJaxrsContext method getResourceGroupsByPath.

public List<ResourceGroup> getResourceGroupsByPath(ApiRegistrationContext registrationContext) {
    Map<String, PathBasedResourceGroupImpl> resourcesByPath = new HashMap<String, PathBasedResourceGroupImpl>();
    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.ServiceContextRoot context = method.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
                com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = method.getParent();
                while (context == null && resource != null) {
                    context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
                    resource = resource.getParent();
                }
                String path = method.getFullpath();
                PathBasedResourceGroupImpl resourceGroup = resourcesByPath.get(path);
                if (resourceGroup == null) {
                    String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
                    resourceGroup = new PathBasedResourceGroupImpl(contextPath, path, new ArrayList<Resource>());
                    resourcesByPath.put(path, resourceGroup);
                }
                resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
            }
        }
    }
    ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByPath.values());
    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) PathBasedResourceGroupImpl(com.webcohesion.enunciate.modules.jaxrs.api.impl.PathBasedResourceGroupImpl) ResourceImpl(com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceImpl) ResourceMethod(com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Example 2 with ResourceMethod

use of com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod in project enunciate by stoicflame.

the class StatusCodeImpl method getMediaTypes.

@Override
public List<? extends MediaTypeDescriptor> getMediaTypes() {
    ArrayList<MediaTypeDescriptor> mts = new ArrayList<MediaTypeDescriptor>();
    DecoratedTypeMirror type = this.responseCode.getType();
    if (type != null) {
        ResourceMethod resourceMethod = this.responseCode.getResourceMethod();
        Set<MediaType> produces = resourceMethod.getProducesMediaTypes();
        for (com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType mt : produces) {
            for (Syntax syntax : resourceMethod.getContext().getContext().getApiRegistry().getSyntaxes(registrationContext)) {
                MediaTypeDescriptor descriptor = syntax.findMediaTypeDescriptor(mt.getMediaType(), type);
                if (descriptor != null) {
                    mts.add(new MediaTypeDescriptorImpl(descriptor, mt, descriptor.getExample()));
                }
            }
        }
    }
    return mts;
}
Also used : DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) ArrayList(java.util.ArrayList) MediaTypeDescriptor(com.webcohesion.enunciate.api.resources.MediaTypeDescriptor) MediaType(com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType) MediaType(com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType) Syntax(com.webcohesion.enunciate.api.datatype.Syntax) ResourceMethod(com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod)

Example 3 with ResourceMethod

use of com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod 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)

Aggregations

ResourceMethod (com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod)3 ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)2 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)2 ResourceImpl (com.webcohesion.enunciate.modules.jaxrs.api.impl.ResourceImpl)2 RootResource (com.webcohesion.enunciate.modules.jaxrs.model.RootResource)2 Syntax (com.webcohesion.enunciate.api.datatype.Syntax)1 MediaTypeDescriptor (com.webcohesion.enunciate.api.resources.MediaTypeDescriptor)1 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 AnnotationBasedResourceGroupImpl (com.webcohesion.enunciate.modules.jaxrs.api.impl.AnnotationBasedResourceGroupImpl)1 PathBasedResourceGroupImpl (com.webcohesion.enunciate.modules.jaxrs.api.impl.PathBasedResourceGroupImpl)1 MediaType (com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType)1 ArrayList (java.util.ArrayList)1