Search in sources :

Example 31 with FacetFilter

use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.

the class SyntaxImpl method getTypes.

@Override
public List<? extends DataType> getTypes() {
    Collection<TypeDefinition> typeDefinitions = this.context.getTypeDefinitions();
    ArrayList<DataType> dataTypes = new ArrayList<DataType>();
    FacetFilter facetFilter = registrationContext.getFacetFilter();
    for (TypeDefinition typeDefinition : typeDefinitions) {
        if (!facetFilter.accept(typeDefinition)) {
            continue;
        }
        if (typeDefinition instanceof ObjectTypeDefinition) {
            dataTypes.add(new ObjectDataTypeImpl((ObjectTypeDefinition) typeDefinition, registrationContext));
        } else if (typeDefinition instanceof EnumTypeDefinition) {
            dataTypes.add(new EnumDataTypeImpl((EnumTypeDefinition) typeDefinition, registrationContext));
        }
    }
    Collections.sort(dataTypes, new Comparator<DataType>() {

        @Override
        public int compare(DataType o1, DataType o2) {
            return o1.getLabel().compareTo(o2.getLabel());
        }
    });
    return dataTypes;
}
Also used : ObjectTypeDefinition(com.webcohesion.enunciate.modules.jackson1.model.ObjectTypeDefinition) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) EnumTypeDefinition(com.webcohesion.enunciate.modules.jackson1.model.EnumTypeDefinition) TypeDefinition(com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition) EnumTypeDefinition(com.webcohesion.enunciate.modules.jackson1.model.EnumTypeDefinition) ObjectTypeDefinition(com.webcohesion.enunciate.modules.jackson1.model.ObjectTypeDefinition)

Example 32 with FacetFilter

use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.

the class EnunciateSpringWebContext 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 (SpringController springController : controllers) {
        if (!facetFilter.accept(springController)) {
            continue;
        }
        String slug = springController.getSimpleName().toString();
        if (slugs.contains(slug)) {
            slug = "";
            String[] qualifiedNameTokens = springController.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);
        ResourceGroup group = new ResourceClassResourceGroupImpl(springController, slug, relativeContextPath, registrationContext);
        if (!group.getResources().isEmpty()) {
            resourceGroups.add(group);
        }
    }
    Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
    return resourceGroups;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ResourceClassResourceGroupImpl(com.webcohesion.enunciate.modules.spring_web.api.impl.ResourceClassResourceGroupImpl) SpringController(com.webcohesion.enunciate.modules.spring_web.model.SpringController) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Example 33 with FacetFilter

use of com.webcohesion.enunciate.facets.FacetFilter in project enunciate by stoicflame.

the class RubyJSONClientModule method call.

@Override
public void call(EnunciateContext context) {
    if ((this.jacksonModule == null || this.jacksonModule.getJacksonContext() == null || this.jacksonModule.getJacksonContext().getTypeDefinitions().isEmpty()) && (this.jackson1Module == null || this.jackson1Module.getJacksonContext() == null || this.jackson1Module.getJacksonContext().getTypeDefinitions().isEmpty())) {
        info("No Jackson JSON data types: Ruby JSON client will not be generated.");
        return;
    }
    detectAccessorNamingErrors();
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the Ruby JSON client. Ruby JSON client will not be generated.");
        return;
    }
    Map<String, String> packageToModuleConversions = getPackageToModuleConversions();
    List<DecoratedTypeElement> schemaTypes = new ArrayList<DecoratedTypeElement>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    EnunciateJacksonContext jacksonContext = null;
    EnunciateJackson1Context jackson1Context = null;
    if (this.jacksonModule != null) {
        jacksonContext = this.jacksonModule.getJacksonContext();
        for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToModuleConversions.containsKey(pckg)) {
                packageToModuleConversions.put(pckg, packageToModule(pckg));
            }
            int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
            if (position < 0) {
                position = -position - 1;
            }
            schemaTypes.add(position, typeDefinition);
        }
    }
    if (this.jackson1Module != null) {
        jackson1Context = this.jackson1Module.getJacksonContext();
        for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToModuleConversions.containsKey(pckg)) {
                packageToModuleConversions.put(pckg, packageToModule(pckg));
            }
            schemaTypes.add(typeDefinition);
        }
    }
    File srcDir = getSourceDir();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("schemaTypes", schemaTypes);
    model.put("schemaTypes", schemaTypes);
    model.put("packages2modules", packageToModuleConversions);
    model.put("moduleFor", new ClientPackageForMethod(packageToModuleConversions, this.context));
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToModuleConversions, jacksonContext, jackson1Context);
    model.put("classnameFor", classnameFor);
    SimpleNameWithParamsMethod simpleNameFor = new SimpleNameWithParamsMethod(classnameFor);
    model.put("simpleNameFor", simpleNameFor);
    model.put("rubyFileName", getSourceFileName());
    model.put("file", new FileDirective(srcDir, 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));
    if (!isUpToDateWithSources(srcDir)) {
        debug("Generating the Ruby JSON data classes...");
        URL apiTemplate = getTemplateURL("api.fmt");
        try {
            processTemplate(apiTemplate, model);
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping Ruby code generation because everything appears up-to-date.");
    }
    ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "ruby.json.client.library", "Ruby JSON Client Library");
    artifactBundle.setPlatform("Ruby");
    FileArtifact sourceScript = new FileArtifact(getName(), "ruby.json.client", new File(srcDir, getSourceFileName()));
    // binaries and sources are the same thing in ruby
    sourceScript.setArtifactType(ArtifactType.binaries);
    sourceScript.setPublic(false);
    // read in the description from file
    String description = readResource("library_description.fmt", model);
    artifactBundle.setDescription(description);
    artifactBundle.addArtifact(sourceScript);
    this.enunciate.addArtifact(artifactBundle);
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jackson.model.TypeDefinition) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateJackson1Context(com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context) TemplateException(freemarker.template.TemplateException) EnunciateJacksonContext(com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext) IOException(java.io.IOException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) File(java.io.File)

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