use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor in project mule by mulesoft.
the class MetadataInputDelegate method getParameterMetadataDescriptor.
/**
* Creates a {@link TypeMetadataDescriptor} representing the Component's Content metadata using the
* {@link InputTypeResolver}, if one is available to resolve the {@link MetadataType}. If no the Component has no Content
* parameter, then {@link Optional#empty()} is returned.
*
* @param context current {@link MetadataContext} that will be used by the {@link InputTypeResolver}
* @param key {@link MetadataKey} of the type which's structure has to be resolved
* @return Success with an {@link Optional} {@link TypeMetadataDescriptor} representing the Component's Content metadata,
* resolved using the {@link InputTypeResolver} if one is available to resolve its {@link MetadataType}, returning
* {@link Optional#empty()} if no Content parameter is present Failure if the dynamic resolution fails for any reason.
*/
private MetadataResult<ParameterMetadataDescriptor> getParameterMetadataDescriptor(ParameterModel parameter, MetadataContext context, Object key) {
ParameterMetadataDescriptorBuilder descriptorBuilder = ParameterMetadataDescriptor.builder(parameter.getName());
if (!parameter.hasDynamicType()) {
return success(descriptorBuilder.withType(parameter.getType()).build());
}
descriptorBuilder.dynamic(true);
MetadataResult<MetadataType> inputMetadataResult = getParameterMetadata(parameter, context, key);
MetadataType type = inputMetadataResult.get() == null ? parameter.getType() : inputMetadataResult.get();
ParameterMetadataDescriptor descriptor = descriptorBuilder.withType(type).build();
return inputMetadataResult.isSuccess() ? success(descriptor) : failure(descriptor, inputMetadataResult.getFailures());
}
use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor in project mule by mulesoft.
the class MetadataInputDelegate method getInputMetadataDescriptors.
/**
* For each of the Component's {@link ParameterModel} creates the corresponding {@link TypeMetadataDescriptor} using only its
* static {@link MetadataType} and ignoring if any parameter has a dynamic type.
*
* @return A {@link List} containing a {@link MetadataResult} of {@link TypeMetadataDescriptor} for each input parameter using
* only its static {@link MetadataType} and ignoring if any parameter has a dynamic type.
*/
MetadataResult<InputMetadataDescriptor> getInputMetadataDescriptors(MetadataContext context, Object key) {
InputMetadataDescriptor.InputMetadataDescriptorBuilder input = InputMetadataDescriptor.builder();
List<MetadataResult<ParameterMetadataDescriptor>> results = new LinkedList<>();
for (ParameterModel parameter : component.getAllParameterModels()) {
MetadataResult<ParameterMetadataDescriptor> result = getParameterMetadataDescriptor(parameter, context, key);
input.withParameter(parameter.getName(), result.get());
results.add(result);
}
List<MetadataFailure> failures = results.stream().flatMap(e -> e.getFailures().stream()).collect(toList());
return failures.isEmpty() ? success(input.build()) : failure(input.build(), failures);
}
use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor in project mule by mulesoft.
the class MetadataMediator method resolveParameterGroupModelType.
private List<ParameterGroupModel> resolveParameterGroupModelType(List<ParameterGroupModel> untypedParameterGroups, Map<String, ParameterMetadataDescriptor> inputTypeDescriptors) {
List<ParameterGroupModel> parameterGroups = new LinkedList<>();
untypedParameterGroups.forEach(parameterGroup -> {
List<ParameterModel> parameters = new LinkedList<>();
parameterGroup.getParameterModels().forEach(parameterModel -> {
ParameterMetadataDescriptor parameterMetadataDescriptor = inputTypeDescriptors.get(parameterModel.getName());
ParameterModel typedParameterModel = new ImmutableParameterModel(parameterModel.getName(), parameterModel.getDescription(), parameterMetadataDescriptor.getType(), parameterMetadataDescriptor.isDynamic(), parameterModel.isRequired(), parameterModel.isOverrideFromConfig(), parameterModel.getExpressionSupport(), parameterModel.getDefaultValue(), parameterModel.getRole(), parameterModel.getDslConfiguration(), parameterModel.getDisplayModel().orElse(null), parameterModel.getLayoutModel().orElse(null), parameterModel.getValueProviderModel().orElse(null), parameterModel.getAllowedStereotypes(), parameterModel.getModelProperties());
parameters.add(typedParameterModel);
});
parameterGroups.add(new ImmutableParameterGroupModel(parameterGroup.getName(), parameterGroup.getDescription(), parameters, parameterGroup.getExclusiveParametersModels(), parameterGroup.isShowInDsl(), parameterGroup.getDisplayModel().orElse(null), parameterGroup.getLayoutModel().orElse(null), parameterGroup.getModelProperties()));
});
return parameterGroups;
}
Aggregations