Search in sources :

Example 6 with FacetFilter

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;
}
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 7 with FacetFilter

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;
}
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 8 with FacetFilter

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;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter)

Example 9 with FacetFilter

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;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) ClientPackageForMethod(com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod) URL(java.net.URL) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) WsdlInfo(com.webcohesion.enunciate.modules.jaxws.WsdlInfo)

Example 10 with FacetFilter

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);
    }
}
Also used : ServiceGroup(com.webcohesion.enunciate.api.services.ServiceGroup) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ServiceApi(com.webcohesion.enunciate.api.services.ServiceApi) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) ClientLibraryJavaArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryJavaArtifact) Artifact(com.webcohesion.enunciate.artifacts.Artifact) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) Namespace(com.webcohesion.enunciate.api.datatype.Namespace) ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) Syntax(com.webcohesion.enunciate.api.datatype.Syntax)

Aggregations

FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)33 EnunciateException (com.webcohesion.enunciate.EnunciateException)11 TemplateException (freemarker.template.TemplateException)10 URL (java.net.URL)10 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)7 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)7 TypeDefinition (com.webcohesion.enunciate.modules.jackson.model.TypeDefinition)7 ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)6 File (java.io.File)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 TypeElement (javax.lang.model.element.TypeElement)6 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)5 EnunciateJacksonContext (com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext)5 EnunciateJackson1Context (com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context)5 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)5 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)5 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)5 TypeMirror (javax.lang.model.type.TypeMirror)5 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)4