use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class ParameterGroupModelValidator method validate.
@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
boolean isCompileTime = extensionModel.getModelProperty(CompileTimeModelProperty.class).isPresent();
new ExtensionWalker() {
@Override
protected void onParameterGroup(ParameterizedModel owner, ParameterGroupModel model) {
validateIsInstantiable(model, problemsReporter);
if (isCompileTime) {
validateNonEmptyGroup(model, problemsReporter);
}
}
}.walk(extensionModel);
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel 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;
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class ParametersResolver method getParametersAsResolverSet.
/**
* Constructs a {@link ResolverSet} from the parameters, using {@link #toValueResolver(Object, Set)} to process the values.
*
* @return a {@link ResolverSet}
*/
public ResolverSet getParametersAsResolverSet(ParameterizedModel model, MuleContext muleContext) throws ConfigurationException {
List<ParameterGroupModel> inlineGroups = getInlineGroups(model.getParameterGroupModels());
List<ParameterModel> flatParameters = getFlatParameters(inlineGroups, model.getAllParameterModels());
ResolverSet resolverSet = getParametersAsResolverSet(model, flatParameters, muleContext);
for (ParameterGroupModel group : inlineGroups) {
getInlineGroupResolver(group, resolverSet, muleContext);
}
return resolverSet;
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class ParametersResolver method getParametersAsResolverSet.
/**
* Constructs a {@link ResolverSet} from the parameters groups, using {@link #toValueResolver(Object, Set)} to process the values.
*
* @return a {@link ResolverSet}
*/
public ResolverSet getParametersAsResolverSet(MuleContext muleContext, ParameterizedModel model, List<ParameterGroupModel> groups) throws ConfigurationException {
List<ParameterGroupModel> inlineGroups = getInlineGroups(groups);
List<ParameterModel> allParameters = groups.stream().flatMap(g -> g.getParameterModels().stream()).collect(toList());
ResolverSet resolverSet = getParametersAsResolverSet(model, getFlatParameters(inlineGroups, allParameters), muleContext);
for (ParameterGroupModel group : inlineGroups) {
getInlineGroupResolver(group, resolverSet, muleContext);
}
return resolverSet;
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class ObjectBasedParameterValueResolver method getParameterValue.
@Override
public Object getParameterValue(String parameterName) throws ValueResolvingException {
try {
Optional<Field> field = getField(object.getClass(), parameterName, reflectionCache);
if (field.isPresent()) {
return getFieldValue(object, parameterName, reflectionCache);
} else {
for (ParameterGroupModel parameterGroupModel : parameterizedModel.getParameterGroupModels()) {
Optional<ParameterGroupModelProperty> modelProperty = parameterGroupModel.getModelProperty(ParameterGroupModelProperty.class);
if (modelProperty.isPresent()) {
ParameterGroupModelProperty property = modelProperty.get();
Field container = (Field) property.getDescriptor().getContainer();
Object parameterGroup = getFieldValue(object, container.getName(), reflectionCache);
Optional<Field> desiredField = getField(parameterGroup.getClass(), parameterName, reflectionCache);
if (desiredField.isPresent()) {
return getFieldValue(parameterGroup, parameterName, reflectionCache);
}
}
}
}
} catch (Exception e) {
throw new ValueResolvingException("An error occurred trying to obtain the value for the parameter: " + parameterName);
}
throw new ValueResolvingException("Unable to resolve value for the parameter: " + parameterName);
}
Aggregations