1 package org.openecomp.sdc.be.components.validation;
3 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
4 import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
5 import org.openecomp.sdc.be.datatypes.elements.Annotation;
6 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
7 import org.openecomp.sdc.be.impl.ComponentsUtils;
8 import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
9 import org.openecomp.sdc.be.model.DataTypeDefinition;
10 import org.openecomp.sdc.be.model.PropertyDefinition;
11 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
12 import org.openecomp.sdc.common.log.wrappers.Logger;
13 import org.springframework.stereotype.Component;
15 import java.util.ArrayList;
16 import java.util.List;
20 public class AnnotationValidator {
23 private final PropertyValidator propertyValidator;
24 private final ExceptionUtils exceptionUtils;
25 private final ApplicationDataTypeCache dataTypeCache;
26 private final ComponentsUtils componentsUtils;
28 private static final Logger log = Logger.getLogger(ResourceImportManager.class);
31 public AnnotationValidator(PropertyValidator propertyValidator
32 , ExceptionUtils exceptionUtils, ApplicationDataTypeCache dataTypeCache
33 ,ComponentsUtils componentsUtils) {
34 this.propertyValidator = propertyValidator;
35 this.exceptionUtils = exceptionUtils;
36 this.dataTypeCache = dataTypeCache;
37 this.componentsUtils = componentsUtils;
40 public List<Annotation> validateAnnotationsProperties(Annotation annotation, AnnotationTypeDefinition dbAnnotationTypeDefinition) {
41 List<Annotation> validAnnotations = new ArrayList<>();
42 if (annotation != null && propertiesValidator(
43 annotation.getProperties(), dbAnnotationTypeDefinition.getProperties())) {
44 validAnnotations.add(annotation);
46 return validAnnotations;
49 private boolean propertiesValidator(List<PropertyDataDefinition> properties, List<PropertyDefinition> dbAnnotationTypeDefinitionProperties) {
50 List<PropertyDefinition> propertyDefinitionsList = new ArrayList<>();
51 if (properties == null || dbAnnotationTypeDefinitionProperties == null) {
55 .forEach(property -> propertyDefinitionsList.add(new PropertyDefinition(property)));
56 Map<String, DataTypeDefinition> allDataTypes = dataTypeCache.getAll()
58 .on( error -> exceptionUtils
59 .rollBackAndThrow(error));
60 propertyValidator.thinPropertiesValidator(propertyDefinitionsList, dbAnnotationTypeDefinitionProperties, allDataTypes);