2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.validation;
23 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
24 import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
25 import org.openecomp.sdc.be.datatypes.elements.Annotation;
26 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
27 import org.openecomp.sdc.be.impl.ComponentsUtils;
28 import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
29 import org.openecomp.sdc.be.model.DataTypeDefinition;
30 import org.openecomp.sdc.be.model.PropertyDefinition;
31 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
32 import org.openecomp.sdc.common.log.wrappers.Logger;
33 import org.springframework.stereotype.Component;
35 import java.util.ArrayList;
36 import java.util.List;
40 public class AnnotationValidator {
43 private final PropertyValidator propertyValidator;
44 private final ExceptionUtils exceptionUtils;
45 private final ApplicationDataTypeCache dataTypeCache;
46 private final ComponentsUtils componentsUtils;
48 private static final Logger log = Logger.getLogger(ResourceImportManager.class);
51 public AnnotationValidator(PropertyValidator propertyValidator
52 , ExceptionUtils exceptionUtils, ApplicationDataTypeCache dataTypeCache
53 ,ComponentsUtils componentsUtils) {
54 this.propertyValidator = propertyValidator;
55 this.exceptionUtils = exceptionUtils;
56 this.dataTypeCache = dataTypeCache;
57 this.componentsUtils = componentsUtils;
60 public List<Annotation> validateAnnotationsProperties(Annotation annotation, AnnotationTypeDefinition dbAnnotationTypeDefinition) {
61 List<Annotation> validAnnotations = new ArrayList<>();
62 if (annotation != null && propertiesValidator(
63 annotation.getProperties(), dbAnnotationTypeDefinition.getProperties())) {
64 validAnnotations.add(annotation);
66 return validAnnotations;
69 private boolean propertiesValidator(List<PropertyDataDefinition> properties, List<PropertyDefinition> dbAnnotationTypeDefinitionProperties) {
70 List<PropertyDefinition> propertyDefinitionsList = new ArrayList<>();
71 if (properties == null || dbAnnotationTypeDefinitionProperties == null) {
75 .forEach(property -> propertyDefinitionsList.add(new PropertyDefinition(property)));
76 Map<String, DataTypeDefinition> allDataTypes = dataTypeCache.getAll()
78 .on( error -> exceptionUtils
79 .rollBackAndThrow(error));
80 propertyValidator.thinPropertiesValidator(propertyDefinitionsList, dbAnnotationTypeDefinitionProperties, allDataTypes);