Search in sources :

Example 26 with ExtensionDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.

the class JavaDeclarationDelegateTestCase method categoryDefaultValueIsDescribedCorrectly.

@Test
public void categoryDefaultValueIsDescribedCorrectly() {
    setLoader(loaderFor(PetStoreConnector.class));
    ExtensionDeclarer declarer = declareExtension();
    final ExtensionDeclaration declaration = declarer.getDeclaration();
    assertThat(declaration.getCategory(), is(COMMUNITY));
}
Also used : PetStoreConnector(org.mule.test.petstore.extension.PetStoreConnector) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 27 with ExtensionDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.

the class ErrorsDeclarationEnricher method collectErrorOperations.

private List<Pair<ComponentDeclaration, MethodElement>> collectErrorOperations(ExtensionDeclaration declaration) {
    List<Pair<ComponentDeclaration, MethodElement>> operations = new LinkedList<>();
    new IdempotentDeclarationWalker() {

        @Override
        public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
            addComponent(declaration);
        }

        @Override
        protected void onConstruct(ConstructDeclaration declaration) {
            addComponent(declaration);
        }

        private void addComponent(ComponentDeclaration<?> declaration) {
            declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class).ifPresent(implementingMethodModelProperty -> operations.add(new Pair<>(declaration, implementingMethodModelProperty.getOperationMethod())));
        }
    }.walk(declaration);
    return operations;
}
Also used : MuleExtensionUtils.getExtensionsNamespace(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getExtensionsNamespace) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) MuleErrors(org.mule.runtime.extension.api.error.MuleErrors) ConstructDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclaration) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) Pair(org.mule.runtime.api.util.Pair) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) LinkedList(java.util.LinkedList) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) ComponentDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ComponentDeclaration) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Throws(org.mule.runtime.extension.api.annotation.error.Throws) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) List(java.util.List) Stream(java.util.stream.Stream) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) INITIALIZE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ConstructDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclaration) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) LinkedList(java.util.LinkedList) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) Pair(org.mule.runtime.api.util.Pair)

Example 28 with ExtensionDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.

the class ErrorsDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    String extensionNamespace = getExtensionsNamespace(declaration);
    Optional<ExtensionTypeDescriptorModelProperty> implementingType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    ErrorsModelFactory errorModelDescriber = new ErrorsModelFactory(extensionNamespace);
    errorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
    if (implementingType.isPresent() && implementingType.get().getType().getDeclaringClass().isPresent()) {
        Type extensionElement = implementingType.get().getType();
        Optional<ErrorTypes> errorAnnotation = extensionElement.getAnnotation(ErrorTypes.class);
        List<Pair<ComponentDeclaration, MethodElement>> errorOperations = collectErrorOperations(declaration);
        if (errorAnnotation.isPresent()) {
            ErrorTypeDefinition<?>[] errorTypes = (ErrorTypeDefinition<?>[]) errorAnnotation.get().value().getEnumConstants();
            if (errorTypes.length > 0) {
                ErrorsModelFactory operationErrorModelDescriber = new ErrorsModelFactory(errorTypes, extensionNamespace);
                operationErrorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
                errorOperations.stream().forEach(pair -> registerOperationErrorTypes(pair.getSecond(), pair.getFirst(), operationErrorModelDescriber, errorTypes, extensionElement));
            } else {
                handleNoErrorTypes(extensionElement, errorOperations);
            }
        } else {
            handleNoErrorTypes(extensionElement, errorOperations);
        }
    }
}
Also used : ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) Pair(org.mule.runtime.api.util.Pair)

Example 29 with ExtensionDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.

the class ExtensionDescriptionsEnricher method document.

/**
 * Fills all the descriptions in the provided {@link ExtensionDeclaration} based on the
 * <strong>extensions-descriptions.xml</strong> file.
 *
 * @param declaration   the declaration to describe.
 * @param documentation the extension documentation with its corresponding description.
 */
private void document(ExtensionDeclaration declaration, XmlExtensionDocumentation documentation) {
    declaration.setDescription(documentation.getExtension().getDescription());
    new DeclarationWalker() {

        @Override
        protected void onConfiguration(ConfigurationDeclaration declaration) {
            document(declaration, documentation.getConfigs());
        }

        @Override
        protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
            document(declaration, documentation.getOperations());
        }

        @Override
        protected void onConnectionProvider(ConnectedDeclaration owner, ConnectionProviderDeclaration declaration) {
            document(declaration, documentation.getConnections());
        }

        @Override
        protected void onSource(WithSourcesDeclaration owner, SourceDeclaration declaration) {
            document(declaration, documentation.getSources());
        }

        private void document(ParameterizedDeclaration<?> declaration, List<XmlExtensionElementDocumentation> elements) {
            elements.stream().filter(e -> e.getName().equals(declaration.getName())).findAny().ifPresent(e -> {
                declaration.setDescription(e.getDescription());
                declaration.getAllParameters().forEach(param -> e.getParameters().stream().filter(p -> p.getName().equals(param.getName())).findAny().ifPresent(p -> param.setDescription(p.getDescription())));
            });
        }
    }.walk(declaration);
}
Also used : XmlExtensionDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation) WithSourcesDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration) URL(java.net.URL) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) IOException(java.io.IOException) XmlExtensionElementDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation) ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ConnectedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) ExtensionDescriptionsSerializer(org.mule.runtime.module.extension.internal.resources.documentation.ExtensionDescriptionsSerializer) ConnectionProviderDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration) ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ConnectionProviderDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) ConnectedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) XmlExtensionElementDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation) WithSourcesDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 30 with ExtensionDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.

the class ImportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
    ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
    final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (!extensionType.isPresent()) {
        return;
    }
    Type type = extensionType.get().getType();
    final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
    if (!importTypes.isEmpty()) {
        if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
            throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
        }
        importTypes.forEach(imported -> {
            MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
            if (!(importedType instanceof ObjectType)) {
                throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
            }
            extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
        });
    }
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectType(org.mule.metadata.api.model.ObjectType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) AnnotationValueFetcher(org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)

Aggregations

ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)36 Test (org.junit.Test)24 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)14 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)14 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)12 SmallTest (org.mule.tck.size.SmallTest)12 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)9 SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)6 IdempotentDeclarationWalker (org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)6 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)5 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)5 List (java.util.List)3 Optional (java.util.Optional)3 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)3 ObjectType (org.mule.metadata.api.model.ObjectType)3 WithOperationsDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration)3 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)3 DeclarationEnricher (org.mule.runtime.extension.api.loader.DeclarationEnricher)3 String.format (java.lang.String.format)2 Optional.ofNullable (java.util.Optional.ofNullable)2