use of org.mule.runtime.module.extension.internal.runtime.exception.RequiredParameterNotSetException in project mule by mulesoft.
the class ParametersResolver method resolveParameters.
/**
* {@inheritDoc}
*/
@Override
public void resolveParameters(ObjectType objectType, DefaultObjectBuilder builder) {
final Class<?> objectClass = getType(objectType);
final boolean isParameterGroup = isFlattenedParameterGroup(objectType);
objectType.getFields().forEach(field -> {
final String key = getLocalPart(field);
ValueResolver<?> valueResolver = null;
Field objectField = getField(objectClass, key);
if (parameters.containsKey(key)) {
valueResolver = toValueResolver(parameters.get(key));
} else if (!isParameterGroup) {
valueResolver = getDefaultValue(field).isPresent() ? getFieldDefaultValueValueResolver(field, muleContext) : null;
}
Optional<NullSafeTypeAnnotation> nullSafe = field.getAnnotation(NullSafeTypeAnnotation.class);
if (nullSafe.isPresent()) {
ValueResolver<?> delegate = valueResolver != null ? valueResolver : new StaticValueResolver<>(null);
MetadataType type = getMetadataType(nullSafe.get().getType(), ExtensionsTypeLoaderFactory.getDefault().createTypeLoader());
valueResolver = NullSafeValueResolverWrapper.of(delegate, type, reflectionCache, muleContext, this);
}
if (field.getAnnotation(ConfigOverrideTypeAnnotation.class).isPresent()) {
valueResolver = ConfigOverrideValueResolverWrapper.of(valueResolver != null ? valueResolver : new StaticValueResolver<>(null), key, reflectionCache, muleContext);
}
if (valueResolver != null) {
try {
initialiseIfNeeded(valueResolver, true, muleContext);
builder.addPropertyResolver(objectField.getName(), valueResolver);
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
} else if (field.isRequired() && !isFlattenedParameterGroup(field) && !lazyInitEnabled) {
throw new RequiredParameterNotSetException(objectField.getName());
}
});
}
use of org.mule.runtime.module.extension.internal.runtime.exception.RequiredParameterNotSetException in project mule by mulesoft.
the class ParametersResolver method getResolverSet.
private ResolverSet getResolverSet(Optional<ParameterizedModel> model, List<ParameterGroupModel> groups, List<ParameterModel> parameterModels, MuleContext muleContext, ResolverSet resolverSet) throws ConfigurationException {
Map<String, String> aliasedParameterNames = new HashMap<>();
parameterModels.forEach(p -> {
final String parameterName = getMemberName(p, p.getName());
if (!parameterName.equals(p.getName())) {
aliasedParameterNames.put(parameterName, p.getName());
}
ValueResolver<?> resolver = getParameterValueResolver(p, parameterName, muleContext);
if (resolver != null) {
resolverSet.add(parameterName, resolver);
} else if (p.isRequired() && !lazyInitEnabled) {
throw new RequiredParameterNotSetException(p);
}
});
checkParameterGroupExclusiveness(model, groups, parameters.keySet().stream().map(k -> aliasedParameterNames.getOrDefault(k, k)).collect(Collectors.toSet()));
return resolverSet;
}
Aggregations