Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / merge / input / GlobalInputsMergeCommand.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.impl.utils.ExceptionUtils;
24 import org.openecomp.sdc.be.components.merge.ComponentsGlobalMergeCommand;
25 import org.openecomp.sdc.be.components.merge.GlobalInputsFilteringBusinessLogic;
26 import org.openecomp.sdc.be.dao.api.ActionStatus;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
28 import org.openecomp.sdc.be.impl.ComponentsUtils;
29 import org.openecomp.sdc.be.model.Component;
30 import org.openecomp.sdc.be.model.InputDefinition;
31 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
32 import org.springframework.core.annotation.Order;
33
34 import java.util.List;
35 import java.util.Map;
36 import java.util.stream.Stream;
37
38 import static java.util.stream.Collectors.toMap;
39 import static org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic.LAST_COMMAND;
40 import static org.openecomp.sdc.be.utils.PropertyDefinitionUtils.convertListOfProperties;
41
42 @org.springframework.stereotype.Component
43 @Order(LAST_COMMAND)
44 public class GlobalInputsMergeCommand extends InputsMergeCommand implements ComponentsGlobalMergeCommand {
45
46     private GlobalInputsFilteringBusinessLogic globalInputsFilteringBusinessLogic;
47     private ExceptionUtils exceptionUtils;
48
49     public GlobalInputsMergeCommand(InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic, DeclaredInputsResolver declaredInputsResolver, ToscaOperationFacade toscaOperationFacade, ComponentsUtils componentsUtils, GlobalInputsFilteringBusinessLogic globalInputsFilteringBusinessLogic, ExceptionUtils exceptionUtils) {
50         super(inputsValuesMergingBusinessLogic, declaredInputsResolver, toscaOperationFacade, componentsUtils);
51         this.globalInputsFilteringBusinessLogic = globalInputsFilteringBusinessLogic;
52         this.exceptionUtils = exceptionUtils;
53     }
54
55     @Override
56     public ActionStatus mergeComponents(Component prevComponent, Component currentComponent) {
57         return super.redeclareAndMergeInputsValues(prevComponent, currentComponent);
58     }
59
60     @Override
61     public String description() {
62         return "merge global (non vsp) inputs";
63     }
64
65     @Override
66     List<InputDefinition> getInputsToMerge(Component component) {
67         return globalInputsFilteringBusinessLogic.filterGlobalInputs(component).left().on(err -> exceptionUtils.rollBackAndThrow(err));
68     }
69
70     @Override
71     Map<String, List<PropertyDataDefinition>> getProperties(Component component) {
72         return Stream.of(component.safeGetUiComponentInstancesProperties(),
73                          component.safeGetUiComponentInstancesInputs(),
74                          component.safeGetGroupsProperties(),
75                          component.safeGetPolicyProperties())
76                 .flatMap(map -> map.entrySet().stream())
77                 .collect(toMap(Map.Entry::getKey, entry -> convertListOfProperties(entry.getValue())));
78     }
79
80 }