Search in sources :

Example 16 with ParameterModel

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

the class SchemaBuilder method addInlineParameterGroup.

void addInlineParameterGroup(ParameterGroupModel group, ExplicitGroup parentSequence) {
    DslElementSyntax groupDsl = dslResolver.resolveInline(group);
    LocalComplexType complexType = objectTypeDelegate.createTypeExtension(MULE_ABSTRACT_EXTENSION_TYPE);
    ExplicitGroup groupSequence = new ExplicitGroup();
    List<ParameterModel> groupParameters = group.getParameterModels();
    List<TopLevelElement> parameterElements = registerParameters(complexType.getComplexContent().getExtension(), groupParameters);
    addParameterToSequence(parameterElements, groupSequence);
    BigInteger minOccurs = ExtensionModelUtils.isRequired(group) ? ONE : ZERO;
    TopLevelElement groupElement = createTopLevelElement(groupDsl.getElementName(), minOccurs, MAX_ONE);
    groupElement.setComplexType(complexType);
    complexType.getComplexContent().getExtension().setSequence(groupSequence);
    parentSequence.getParticle().add(objectFactory.createElement(groupElement));
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) BigInteger(java.math.BigInteger) 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 17 with ParameterModel

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

the class SchemaBuilder method registerParameters.

List<TopLevelElement> registerParameters(ExtensionType type, Collection<ParameterModel> parameterModels) {
    List<TopLevelElement> all = new ArrayList<>(parameterModels.size());
    getSortedParameterModels(parameterModels).stream().filter(p -> !p.getModelProperty(QNameModelProperty.class).isPresent()).forEach(parameterModel -> {
        DslElementSyntax paramDsl = dslResolver.resolve(parameterModel);
        declareAsParameter(parameterModel.getType(), type, parameterModel, paramDsl, all);
    });
    return all;
}
Also used : InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) SCHEDULING_STRATEGY_ELEMENT(org.mule.runtime.config.internal.dsl.SchemaConstants.SCHEDULING_STRATEGY_ELEMENT) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ENUM_TYPE_SUFFIX(org.mule.runtime.config.internal.dsl.SchemaConstants.ENUM_TYPE_SUFFIX) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) TLS_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TLS_PARAMETER_NAME) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) ArrayType(org.mule.metadata.api.model.ArrayType) Union(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Union) BigInteger(java.math.BigInteger) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) StringUtils(org.mule.runtime.core.api.util.StringUtils) ParameterDslConfiguration(org.mule.runtime.api.meta.model.ParameterDslConfiguration) ExtensionModelUtils.isContent(org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectStore(org.mule.runtime.api.store.ObjectStore) EE_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.EE_SCHEMA_LOCATION) SchemaConstants(org.mule.runtime.config.internal.dsl.SchemaConstants) Set(java.util.Set) OperationTransactionalAction(org.mule.runtime.extension.api.tx.OperationTransactionalAction) USE_OPTIONAL(org.mule.runtime.config.internal.dsl.SchemaConstants.USE_OPTIONAL) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) Attribute(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) StringType(org.mule.metadata.api.model.StringType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) USE_REQUIRED(org.mule.runtime.config.internal.dsl.SchemaConstants.USE_REQUIRED) ParameterModelComparator(org.mule.runtime.extension.api.util.ParameterModelComparator) SPRING_FRAMEWORK_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.SPRING_FRAMEWORK_SCHEMA_LOCATION) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Import(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Import) QName(javax.xml.namespace.QName) ZERO(java.math.BigInteger.ZERO) FormChoice(org.mule.runtime.module.extension.internal.capability.xml.schema.model.FormChoice) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) ObjectTypeSchemaDelegate.getAbstractElementName(org.mule.runtime.module.extension.internal.capability.xml.schema.builder.ObjectTypeSchemaDelegate.getAbstractElementName) CORE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.CORE_NAMESPACE) TLS_CONTEXT_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.TLS_CONTEXT_TYPE) ArrayList(java.util.ArrayList) MULE_TLS_NAMESPACE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_TLS_NAMESPACE) SPRING_FRAMEWORK_NAMESPACE(org.mule.runtime.config.internal.dsl.SchemaConstants.SPRING_FRAMEWORK_NAMESPACE) MULE_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_SCHEMA_LOCATION) XML_NAMESPACE(org.mule.runtime.config.internal.dsl.SchemaConstants.XML_NAMESPACE) TopLevelSimpleType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelSimpleType) LinkedHashSet(java.util.LinkedHashSet) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup) JAXBElement(javax.xml.bind.JAXBElement) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) TransactionType(org.mule.runtime.api.tx.TransactionType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) STRING(org.mule.runtime.config.internal.dsl.SchemaConstants.STRING) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) Documentation(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Documentation) PRIVATE_OBJECT_STORE_ELEMENT(org.mule.runtime.config.internal.dsl.SchemaConstants.PRIVATE_OBJECT_STORE_ELEMENT) MULE_TLS_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_TLS_SCHEMA_LOCATION) SubstitutionGroup(org.mule.runtime.extension.api.declaration.type.annotation.SubstitutionGroup) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) ONE(java.math.BigInteger.ONE) MULE_TRANSACTION_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_TRANSACTION_TYPE) Restriction(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Restriction) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) MAX_ONE(org.mule.runtime.config.internal.dsl.SchemaConstants.MAX_ONE) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Collections.singleton(java.util.Collections.singleton) ExtensionModelUtils.componentHasAnImplicitConfiguration(org.mule.runtime.extension.api.util.ExtensionModelUtils.componentHasAnImplicitConfiguration) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.SUPPORTED) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) Collection(java.util.Collection) String.format(java.lang.String.format) NAME_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.NAME_ATTRIBUTE_NAME) Objects(java.util.Objects) ExtensionMetadataTypeUtils.getSubstitutionGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getSubstitutionGroup) List(java.util.List) NamedGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.NamedGroup) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) Optional(java.util.Optional) EE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.EE_PREFIX) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) EE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.EE_NAMESPACE) Schema(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Schema) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ObjectFactory(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ObjectFactory) TypeCatalog(org.mule.runtime.api.meta.type.TypeCatalog) LOCAL(org.mule.runtime.api.tx.TransactionType.LOCAL) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) NoFixedFacet(org.mule.runtime.module.extension.internal.capability.xml.schema.model.NoFixedFacet) Comparator.comparing(java.util.Comparator.comparing) LocalSimpleType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalSimpleType) LinkedList(java.util.LinkedList) ExpressionSupport(org.mule.runtime.api.meta.ExpressionSupport) SchemaTypeConversion(org.mule.runtime.module.extension.internal.capability.xml.schema.model.SchemaTypeConversion) ExtensionModelUtils(org.mule.runtime.extension.api.util.ExtensionModelUtils) MULE_ABSTRACT_EXTENSION_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_ABSTRACT_EXTENSION_TYPE) ExtensionMetadataTypeUtils(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils) MULE_OPERATION_TRANSACTIONAL_ACTION_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_OPERATION_TRANSACTIONAL_ACTION_TYPE) NameUtils.sanitizeName(org.mule.runtime.extension.api.util.NameUtils.sanitizeName) Annotation(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Annotation) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ArrayList(java.util.ArrayList)

Example 18 with ParameterModel

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

the class InjectedFieldsModelValidator method validate.

@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
    final Set<Class<?>> validatedTypes = new HashSet<>();
    // TODO - MULE-14401 - Make InjectedFieldsModelValidator work in AST Mode
    Boolean isASTMode = !extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class).map(mp -> mp.getType().getDeclaringClass().isPresent()).orElse(false);
    if (!isASTMode) {
        extensionModel.getModelProperty(ClassLoaderModelProperty.class).ifPresent(classLoaderModelProperty -> {
            new ExtensionWalker() {

                @Override
                protected void onSource(HasSourceModels owner, SourceModel model) {
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
                }

                @Override
                protected void onConfiguration(ConfigurationModel model) {
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), RefName.class);
                }

                @Override
                protected void onOperation(HasOperationModels owner, OperationModel model) {
                    validateArguments(model, model.getModelProperty(ExtensionOperationDescriptorModelProperty.class), DefaultEncoding.class);
                }

                @Override
                protected void onConnectionProvider(HasConnectionProviderModels owner, ConnectionProviderModel model) {
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), RefName.class);
                }

                @Override
                protected void onParameter(ParameterizedModel owner, ParameterGroupModel groupModel, ParameterModel model) {
                    if (model.getType().getMetadataFormat().equals(JAVA)) {
                        model.getType().accept(new MetadataTypeVisitor() {

                            @Override
                            public void visitObject(ObjectType objectType) {
                                if (!objectType.getAnnotation(InfrastructureTypeAnnotation.class).isPresent()) {
                                    try {
                                        Class<?> type = getType(objectType, classLoaderModelProperty.getClassLoader());
                                        if (validatedTypes.add(type)) {
                                            validateType(model, type, DefaultEncoding.class);
                                        }
                                    } catch (Exception e) {
                                        problemsReporter.addWarning(new Problem(model, "Could not validate Class: " + e.getMessage()));
                                    }
                                }
                            }
                        });
                    }
                }

                private void validateArguments(NamedObject model, Optional<ExtensionOperationDescriptorModelProperty> modelProperty, Class<? extends Annotation> annotationClass) {
                    modelProperty.ifPresent(operationDescriptorModelProperty -> {
                        MethodElement operation = operationDescriptorModelProperty.getOperationMethod();
                        int size = operation.getParametersAnnotatedWith(annotationClass).size();
                        if (size == 0) {
                            return;
                        } else if (size > 1) {
                            problemsReporter.addError(new Problem(model, format("Operation method '%s' has %d arguments annotated with @%s. Only one argument may carry that annotation", operation.getName(), size, annotationClass.getSimpleName())));
                        }
                        ExtensionParameter argument = operation.getParametersAnnotatedWith(annotationClass).get(0);
                        if (!argument.getType().isSameType(String.class)) {
                            problemsReporter.addError(new Problem(model, format("Operation method '%s' declares an argument '%s' which is annotated with @%s and is of type '%s'. Only " + "arguments of type String are allowed to carry such annotation", operation.getName(), argument.getName(), annotationClass.getSimpleName(), argument.getType().getName())));
                        }
                    });
                }

                private void validateFields(NamedObject model, Optional<ImplementingTypeModelProperty> modelProperty, Class<? extends Annotation> annotationClass) {
                    modelProperty.ifPresent(implementingTypeModelProperty -> {
                        validateType(model, implementingTypeModelProperty.getType(), annotationClass);
                    });
                }

                private void validateType(NamedObject model, Class<?> type, Class<? extends Annotation> annotationClass) {
                    List<Field> fields = getAnnotatedFields(type, annotationClass);
                    if (fields.isEmpty()) {
                        return;
                    } else if (fields.size() > 1) {
                        problemsReporter.addError(new Problem(model, format("Class '%s' has %d fields annotated with @%s. Only one field may carry that annotation", type.getName(), fields.size(), annotationClass.getSimpleName())));
                    }
                    Field field = fields.get(0);
                    if (!String.class.equals(field.getType())) {
                        problemsReporter.addError(new Problem(model, format("Class '%s' declares the field '%s' which is annotated with @%s and is of type '%s'. Only " + "fields of type String are allowed to carry such annotation", type.getName(), field.getName(), annotationClass.getSimpleName(), field.getType().getName())));
                    }
                }
            }.walk(extensionModel);
        });
    }
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) IntrospectionUtils.getAnnotatedFields(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getAnnotatedFields) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) NamedObject(org.mule.runtime.api.meta.NamedObject) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashSet(java.util.HashSet) InfrastructureTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.InfrastructureTypeAnnotation) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Problem(org.mule.runtime.extension.api.loader.Problem) HasConnectionProviderModels(org.mule.runtime.api.meta.model.connection.HasConnectionProviderModels) ExtensionModelValidator(org.mule.runtime.extension.api.loader.ExtensionModelValidator) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter) Set(java.util.Set) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) Field(java.lang.reflect.Field) String.format(java.lang.String.format) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DefaultEncoding(org.mule.runtime.extension.api.annotation.param.DefaultEncoding) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) RefName(org.mule.runtime.extension.api.annotation.param.RefName) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) RefName(org.mule.runtime.extension.api.annotation.param.RefName) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ObjectType(org.mule.metadata.api.model.ObjectType) Field(java.lang.reflect.Field) List(java.util.List) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) HashSet(java.util.HashSet) ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) NamedObject(org.mule.runtime.api.meta.NamedObject) HasConnectionProviderModels(org.mule.runtime.api.meta.model.connection.HasConnectionProviderModels) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Problem(org.mule.runtime.extension.api.loader.Problem) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) DefaultEncoding(org.mule.runtime.extension.api.annotation.param.DefaultEncoding) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 19 with ParameterModel

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

the class MetadataKeyIdObjectResolver method reconstructKeyFromType.

/**
 * Given a {@link Object} representing the resolved value for a {@link MetadataKey}, generates the {@link MetadataKey} object.
 *
 * @param resolvedKey
 * @return {@link MetadataKey} reconstructed from the resolved object key
 * @throws MetadataResolvingException
 */
MetadataKey reconstructKeyFromType(Object resolvedKey, ReflectionCache reflectionCache) throws MetadataResolvingException {
    if (isKeyLess() || resolvedKey == null) {
        return new NullMetadataKey();
    }
    if (keyParts.size() == 1) {
        return newKey(valueOf(resolvedKey)).build();
    }
    MetadataKeyBuilder rootBuilder = null;
    MetadataKeyBuilder childBuilder = null;
    for (ParameterModel p : keyParts) {
        try {
            if (p.getModelProperty(DeclaringMemberModelProperty.class).isPresent()) {
                MetadataKeyBuilder fieldBuilder = getKeyFromField(resolvedKey, p.getModelProperty(DeclaringMemberModelProperty.class).get(), reflectionCache);
                if (rootBuilder == null) {
                    rootBuilder = fieldBuilder;
                    childBuilder = rootBuilder;
                } else {
                    childBuilder.withChild(fieldBuilder);
                    childBuilder = fieldBuilder;
                }
            }
        } catch (Exception e) {
            throw new MetadataResolvingException("Could not construct Metadata Key part for parameter " + p.getName(), FailureCode.INVALID_METADATA_KEY, e);
        }
    }
    return rootBuilder != null ? rootBuilder.build() : new NullMetadataKey();
}
Also used : DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) MetadataKeyBuilder(org.mule.runtime.api.metadata.MetadataKeyBuilder) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Example 20 with ParameterModel

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

the class MetadataKeysDelegate method getMetadataKeys.

MetadataResult<MetadataKeysContainer> getMetadataKeys(MetadataContext context, Object partialKey, ReflectionCache reflectionCache) {
    final TypeKeysResolver keyResolver = resolverFactory.getKeyResolver();
    final String componentResolverName = keyResolver.getCategoryName();
    final MetadataKeysContainerBuilder keysContainer = MetadataKeysContainerBuilder.getInstance();
    if (keyParts.isEmpty()) {
        return success(keysContainer.add(componentResolverName, ImmutableSet.of(new NullMetadataKey())).build());
    }
    try {
        final Map<Integer, ParameterModel> partsByOrder = getPartOrderMapping(keyParts);
        Set<MetadataKey> metadataKeys;
        if (keyResolver instanceof PartialTypeKeysResolver && hasInitialLevel(partialKey, partsByOrder, reflectionCache)) {
            metadataKeys = singleton(((PartialTypeKeysResolver) keyResolver).resolveChilds(context, partialKey));
        } else {
            metadataKeys = keyResolver.getKeys(context);
        }
        final Set<MetadataKey> enrichedMetadataKeys = metadataKeys.stream().map(metadataKey -> cloneAndEnrichMetadataKey(metadataKey, partsByOrder)).map(MetadataKeyBuilder::build).collect(toSet());
        keysContainer.add(componentResolverName, enrichedMetadataKeys);
        return success(keysContainer.build());
    } catch (Exception e) {
        return failure(newFailure(e).onKeys());
    }
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) MetadataKeysContainerBuilder(org.mule.runtime.api.metadata.MetadataKeysContainerBuilder) PartialTypeKeysResolver(org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver) TypeKeysResolver(org.mule.runtime.api.metadata.resolving.TypeKeysResolver) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) PartialTypeKeysResolver(org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver)

Aggregations

ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)133 Test (org.junit.Test)91 SmallTest (org.mule.tck.size.SmallTest)68 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)21 List (java.util.List)19 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)19 Optional (java.util.Optional)16 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)15 Collectors.toList (java.util.stream.Collectors.toList)13 ObjectType (org.mule.metadata.api.model.ObjectType)13 String.format (java.lang.String.format)12 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)12 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)12 ExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory)12 StringType (org.mule.metadata.api.model.StringType)11 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)10 ArrayType (org.mule.metadata.api.model.ArrayType)10 MetadataType (org.mule.metadata.api.model.MetadataType)10 Map (java.util.Map)9