Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / merge / input / ComponentInputsMergeBL.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.merge.input;
22
23 import org.openecomp.sdc.be.components.merge.VspComponentsMergeCommand;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
26 import org.openecomp.sdc.be.impl.ComponentsUtils;
27 import org.openecomp.sdc.be.model.Component;
28 import org.openecomp.sdc.be.model.InputDefinition;
29 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
30 import org.springframework.core.annotation.Order;
31
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Map.Entry;
35 import java.util.stream.Stream;
36
37 import static java.util.stream.Collectors.toMap;
38 import static org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic.PENULTIMATE_COMMAND;
39 import static org.openecomp.sdc.be.utils.PropertyDefinitionUtils.convertListOfProperties;
40
41 @org.springframework.stereotype.Component
42 @Order(PENULTIMATE_COMMAND)//must run after all properties values were merged but before component instance relations merge
43 public class ComponentInputsMergeBL extends InputsMergeCommand implements VspComponentsMergeCommand {
44
45     public ComponentInputsMergeBL(InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic, DeclaredInputsResolver declaredInputsResolver, ToscaOperationFacade toscaOperationFacade, ComponentsUtils componentsUtils) {
46         super(inputsValuesMergingBusinessLogic, declaredInputsResolver, toscaOperationFacade, componentsUtils);
47     }
48
49     @Override
50     public ActionStatus mergeComponents(Component prevComponent, Component currentComponent) {
51         return super.redeclareAndMergeInputsValues(prevComponent, currentComponent);
52     }
53
54     @Override
55     public String description() {
56         return "merge component inputs";
57     }
58
59     @Override
60     List<InputDefinition> getInputsToMerge(Component component) {
61         return component.safeGetInputs();
62     }
63
64     @Override
65     Map<String, List<PropertyDataDefinition>> getProperties(Component component) {
66         return Stream.of(component.safeGetComponentInstancesProperties(),
67                          component.safeGetComponentInstancesInputs(),
68                          component.safeGetGroupsProperties(),
69                          component.safeGetPolicyProperties())
70                 .flatMap(map -> map.entrySet().stream())
71                 .collect(toMap(Entry::getKey, entry -> convertListOfProperties(entry.getValue())));
72     }
73
74 }