Search in sources :

Example 6 with Resource

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

the class ResourceClassResourceGroupImpl method getPaths.

@Override
public List<PathSummary> getPaths() {
    HashMap<String, PathSummary> summaries = new HashMap<String, PathSummary>();
    for (Resource resource : this.resources) {
        Set<String> methods = new TreeSet<String>();
        for (Method method : resource.getMethods()) {
            methods.add(method.getHttpMethod());
        }
        PathSummary summary = summaries.get(resource.getPath());
        if (summary == null) {
            summary = new PathSummaryImpl(resource.getPath(), methods, resource.getStyles());
            summaries.put(resource.getPath(), summary);
        } else {
            summary.getMethods().addAll(methods);
        }
    }
    ArrayList<PathSummary> pathSummaries = new ArrayList<PathSummary>(summaries.values());
    Collections.sort(pathSummaries, new PathSummaryComparator(resourceClass.getContext().getPathSortStrategy()));
    return pathSummaries;
}
Also used : PathSummaryComparator(com.webcohesion.enunciate.util.PathSummaryComparator) PathSummary(com.webcohesion.enunciate.api.PathSummary) Resource(com.webcohesion.enunciate.api.resources.Resource) Method(com.webcohesion.enunciate.api.resources.Method) ResourceMethod(com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod)

Example 7 with Resource

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

the class UniquePathParametersForMethod method exec.

public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The uniqueMediaTypesFor method must have a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = FreemarkerUtil.unwrap(from);
    Map<String, Parameter> uniquePathParams = new HashMap<String, Parameter>();
    if (unwrapped instanceof Resource) {
        Resource entity = (Resource) unwrapped;
        List<? extends Method> methods = entity.getMethods();
        if (methods != null) {
            for (Method method : methods) {
                List<? extends Parameter> params = method.getParameters();
                if (params != null) {
                    for (Parameter param : params) {
                        if (param.getTypeLabel().equals("path")) {
                            uniquePathParams.put(param.getName(), param);
                        }
                    }
                }
            }
        }
    }
    return uniquePathParams.values();
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) HashMap(java.util.HashMap) Resource(com.webcohesion.enunciate.api.resources.Resource) Parameter(com.webcohesion.enunciate.api.resources.Parameter) TemplateModel(freemarker.template.TemplateModel) Method(com.webcohesion.enunciate.api.resources.Method)

Example 8 with Resource

use of com.webcohesion.enunciate.api.resources.Resource 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 9 with Resource

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

the class AnnotationBasedResourceGroupImpl method getPaths.

@Override
public List<PathSummary> getPaths() {
    HashMap<String, PathSummary> paths = new HashMap<String, PathSummary>();
    for (Resource resource : this.resources) {
        PathSummary pathSummary = paths.get(resource.getPath());
        if (pathSummary == null) {
            pathSummary = new PathSummaryImpl(resource.getPath(), new TreeSet<String>(), resource.getStyles());
            paths.put(resource.getPath(), pathSummary);
        }
        for (Method method : resource.getMethods()) {
            pathSummary.getMethods().add(method.getHttpMethod());
        }
    }
    ArrayList<PathSummary> pathSummaries = new ArrayList<PathSummary>(paths.values());
    Collections.sort(pathSummaries, new PathSummaryComparator(sortStrategy));
    return pathSummaries;
}
Also used : PathSummaryComparator(com.webcohesion.enunciate.util.PathSummaryComparator) PathSummary(com.webcohesion.enunciate.api.PathSummary) Resource(com.webcohesion.enunciate.api.resources.Resource) Method(com.webcohesion.enunciate.api.resources.Method)

Example 10 with Resource

use of com.webcohesion.enunciate.api.resources.Resource 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

Method (com.webcohesion.enunciate.api.resources.Method)11 Resource (com.webcohesion.enunciate.api.resources.Resource)11 PathSummary (com.webcohesion.enunciate.api.PathSummary)4 TypeElementComparator (com.webcohesion.enunciate.javac.TypeElementComparator)4 PathSummaryComparator (com.webcohesion.enunciate.util.PathSummaryComparator)4 SpringController (com.webcohesion.enunciate.modules.spring_web.model.SpringController)2 Parameter (com.webcohesion.enunciate.api.resources.Parameter)1 ResourceMethod (com.webcohesion.enunciate.modules.jaxrs.model.ResourceMethod)1 TemplateModel (freemarker.template.TemplateModel)1 TemplateModelException (freemarker.template.TemplateModelException)1 HashMap (java.util.HashMap)1