Search in sources :

Example 6 with HasOperationModels

use of org.mule.runtime.api.meta.model.operation.HasOperationModels in project mule by mulesoft.

the class MacroExpansionModuleModel method lookForOperation.

/**
 * Looks for an operation checking if it is defined within the scope of a {@link ConfigurationModel} or the
 * {@link ExtensionModel}.
 *
 * @param operationIdentifier element to look for in the current {@link #extensionModel}
 * @param prefix to check if the {@code operationIdentifier} namespace targets an operation of the <module/> (usually maps to
 *        the {@link ExtensionModel} prefix, or the {@link #TNS_PREFIX}.
 * @return an {@link OperationModel} if found, {@link Optional#empty()} otherwise.
 */
private Optional<OperationModel> lookForOperation(ComponentIdentifier operationIdentifier, String prefix) {
    Optional<OperationModel> result = Optional.empty();
    final String operationName = operationIdentifier.getName();
    if (operationIdentifier.getNamespace().equals(prefix)) {
        // As the operation can be inside the extension or the config, it has to be looked up in both elements.
        final HasOperationModels hasOperationModels = getConfigurationModel().map(configurationModel -> (HasOperationModels) configurationModel).orElse(extensionModel);
        result = hasOperationModels.getOperationModel(operationName);
    }
    // If the operation is not present, it might be a private one and it must be looked inside of the model property
    if (!result.isPresent() && extensionModel.getModelProperty(PrivateOperationsModelProperty.class).isPresent()) {
        result = extensionModel.getModelProperty(PrivateOperationsModelProperty.class).get().getOperationModel(operationName);
    }
    return result;
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) IntStream(java.util.stream.IntStream) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) CommonBeanDefinitionCreator(org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator) MODULE_OPERATION_CHAIN(org.mule.runtime.config.internal.model.ApplicationModel.MODULE_OPERATION_CHAIN) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) NAME_ATTRIBUTE(org.mule.runtime.config.internal.model.ApplicationModel.NAME_ATTRIBUTE) Collectors.toSet(java.util.stream.Collectors.toSet) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) Collections.emptyMap(java.util.Collections.emptyMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) VARS(org.mule.runtime.api.el.BindingContextUtils.VARS) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) MODULE_CONFIG_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONFIG_GLOBAL_ELEMENT_NAME) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 7 with HasOperationModels

use of org.mule.runtime.api.meta.model.operation.HasOperationModels 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

HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)6 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)6 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)5 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)5 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)5 List (java.util.List)4 Optional (java.util.Optional)4 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)4 HasConstructModels (org.mule.runtime.api.meta.model.construct.HasConstructModels)4 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)4 String.format (java.lang.String.format)3 Map (java.util.Map)3 Set (java.util.Set)3 ObjectType (org.mule.metadata.api.model.ObjectType)3 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)3 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)3 ComponentIdentifier.builder (org.mule.runtime.api.component.ComponentIdentifier.builder)3 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)3 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)3