use of org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor in project mule by mulesoft.
the class QueryMetadataTestCase method getEntityMetadata.
@Test
public void getEntityMetadata() throws Exception {
MetadataResult<TypeMetadataDescriptor> entityMetadata = metadataService.getEntityMetadata(QUERY_LOCATION, CIRCLE_METADATA_KEY);
assertThat(entityMetadata.isSuccess(), is(true));
TypeMetadataDescriptor descriptor = entityMetadata.get();
assertThat(descriptor.getType(), is(toMetadataType(Circle.class)));
}
use of org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor in project mule by mulesoft.
the class MetadataOutputDelegate method toMetadataDescriptorResult.
private MetadataResult<TypeMetadataDescriptor> toMetadataDescriptorResult(MetadataType type, boolean isDynamic, MetadataResult<MetadataType> result) {
MetadataType resultingType = result.get() == null ? type : result.get();
TypeMetadataDescriptor descriptor = TypeMetadataDescriptor.builder().withType(resultingType).dynamic(isDynamic).build();
return result.isSuccess() ? success(descriptor) : failure(descriptor, result.getFailures());
}
use of org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor 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);
}
use of org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor 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