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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations