summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java
new file mode 100644
index 0000000000..c73f168c9a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java
@@ -0,0 +1,68 @@
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.components.validation.AnnotationValidator;
+import org.openecomp.sdc.be.dao.utils.MapUtil;
+import org.openecomp.sdc.be.datatypes.elements.Annotation;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+
+import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+
+@Component
+public class AnnotationBusinessLogic {
+
+ private final AnnotationTypeOperations annotationTypeOperations;
+
+ private final AnnotationValidator annotationValidator;
+
+ public AnnotationBusinessLogic(AnnotationTypeOperations annotationTypeOperations,
+ AnnotationValidator annotationValidator){
+ this.annotationTypeOperations = annotationTypeOperations;
+ this.annotationValidator = annotationValidator;
+ }
+
+ public void validateAndMergeAnnotationsAndAssignToInput(Map<String, InputDefinition> inputs) {
+ if (!inputs.isEmpty()){
+ for (InputDefinition input : inputs.values()) {
+ List<Annotation> inputAnnotationList = input.getAnnotations();
+ if (isNotEmpty(inputAnnotationList)) {
+ for (Annotation annotation : inputAnnotationList) {
+ AnnotationTypeDefinition dbAnnotationTypeDefinition = annotationTypeOperations.getLatestType(annotation.getType());
+ validateMergeAndSetAnnoProps(annotation, dbAnnotationTypeDefinition);
+ }
+ }
+ input.setAnnotations(inputAnnotationList);
+ }
+ }
+ }
+
+ public AnnotationTypeOperations getAnnotationTypeOperations() {
+ return annotationTypeOperations;
+ }
+
+ private void validateMergeAndSetAnnoProps(Annotation annotation, AnnotationTypeDefinition dbAnnotationTypeDefinition) {
+ annotationValidator.validateAnnotationsProperties(annotation, dbAnnotationTypeDefinition);
+ List<PropertyDataDefinition> mergedPropertiesList = mergePropsOfAnnoDataTypeWithParsedAnnoProps(annotation.getProperties(), dbAnnotationTypeDefinition.getProperties());
+ annotation.setProperties(mergedPropertiesList);
+ }
+
+ private List<PropertyDataDefinition> mergePropsOfAnnoDataTypeWithParsedAnnoProps(List<PropertyDataDefinition> annoProperties, List<PropertyDefinition> typePropertiesList) {
+ Set<PropertyDataDefinition> mergedPropertiesSet = new HashSet<>(typePropertiesList);
+ Map<String, PropertyDefinition> typePropsMap = MapUtil.toMap(typePropertiesList, PropertyDefinition::getName);
+ for (PropertyDataDefinition propertyDataDefinitionObject : annoProperties) {
+ PropertyDefinition foundTypePropertyDefinitionObject = typePropsMap.get(propertyDataDefinitionObject.getName());
+ //The case of unexisting property was already handled in the validation process (result: failure)
+ PropertyDataDefinition modifiedPropertyDataObject = new PropertyDataDefinition(foundTypePropertyDefinitionObject);
+ modifiedPropertyDataObject.setValue(propertyDataDefinitionObject.getValue());
+ mergedPropertiesSet.add(modifiedPropertyDataObject);
+ }
+ return new ArrayList<>(mergedPropertiesSet);
+ }
+
+}