use of org.mule.runtime.api.metadata.resolving.MetadataResult in project mule by mulesoft.
the class MetadataExtensionFunctionalTestCase method getSuccessComponentDynamicMetadata.
private ComponentMetadataDescriptor<T> getSuccessComponentDynamicMetadata(MetadataKey key, BiConsumer<MetadataResult<ComponentMetadataDescriptor<T>>, MetadataKey> assertKeys) {
MetadataResult<ComponentMetadataDescriptor<T>> componentMetadata = getComponentDynamicMetadata(key);
String msg = componentMetadata.getFailures().stream().map(f -> "Failure: " + f.getMessage()).collect(joining(", "));
assertThat(msg, componentMetadata.isSuccess(), is(true));
assertKeys.accept(componentMetadata, key);
return componentMetadata.get();
}
use of org.mule.runtime.api.metadata.resolving.MetadataResult in project mule by mulesoft.
the class MetadataMediator method getMetadata.
/**
* Resolves the {@link ComponentMetadataDescriptor} for the associated {@code context} using the component
* {@link ParameterValueResolver} to resolve an object with the value of the {@link MetadataKey}.
*
* @param context current {@link MetadataContext} that will be used by the metadata resolvers.
* @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
*/
public MetadataResult<ComponentMetadataDescriptor<T>> getMetadata(MetadataContext context, ParameterValueResolver metadataKeyResolver, ReflectionCache reflectionCache) {
try {
Object keyValue;
MetadataResult keyValueResult = getMetadataKeyObjectValue(metadataKeyResolver);
if (!keyValueResult.isSuccess()) {
return keyValueResult;
}
keyValue = keyValueResult.get();
if (keyValue == null && !keyIdObjectResolver.isKeyLess()) {
return failure(newFailure().withFailureCode(INVALID_METADATA_KEY).withMessage("MetadataKey resolved to null").onComponent());
}
MetadataAttributes.MetadataAttributesBuilder builder = MetadataAttributes.builder();
if (!keyIdObjectResolver.isKeyLess()) {
builder.withKey(keyIdObjectResolver.reconstructKeyFromType(keyValue, reflectionCache));
}
return getMetadata(context, keyValue, builder);
} catch (MetadataResolvingException e) {
return failure(newFailure(e).onComponent());
}
}
use of org.mule.runtime.api.metadata.resolving.MetadataResult 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);
}
Aggregations