Search in sources :

Example 6 with SourceDeclaration

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

the class BackPressureDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    final ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    new IdempotentDeclarationWalker() {

        @Override
        protected void onSource(SourceDeclaration sourceDeclaration) {
            BackPressureStrategyModelProperty property;
            Optional<ExtensionTypeDescriptorModelProperty> extensionTypeDescriptorModelProperty = sourceDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
            if (extensionTypeDescriptorModelProperty.isPresent()) {
                Type sourceType = extensionTypeDescriptorModelProperty.get().getType();
                property = sourceType.getAnnotation(BackPressure.class).map(BackPressureStrategyModelProperty::of).orElseGet(BackPressureStrategyModelProperty::getDefault);
                sourceDeclaration.addModelProperty(property);
                if (property.getSupportedModes().size() > 1) {
                    addBackPressureParameter(extensionDeclaration, sourceDeclaration, property);
                }
            }
        }
    }.walk(extensionDeclaration);
}
Also used : Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) BackPressureStrategyModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.BackPressureStrategyModelProperty) Optional(java.util.Optional) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 7 with SourceDeclaration

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

the class JavaDeclarationDelegateTestCase method flyweight.

@Test
public void flyweight() {
    setLoader(loaderFor(VeganExtension.class));
    ExtensionDeclarer declarer = declareExtension();
    final ExtensionDeclaration declaration = declarer.getDeclaration();
    final ConfigurationDeclaration appleConfiguration = findDeclarationByName(declaration.getConfigurations(), APPLE);
    final ConfigurationDeclaration bananaConfiguration = findDeclarationByName(declaration.getConfigurations(), BANANA);
    final String sourceName = PaulMcCartneySource.class.getSimpleName();
    SourceDeclaration appleSource = findDeclarationByName(appleConfiguration.getMessageSources(), sourceName);
    SourceDeclaration bananaSource = findDeclarationByName(bananaConfiguration.getMessageSources(), sourceName);
    assertThat(appleSource, is(sameInstance(bananaSource)));
    final String operationName = "spreadTheWord";
    OperationDeclaration appleOperation = findDeclarationByName(appleConfiguration.getOperations(), operationName);
    OperationDeclaration bananaOperation = findDeclarationByName(bananaConfiguration.getOperations(), operationName);
    assertThat(appleOperation, is(sameInstance(bananaOperation)));
}
Also used : ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) VeganExtension(org.mule.test.vegan.extension.VeganExtension) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 8 with SourceDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration 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 9 with SourceDeclaration

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

the class DynamicMetadataDeclarationEnricherTestCase method declareStaticAndDynamicTypesInSource.

@Test
public void declareStaticAndDynamicTypesInSource() {
    List<SourceDeclaration> messageSources = declaration.getConfigurations().get(0).getMessageSources();
    SourceDeclaration sourceDynamicAttributes = getDeclaration(messageSources, "MetadataSource");
    assertOutputType(sourceDynamicAttributes.getOutput(), TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))).openWith(TYPE_LOADER.load(Object.class)).build(), true);
    assertOutputType(sourceDynamicAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false);
    assertParameterType(getDeclaration(sourceDynamicAttributes.getAllParameters(), "type"), toMetadataType(String.class));
    messageSources = declaration.getMessageSources();
    SourceDeclaration sourceStaticAttributes = getDeclaration(messageSources, "MetadataSourceWithMultilevel");
    assertOutputType(sourceStaticAttributes.getOutput(), TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))).openWith(TYPE_LOADER.load(Object.class)).build(), true);
    assertOutputType(sourceStaticAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false);
    List<ParameterDeclaration> locationKey = sourceStaticAttributes.getAllParameters();
    assertParameterType(getDeclaration(locationKey, "continent"), toMetadataType(String.class));
    assertParameterType(getDeclaration(locationKey, "country"), toMetadataType(String.class));
    assertParameterType(getDeclaration(locationKey, "city"), toMetadataType(String.class));
}
Also used : StringAttributes(org.mule.tck.message.StringAttributes) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) Test(org.junit.Test)

Example 10 with SourceDeclaration

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

the class JavaConfigurationDeclarationEnricherTestCase method verifyConfigurationModelPropertyOnSource.

@Test
public void verifyConfigurationModelPropertyOnSource() {
    SourceDeclaration sourceDeclaration = getDeclaration(declaration.getConfigurations().get(0).getMessageSources(), LISTEN_PAYMENTS);
    final ConfigTypeModelProperty configTypeModelProperty = checkIsPresent(sourceDeclaration, ConfigTypeModelProperty.class);
    assertType(configTypeModelProperty);
}
Also used : ConfigTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConfigTypeModelProperty) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) Test(org.junit.Test)

Aggregations

SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)10 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)7 IdempotentDeclarationWalker (org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)5 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)4 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)4 Test (org.junit.Test)3 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)3 MetadataType (org.mule.metadata.api.model.MetadataType)3 DeclarationEnricher (org.mule.runtime.extension.api.loader.DeclarationEnricher)3 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)3 Optional (java.util.Optional)2 ObjectType (org.mule.metadata.api.model.ObjectType)2 ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)2 ConnectionProviderDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration)2 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)2 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)2 WithOperationsDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration)2 Reference (org.mule.runtime.api.util.Reference)2 ExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory)2 DeclarationEnricherPhase (org.mule.runtime.extension.api.loader.DeclarationEnricherPhase)2