Search in sources :

Example 1 with ValueResolvingException

use of org.mule.runtime.extension.api.values.ValueResolvingException in project mule by mulesoft.

the class ValueProviderFactory method createValueProvider.

ValueProvider createValueProvider() throws ValueResolvingException {
    Class<? extends ValueProvider> resolverClass = factoryModelProperty.getValueProvider();
    try {
        ValueProvider resolver = instantiateClass(resolverClass);
        initialiseIfNeeded(resolver, true, muleContext);
        injectValueProviderFields(resolver);
        if (factoryModelProperty.usesConnection()) {
            injectValueIntoField(resolver, connectionSupplier.get(), connectionField);
        }
        if (factoryModelProperty.usesConfig()) {
            injectValueIntoField(resolver, configurationSupplier.get(), configField);
        }
        return resolver;
    } catch (ValueResolvingException e) {
        throw e;
    } catch (Exception e) {
        throw new ValueResolvingException("An error occurred trying to create a ValueProvider", UNKNOWN, e);
    }
}
Also used : ValueProvider(org.mule.runtime.extension.api.values.ValueProvider) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException)

Example 2 with ValueResolvingException

use of org.mule.runtime.extension.api.values.ValueResolvingException in project mule by mulesoft.

the class ConfigurationProviderToolingAdapter method withConnectionProviderInfo.

private <T> T withConnectionProviderInfo(WithConnectionProviderCallable<T> withConnectionProviderCallable) throws ValueResolvingException {
    ConnectionProvider<?> connectionProvider = configuration.getConnectionProvider().orElseThrow(() -> new ValueResolvingException("Unable to obtain the Connection Provider Instance", UNKNOWN));
    ConnectionProvider unwrap = unwrapProviderWrapper(connectionProvider);
    ConnectionProviderModel connectionProviderModel = getConnectionProviderModel(unwrap.getClass(), getAllConnectionProviders(getExtensionModel(), getConfigurationModel())).orElseThrow(() -> new ValueResolvingException("Internal error. Unable to obtain the Connection Provider Model", UNKNOWN));
    return withConnectionProviderCallable.call(unwrap, connectionProviderModel);
}
Also used : IntrospectionUtils.getConnectionProviderModel(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getConnectionProviderModel) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider)

Example 3 with ValueResolvingException

use of org.mule.runtime.extension.api.values.ValueResolvingException in project mule by mulesoft.

the class ValueProviderMediator method getValues.

/**
 * Given the name of a parameter or parameter group, and if the parameter supports it, this will try to resolve
 * the {@link Value values} for the parameter.
 *
 * @param parameterName          the name of the parameter to resolve their possible {@link Value values}
 * @param parameterValueResolver parameter resolver required if the associated {@link ValueProvider} requires
 *                               the value of parameters from the same parameter container.
 * @param connectionSupplier     supplier of connection instances related to the container and used, if necessary, by the
 *                               {@link ValueProvider}
 * @param configurationSupplier  supplier of connection instances related to the container and used, if necessary, by the
 *                               {@link ValueProvider}
 * @return a {@link Set} of {@link Value} correspondent to the given parameter
 * @throws ValueResolvingException if an error occurs resolving {@link Value values}
 */
public Set<Value> getValues(String parameterName, ParameterValueResolver parameterValueResolver, Supplier<Object> connectionSupplier, Supplier<Object> configurationSupplier) throws ValueResolvingException {
    List<ParameterModel> parameters = getParameters(parameterName);
    if (parameters.isEmpty()) {
        throw new ValueResolvingException(format("Unable to find model for parameter or parameter group with name '%s'.", parameterName), INVALID_VALUE_RESOLVER_NAME);
    }
    ParameterModel parameterModel = parameters.get(0);
    ValueProviderFactoryModelProperty factoryModelProperty = parameterModel.getModelProperty(ValueProviderFactoryModelProperty.class).orElseThrow(() -> new ValueResolvingException(format("The parameter with name '%s' is not an Values Provider", parameterName), INVALID_VALUE_RESOLVER_NAME));
    try {
        return resolveValues(parameters, factoryModelProperty, parameterValueResolver, connectionSupplier, configurationSupplier);
    } catch (Exception e) {
        throw new ValueResolvingException(format("An error occurred trying to resolve the Values for parameter '%s' of component '%s'", parameterName, containerModel.getName()), UNKNOWN, e);
    }
}
Also used : ValueProviderFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException)

Example 4 with ValueResolvingException

use of org.mule.runtime.extension.api.values.ValueResolvingException in project mule by mulesoft.

the class ValueProviderFactory method injectValueProviderFields.

private void injectValueProviderFields(ValueProvider resolver) throws ValueResolvingException {
    List<String> missingParameters = new ArrayList<>();
    for (InjectableParameterInfo injectableParam : factoryModelProperty.getInjectableParameters()) {
        Object parameterValue = null;
        String parameterName = injectableParam.getParameterName();
        try {
            parameterValue = parameterValueResolver.getParameterValue(parameterName);
        } catch (org.mule.runtime.module.extension.internal.runtime.ValueResolvingException ignored) {
            LOGGER.debug("An error occurred while resolving parameter " + parameterName, ignored);
        }
        if (parameterValue != null) {
            injectValueIntoField(resolver, parameterValue, parameterName, reflectionCache);
        } else if (injectableParam.isRequired()) {
            missingParameters.add(parameterName);
        }
    }
    if (!missingParameters.isEmpty()) {
        throw new ValueResolvingException("Unable to retrieve values. There are missing required parameters for the resolution: " + missingParameters, MISSING_REQUIRED_PARAMETERS);
    }
}
Also used : InjectableParameterInfo(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.InjectableParameterInfo) ArrayList(java.util.ArrayList) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException)

Aggregations

ValueResolvingException (org.mule.runtime.extension.api.values.ValueResolvingException)4 ArrayList (java.util.ArrayList)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)1 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)1 ValueProvider (org.mule.runtime.extension.api.values.ValueProvider)1 ValueProviderFactoryModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty)1 InjectableParameterInfo (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.InjectableParameterInfo)1 IntrospectionUtils.getConnectionProviderModel (org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getConnectionProviderModel)1