use of org.mule.runtime.extension.api.metadata.MetadataResolverFactory in project mule by mulesoft.
the class MetadataComponentModelValidator method validateResolversName.
private void validateResolversName(ComponentModel model, MetadataResolverFactory resolverFactory, Table<String, String, Class<?>> names, ProblemsReporter problemsReporter) {
List<NamedTypeResolver> resolvers = new LinkedList<>();
resolvers.addAll(getAllInputResolvers(model, resolverFactory));
resolvers.add(resolverFactory.getOutputResolver());
resolvers.stream().filter(r -> !r.getClass().equals(NullMetadataResolver.class)).forEach(r -> {
if (isBlank(r.getResolverName())) {
problemsReporter.addError(new Problem(model, format(EMPTY_RESOLVER_NAME, getComponentModelTypeName(model), model.getName(), r.getClass().getSimpleName(), "resolver")));
} else {
if (names.get(r.getCategoryName(), r.getResolverName()) != null && names.get(r.getCategoryName(), r.getResolverName()) != r.getClass()) {
problemsReporter.addError(new Problem(model, format("%s [%s] specifies metadata resolvers with repeated name [%s] for the same category [%s]. Resolver names should be unique for a given category. Affected resolvers are '%s' and '%s'", getComponentModelTypeName(model), model.getName(), r.getResolverName(), r.getCategoryName(), names.get(r.getCategoryName(), r.getResolverName()).getSimpleName(), r.getClass().getSimpleName())));
}
names.put(r.getCategoryName(), r.getResolverName(), r.getClass());
}
});
}
use of org.mule.runtime.extension.api.metadata.MetadataResolverFactory in project mule by mulesoft.
the class MetadataComponentModelValidator method validate.
@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
// TODO - MULE-14397 - Improve Dynamic Metadata Enricher to enrich without requiring Classes
// This is skipped if the extension is loaded with java, but it doesn't have classes which means AST Mode
Optional<ExtensionTypeDescriptorModelProperty> property = extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (property.isPresent()) {
if (!property.get().getType().getDeclaringClass().isPresent()) {
return;
}
}
final Table<String, String, Class<?>> names = HashBasedTable.create();
new ExtensionWalker() {
@Override
public void onOperation(HasOperationModels owner, OperationModel model) {
validateComponent(model);
}
@Override
public void onSource(HasSourceModels owner, SourceModel model) {
validateComponent(model);
}
private void validateComponent(ConnectableComponentModel model) {
validateMetadataReturnType(extensionModel, model, problemsReporter);
MetadataResolverFactory resolverFactory = MuleExtensionUtils.getMetadataResolverFactory(model);
validateMetadataOutputAttributes(model, resolverFactory, problemsReporter);
validateMetadataKeyId(model, resolverFactory, problemsReporter);
validateCategoriesInScope(model, resolverFactory, problemsReporter);
validateResolversName(model, resolverFactory, names, problemsReporter);
}
}.walk(extensionModel);
}
Aggregations