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.input;
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;
34 import java.util.List;
36 import java.util.stream.Stream;
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;
42 @org.springframework.stereotype.Component
44 public class GlobalInputsMergeCommand extends InputsMergeCommand implements ComponentsGlobalMergeCommand {
46 private GlobalInputsFilteringBusinessLogic globalInputsFilteringBusinessLogic;
47 private ExceptionUtils exceptionUtils;
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;
56 public ActionStatus mergeComponents(Component prevComponent, Component currentComponent) {
57 return super.redeclareAndMergeInputsValues(prevComponent, currentComponent);
61 public String description() {
62 return "merge global (non vsp) inputs";
66 List<InputDefinition> getInputsToMerge(Component component) {
67 return globalInputsFilteringBusinessLogic.filterGlobalInputs(component).left().on(err -> exceptionUtils.rollBackAndThrow(err));
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())));