Search in sources :

Example 1 with StereotypeTypeAnnotation

use of org.mule.runtime.extension.api.declaration.type.annotation.StereotypeTypeAnnotation in project mule by mulesoft.

the class InputParametersTypeModelValidator method validateType.

private void validateType(String message, NamedObject namedObject, MetadataType type, ProblemsReporter problems, Set<Class<?>> validatedTypes) {
    ReflectionCache reflectionCache = new ReflectionCache();
    getClassForValidation(type).ifPresent(parameterType -> type.accept(new MetadataTypeVisitor() {

        @Override
        public void visitObject(ObjectType objectType) {
            if (validatedTypes.add(parameterType)) {
                Collection<ObjectFieldType> parameters = objectType.getFields();
                Set<String> fieldsWithGetters = getFieldsWithGetters(parameterType, reflectionCache).stream().map(TypeUtils::getAlias).map(String::toLowerCase).collect(toSet());
                Set<String> parameterWithoutGetters = parameters.stream().filter(p -> {
                    StereotypeTypeAnnotation stereotypes = p.getAnnotation(StereotypeTypeAnnotation.class).orElse(null);
                    return stereotypes != null ? stereotypes.getAllowedStereotypes().isEmpty() : true;
                }).map(f -> f.getKey().getName().getLocalPart()).filter(fieldName -> !fieldsWithGetters.contains(fieldName.toLowerCase())).collect(toSet());
                if (!parameterWithoutGetters.isEmpty()) {
                    problems.addError(new Problem(namedObject, format("%s of type '%s' which contains fields (%s) that doesn't have the corresponding getter methods or getter methods that doesn't correspond to any of the present fields", message, parameterType.getName(), parameterWithoutGetters.stream().collect(joining(", ")))));
                }
            }
        }

        @Override
        public void visitArrayType(ArrayType arrayType) {
            validateType(message, namedObject, arrayType.getType(), problems, validatedTypes);
        }
    }));
}
Also used : Optional.empty(java.util.Optional.empty) StereotypeTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.StereotypeTypeAnnotation) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) NamedObject(org.mule.runtime.api.meta.NamedObject) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashSet(java.util.HashSet) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ArrayType(org.mule.metadata.api.model.ArrayType) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) Problem(org.mule.runtime.extension.api.loader.Problem) Collectors.toSet(java.util.stream.Collectors.toSet) IntrospectionUtils.getFieldsWithGetters(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldsWithGetters) TypeUtils(org.mule.runtime.extension.api.declaration.type.TypeUtils) ExtensionModelValidator(org.mule.runtime.extension.api.loader.ExtensionModelValidator) ObjectType(org.mule.metadata.api.model.ObjectType) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter) Collection(java.util.Collection) Set(java.util.Set) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionMetadataTypeUtils.getType(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getType) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) NameUtils.getComponentModelTypeName(org.mule.runtime.extension.api.util.NameUtils.getComponentModelTypeName) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) ArrayType(org.mule.metadata.api.model.ArrayType) ObjectType(org.mule.metadata.api.model.ObjectType) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) StereotypeTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.StereotypeTypeAnnotation) Problem(org.mule.runtime.extension.api.loader.Problem) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) TypeUtils(org.mule.runtime.extension.api.declaration.type.TypeUtils) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor)

Aggregations

String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 ArrayType (org.mule.metadata.api.model.ArrayType)1 JAVA (org.mule.metadata.api.model.MetadataFormat.JAVA)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1 NamedObject (org.mule.runtime.api.meta.NamedObject)1 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)1 SourceCallbackModel (org.mule.runtime.api.meta.model.source.SourceCallbackModel)1 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)1