Search in sources :

Example 1 with ConnectableComponentModel

use of org.mule.runtime.api.meta.model.ConnectableComponentModel in project mule by mulesoft.

the class ValueProviderModelValidator method validateOptionsResolver.

private void validateOptionsResolver(ParameterModel param, ValueProviderFactoryModelProperty modelProperty, ParameterizedModel model, ProblemsReporter problemsReporter, boolean supportsConnectionsAndConfigs, ReflectionCache reflectionCache) {
    Class<? extends ValueProvider> valueProvider = modelProperty.getValueProvider();
    String providerName = valueProvider.getSimpleName();
    Map<String, MetadataType> allParameters = model.getAllParameterModels().stream().collect(toMap(IntrospectionUtils::getImplementingName, ParameterModel::getType));
    String modelName = NameUtils.getModelName(model);
    String modelTypeName = NameUtils.getComponentModelTypeName(model);
    if (!isInstantiable(valueProvider, reflectionCache)) {
        problemsReporter.addError(new Problem(model, format("The Value Provider [%s] is not instantiable but it should", providerName)));
    }
    if (!(param.getType() instanceof StringType)) {
        problemsReporter.addError(new Problem(model, format("The parameter [%s] of the %s '%s' is not of String type. Parameters that provides Values should be of String type.", param.getName(), modelTypeName, modelName)));
    }
    for (InjectableParameterInfo parameterInfo : modelProperty.getInjectableParameters()) {
        if (!allParameters.containsKey(parameterInfo.getParameterName())) {
            problemsReporter.addError(new Problem(model, format("The Value Provider [%s] declares a parameter '%s' which doesn't exist in the %s '%s'", providerName, parameterInfo.getParameterName(), modelTypeName, modelName)));
        } else {
            MetadataType metadataType = allParameters.get(parameterInfo.getParameterName());
            Class<?> expectedType = getType(metadataType).orElseThrow(() -> new IllegalStateException(format("Unable to get Class for parameter: %s", parameterInfo.getParameterName())));
            Class<?> gotType = getType(parameterInfo.getType()).orElseThrow(() -> new IllegalStateException(format("Unable to get Class for parameter: %s", parameterInfo.getParameterName())));
            if (!expectedType.equals(gotType)) {
                problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines a parameter '%s' of type '%s' but in the %s '%s' is of type '%s'", providerName, parameterInfo.getParameterName(), gotType, modelTypeName, modelName, expectedType)));
            }
        }
    }
    if (supportsConnectionsAndConfigs && modelProperty.usesConnection() && model instanceof ConnectableComponentModel) {
        boolean requiresConnection = ((ConnectableComponentModel) model).requiresConnection();
        if (requiresConnection != modelProperty.usesConnection()) {
            problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines that requires a connection, but is used in the %s '%s' which is connection less", providerName, modelTypeName, modelName)));
        }
    }
    if (!supportsConnectionsAndConfigs) {
        if (modelProperty.usesConnection()) {
            problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines that requires a connection which is not allowed for a Value Provider of a %s's parameter [%s]", providerName, modelTypeName, modelName)));
        }
        if (modelProperty.usesConfig()) {
            problemsReporter.addError(new Problem(model, format("The Value Provider [%s] defines that requires a configuration which is not allowed for a Value Provider of a %s's parameter [%s]", providerName, modelTypeName, modelName)));
        }
    }
}
Also used : StringType(org.mule.metadata.api.model.StringType) InjectableParameterInfo(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.InjectableParameterInfo) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) MetadataType(org.mule.metadata.api.model.MetadataType) Problem(org.mule.runtime.extension.api.loader.Problem)

Example 2 with ConnectableComponentModel

use of org.mule.runtime.api.meta.model.ConnectableComponentModel 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 MetadataType (org.mule.metadata.api.model.MetadataType)1 StringType (org.mule.metadata.api.model.StringType)1 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)1 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)1 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)1 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)1 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)1 Problem (org.mule.runtime.extension.api.loader.Problem)1 MetadataResolverFactory (org.mule.runtime.extension.api.metadata.MetadataResolverFactory)1 InjectableParameterInfo (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.InjectableParameterInfo)1 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)1