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