Search in sources :

Example 1 with NestedChainModel

use of org.mule.runtime.api.meta.model.nested.NestedChainModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method flow.

@Test
public void flow() {
    final ConstructModel flow = coreExtensionModel.getConstructModel("flow").get();
    assertThat(flow.getStereotype().getType(), is(FLOW.getType()));
    assertThat(flow.allowsTopLevelDeclaration(), is(true));
    final List<ParameterModel> paramModels = flow.getAllParameterModels();
    assertThat(paramModels, hasSize(2));
    ParameterModel initialState = paramModels.get(0);
    assertThat(initialState.getName(), is("initialState"));
    assertThat(initialState.getDefaultValue(), is("started"));
    ParameterModel maxConcurrency = paramModels.get(1);
    assertThat(maxConcurrency.getName(), is("maxConcurrency"));
    List<? extends NestableElementModel> nestedComponents = flow.getNestedComponents();
    assertThat(nestedComponents, hasSize(3));
    NestableElementModel source = nestedComponents.get(0);
    assertThat(source.getName(), is("source"));
    assertThat(source.isRequired(), is(false));
    assertThat(source, instanceOf(NestedComponentModel.class));
    assertThat(((NestedComponentModel) source).getAllowedStereotypes(), contains(SOURCE));
    NestableElementModel chain = nestedComponents.get(1);
    assertThat(chain.getName(), is("processors"));
    assertThat(chain.isRequired(), is(true));
    assertThat(chain, instanceOf(NestedChainModel.class));
    assertThat(((NestedChainModel) chain).getAllowedStereotypes().stream().anyMatch(s -> s.getType().equals(PROCESSOR.getType())), is(true));
    NestableElementModel errorHandler = nestedComponents.get(2);
    assertThat(errorHandler.getName(), is("errorHandler"));
    assertThat(errorHandler.isRequired(), is(false));
    assertThat(errorHandler, instanceOf(NestedComponentModel.class));
    assertThat(((NestedComponentModel) errorHandler).getAllowedStereotypes(), contains(ERROR_HANDLER));
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ErrorModelBuilder.newError(org.mule.runtime.api.meta.model.error.ErrorModelBuilder.newError) DefaultAnyType(org.mule.metadata.api.model.impl.DefaultAnyType) VoidType(org.mule.metadata.api.model.VoidType) Assert.assertThat(org.junit.Assert.assertThat) CPU_LITE(org.mule.runtime.api.meta.model.operation.ExecutionType.CPU_LITE) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) IsCollectionContaining.hasItem(org.hamcrest.core.IsCollectionContaining.hasItem) ArrayType(org.mule.metadata.api.model.ArrayType) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) ON_ERROR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.ON_ERROR) SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.SUPPORTED) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) TypeIdAnnotation(org.mule.metadata.api.annotation.TypeIdAnnotation) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ObjectType(org.mule.metadata.api.model.ObjectType) REQUIRED(org.mule.runtime.api.meta.ExpressionSupport.REQUIRED) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) DefaultObjectType(org.mule.metadata.api.model.impl.DefaultObjectType) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) MuleManifest.getVendorName(org.mule.runtime.core.api.config.MuleManifest.getVendorName) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) StringType(org.mule.metadata.api.model.StringType) Matchers.contains(org.hamcrest.Matchers.contains) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FLOW(org.mule.runtime.extension.api.stereotype.MuleStereotypes.FLOW) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) TRANSFORMATION(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.TRANSFORMATION) SOURCE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.SOURCE) COMMUNITY(org.mule.runtime.api.meta.Category.COMMUNITY) OBJECT_STORE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.OBJECT_STORE) Iterator(java.util.Iterator) ERROR_HANDLER(org.mule.runtime.extension.api.stereotype.MuleStereotypes.ERROR_HANDLER) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) DefaultBooleanType(org.mule.metadata.api.model.impl.DefaultBooleanType) Test(org.junit.Test) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MULE_VERSION(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.MULE_VERSION) MuleExtensionModelProvider.getExtensionModel(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.getExtensionModel) PROCESSOR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.PROCESSOR) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) MULE_NAME(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.MULE_NAME) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) SubTypesModel(org.mule.runtime.api.meta.model.SubTypesModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) Test(org.junit.Test)

Example 2 with NestedChainModel

use of org.mule.runtime.api.meta.model.nested.NestedChainModel in project mule by mulesoft.

the class ExecutableTypeSchemaDelegate method generateNestedRouteElement.

private void generateNestedRouteElement(ExtensionType type, DslElementSyntax routeDsl, NestedRouteModel routeModel) {
    NestedChainModel chain = (NestedChainModel) routeModel.getNestedComponents().get(0);
    LocalComplexType complexType = builder.getObjectSchemaDelegate().createTypeExtension(MULE_ABSTRACT_EXTENSION_TYPE);
    ExplicitGroup routeSequence = new ExplicitGroup();
    complexType.getComplexContent().getExtension().setSequence(routeSequence);
    generateNestedProcessorElement(complexType.getComplexContent().getExtension(), chain);
    registerParameters(complexType.getComplexContent().getExtension(), routeModel.getAllParameterModels());
    TopLevelElement routeElement = builder.createTopLevelElement(routeDsl.getElementName(), BigInteger.valueOf(routeModel.getMinOccurs()), MAX_ONE);
    routeElement.setComplexType(complexType);
    type.getSequence().getParticle().add(objectFactory.createElement(routeElement));
    if (routeModel.getMinOccurs() > 0) {
        type.getSequence().setMinOccurs(ONE);
    }
}
Also used : NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 3 with NestedChainModel

use of org.mule.runtime.api.meta.model.nested.NestedChainModel in project mule by mulesoft.

the class AbstractComponentDefinitionParser method doParse.

@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
    Builder finalBuilder = definitionBuilder.withIdentifier(operationDsl.getElementName()).withTypeDefinition(fromType(getMessageProcessorType())).withObjectFactoryType(getMessageProcessorFactoryType()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(componentModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withConstructorParameterDefinition(fromReferenceObject(Registry.class).build()).withConstructorParameterDefinition(fromReferenceObject(PolicyManager.class).build()).withSetterParameterDefinition(TARGET_PARAMETER_NAME, fromSimpleParameter(TARGET_PARAMETER_NAME).build()).withSetterParameterDefinition(TARGET_VALUE_PARAMETER_NAME, fromSimpleParameter(TARGET_VALUE_PARAMETER_NAME).build()).withSetterParameterDefinition(CONFIG_PROVIDER_ATTRIBUTE_NAME, fromSimpleReferenceParameter(CONFIG_ATTRIBUTE_NAME).build()).withSetterParameterDefinition(CURSOR_PROVIDER_FACTORY_FIELD_NAME, fromChildConfiguration(CursorProviderFactory.class).build()).withSetterParameterDefinition("retryPolicyTemplate", fromChildConfiguration(RetryPolicyTemplate.class).build());
    Optional<? extends NestableElementModel> nestedChain = componentModel.getNestedComponents().stream().filter(c -> c instanceof NestedChainModel).findFirst();
    if (nestedChain.isPresent()) {
        // TODO MULE-13483: improve parsers to support things like [source, chainOfProcessors, errorHandler]
        // or [chainOfProcessors, errorHandler]
        finalBuilder = finalBuilder.withSetterParameterDefinition("nestedProcessors", fromChildCollectionConfiguration(Processor.class).build());
        parseParameters(componentModel.getAllParameterModels());
    } else {
        List<ParameterGroupModel> inlineGroups = getInlineGroups(componentModel);
        parseParameters(getFlatParameters(inlineGroups, componentModel.getAllParameterModels()));
        for (ParameterGroupModel group : inlineGroups) {
            parseInlineParameterGroup(group);
        }
        // TODO MULE-13483
        parseNestedComponents(componentModel.getNestedComponents());
    }
    return finalBuilder;
}
Also used : ExtensionDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.ExtensionDefinitionParser) Builder.fromReferenceObject(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromReferenceObject) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) CONFIG_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.CONFIG_ATTRIBUTE_NAME) ExtensionParsingContext(org.mule.runtime.module.extension.internal.config.dsl.ExtensionParsingContext) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) Builder.fromChildConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildConfiguration) Builder.fromSimpleReferenceParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleReferenceParameter) Processor(org.mule.runtime.core.api.processor.Processor) Builder.fromFixedValue(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromFixedValue) Builder.fromSimpleParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleParameter) OperationMessageProcessorObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.operation.OperationMessageProcessorObjectFactory) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) MuleContext(org.mule.runtime.core.api.MuleContext) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) Registry(org.mule.runtime.api.artifact.Registry) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) Builder.fromChildCollectionConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildCollectionConfiguration) TypeDefinition.fromType(org.mule.runtime.dsl.api.component.TypeDefinition.fromType) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ComponentMessageProcessorObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.ComponentMessageProcessorObjectFactory) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) OperationMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ComponentMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.ComponentMessageProcessor) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Optional(java.util.Optional) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) MuleContext(org.mule.runtime.core.api.MuleContext) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) Processor(org.mule.runtime.core.api.processor.Processor) OperationMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessor) ComponentMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.ComponentMessageProcessor) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)

Aggregations

NestedChainModel (org.mule.runtime.api.meta.model.nested.NestedChainModel)3 List (java.util.List)2 Optional (java.util.Optional)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 NestableElementModel (org.mule.runtime.api.meta.model.nested.NestableElementModel)2 TARGET_PARAMETER_NAME (org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME)2 TARGET_VALUE_PARAMETER_NAME (org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME)2 Iterator (java.util.Iterator)1 Matchers.arrayContainingInAnyOrder (org.hamcrest.Matchers.arrayContainingInAnyOrder)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Matchers.is (org.hamcrest.Matchers.is)1 IsCollectionWithSize.hasSize (org.hamcrest.collection.IsCollectionWithSize.hasSize)1 IsEmptyCollection.empty (org.hamcrest.collection.IsEmptyCollection.empty)1 IsCollectionContaining.hasItem (org.hamcrest.core.IsCollectionContaining.hasItem)1 Assert.assertThat (org.junit.Assert.assertThat)1 Test (org.junit.Test)1 EnumAnnotation (org.mule.metadata.api.annotation.EnumAnnotation)1 TypeIdAnnotation (org.mule.metadata.api.annotation.TypeIdAnnotation)1 ArrayType (org.mule.metadata.api.model.ArrayType)1