use of com.webcohesion.enunciate.facets.FacetFilter 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;
}
use of com.webcohesion.enunciate.facets.FacetFilter 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;
}
use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.
the class ComplexDataTypeImpl method getProperties.
@Override
public List<? extends Property> getProperties() {
ArrayList<Property> properties = new ArrayList<Property>();
FacetFilter facetFilter = this.registrationContext.getFacetFilter();
List<Property> attributeProperties = new ArrayList<Property>();
for (Attribute attribute : this.typeDefinition.getAttributes()) {
if (!facetFilter.accept(attribute)) {
continue;
}
attributeProperties.add(new PropertyImpl(attribute, registrationContext));
}
if (this.typeDefinition.getPropertyOrder() == null) {
// if the property order isn't explicit, sort the attributes by name, then add them to the list.
Collections.sort(attributeProperties, new Comparator<Property>() {
@Override
public int compare(Property o1, Property o2) {
return o1.getName().compareTo(o2.getName());
}
});
}
properties.addAll(attributeProperties);
if (this.typeDefinition.getValue() != null) {
properties.add(new PropertyImpl(this.typeDefinition.getValue(), registrationContext));
} else {
List<Property> elementProperties = new ArrayList<Property>();
for (Element element : this.typeDefinition.getElements()) {
if (!facetFilter.accept(element)) {
continue;
}
boolean wrapped = element.isWrapped();
String wrapperName = wrapped ? element.getWrapperName() : null;
String wrapperNamespace = wrapped ? element.getWrapperNamespace() : null;
for (Element choice : element.getChoices()) {
elementProperties.add(wrapped ? new WrappedPropertyImpl(choice, wrapperName, wrapperNamespace, registrationContext) : new PropertyImpl(choice, registrationContext));
}
}
if (this.typeDefinition.getPropertyOrder() == null) {
// if the property order isn't explicit, sort the elements by name, then add them to the list.
Collections.sort(elementProperties, new Comparator<Property>() {
@Override
public int compare(Property o1, Property o2) {
return o1.getName().compareTo(o2.getName());
}
});
}
properties.addAll(elementProperties);
}
return properties;
}
use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.
the class CSharpXMLClientModule method generateSources.
private File generateSources(Map<String, String> packageToNamespaceConversions) {
File srcDir = getSourceDir();
srcDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
ClientPackageForMethod namespaceFor = new ClientPackageForMethod(packageToNamespaceConversions, this.context);
Collection<WsdlInfo> wsdls = new ArrayList<WsdlInfo>();
if (this.jaxwsModule != null) {
wsdls = this.jaxwsModule.getJaxwsContext().getWsdls().values();
}
model.put("wsdls", wsdls);
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
model.put("schemas", jaxbContext.getSchemas().values());
model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
model.put("namespaceFor", namespaceFor);
model.put("findRootElement", new FindRootElementMethod(jaxbContext));
model.put("requestDocumentQName", new RequestDocumentQNameMethod());
model.put("responseDocumentQName", new ResponseDocumentQNameMethod());
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
model.put("classnameFor", classnameFor);
model.put("listsAsArraysClassnameFor", new ListsAsArraysClientClassnameForMethod(packageToNamespaceConversions, jaxbContext));
model.put("simpleNameFor", new SimpleNameFor(classnameFor));
model.put("csFileName", getSourceFileName());
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
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));
if (!isUpToDateWithSources(srcDir)) {
debug("Generating the C# client classes...");
URL apiTemplate = isSingleFilePerClass() ? getTemplateURL("api-multiple-files.fmt") : getTemplateURL("api.fmt");
try {
processTemplate(apiTemplate, model);
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping C# code generation because everything appears up-to-date.");
}
this.context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return srcDir;
}
use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.
the class DocsModule method call.
@Override
public void call(EnunciateContext context) {
try {
File docsDir = getDocsDir();
String subDir = getDocsSubdir();
if (subDir != null) {
docsDir = new File(docsDir, subDir);
}
if (!isUpToDateWithSources(docsDir)) {
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);
ApiRegistrationContext registrationContext = new DocsRegistrationContext(this.apiRegistry, facetFilter);
List<ResourceApi> resourceApis = this.apiRegistry.getResourceApis(registrationContext);
Set<Syntax> syntaxes = this.apiRegistry.getSyntaxes(registrationContext);
List<ServiceApi> serviceApis = this.apiRegistry.getServiceApis(registrationContext);
Set<Artifact> documentationArtifacts = findDocumentationArtifacts();
if (syntaxes.isEmpty() && serviceApis.isEmpty() && resourceApis.isEmpty() && documentationArtifacts.isEmpty()) {
warn("No documentation generated: there are no data types, services, or resources to document.");
return;
}
// make sure the docs dir exists.
docsDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
String intro = this.enunciate.getConfiguration().readDescription(context, false, registrationContext.getTagHandler());
if (intro != null) {
model.put("apiDoc", intro);
}
String copyright = this.enunciate.getConfiguration().getCopyright();
if (copyright != null) {
model.put("copyright", copyright);
}
String title = this.enunciate.getConfiguration().getTitle();
model.put("title", title == null ? "Web Service API" : title);
// extract out the documentation base
String cssPath = buildBase(docsDir);
if (cssPath != null) {
model.put("cssFile", cssPath);
}
model.put("file", new FileDirective(docsDir, this.enunciate.getLogger()));
model.put("apiRelativePath", getRelativePathToRootDir());
model.put("includeApplicationPath", isIncludeApplicationPath());
model.put("includeDataTypesHomeIndex", isIncludeDataTypesHomeIndex());
model.put("favicon", getFavicon());
// iterate through schemas and make sure the schema is copied to the docs dir
for (Syntax syntax : syntaxes) {
for (Namespace namespace : syntax.getNamespaces()) {
if (namespace.getSchemaFile() != null) {
namespace.getSchemaFile().writeTo(docsDir);
}
}
}
model.put("data", syntaxes);
for (ResourceApi resourceApi : resourceApis) {
if (resourceApi.getWadlFile() != null) {
resourceApi.getWadlFile().writeTo(docsDir);
}
}
model.put("resourceApis", resourceApis);
InterfaceDescriptionFile swaggerUI = this.apiRegistry.getSwaggerUI();
if (swaggerUI != null) {
swaggerUI.writeTo(docsDir);
model.put("swaggerUI", swaggerUI);
}
// iterate through wsdls and make sure the wsdl is copied to the docs dir
for (ServiceApi serviceApi : serviceApis) {
for (ServiceGroup serviceGroup : serviceApi.getServiceGroups()) {
if (serviceGroup.getWsdlFile() != null) {
serviceGroup.getWsdlFile().writeTo(docsDir);
}
}
}
model.put("serviceApis", serviceApis);
model.put("downloads", copyDocumentationArtifacts(documentationArtifacts, docsDir));
model.put("indexPageName", getIndexPageName());
model.put("disableMountpoint", isDisableRestMountpoint());
model.put("additionalCssFiles", getAdditionalCss());
model.put("disableResourceLinks", isDisableResourceLinks());
processTemplate(getDocsTemplateURL(), model);
} else {
info("Skipping documentation source generation as everything appears up-to-date...");
}
this.enunciate.addArtifact(new FileArtifact(getName(), "docs", docsDir));
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
}
Aggregations