2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
22 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER;
23 import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
24 import java.util.HashMap;
25 import java.util.List;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter;
29 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParametersProvider;
30 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.NullInputParameter;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
32 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
33 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
34 import org.onap.so.client.exception.BBObjectNotFoundException;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
41 * This class retrieve input parameters
43 * @author waqas.ikram@est.tech
46 public class InputParameterRetrieverTask {
48 private static final Logger LOGGER = LoggerFactory.getLogger(InputParameterRetrieverTask.class);
50 private final InputParametersProvider<GenericVnf> sdncInputParametersProvider;
52 private final ExtractPojosForBB extractPojosForBB;
54 private final InputParametersProvider<Map<String, Object>> userParamInputParametersProvider;
57 public InputParameterRetrieverTask(final InputParametersProvider<GenericVnf> inputParametersProvider,
58 final InputParametersProvider<Map<String, Object>> userParamInputParametersProvider,
59 final ExtractPojosForBB extractPojosForBB) {
60 this.sdncInputParametersProvider = inputParametersProvider;
61 this.userParamInputParametersProvider = userParamInputParametersProvider;
62 this.extractPojosForBB = extractPojosForBB;
65 public void getInputParameters(final BuildingBlockExecution execution) {
67 LOGGER.debug("Executing getInputParameters ...");
69 final InputParameter inputParameter = new InputParameter();
71 final InputParameter userParamsInputParameter = getUserParamsInputParameter(execution);
72 final InputParameter sdncInputParameter = getSdncInputParameter(execution);
74 inputParameter.putAdditionalParams(sdncInputParameter.getAdditionalParams());
75 inputParameter.addExtVirtualLinks(sdncInputParameter.getExtVirtualLinks());
77 inputParameter.putAdditionalParams(userParamsInputParameter.getAdditionalParams());
78 inputParameter.addExtVirtualLinks(userParamsInputParameter.getExtVirtualLinks());
80 LOGGER.debug("inputParameter: {}", inputParameter);
81 execution.setVariable(INPUT_PARAMETER, inputParameter);
83 LOGGER.debug("Finished executing getInputParameters ...");
84 } catch (final Exception exception) {
85 LOGGER.error("Unable to get input parameters", exception);
86 execution.setVariable(INPUT_PARAMETER, NullInputParameter.NULL_INSTANCE);
90 private InputParameter getSdncInputParameter(final BuildingBlockExecution execution)
91 throws BBObjectNotFoundException {
92 final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
93 return sdncInputParametersProvider.getInputParameter(vnf);
96 private InputParameter getUserParamsInputParameter(final BuildingBlockExecution execution) {
97 final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock();
99 if (generalBuildingBlock != null && generalBuildingBlock.getRequestContext() != null
100 && generalBuildingBlock.getRequestContext().getRequestParameters() != null) {
102 final List<Map<String, Object>> userParams =
103 generalBuildingBlock.getRequestContext().getRequestParameters().getUserParams();
104 if (userParams != null) {
105 final Map<String, Object> params = new HashMap<>();
107 userParams.stream().forEach(obj -> {
110 LOGGER.info("User params found : {}", params);
111 if (userParams != null && !userParams.isEmpty()) {
112 return userParamInputParametersProvider.getInputParameter(params);
117 LOGGER.warn("No input parameters found in userparams ...");
118 return NullInputParameter.NULL_INSTANCE;