use of com.webcohesion.enunciate.facets.FacetFilter 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;
}
use of com.webcohesion.enunciate.facets.FacetFilter 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;
}
use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.
the class ServiceGroupImpl method getServices.
@Override
public List<? extends Service> getServices() {
ArrayList<Service> services = new ArrayList<Service>();
FacetFilter facetFilter = this.registrationContext.getFacetFilter();
for (EndpointInterface endpointInterface : this.wsdlInfo.getEndpointInterfaces()) {
if (!facetFilter.accept(endpointInterface)) {
continue;
}
services.add(new ServiceImpl(endpointInterface, "", registrationContext));
}
Collections.sort(services, new Comparator<Service>() {
@Override
public int compare(Service o1, Service o2) {
return o1.getLabel().compareTo(o2.getLabel());
}
});
return services;
}
use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.
the class ServiceImpl method getOperations.
@Override
public List<? extends Operation> getOperations() {
ArrayList<Operation> operations = new ArrayList<Operation>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (WebMethod webMethod : this.ei.getWebMethods()) {
if (facetFilter.accept(webMethod)) {
operations.add(new OperationImpl(webMethod, this, registrationContext));
}
}
return operations;
}
use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.
the class GWTJSONOverlayModule method generateClientSources.
protected File generateClientSources() {
File sourceDir = getSourceDir();
sourceDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> conversions = getClientPackageConversions();
EnunciateJacksonContext jacksonContext = this.jacksonModule != null ? this.jacksonModule.getJacksonContext() : null;
EnunciateJackson1Context jackson1Context = this.jackson1Module != null ? this.jackson1Module.getJacksonContext() : null;
MergedJsonContext jsonContext = new MergedJsonContext(jacksonContext, jackson1Context);
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jsonContext);
model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
model.put("classnameFor", classnameFor);
model.put("simpleNameFor", new SimpleNameForMethod(classnameFor, jsonContext));
model.put("isAccessorOfTypeLong", new IsAccessorOfTypeLongMethod());
model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
facetIncludes.addAll(getFacetIncludes());
Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
facetExcludes.addAll(getFacetExcludes());
FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
boolean upToDate = isUpToDateWithSources(sourceDir);
if (!upToDate) {
try {
debug("Generating the GWT JSON Overlay...");
if (jacksonContext != null) {
for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
processTemplate(template, model);
}
}
}
if (jackson1Context != null) {
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
processTemplate(template, model);
}
}
}
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping generation of GWT JSON Overlay as everything appears up-to-date...");
}
context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return sourceDir;
}
Aggregations