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;
}
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 resource class.
String description = null;
Set<com.webcohesion.enunciate.modules.jaxrs.model.Resource> definingResourceClasses = new TreeSet<com.webcohesion.enunciate.modules.jaxrs.model.Resource>(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).resourceMethod.getParent());
}
}
if ((methodCount > 1 || description == null) && definingResourceClasses.size() == 1) {
// if there's only one class, it's javadoc is probably a better description than the method-level.
description = definingResourceClasses.iterator().next().getDocValue();
}
return description;
}
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(controllerClass.getContext().getPathSortStrategy()));
return pathSummaries;
}
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 resource class.
String description = null;
Set<com.webcohesion.enunciate.modules.jaxrs.model.Resource> definingResourceClasses = new TreeSet<com.webcohesion.enunciate.modules.jaxrs.model.Resource>(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).resourceMethod.getParent());
}
}
if ((methodCount > 1 || description == null) && definingResourceClasses.size() == 1) {
description = definingResourceClasses.iterator().next().getDocValue();
}
return description;
}
use of com.webcohesion.enunciate.api.resources.Resource in project enunciate by stoicflame.
the class PathBasedResourceGroupImpl method getPaths.
@Override
public List<PathSummary> getPaths() {
Set<String> methods = new TreeSet<String>();
Set<String> styles = new TreeSet<String>();
for (Resource resource : this.resources) {
for (Method method : resource.getMethods()) {
methods.add(method.getHttpMethod());
styles.addAll(method.getStyles());
}
}
return Collections.singletonList((PathSummary) new PathSummaryImpl(this.path, methods, styles));
}
Aggregations