Search in sources :

Example 16 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class DefaultExtensionSchemaGenerator method generate.

/**
 * {@inheritDoc}
 */
@Override
public String generate(ExtensionModel extensionModel, DslResolvingContext dslContext) {
    XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
    validate(extensionModel, xmlDslModel);
    SchemaBuilder schemaBuilder = SchemaBuilder.newSchema(extensionModel, xmlDslModel, dslContext);
    new IdempotentExtensionWalker() {

        @Override
        public void onConfiguration(ConfigurationModel model) {
            schemaBuilder.registerConfigElement(model);
        }

        @Override
        protected void onConstruct(ConstructModel model) {
            schemaBuilder.registerOperation(model);
        }

        @Override
        public void onOperation(OperationModel model) {
            schemaBuilder.registerOperation(model);
        }

        @Override
        public void onConnectionProvider(ConnectionProviderModel model) {
            schemaBuilder.registerConnectionProviderElement(model);
        }

        @Override
        public void onSource(SourceModel model) {
            schemaBuilder.registerMessageSource(model);
        }
    }.walk(extensionModel);
    schemaBuilder.registerEnums();
    // Make sure the XML libs use the container classloader internally
    return withContextClassLoader(DefaultExtensionSchemaGenerator.class.getClassLoader(), () -> renderSchema(schemaBuilder.build()));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) SchemaBuilder(org.mule.runtime.module.extension.internal.capability.xml.schema.builder.SchemaBuilder) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 17 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class SourceSchemaDelegate method registerSourceType.

private void registerSourceType(String name, SourceModel sourceModel, DslElementSyntax dslSyntax, boolean hasImplicitConfig) {
    final ExtensionType sourceType = createExecutableType(name, MULE_ABSTRACT_MESSAGE_SOURCE_TYPE, dslSyntax, hasImplicitConfig);
    initialiseSequence(sourceType);
    ExplicitGroup sequence = sourceType.getSequence();
    builder.addInfrastructureParameters(sourceType, sourceModel, sequence);
    List<ParameterModel> visitedParameters = new LinkedList<>();
    sourceModel.getParameterGroupModels().forEach(group -> {
        registerParameterGroup(sourceType, group);
        visitedParameters.addAll(group.getParameterModels());
    });
    sourceModel.getSuccessCallback().map(ParameterizedModel::getParameterGroupModels).ifPresent(groups -> groups.forEach(group -> registerCallbackParameters(sourceType, visitedParameters, group)));
    sourceModel.getErrorCallback().map(ParameterizedModel::getParameterGroupModels).ifPresent(groups -> groups.forEach(group -> registerCallbackParameters(sourceType, visitedParameters, group)));
}
Also used : TYPE_SUFFIX(org.mule.runtime.config.internal.dsl.SchemaConstants.TYPE_SUFFIX) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) StringUtils.capitalize(org.apache.commons.lang3.StringUtils.capitalize) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) Element(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Element) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MULE_ABSTRACT_MESSAGE_SOURCE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_ABSTRACT_MESSAGE_SOURCE) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MULE_ABSTRACT_MESSAGE_SOURCE_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_ABSTRACT_MESSAGE_SOURCE_TYPE) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) SOURCE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.SOURCE) QName(javax.xml.namespace.QName) LinkedList(java.util.LinkedList) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) LinkedList(java.util.LinkedList) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 18 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class DefaultExtensionModelFactoryTestCase method sourceWithReducedBackPressureStrategies.

@Test
public void sourceWithReducedBackPressureStrategies() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    SourceModel source = extensionModel.getConfigurationModels().get(0).getSourceModel("ListenPayments").get();
    ParameterModel parameter = source.getAllParameterModels().stream().filter(p -> BACK_PRESSURE_STRATEGY_PARAMETER_NAME.equals(p.getName())).findAny().orElseThrow(() -> new IllegalStateException("No backPressureStrategy parameter"));
    assertThat(parameter.getType(), is(instanceOf(StringType.class)));
    assertThat(parameter.getDefaultValue(), is(FAIL));
    EnumAnnotation enumAnnotation = parameter.getType().getAnnotation(EnumAnnotation.class).orElseThrow(() -> new IllegalStateException("No enum annotation"));
    assertThat(asList(enumAnnotation.getValues()), containsInAnyOrder(FAIL.name(), DROP.name()));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 19 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class DefaultExtensionModelFactoryTestCase method streamingHintOnSource.

@Test
public void streamingHintOnSource() throws Exception {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    SourceModel sourceModel = extensionModel.getConfigurationModels().get(0).getSourceModel("ListenPayments").get();
    ParameterModel streamingParameter = sourceModel.getAllParameterModels().stream().filter(p -> p.getName().equals(STREAMING_STRATEGY_PARAMETER_NAME)).findFirst().get();
    assertStreamingStrategy(streamingParameter);
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 20 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class MetadataComponentModelValidator method validate.

@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
    // TODO - MULE-14397 - Improve Dynamic Metadata Enricher to enrich without requiring Classes
    // This is skipped if the extension is loaded with java, but it doesn't have classes which means AST Mode
    Optional<ExtensionTypeDescriptorModelProperty> property = extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (property.isPresent()) {
        if (!property.get().getType().getDeclaringClass().isPresent()) {
            return;
        }
    }
    final Table<String, String, Class<?>> names = HashBasedTable.create();
    new ExtensionWalker() {

        @Override
        public void onOperation(HasOperationModels owner, OperationModel model) {
            validateComponent(model);
        }

        @Override
        public void onSource(HasSourceModels owner, SourceModel model) {
            validateComponent(model);
        }

        private void validateComponent(ConnectableComponentModel model) {
            validateMetadataReturnType(extensionModel, model, problemsReporter);
            MetadataResolverFactory resolverFactory = MuleExtensionUtils.getMetadataResolverFactory(model);
            validateMetadataOutputAttributes(model, resolverFactory, problemsReporter);
            validateMetadataKeyId(model, resolverFactory, problemsReporter);
            validateCategoriesInScope(model, resolverFactory, problemsReporter);
            validateResolversName(model, resolverFactory, names, problemsReporter);
        }
    }.walk(extensionModel);
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MetadataResolverFactory(org.mule.runtime.extension.api.metadata.MetadataResolverFactory) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Aggregations

SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)25 Test (org.junit.Test)14 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)13 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)12 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)9 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)8 SmallTest (org.mule.tck.size.SmallTest)8 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)7 List (java.util.List)6 Optional (java.util.Optional)6 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)6 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)6 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)6 Collectors.toList (java.util.stream.Collectors.toList)5 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)5 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)5 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)5 Reference (org.mule.runtime.api.util.Reference)5 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)4 ObjectType (org.mule.metadata.api.model.ObjectType)4