use of org.mule.runtime.api.metadata.MetadataContext in project mule by mulesoft.
the class ExtensionComponent method runWithMetadataContext.
protected <R> R runWithMetadataContext(Function<MetadataContext, R> metadataContextFunction) throws MetadataResolvingException, ConnectionException {
MetadataContext context = null;
R result;
try {
context = withContextClassLoader(getClassLoader(this.extensionModel), this::getMetadataContext);
result = metadataContextFunction.apply(context);
} catch (MuleRuntimeException e) {
// TODO(MULE-13621) this should be deleted once the configuration is created lazily in the getMetadataContext method.
try {
throw e.getCause();
} catch (MetadataResolvingException | ConnectionException cause) {
throw cause;
} catch (Throwable t) {
throw e;
}
} finally {
if (context != null) {
context.dispose();
}
}
return result;
}
use of org.mule.runtime.api.metadata.MetadataContext in project mule by mulesoft.
the class ConfigurationProviderToolingAdapter method getMetadataKeys.
/**
* {@inheritDoc}
*/
@Override
public MetadataResult<MetadataKeysContainer> getMetadataKeys() throws MetadataResolvingException {
MetadataKeysContainerBuilder keysBuilder = MetadataKeysContainerBuilder.getInstance();
try {
MetadataContext metadataContext = getMetadataContext();
addComponentKeys(getConfigurationModel().getOperationModels(), metadataContext, keysBuilder);
addComponentKeys(getConfigurationModel().getSourceModels(), metadataContext, keysBuilder);
metadataContext.dispose();
} catch (Exception e) {
return failure(newFailure(e).onKeys());
}
return success(keysBuilder.build());
}
use of org.mule.runtime.api.metadata.MetadataContext in project mule by mulesoft.
the class DsqlQueryMetadataResolver method getOutputType.
/**
* Automatically resolves the output metadata for the {@link DsqlQuery}.
* <p>
* The base entity is resolved using the component {@link QueryEntityResolver} and assuming the key of the entity is the DSQL
* {@link DsqlQuery#getType() type}.
*
* @param context {@link MetadataContext} of the MetaData resolution
* @param query the {@link DsqlQuery} to resolve the output metadata from.
*/
@Override
public MetadataType getOutputType(MetadataContext context, Object query) throws MetadataResolvingException, ConnectionException {
if (query instanceof DsqlQuery) {
DsqlQuery dsqlQuery = (DsqlQuery) query;
MetadataType entityMetadata = entityResolver.getEntityMetadata(context, dsqlQuery.getType().getName());
BaseTypeBuilder builder = context.getTypeBuilder();
final List<Field> fields = dsqlQuery.getFields();
if (fields.size() == 1 && fields.get(0).getName().equals("*")) {
return entityMetadata;
}
entityMetadata.accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
ObjectTypeBuilder objectTypeBuilder = builder.objectType();
objectType.getFields().stream().filter(p -> fields.stream().anyMatch(f -> f.getName().equalsIgnoreCase(p.getKey().getName().getLocalPart()))).forEach(p -> {
ObjectFieldTypeBuilder field = objectTypeBuilder.addField();
field.key(p.getKey().getName());
field.value(p.getValue());
});
}
});
return builder.build();
} else {
return nativeOutputResolver.getOutputType(context, query);
}
}
use of org.mule.runtime.api.metadata.MetadataContext 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