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.merge.property;
23 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
24 import org.openecomp.sdc.be.model.InputDefinition;
25 import org.springframework.stereotype.Component;
27 import java.util.Collections;
28 import java.util.List;
30 import static org.apache.commons.collections.CollectionUtils.isEmpty;
31 import static org.openecomp.sdc.be.components.merge.property.PropertyInstanceMergeDataBuilder.buildDataForMerging;
34 public class DataDefinitionsValuesMergingBusinessLogic {
36 private PropertyDataValueMergeBusinessLogic propertyValueMergeBL;
38 public DataDefinitionsValuesMergingBusinessLogic(PropertyDataValueMergeBusinessLogic propertyValueMergeBL) {
39 this.propertyValueMergeBL = propertyValueMergeBL;
43 * Merge previous version data definition values into the new version data definition.
44 * A data definition value is merged if it had a value in previous version and has no value in the current version.
45 * in case a property get input value has no corresponding input in the current version its value will not be merged
46 * @param oldInstanceDataDefinition the currently persisted instance data definitions
47 * @param oldInputs the previous version inputs
48 * @param updatedInstanceDataDefinition the currently being update instance data definitions
49 * @param newInputs the new version inputs
51 public <T extends PropertyDataDefinition> void mergeInstanceDataDefinitions(List<T> oldInstanceDataDefinition, List<InputDefinition> oldInputs, List<T> updatedInstanceDataDefinition, List<InputDefinition> newInputs) {
52 if (isEmpty(updatedInstanceDataDefinition) || isEmpty(oldInstanceDataDefinition)) {
55 List<MergePropertyData> mergePropertyData = buildDataForMerging(oldInstanceDataDefinition, oldInputs, updatedInstanceDataDefinition, newInputs);
56 mergePropertyData.forEach(this::mergeInstanceDefinition);
60 public <T extends PropertyDataDefinition> void mergeInstanceDataDefinitions(List<T> oldInstanceDataDefinition, List<T> updatedInstanceDataDefinition) {
61 List<InputDefinition> emptyInputsList = Collections.emptyList();
62 mergeInstanceDataDefinitions(oldInstanceDataDefinition, emptyInputsList, updatedInstanceDataDefinition, emptyInputsList);
65 private void mergeInstanceDefinition(MergePropertyData mergeData) {
66 if (isSameType(mergeData.getOldProp(), mergeData.getNewProp())) {
67 propertyValueMergeBL.mergePropertyValue(mergeData.getOldProp(), mergeData.getNewProp(), mergeData.getGetInputNamesToMerge());
71 private boolean isSameType(PropertyDataDefinition oldDataDefinition, PropertyDataDefinition updatedDataDefinition) {
72 return oldDataDefinition.typeEquals(updatedDataDefinition);