Search in sources :

Example 16 with ParameterGroupModel

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

the class ParameterGroupModelValidator method validate.

@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
    boolean isCompileTime = extensionModel.getModelProperty(CompileTimeModelProperty.class).isPresent();
    new ExtensionWalker() {

        @Override
        protected void onParameterGroup(ParameterizedModel owner, ParameterGroupModel model) {
            validateIsInstantiable(model, problemsReporter);
            if (isCompileTime) {
                validateNonEmptyGroup(model, problemsReporter);
            }
        }
    }.walk(extensionModel);
}
Also used : ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) CompileTimeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.CompileTimeModelProperty) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)

Example 17 with ParameterGroupModel

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

the class ImplicitObjectUtils method buildImplicitResolverSet.

/**
 * Creates a {@link ResolverSet} based on the default values for the {@link ParameterModel}s in the {@code parametrizedModel}.
 * <p>
 * If a {@link ParameterModel} returns {@code null} for {@link ParameterModel#getDefaultValue()} then it's ignored
 *
 * @param model a model holding the {@link ParameterModel}s to consider
 * @param muleContext the Mule node.
 * @return a {@link ResolverSet}
 */
public static ResolverSet buildImplicitResolverSet(ParameterizedModel model, ReflectionCache reflectionCache, MuleContext muleContext) {
    ResolverSet resolverSet = new HashedResolverSet(muleContext);
    ParametersResolver parametersResolver = ParametersResolver.fromDefaultValues(model, muleContext, reflectionCache);
    for (ParameterGroupModel groupModel : model.getParameterGroupModels()) {
        Optional<ParameterGroupDescriptor> descriptor = groupModel.getModelProperty(ParameterGroupModelProperty.class).map(ParameterGroupModelProperty::getDescriptor);
        if (descriptor.isPresent() && groupModel.getParameterModels().stream().noneMatch(ParameterModel::isRequired)) {
            String groupKey = getContainerName(descriptor.get().getContainer());
            resolverSet.add(groupKey, NullSafeValueResolverWrapper.of(new StaticValueResolver<>(null), descriptor.get().getMetadataType(), reflectionCache, muleContext, parametersResolver));
        } else {
            groupModel.getParameterModels().forEach(parameterModel -> {
                Object defaultValue = parameterModel.getDefaultValue();
                ValueResolver<?> resolver;
                if (defaultValue instanceof String) {
                    resolver = getExpressionBasedValueResolver((String) defaultValue, parameterModel.getType(), muleContext);
                } else {
                    resolver = new StaticValueResolver<>(null);
                }
                if (parameterModel.getModelProperty(NullSafeModelProperty.class).isPresent()) {
                    MetadataType metadataType = parameterModel.getModelProperty(NullSafeModelProperty.class).get().defaultType();
                    resolver = NullSafeValueResolverWrapper.of(resolver, metadataType, reflectionCache, muleContext, parametersResolver);
                }
                resolverSet.add(parameterModel.getName(), resolver);
            });
        }
    }
    return resolverSet;
}
Also used : HashedResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.HashedResolverSet) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) NullSafeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.NullSafeModelProperty) HashedResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.HashedResolverSet) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) MetadataType(org.mule.metadata.api.model.MetadataType) ParametersResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ParametersResolver) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)

Example 18 with ParameterGroupModel

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

the class ParametersResolver method getParametersAsResolverSet.

/**
 * Constructs a {@link ResolverSet} from the parameters, using {@link #toValueResolver(Object, Set)} to process the values.
 *
 * @return a {@link ResolverSet}
 */
public ResolverSet getParametersAsResolverSet(ParameterizedModel model, MuleContext muleContext) throws ConfigurationException {
    List<ParameterGroupModel> inlineGroups = getInlineGroups(model.getParameterGroupModels());
    List<ParameterModel> flatParameters = getFlatParameters(inlineGroups, model.getAllParameterModels());
    ResolverSet resolverSet = getParametersAsResolverSet(model, flatParameters, muleContext);
    for (ParameterGroupModel group : inlineGroups) {
        getInlineGroupResolver(group, resolverSet, muleContext);
    }
    return resolverSet;
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)

Example 19 with ParameterGroupModel

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

the class ParametersResolver method getParametersAsResolverSet.

/**
 * Constructs a {@link ResolverSet} from the parameters groups, using {@link #toValueResolver(Object, Set)} to process the values.
 *
 * @return a {@link ResolverSet}
 */
public ResolverSet getParametersAsResolverSet(MuleContext muleContext, ParameterizedModel model, List<ParameterGroupModel> groups) throws ConfigurationException {
    List<ParameterGroupModel> inlineGroups = getInlineGroups(groups);
    List<ParameterModel> allParameters = groups.stream().flatMap(g -> g.getParameterModels().stream()).collect(toList());
    ResolverSet resolverSet = getParametersAsResolverSet(model, getFlatParameters(inlineGroups, allParameters), muleContext);
    for (ParameterGroupModel group : inlineGroups) {
        getInlineGroupResolver(group, resolverSet, muleContext);
    }
    return resolverSet;
}
Also used : ResolverUtils.getDefaultValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverUtils.getDefaultValueResolver) CollectionUtils.intersection(org.apache.commons.collections.CollectionUtils.intersection) IntrospectionUtils.getMemberName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMemberName) NameUtils.getModelName(org.mule.runtime.extension.api.util.NameUtils.getModelName) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ConfigOverrideTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.ConfigOverrideTypeAnnotation) NullSafeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.NullSafeModelProperty) Map(java.util.Map) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ModelProperty(org.mule.runtime.api.meta.model.ModelProperty) MuleExtensionUtils.isNullSafe(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.isNullSafe) MetadataTypeUtils.getLocalPart(org.mule.metadata.api.utils.MetadataTypeUtils.getLocalPart) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ResolverUtils.getFieldDefaultValueValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverUtils.getFieldDefaultValueValueResolver) Collectors.toImmutableList(org.mule.runtime.api.util.collection.Collectors.toImmutableList) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ExclusiveParametersModel(org.mule.runtime.api.meta.model.parameter.ExclusiveParametersModel) ObjectStore(org.mule.runtime.api.store.ObjectStore) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) Collection(java.util.Collection) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) IntrospectionUtils.getFieldByNameOrAlias(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldByNameOrAlias) ExclusiveOptionalsTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.ExclusiveOptionalsTypeAnnotation) List(java.util.List) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) NameUtils.getComponentModelTypeName(org.mule.runtime.extension.api.util.NameUtils.getComponentModelTypeName) ExclusiveParameterGroupObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ExclusiveParameterGroupObjectBuilder) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) IntrospectionUtils.getContainerName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getContainerName) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) Joiner(com.google.common.base.Joiner) StackedTypesModelProperty.getStackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty.getStackedTypesModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataTypeUtils.getDefaultValue(org.mule.metadata.api.utils.MetadataTypeUtils.getDefaultValue) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) LinkedHashMap(java.util.LinkedHashMap) ExtensionMetadataTypeUtils.isFlattenedParameterGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isFlattenedParameterGroup) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) RequiredParameterNotSetException(org.mule.runtime.module.extension.internal.runtime.exception.RequiredParameterNotSetException) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) LinkedList(java.util.LinkedList) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) Collections.emptySet(java.util.Collections.emptySet) NullSafeTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.NullSafeTypeAnnotation) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ImmutableList.copyOf(com.google.common.collect.ImmutableList.copyOf) IntrospectionUtils.getMetadataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMetadataType) Field(java.lang.reflect.Field) Collectors.toList(java.util.stream.Collectors.toList) ExtensionMetadataTypeUtils(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)

Example 20 with ParameterGroupModel

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

the class ObjectBasedParameterValueResolver method getParameterValue.

@Override
public Object getParameterValue(String parameterName) throws ValueResolvingException {
    try {
        Optional<Field> field = getField(object.getClass(), parameterName, reflectionCache);
        if (field.isPresent()) {
            return getFieldValue(object, parameterName, reflectionCache);
        } else {
            for (ParameterGroupModel parameterGroupModel : parameterizedModel.getParameterGroupModels()) {
                Optional<ParameterGroupModelProperty> modelProperty = parameterGroupModel.getModelProperty(ParameterGroupModelProperty.class);
                if (modelProperty.isPresent()) {
                    ParameterGroupModelProperty property = modelProperty.get();
                    Field container = (Field) property.getDescriptor().getContainer();
                    Object parameterGroup = getFieldValue(object, container.getName(), reflectionCache);
                    Optional<Field> desiredField = getField(parameterGroup.getClass(), parameterName, reflectionCache);
                    if (desiredField.isPresent()) {
                        return getFieldValue(parameterGroup, parameterName, reflectionCache);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new ValueResolvingException("An error occurred trying to obtain the value for the parameter: " + parameterName);
    }
    throw new ValueResolvingException("Unable to resolve value for the parameter: " + parameterName);
}
Also used : IntrospectionUtils.getField(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getField) Field(java.lang.reflect.Field) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) ValueResolvingException(org.mule.runtime.module.extension.internal.runtime.ValueResolvingException) ValueResolvingException(org.mule.runtime.module.extension.internal.runtime.ValueResolvingException)

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