Search in sources :

Example 1 with HasOutputModel

use of org.mule.runtime.api.meta.model.HasOutputModel 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 HasOutputModel

use of org.mule.runtime.api.meta.model.HasOutputModel in project mule by mulesoft.

the class MetadataOutputDelegate method getOutputMetadata.

/**
 * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's
 * output using the {@link OutputTypeResolver} associated to the current component.
 *
 * @param context {@link MetadataContext} of the Metadata resolution
 * @param key     {@link MetadataKey} of the type which's structure has to be resolved
 * @return a {@link MetadataResult} with the {@link MetadataType} of the component's output
 */
private MetadataResult<MetadataType> getOutputMetadata(final MetadataContext context, final Object key) {
    OutputModel output = ((HasOutputModel) component).getOutput();
    if (isVoid(output.getType()) || !output.hasDynamicType()) {
        return success(output.getType());
    }
    try {
        MetadataType metadata = resolverFactory.getOutputResolver().getOutputType(context, key);
        if (isMetadataResolvedCorrectly(metadata, true)) {
            return success(adaptToListIfNecessary(metadata, key, context));
        }
        MetadataFailure failure = newFailure().withMessage("Error resolving Output Payload metadata").withFailureCode(NO_DYNAMIC_TYPE_AVAILABLE).withReason(NULL_TYPE_ERROR).onOutputPayload();
        return failure(output.getType(), failure);
    } catch (Exception e) {
        return failure(output.getType(), newFailure(e).onOutputAttributes());
    }
}
Also used : 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) OutputModel(org.mule.runtime.api.meta.model.OutputModel) HasOutputModel(org.mule.runtime.api.meta.model.HasOutputModel) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Aggregations

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