Search in sources :

Example 1 with ParameterMetadataDescriptorBuilder

use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder 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());
}
Also used : ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) ParameterMetadataDescriptorBuilder(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder) MetadataType(org.mule.metadata.api.model.MetadataType)

Aggregations

MetadataType (org.mule.metadata.api.model.MetadataType)1 ParameterMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor)1 ParameterMetadataDescriptorBuilder (org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder)1