use of org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.InjectableParameterInfo in project mule by mulesoft.
the class ValueProviderModelValidator method validateOptionsResolver.
private void validateOptionsResolver(ParameterModel param, ValueProviderFactoryModelProperty modelProperty, ParameterizedModel model, ProblemsReporter problemsReporter, boolean supportsConnectionsAndConfigs, ReflectionCache reflectionCache) {
Class<? extends ValueProvider> valueProvider = modelProperty.getValueProvider();
String providerName = valueProvider.getSimpleName();
Map<String, MetadataType> allParameters = model.getAllParameterModels().stream().collect(toMap(IntrospectionUtils::getImplementingName, ParameterModel::getType));
String modelName = NameUtils.getModelName(model);
String modelTypeName = NameUtils.getComponentModelTypeName(model);
if (!isInstantiable(valueProvider, reflectionCache)) {
problemsReporter.addError(new Problem(model, format("The Value Provider [%s] is not instantiable but it should", providerName)));
}
if (!(param.getType() instanceof StringType)) {
problemsReporter.addError(new Problem(model, format("The parameter [%s] of the %s '%s' is not of String type. Parameters that provides Values should be of String type.", param.getName(), modelTypeName, modelName)));
}
for (InjectableParameterInfo parameterInfo : modelProperty.getInjectableParameters()) {
if (!allParameters.containsKey(parameterInfo.getParameterName())) {
problemsReporter.addError(new Problem(model, format("The Value Provider [%s] declares a parameter '%s' which doesn't exist in the %s '%s'", providerName, parameterInfo.getParameterName(), modelTypeName, modelName)));
} else {
MetadataType metadataType = allParameters.get(parameterInfo.getParameterName());
Class<?> expectedType = getType(metadataType).orElseThrow(() -> new IllegalStateException(format("Unable to get Class for parameter: %s", parameterInfo.getParameterName())));
Class<?> gotType = getType(parameterInfo.getType()).orElseThrow(() -> new IllegalStateException(format("Unable to get Class for parameter: %s", parameterInfo.getParameterName())));
if (!expectedType.equals(gotType)) {
problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines a parameter '%s' of type '%s' but in the %s '%s' is of type '%s'", providerName, parameterInfo.getParameterName(), gotType, modelTypeName, modelName, expectedType)));
}
}
}
if (supportsConnectionsAndConfigs && modelProperty.usesConnection() && model instanceof ConnectableComponentModel) {
boolean requiresConnection = ((ConnectableComponentModel) model).requiresConnection();
if (requiresConnection != modelProperty.usesConnection()) {
problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines that requires a connection, but is used in the %s '%s' which is connection less", providerName, modelTypeName, modelName)));
}
}
if (!supportsConnectionsAndConfigs) {
if (modelProperty.usesConnection()) {
problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines that requires a connection which is not allowed for a Value Provider of a %s's parameter [%s]", providerName, modelTypeName, modelName)));
}
if (modelProperty.usesConfig()) {
problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines that requires a configuration which is not allowed for a Value Provider of a %s's parameter [%s]", providerName, modelTypeName, modelName)));
}
}
}
use of org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.InjectableParameterInfo 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