Search in sources :

Example 1 with MetadataResolverFactory

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());
        }
    });
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Message(org.mule.runtime.api.message.Message) NamedObject(org.mule.runtime.api.meta.NamedObject) HashBasedTable(com.google.common.collect.HashBasedTable) MetadataKeyIdModelProperty(org.mule.runtime.extension.api.property.MetadataKeyIdModelProperty) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ModelLoaderUtils.isScope(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isScope) ArrayType(org.mule.metadata.api.model.ArrayType) MetadataKeyPartModelProperty(org.mule.runtime.extension.api.property.MetadataKeyPartModelProperty) Map(java.util.Map) StringUtils(org.mule.runtime.core.api.util.StringUtils) Collectors.toSet(java.util.stream.Collectors.toSet) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) ObjectType(org.mule.metadata.api.model.ObjectType) OutputTypeResolver(org.mule.runtime.api.metadata.resolving.OutputTypeResolver) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter) InputTypeResolver(org.mule.runtime.api.metadata.resolving.InputTypeResolver) Set(java.util.Set) String.format(java.lang.String.format) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) MuleExtensionUtils(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils) Serializable(java.io.Serializable) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) NameUtils.getComponentModelTypeName(org.mule.runtime.extension.api.util.NameUtils.getComponentModelTypeName) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) CustomDefinedStaticTypeAnnotation(org.mule.runtime.module.extension.internal.loader.annotations.CustomDefinedStaticTypeAnnotation) StringUtils.join(org.apache.commons.lang3.StringUtils.join) NullMetadataResolver(org.mule.runtime.extension.api.metadata.NullMetadataResolver) Problem(org.mule.runtime.extension.api.loader.Problem) LinkedList(java.util.LinkedList) MetadataResolverUtils.isNullResolver(org.mule.runtime.extension.api.metadata.MetadataResolverUtils.isNullResolver) ExtensionModelValidator(org.mule.runtime.extension.api.loader.ExtensionModelValidator) MetadataTypeUtils.isVoid(org.mule.metadata.api.utils.MetadataTypeUtils.isVoid) MetadataResolverUtils.getAllResolvers(org.mule.runtime.extension.api.metadata.MetadataResolverUtils.getAllResolvers) MetadataTypeUtils.isCollection(org.mule.metadata.api.utils.MetadataTypeUtils.isCollection) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ModelLoaderUtils.isRouter(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isRouter) Collectors.toList(java.util.stream.Collectors.toList) ExtensionMetadataTypeUtils.getType(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getType) ExtensionMetadataTypeUtils(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) MetadataResolverFactory(org.mule.runtime.extension.api.metadata.MetadataResolverFactory) NamedTypeResolver(org.mule.runtime.api.metadata.resolving.NamedTypeResolver) Table(com.google.common.collect.Table) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) NullMetadataResolver(org.mule.runtime.extension.api.metadata.NullMetadataResolver) NamedTypeResolver(org.mule.runtime.api.metadata.resolving.NamedTypeResolver) Problem(org.mule.runtime.extension.api.loader.Problem) LinkedList(java.util.LinkedList)

Example 2 with MetadataResolverFactory

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);
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MetadataResolverFactory(org.mule.runtime.extension.api.metadata.MetadataResolverFactory) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Aggregations

ConnectableComponentModel (org.mule.runtime.api.meta.model.ConnectableComponentModel)2 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)2 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)2 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)2 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)2 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)2 MetadataResolverFactory (org.mule.runtime.extension.api.metadata.MetadataResolverFactory)2 HashBasedTable (com.google.common.collect.HashBasedTable)1 Table (com.google.common.collect.Table)1 Serializable (java.io.Serializable)1 String.format (java.lang.String.format)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1 StringUtils.join (org.apache.commons.lang3.StringUtils.join)1