Search in sources :

Example 21 with ParameterGroupModel

use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.

the class MetadataMediator method resolveParameterGroupModelType.

private List<ParameterGroupModel> resolveParameterGroupModelType(List<ParameterGroupModel> untypedParameterGroups, Map<String, ParameterMetadataDescriptor> inputTypeDescriptors) {
    List<ParameterGroupModel> parameterGroups = new LinkedList<>();
    untypedParameterGroups.forEach(parameterGroup -> {
        List<ParameterModel> parameters = new LinkedList<>();
        parameterGroup.getParameterModels().forEach(parameterModel -> {
            ParameterMetadataDescriptor parameterMetadataDescriptor = inputTypeDescriptors.get(parameterModel.getName());
            ParameterModel typedParameterModel = new ImmutableParameterModel(parameterModel.getName(), parameterModel.getDescription(), parameterMetadataDescriptor.getType(), parameterMetadataDescriptor.isDynamic(), parameterModel.isRequired(), parameterModel.isOverrideFromConfig(), parameterModel.getExpressionSupport(), parameterModel.getDefaultValue(), parameterModel.getRole(), parameterModel.getDslConfiguration(), parameterModel.getDisplayModel().orElse(null), parameterModel.getLayoutModel().orElse(null), parameterModel.getValueProviderModel().orElse(null), parameterModel.getAllowedStereotypes(), parameterModel.getModelProperties());
            parameters.add(typedParameterModel);
        });
        parameterGroups.add(new ImmutableParameterGroupModel(parameterGroup.getName(), parameterGroup.getDescription(), parameters, parameterGroup.getExclusiveParametersModels(), parameterGroup.isShowInDsl(), parameterGroup.getDisplayModel().orElse(null), parameterGroup.getLayoutModel().orElse(null), parameterGroup.getModelProperties()));
    });
    return parameterGroups;
}
Also used : ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) ImmutableParameterModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ImmutableParameterGroupModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterGroupModel) ImmutableParameterGroupModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterGroupModel) LinkedList(java.util.LinkedList) ImmutableParameterModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterModel)

Example 22 with ParameterGroupModel

use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.

the class ConfigurationBasedElementModelFactory method addElementParameter.

private void addElementParameter(Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementSyntax groupDsl, DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel paramModel) {
    groupDsl.getContainedElement(paramModel.getName()).ifPresent(paramDsl -> {
        if (isInfrastructure(paramModel)) {
            handleInfrastructure(paramModel, paramDsl, innerComponents, parameters, groupElementBuilder);
            return;
        }
        ComponentConfiguration paramComponent = getSingleComponentConfiguration(innerComponents, getIdentifier(paramDsl));
        if (paramDsl.isWrapped()) {
            resolveWrappedElement(groupElementBuilder, paramModel, paramDsl, paramComponent);
            return;
        }
        String value = paramDsl.supportsAttributeDeclaration() ? parameters.get(paramDsl.getAttributeName()) : null;
        Optional<String> defaultValue = getDefaultValue(paramModel);
        if (paramComponent != null || !isBlank(value) || defaultValue.isPresent()) {
            DslElementModel.Builder<ParameterModel> paramElementBuilder = DslElementModel.<ParameterModel>builder().withModel(paramModel).withDsl(paramDsl);
            if (paramComponent != null && !isContent(paramModel)) {
                paramElementBuilder.withConfig(paramComponent);
                paramModel.getType().accept(new MetadataTypeVisitor() {

                    @Override
                    public void visitArrayType(ArrayType arrayType) {
                        MetadataType itemType = arrayType.getType();
                        paramDsl.getGeneric(itemType).ifPresent(itemdsl -> {
                            ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
                            paramComponent.getNestedComponents().forEach(c -> {
                                if (c.getIdentifier().equals(itemIdentifier)) {
                                    itemType.accept(getComponentChildVisitor(paramElementBuilder, c, itemType, VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, new ArrayDeque<>()));
                                }
                            });
                        });
                    }

                    @Override
                    public void visitObject(ObjectType objectType) {
                        if (isMap(objectType)) {
                            populateMapEntries(objectType, paramDsl, paramElementBuilder, paramComponent);
                            return;
                        }
                        populateObjectFields(objectType, paramComponent, paramDsl, paramElementBuilder, new ArrayDeque<>());
                    }
                });
            } else {
                if (isBlank(value)) {
                    if (paramComponent != null && paramComponent.getValue().isPresent() && !isBlank(paramComponent.getValue().get())) {
                        value = paramComponent.getValue().get().trim();
                    } else if (defaultValue.isPresent()) {
                        value = defaultValue.get();
                        paramElementBuilder.isExplicitInDsl(false);
                    }
                }
                paramElementBuilder.withValue(value);
            }
            groupElementBuilder.containing(paramElementBuilder.build());
        }
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) RECONNECT_FOREVER_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.RECONNECT_FOREVER_ELEMENT_IDENTIFIER) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) Optional.of(java.util.Optional.of) TLS_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TLS_PARAMETER_NAME) FlattenedTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.FlattenedTypeAnnotation) ComposableModel(org.mule.runtime.api.meta.model.ComposableModel) EXPIRATION_POLICY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.EXPIRATION_POLICY_ELEMENT_IDENTIFIER) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) REDELIVERY_POLICY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.REDELIVERY_POLICY_ELEMENT_IDENTIFIER) ArrayType(org.mule.metadata.api.model.ArrayType) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) REDELIVERY_POLICY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.REDELIVERY_POLICY_PARAMETER_NAME) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) DslElementModelFactory(org.mule.runtime.config.api.dsl.model.DslElementModelFactory) MetadataTypeUtils.getLocalPart(org.mule.metadata.api.utils.MetadataTypeUtils.getLocalPart) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ExtensionModelUtils.isContent(org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent) RECONNECT_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.RECONNECT_ELEMENT_IDENTIFIER) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) SCHEDULING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_NAME) ObjectType(org.mule.metadata.api.model.ObjectType) RECONNECTION_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.RECONNECTION_STRATEGY_PARAMETER_NAME) Set(java.util.Set) ExtensionModelUtils.isText(org.mule.runtime.extension.api.util.ExtensionModelUtils.isText) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) POOLING_PROFILE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.POOLING_PROFILE_PARAMETER_NAME) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) Objects(java.util.Objects) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) NON_REPEATABLE_BYTE_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.NON_REPEATABLE_BYTE_STREAM_ALIAS) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) REPEATABLE_FILE_STORE_OBJECTS_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_FILE_STORE_OBJECTS_STREAM_ALIAS) ExtensionModelUtils.isInfrastructure(org.mule.runtime.extension.api.util.ExtensionModelUtils.isInfrastructure) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Optional(java.util.Optional) EE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.EE_PREFIX) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) NON_REPEATABLE_OBJECTS_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.NON_REPEATABLE_OBJECTS_STREAM_ALIAS) ExtensionModelUtils.isRequired(org.mule.runtime.extension.api.util.ExtensionModelUtils.isRequired) Optional.empty(java.util.Optional.empty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) CronScheduler(org.mule.runtime.core.api.source.scheduler.CronScheduler) CRON_STRATEGY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.CRON_STRATEGY_ELEMENT_IDENTIFIER) REPEATABLE_IN_MEMORY_OBJECTS_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_IN_MEMORY_OBJECTS_STREAM_ALIAS) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) Multimap(com.google.common.collect.Multimap) Deque(java.util.Deque) EXPIRATION_POLICY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.EXPIRATION_POLICY_PARAMETER_NAME) ExtensionModelUtils.getDefaultValue(org.mule.runtime.extension.api.util.ExtensionModelUtils.getDefaultValue) Stream.concat(java.util.stream.Stream.concat) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) Iterator(java.util.Iterator) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) RECONNECTION_CONFIG_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.RECONNECTION_CONFIG_PARAMETER_NAME) FixedFrequencyScheduler(org.mule.runtime.core.api.source.scheduler.FixedFrequencyScheduler) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) Collectors.toList(java.util.stream.Collectors.toList) STREAMING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.STREAMING_STRATEGY_PARAMETER_NAME) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) Reference(org.mule.runtime.api.util.Reference) SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ArrayDeque(java.util.ArrayDeque) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) MetadataType(org.mule.metadata.api.model.MetadataType) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ArrayDeque(java.util.ArrayDeque) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ArrayType(org.mule.metadata.api.model.ArrayType) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel)

Example 23 with ParameterGroupModel

use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.

the class DeclarationBasedElementModelFactory method addInlineGroupElement.

private <T> void addInlineGroupElement(ParameterGroupModel group, DslElementSyntax elementDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder<T> parentElement, Optional<ParameterGroupElementDeclaration> declaration) {
    elementDsl.getChild(group.getName()).ifPresent(groupDsl -> {
        DslElementModel.Builder<ParameterGroupModel> groupElementBuilder = DslElementModel.<ParameterGroupModel>builder().withModel(group).withDsl(groupDsl).isExplicitInDsl(declaration.isPresent());
        InternalComponentConfiguration.Builder groupConfigBuilder = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(groupDsl));
        addGroupParameterElements(group, groupDsl, groupConfigBuilder, groupElementBuilder, declaration);
        ComponentConfiguration groupConfig = groupConfigBuilder.build();
        groupElementBuilder.withConfig(groupConfig);
        parentConfig.withNestedComponent(groupConfig);
        parentElement.containing(groupElementBuilder.build());
    });
}
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) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)

Example 24 with ParameterGroupModel

use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.

the class IntrospectionUtils method getParameterClasses.

/**
 * Traverses through all the {@link ParameterModel}s of the {@code extensionModel} and returns the {@link Class classes} that
 * are modeled by each parameter's {@link ParameterModel#getType()}.
 * <p>
 * This includes every single {@link ParameterModel} in the model, including configs, providers, operations, etc.
 *
 * @param extensionModel a {@link ExtensionModel}
 * @return a non {@code null} {@link Set}
 */
public static Set<Class<?>> getParameterClasses(ExtensionModel extensionModel, ClassLoader extensionClassLoader) {
    Set<Class<?>> parameterClasses = new HashSet<>();
    new ExtensionWalker() {

        @Override
        public void onParameter(ParameterizedModel owner, ParameterGroupModel groupModel, ParameterModel model) {
            parameterClasses.addAll(collectRelativeClasses(model.getType(), extensionClassLoader));
        }
    }.walk(extensionModel);
    return parameterClasses;
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)24 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)11 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)6 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)5 List (java.util.List)4 Optional (java.util.Optional)4 MetadataType (org.mule.metadata.api.model.MetadataType)4 ObjectType (org.mule.metadata.api.model.ObjectType)4 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)4 String.format (java.lang.String.format)3 Field (java.lang.reflect.Field)3 Set (java.util.Set)3 Test (org.junit.Test)3 MetadataTypeUtils.getLocalPart (org.mule.metadata.api.utils.MetadataTypeUtils.getLocalPart)3 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)3 JavaTypeUtils.getType (org.mule.metadata.java.api.utils.JavaTypeUtils.getType)3 NestableElementModel (org.mule.runtime.api.meta.model.nested.NestableElementModel)3 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)3 DslElementModel (org.mule.runtime.config.api.dsl.model.DslElementModel)3 MuleContext (org.mule.runtime.core.api.MuleContext)3