Search in sources :

Example 1 with DslElementModel

use of org.mule.runtime.config.api.dsl.model.DslElementModel 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)

Example 2 with DslElementModel

use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.

the class ConfigurationBasedElementModelFactory method getComponentChildVisitor.

private MetadataTypeVisitor getComponentChildVisitor(final DslElementModel.Builder typeBuilder, final ComponentConfiguration configuration, final MetadataType model, final String name, final DslElementSyntax modelDsl, final Optional<String> defaultValue, Deque<String> typeResolvingStack) {
    final Map<String, String> parameters = configuration.getParameters();
    return new MetadataTypeVisitor() {

        @Override
        protected void defaultVisit(MetadataType metadataType) {
            DslElementModel.Builder<MetadataType> elementBuilder = DslElementModel.<MetadataType>builder().withModel(model).withDsl(modelDsl);
            Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
            String value = parameters.get(name);
            if (isBlank(value)) {
                if (identifier.isPresent()) {
                    ComponentConfiguration nested = getSingleComponentConfiguration(getNestedComponents(configuration), identifier);
                    if (nested != null && nested.getValue().isPresent() && !isBlank(nested.getValue().get())) {
                        value = nested.getValue().get().trim();
                    }
                } else if (defaultValue.isPresent()) {
                    value = defaultValue.get();
                    elementBuilder.isExplicitInDsl(false);
                }
            }
            if (!isBlank(value)) {
                typeBuilder.containing(elementBuilder.withValue(value).build());
            }
        }

        @Override
        public void visitArrayType(ArrayType arrayType) {
            Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
            if (identifier.isPresent()) {
                ComponentConfiguration fieldComponent = getSingleComponentConfiguration(getNestedComponents(configuration), identifier);
                if (fieldComponent != null) {
                    DslElementModel.Builder<Object> list = DslElementModel.builder().withModel(model).withDsl(modelDsl).withConfig(fieldComponent);
                    modelDsl.getGeneric(arrayType.getType()).ifPresent(itemdsl -> {
                        ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
                        fieldComponent.getNestedComponents().forEach(c -> {
                            if (c.getIdentifier().equals(itemIdentifier)) {
                                getComponentChildVisitor(list, c, arrayType.getType(), VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, typeResolvingStack);
                            }
                        });
                    });
                    typeBuilder.containing(list.build());
                    return;
                }
            }
            defaultValue.ifPresent(s -> typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(defaultValue.get()).isExplicitInDsl(false).build()));
        }

        @Override
        public void visitObject(ObjectType objectType) {
            Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
            if (identifier.isPresent()) {
                if (isMap(objectType)) {
                    typeBuilder.containing(createMapElement(objectType, modelDsl, configuration));
                    return;
                }
                Multimap<ComponentIdentifier, ComponentConfiguration> nestedComponents = getNestedComponents(configuration);
                ComponentConfiguration fieldComponent = nestedComponents.containsKey(identifier.get()) ? nestedComponents.get(identifier.get()).iterator().next() : null;
                fieldComponent = fieldComponent == null ? configuration : fieldComponent;
                String value = fieldComponent.getParameters().get(modelDsl.getAttributeName());
                if (!isBlank(value)) {
                    typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(value).build());
                } else {
                    resolveBasedOnType(objectType, fieldComponent, typeResolvingStack).ifPresent(typeBuilder::containing);
                }
                return;
            }
            defaultValue.ifPresent(s -> typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(defaultValue.get()).isExplicitInDsl(false).build()));
        }
    };
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) 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) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel)

Example 3 with DslElementModel

use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.

the class ConfigurationBasedElementModelFactory method createIdentifiedElement.

private DslElementModel createIdentifiedElement(ComponentConfiguration configuration) {
    final ComponentIdentifier identifier = configuration.getIdentifier();
    Optional<Map.Entry<ExtensionModel, DslSyntaxResolver>> entry = resolvers.entrySet().stream().filter(e -> e.getKey().getXmlDslModel().getPrefix().equals(identifier.getNamespace())).findFirst();
    if (!entry.isPresent()) {
        return null;
    }
    currentExtension = entry.get().getKey();
    dsl = entry.get().getValue();
    Reference<DslElementModel> elementModel = new Reference<>();
    new ExtensionWalker() {

        @Override
        protected void onConfiguration(ConfigurationModel model) {
            final DslElementSyntax elementDsl = dsl.resolve(model);
            getIdentifier(elementDsl).ifPresent(elementId -> {
                if (elementId.equals(identifier)) {
                    DslElementModel.Builder<ConfigurationModel> element = createElementModel(model, elementDsl, configuration);
                    addConnectionProvider(model, dsl, element, configuration);
                    elementModel.set(element.build());
                    stop();
                }
            });
        }

        @Override
        protected void onConstruct(HasConstructModels owner, ConstructModel model) {
            final DslElementSyntax elementDsl = dsl.resolve(model);
            getIdentifier(elementDsl).ifPresent(elementId -> {
                if (elementId.equals(identifier)) {
                    elementModel.set(createElementModel(model, elementDsl, configuration).build());
                    stop();
                }
            });
        }

        @Override
        protected void onOperation(HasOperationModels owner, OperationModel model) {
            final DslElementSyntax elementDsl = dsl.resolve(model);
            getIdentifier(elementDsl).ifPresent(elementId -> {
                if (elementId.equals(identifier)) {
                    elementModel.set(createElementModel(model, elementDsl, configuration).build());
                    stop();
                }
            });
        }

        @Override
        protected void onSource(HasSourceModels owner, SourceModel model) {
            final DslElementSyntax elementDsl = dsl.resolve(model);
            getIdentifier(elementDsl).ifPresent(elementId -> {
                if (elementId.equals(identifier)) {
                    elementModel.set(createElementModel(model, elementDsl, configuration).build());
                    stop();
                }
            });
        }
    }.walk(currentExtension);
    if (elementModel.get() == null) {
        resolveBasedOnTypes(configuration).ifPresent(elementModel::set);
    }
    return elementModel.get();
}
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) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Reference(org.mule.runtime.api.util.Reference) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 4 with DslElementModel

use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.

the class ConfigurationBasedElementModelFactory method resolveWrappedElement.

private void resolveWrappedElement(DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel p, DslElementSyntax pDsl, ComponentConfiguration paramComponent) {
    if (paramComponent != null) {
        DslElementModel.Builder<ParameterModel> paramElement = DslElementModel.<ParameterModel>builder().withModel(p).withDsl(pDsl).withConfig(paramComponent);
        if (paramComponent.getNestedComponents().size() > 0) {
            ComponentConfiguration wrappedComponent = paramComponent.getNestedComponents().get(0);
            this.create(wrappedComponent).ifPresent(paramElement::containing);
        }
        groupElementBuilder.containing(paramElement.build());
    }
}
Also used : InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel)

Example 5 with DslElementModel

use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.

the class DeclarationBasedElementModelFactory method createTopLevelElement.

private DslElementModel createTopLevelElement(ObjectType model, TopLevelParameterDeclaration declaration) {
    DslElementSyntax objectDsl = dsl.resolve(model).orElseThrow(() -> new IllegalArgumentException("Failed to resolve the DSL syntax for type '" + getId(model) + "'"));
    DslElementModel.Builder<MetadataType> parentElement = DslElementModel.<MetadataType>builder().withModel(model).withDsl(objectDsl);
    InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(objectDsl)).withParameter(NAME_ATTRIBUTE_NAME, declaration.getRefName());
    populateObjectElementFields(model, declaration.getValue(), objectDsl, configuration, parentElement);
    return parentElement.withConfig(configuration.build()).build();
}
Also used : DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MetadataType(org.mule.metadata.api.model.MetadataType) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)

Aggregations

DslElementModel (org.mule.runtime.config.api.dsl.model.DslElementModel)17 InternalComponentConfiguration (org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)14 ComponentConfiguration (org.mule.runtime.dsl.api.component.config.ComponentConfiguration)13 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)12 MetadataType (org.mule.metadata.api.model.MetadataType)10 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)10 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)9 List (java.util.List)8 Optional (java.util.Optional)8 Optional.empty (java.util.Optional.empty)8 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)8 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)8 Reference (org.mule.runtime.api.util.Reference)8 ArrayType (org.mule.metadata.api.model.ArrayType)7 ObjectType (org.mule.metadata.api.model.ObjectType)7 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)7 Map (java.util.Map)6 Collectors.toList (java.util.stream.Collectors.toList)6 Stream.concat (java.util.stream.Stream.concat)6 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)6