Search in sources :

Example 1 with OutputMetadataDescriptor

use of org.mule.runtime.api.metadata.descriptor.OutputMetadataDescriptor in project mule by mulesoft.

the class MetadataOutputDelegate method getOutputMetadataDescriptor.

/**
 * Creates an {@link OutputMetadataDescriptor} representing the Component's output metadata using the
 * {@link OutputTypeResolver}, if one is available to resolve the output {@link MetadataType}.
 *
 * @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 OutputMetadataDescriptor} representing the Component's output metadata, resolved using the
 * {@link OutputTypeResolver} if one is available to resolve its {@link MetadataType}. Failure if the dynamic
 * resolution fails for any reason.
 */
MetadataResult<OutputMetadataDescriptor> getOutputMetadataDescriptor(MetadataContext context, Object key) {
    if (!(component instanceof HasOutputModel)) {
        return failure(MetadataFailure.Builder.newFailure().withMessage("The given component has not output definition to be described").onComponent());
    }
    MetadataResult<MetadataType> output = getOutputMetadata(context, key);
    MetadataResult<MetadataType> attributes = getOutputAttributesMetadata(context, key);
    HasOutputModel componentWithOutput = (HasOutputModel) this.component;
    MetadataResult<TypeMetadataDescriptor> outputDescriptor = toMetadataDescriptorResult(componentWithOutput.getOutput().getType(), componentWithOutput.getOutput().hasDynamicType(), output);
    MetadataResult<TypeMetadataDescriptor> attributesDescriptor = toMetadataDescriptorResult(componentWithOutput.getOutputAttributes().getType(), false, attributes);
    OutputMetadataDescriptor descriptor = OutputMetadataDescriptor.builder().withReturnType(outputDescriptor.get()).withAttributesType(attributesDescriptor.get()).build();
    if (!output.isSuccess() || !attributes.isSuccess()) {
        List<MetadataFailure> failures = ImmutableList.<MetadataFailure>builder().addAll(output.getFailures()).addAll(attributes.getFailures()).build();
        return failure(descriptor, failures);
    }
    return success(descriptor);
}
Also used : TypeMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor) OutputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.OutputMetadataDescriptor) HasOutputModel(org.mule.runtime.api.meta.model.HasOutputModel) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure)

Example 2 with OutputMetadataDescriptor

use of org.mule.runtime.api.metadata.descriptor.OutputMetadataDescriptor in project mule by mulesoft.

the class MetadataMediator method getMetadata.

/**
 * Resolves the {@link ComponentMetadataDescriptor} for the associated {@code context} using static and dynamic resolving of the
 * Component parameters, attributes and output.
 *
 * @param context current {@link MetadataContext} that will be used by the {@link InputTypeResolver} and
 *        {@link OutputTypeResolver}
 * @param keyValue {@link Object} resolved {@link MetadataKey} object
 * @return Successful {@link MetadataResult} if the MetadataTypes are resolved without errors Failure {@link MetadataResult}
 *         when the Metadata retrieval of any element fails for any reason
 */
private MetadataResult<ComponentMetadataDescriptor<T>> getMetadata(MetadataContext context, Object keyValue, MetadataAttributes.MetadataAttributesBuilder attributesBuilder) {
    MetadataResult<OutputMetadataDescriptor> output = outputDelegate.getOutputMetadataDescriptor(context, keyValue);
    MetadataResult<InputMetadataDescriptor> input = inputDelegate.getInputMetadataDescriptors(context, keyValue);
    if (output.isSuccess() && input.isSuccess()) {
        MetadataAttributes metadataAttributes = getMetadataAttributes(attributesBuilder, outputDelegate, input.get());
        T model = getTypedModel(input.get(), output.get());
        return success(ComponentMetadataDescriptor.builder(model).withAttributes(metadataAttributes).build());
    }
    List<MetadataFailure> failures = ImmutableList.<MetadataFailure>builder().addAll(output.getFailures()).addAll(input.getFailures()).build();
    return failure(ComponentMetadataDescriptor.builder(component).build(), failures);
}
Also used : InputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor) OutputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.OutputMetadataDescriptor) MetadataAttributes(org.mule.runtime.api.metadata.MetadataAttributes) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure)

Aggregations

OutputMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.OutputMetadataDescriptor)2 MetadataFailure (org.mule.runtime.api.metadata.resolving.MetadataFailure)2 MetadataType (org.mule.metadata.api.model.MetadataType)1 MessageMetadataType (org.mule.metadata.message.api.MessageMetadataType)1 HasOutputModel (org.mule.runtime.api.meta.model.HasOutputModel)1 MetadataAttributes (org.mule.runtime.api.metadata.MetadataAttributes)1 InputMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor)1 TypeMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor)1