Search in sources :

Example 6 with StaticValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver 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 7 with StaticValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver in project mule by mulesoft.

the class MetadataKeyIdObjectResolver method instantiateFromFieldValue.

private Object instantiateFromFieldValue(Class<?> metadataKeyType, Map<Field, String> fieldValueMap) throws MetadataResolvingException {
    try {
        DefaultObjectBuilder objectBuilder = new DefaultObjectBuilder<>(metadataKeyType);
        fieldValueMap.forEach((f, v) -> objectBuilder.addPropertyResolver(f.getName(), new StaticValueResolver<>(v)));
        return objectBuilder.build(null);
    } catch (Exception e) {
        throw buildException(format("MetadataKey object of type '%s' from the component '%s' could not be instantiated", metadataKeyType.getSimpleName(), component.getName()), e);
    }
}
Also used : StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Aggregations

StaticValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)7 DefaultObjectBuilder (org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder)3 ValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver)3 MetadataType (org.mule.metadata.api.model.MetadataType)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ExpressionBasedParameterResolverValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver)2 ExpressionTypedValueValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver)2 NativeQueryParameterValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver)2 ProcessorChainValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver)2 StaticLiteralValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver)2 TypeSafeExpressionValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver)2 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 DateTime (org.joda.time.DateTime)1 DateTimeType (org.mule.metadata.api.model.DateTimeType)1