Search in sources :

Example 1 with ComponentIdentifier

use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.

the class PolicyPointcutParametersManager method createOperationPointcutParameters.

/**
 * Creates {@link PolicyPointcutParameters} for a specific operation. Stored parameters from the source are included in the
 * newly created parameters to be able to correlate parameters from both source and operation.
 *
 * @param operation the operation component to which policies will be applied
 * @param event the event which will execute the operation policies
 * @param operationParameters a map containing the parameters of the operation
 * @return the created {@link PolicyPointcutParameters}
 */
public PolicyPointcutParameters createOperationPointcutParameters(Component operation, CoreEvent event, Map<String, Object> operationParameters) {
    ComponentIdentifier operationIdentifier = operation.getLocation().getComponentIdentifier().getIdentifier();
    PolicyPointcutParameters sourceParameters = sourceParametersMap.get(event.getContext().getCorrelationId());
    OperationPolicyPointcutParametersParameters parameters = new OperationPolicyPointcutParametersParameters(operation, operationParameters, sourceParameters);
    Function<OperationPolicyPointcutParametersFactory, PolicyPointcutParameters> creationFunction = factory -> {
        try {
            return factory.createPolicyPointcutParameters(parameters);
        } catch (AbstractMethodError error) {
            return factory.createPolicyPointcutParameters(parameters.getOperation(), parameters.getOperationParameters());
        }
    };
    return createPointcutParameters(operation, OperationPolicyPointcutParametersFactory.class, operationPointcutFactories, factory -> factory.supportsOperationIdentifier(operationIdentifier), creationFunction).orElse(new PolicyPointcutParameters(operation, sourceParameters));
}
Also used : Optional.empty(java.util.Optional.empty) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Predicate(java.util.function.Predicate) Optional.of(java.util.Optional.of) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Function(java.util.function.Function) String.format(java.lang.String.format) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) OperationPolicyPointcutParametersParameters(org.mule.runtime.policy.api.OperationPolicyPointcutParametersParameters) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) OperationPolicyPointcutParametersParameters(org.mule.runtime.policy.api.OperationPolicyPointcutParametersParameters) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Example 2 with ComponentIdentifier

use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.

the class AbstractErrorTypeMatcherTestCase method setUp.

@Before
public void setUp() {
    ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    anyErrorType = errorTypeRepository.getAnyErrorType();
    ComponentIdentifier transformationIdentifier = ComponentIdentifier.builder().name(TRANSFORMATION_ERROR_IDENTIFIER).namespace(CORE_NAMESPACE_NAME).build();
    transformationErrorType = errorTypeRepository.lookupErrorType(transformationIdentifier).get();
    ComponentIdentifier expressionIdentifier = ComponentIdentifier.builder().name(EXPRESSION_ERROR_IDENTIFIER).namespace(CORE_NAMESPACE_NAME).build();
    expressionErrorType = errorTypeRepository.lookupErrorType(expressionIdentifier).get();
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) Before(org.junit.Before)

Example 3 with ComponentIdentifier

use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.

the class SingleErrorTypeMatcherTestCase method matchChild.

@Test
public void matchChild() {
    ComponentIdentifier customTransformerIdentifier = ComponentIdentifier.builder().name("custom").namespace(CORE_NAMESPACE_NAME).build();
    ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    ErrorType customTransformerErrorType = errorTypeRepository.addErrorType(customTransformerIdentifier, transformationErrorType);
    ErrorTypeMatcher transformationMatcher = new SingleErrorTypeMatcher(transformationErrorType);
    assertThat(transformationMatcher.match(customTransformerErrorType), is(true));
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorType(org.mule.runtime.api.message.ErrorType) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Test(org.junit.Test)

Example 4 with ComponentIdentifier

use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method extractOutputType.

private void extractOutputType(OutputDeclarer outputDeclarer, ComponentIdentifier componentIdentifier, ComponentModel operationModel, Optional<MetadataType> calculatedOutput) {
    Optional<ComponentModel> outputAttributesComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(componentIdentifier)).findFirst();
    outputAttributesComponentModel.ifPresent(outputComponentModel -> outputDeclarer.describedAs(getDescription(outputComponentModel)));
    MetadataType metadataType = getMetadataType(outputAttributesComponentModel, calculatedOutput);
    outputDeclarer.ofType(metadataType);
}
Also used : PRIMITIVE_TYPES(org.mule.metadata.catalog.api.PrimitiveTypesTypeLoader.PRIMITIVE_TYPES) BEHAVIOUR(org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR) ErrorModelBuilder(org.mule.runtime.api.meta.model.error.ErrorModelBuilder) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) Optional.of(java.util.Optional.of) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) StreamResult(javax.xml.transform.stream.StreamResult) Thread.currentThread(java.lang.Thread.currentThread) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) Collections.singletonList(java.util.Collections.singletonList) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) Document(org.w3c.dom.Document) Map(java.util.Map) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) IllegalParameterModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalParameterModelDefinitionException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) DisplayModel(org.mule.runtime.api.meta.model.display.DisplayModel) IOUtils(org.apache.commons.io.IOUtils) DeclarationOperation(org.mule.runtime.extension.api.loader.xml.declaration.DeclarationOperation) MacroExpansionModulesModel.getUsedNamespaces(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel.getUsedNamespaces) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) XmlModelUtils.createXmlLanguageModel(org.mule.runtime.extension.api.util.XmlModelUtils.createXmlLanguageModel) Category(org.mule.runtime.api.meta.Category) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) DirectedGraph(org.jgrapht.DirectedGraph) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) Optional.empty(java.util.Optional.empty) TransformerException(javax.xml.transform.TransformerException) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) TreeSet(java.util.TreeSet) Placement(org.mule.runtime.extension.api.annotation.param.display.Placement) String.join(java.lang.String.join) LayoutModel.builder(org.mule.runtime.api.meta.model.display.LayoutModel.builder) CycleDetector(org.jgrapht.alg.CycleDetector) DefaultEdge(org.jgrapht.graph.DefaultEdge) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ANY(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.ANY) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) IOException(java.io.IOException) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) NoReconnectionStrategyModelProperty(org.mule.runtime.extension.internal.property.NoReconnectionStrategyModelProperty) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) TransformerFactory(javax.xml.transform.TransformerFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MacroExpansionModulesModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel) URL(java.net.URL) NamedObject(org.mule.runtime.api.meta.NamedObject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ByteArrayInputStream(java.io.ByteArrayInputStream) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) MacroExpansionModuleModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) List(java.util.List) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) NoOpXmlErrorHandler(org.mule.runtime.config.internal.util.NoOpXmlErrorHandler) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashMap(java.util.HashMap) HashSet(java.util.HashSet) TypeResolverException(org.mule.metadata.catalog.api.TypeResolverException) TNS_PREFIX(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel.TNS_PREFIX) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) TypeResolver(org.mule.metadata.catalog.api.TypeResolver) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) Optional.ofNullable(java.util.Optional.ofNullable) ParameterizedDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader) XMLNS_ATTRIBUTE(javax.xml.XMLConstants.XMLNS_ATTRIBUTE) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OutputDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OutputDeclarer) Collections(java.util.Collections) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MetadataType(org.mule.metadata.api.model.MetadataType)

Example 5 with ComponentIdentifier

use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.

the class ConfigurationBasedElementModelFactory method addInlineGroup.

private void addInlineGroup(DslElementSyntax elementDsl, Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementModel.Builder parent, ParameterGroupModel group) {
    elementDsl.getChild(group.getName()).ifPresent(groupDsl -> {
        Optional<ComponentIdentifier> identifier = getIdentifier(groupDsl);
        if (!identifier.isPresent()) {
            return;
        }
        ComponentConfiguration groupComponent = getSingleComponentConfiguration(innerComponents, identifier);
        if (groupComponent != null) {
            DslElementModel.Builder<ParameterGroupModel> groupElementBuilder = DslElementModel.<ParameterGroupModel>builder().withModel(group).withDsl(groupDsl).withConfig(groupComponent);
            Multimap<ComponentIdentifier, ComponentConfiguration> groupInnerComponents = getNestedComponents(groupComponent);
            group.getParameterModels().forEach(p -> addElementParameter(groupInnerComponents, parameters, groupDsl, groupElementBuilder, p));
            parent.containing(groupElementBuilder.build());
        } else if (shoulBuildDefaultGroup(group)) {
            builDefaultInlineGroupElement(parent, group, groupDsl, identifier.get());
        }
    });
}
Also used : InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel)

Aggregations

ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)20 Map (java.util.Map)10 Optional (java.util.Optional)9 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)9 Optional.of (java.util.Optional.of)8 List (java.util.List)7 Optional.empty (java.util.Optional.empty)7 Set (java.util.Set)7 ComponentConfiguration (org.mule.runtime.dsl.api.component.config.ComponentConfiguration)7 String.format (java.lang.String.format)6 MetadataType (org.mule.metadata.api.model.MetadataType)6 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)6 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)6 DslElementModel (org.mule.runtime.config.api.dsl.model.DslElementModel)6 InternalComponentConfiguration (org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)6 HashMap (java.util.HashMap)5 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)5 ComponentIdentifier.builder (org.mule.runtime.api.component.ComponentIdentifier.builder)5 Collectors.toList (java.util.stream.Collectors.toList)4 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)4