Search in sources :

Example 1 with SpringController

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

Example 2 with SpringController

use of com.webcohesion.enunciate.modules.spring_web.model.SpringController in project enunciate by stoicflame.

the class EnunciateSpringWebContext method getResourceGroupsByPath.

public List<ResourceGroup> getResourceGroupsByPath(ApiRegistrationContext registrationContext) {
    Map<String, PathBasedResourceGroupImpl> resourcesByPath = new HashMap<String, PathBasedResourceGroupImpl>();
    FacetFilter facetFilter = registrationContext.getFacetFilter();
    for (SpringController springController : controllers) {
        if (!facetFilter.accept(springController)) {
            continue;
        }
        for (RequestMapping method : springController.getRequestMappings()) {
            if (facetFilter.accept(method)) {
                String path = method.getFullpath();
                PathBasedResourceGroupImpl resourceGroup = resourcesByPath.get(path);
                if (resourceGroup == null) {
                    resourceGroup = new PathBasedResourceGroupImpl(relativeContextPath, 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 : ResourceImpl(com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceImpl) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) PathBasedResourceGroupImpl(com.webcohesion.enunciate.modules.spring_web.api.impl.PathBasedResourceGroupImpl) SpringController(com.webcohesion.enunciate.modules.spring_web.model.SpringController) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup) RequestMapping(com.webcohesion.enunciate.modules.spring_web.model.RequestMapping)

Example 3 with SpringController

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

Example 4 with SpringController

use of com.webcohesion.enunciate.modules.spring_web.model.SpringController in project enunciate by stoicflame.

the class AnnotationBasedResourceGroupImpl method getDescription.

@Override
public String getDescription() {
    if (this.description == null) {
        return this.description;
    }
    // we'll return a description if all descriptions of all methods are the same, or if there's only one defining controller.
    String description = null;
    Set<SpringController> definingResourceClasses = new TreeSet<SpringController>(new TypeElementComparator());
    int methodCount = 0;
    RESOURCES: for (Resource resource : this.resources) {
        for (Method method : resource.getMethods()) {
            methodCount++;
            if (description != null && method.getDescription() != null && !description.equals(method.getDescription())) {
                description = null;
                break RESOURCES;
            }
            description = method.getDescription();
            if (description != null && description.trim().isEmpty()) {
                description = null;
            }
        }
        if (resource instanceof ResourceImpl) {
            definingResourceClasses.add(((ResourceImpl) resource).requestMapping.getParent());
        }
    }
    if ((methodCount > 1 || description == null) && definingResourceClasses.size() == 1) {
        description = definingResourceClasses.iterator().next().getDocValue();
    }
    return description;
}
Also used : TypeElementComparator(com.webcohesion.enunciate.javac.TypeElementComparator) Resource(com.webcohesion.enunciate.api.resources.Resource) Method(com.webcohesion.enunciate.api.resources.Method) SpringController(com.webcohesion.enunciate.modules.spring_web.model.SpringController)

Example 5 with SpringController

use of com.webcohesion.enunciate.modules.spring_web.model.SpringController in project enunciate by stoicflame.

the class PathBasedResourceGroupImpl method getDescription.

@Override
public String getDescription() {
    // we'll return a description if all descriptions of all methods are the same, or if there's only one defining controller.
    String description = null;
    Set<SpringController> definingResourceClasses = new TreeSet<SpringController>(new TypeElementComparator());
    int methodCount = 0;
    RESOURCES: for (Resource resource : this.resources) {
        for (Method method : resource.getMethods()) {
            methodCount++;
            if (description != null && method.getDescription() != null && !description.equals(method.getDescription())) {
                description = null;
                break RESOURCES;
            }
            description = method.getDescription();
            if (description != null && description.trim().isEmpty()) {
                description = null;
            }
        }
        if (resource instanceof ResourceImpl) {
            definingResourceClasses.add(((ResourceImpl) resource).requestMapping.getParent());
        }
    }
    if ((methodCount > 1 || description == null) && definingResourceClasses.size() == 1) {
        description = definingResourceClasses.iterator().next().getDocValue();
    }
    return description;
}
Also used : TypeElementComparator(com.webcohesion.enunciate.javac.TypeElementComparator) Resource(com.webcohesion.enunciate.api.resources.Resource) Method(com.webcohesion.enunciate.api.resources.Method) SpringController(com.webcohesion.enunciate.modules.spring_web.model.SpringController)

Aggregations

SpringController (com.webcohesion.enunciate.modules.spring_web.model.SpringController)5 ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)3 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)3 Method (com.webcohesion.enunciate.api.resources.Method)2 Resource (com.webcohesion.enunciate.api.resources.Resource)2 TypeElementComparator (com.webcohesion.enunciate.javac.TypeElementComparator)2 ResourceImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceImpl)2 RequestMapping (com.webcohesion.enunciate.modules.spring_web.model.RequestMapping)2 AnnotationBasedResourceGroupImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.AnnotationBasedResourceGroupImpl)1 PathBasedResourceGroupImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.PathBasedResourceGroupImpl)1 ResourceClassResourceGroupImpl (com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceClassResourceGroupImpl)1