2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.sdnc;
23 import java.util.Arrays;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.onap.so.bpmn.core.json.JsonUtils;
30 import org.onap.so.client.sdnc.lcm.beans.payload.*;
31 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.REQUEST_PAYLOAD;
32 import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.common.SoPropertyConstants;
34 public class SDNCLcmPayloadBuilder {
36 private static Logger logger = LoggerFactory.getLogger(SDNCLcmPayloadBuilder.class);
38 public static ActivateNESwPayload buildActivateNESwPayload(DelegateExecution execution) {
39 String requestPayload = String.valueOf(execution.getVariable(REQUEST_PAYLOAD));
41 ActivateNESwPayload activateNESwPayload = new ActivateNESwPayload();
43 String ipaddressV4Oam = JsonUtils.getJsonValue(requestPayload, "ipaddressV4Oam");
44 activateNESwPayload.setIpaddressV4Oam(ipaddressV4Oam);
46 String targetSwVersion = String.valueOf(execution.getVariable(SoPropertyConstants.TARGET_SOFTWARE_VERSION));
47 if (targetSwVersion == null) {
48 targetSwVersion = JsonUtils.getJsonValue(requestPayload, "targetSwVersion");
50 activateNESwPayload.setSwVersionToBeActivated(targetSwVersion);
52 String playbookName = JsonUtils.getJsonValue(requestPayload, "activateNESwPlaybook");
53 if (playbookName != null) {
54 activateNESwPayload.setPlaybookName(playbookName);
57 return activateNESwPayload;
60 public static DownloadNESwPayload buildDownloadNESwPayload(DelegateExecution execution) {
61 String requestPayload = String.valueOf(execution.getVariable(REQUEST_PAYLOAD));
63 DownloadNESwPayload downloadNESwPayload = new DownloadNESwPayload();
65 String ipaddressV4Oam = JsonUtils.getJsonValue(requestPayload, "ipaddressV4Oam");
66 downloadNESwPayload.setIpaddressV4Oam(ipaddressV4Oam);
68 String swToBeDownloadedString = JsonUtils.getJsonValue(requestPayload, "swToBeDownloaded");
69 SwToBeDownloadedElement[] swToBeDownloadedArray;
71 ObjectMapper mapper = new ObjectMapper();
73 swToBeDownloadedArray = mapper.readValue(swToBeDownloadedString, SwToBeDownloadedElement[].class);
74 downloadNESwPayload.setSwToBeDownloaded(Arrays.asList(swToBeDownloadedArray));
75 } catch (Exception e) {
76 logger.error("Parse SwToBeDownloaded error: ", e);
79 String playbookName = JsonUtils.getJsonValue(requestPayload, "downloadNESwPlaybook");
80 if (playbookName != null) {
81 downloadNESwPayload.setPlaybookName(playbookName);
84 return downloadNESwPayload;
87 public static UpgradePostCheckPayload buildUpgradePostCheckPayload(DelegateExecution execution) {
88 String requestPayload = String.valueOf(execution.getVariable(REQUEST_PAYLOAD));
90 UpgradePostCheckPayload upgradePostCheckPayload = new UpgradePostCheckPayload();
92 String ipaddressV4Oam = JsonUtils.getJsonValue(requestPayload, "ipaddressV4Oam");
93 upgradePostCheckPayload.setIpaddressV4Oam(ipaddressV4Oam);
95 String oldSwVersion = JsonUtils.getJsonValue(requestPayload, "oldSwVersion");
96 upgradePostCheckPayload.setOldSwVersion(oldSwVersion);
98 String targetSwVersion = String.valueOf(execution.getVariable(SoPropertyConstants.TARGET_SOFTWARE_VERSION));
99 if (targetSwVersion == null) {
100 targetSwVersion = JsonUtils.getJsonValue(requestPayload, "targetSwVersion");
102 upgradePostCheckPayload.setTargetSwVersion(targetSwVersion);
104 String ruleName = JsonUtils.getJsonValue(requestPayload, "postCheckRuleName");
105 upgradePostCheckPayload.setRuleName(ruleName);
107 String additionalData = JsonUtils.getJsonValue(requestPayload, "postCheckAdditionalData");
108 upgradePostCheckPayload.setAdditionalData(additionalData);
110 String playbookName = JsonUtils.getJsonValue(requestPayload, "postCheckPlaybook");
111 if (playbookName != null) {
112 upgradePostCheckPayload.setPlaybookName(playbookName);
115 return upgradePostCheckPayload;
118 public static UpgradePreCheckPayload buildUpgradePreCheckPayload(DelegateExecution execution) {
119 String requestPayload = String.valueOf(execution.getVariable(REQUEST_PAYLOAD));
121 UpgradePreCheckPayload upgradePreCheckPayload = new UpgradePreCheckPayload();
123 String ipaddressV4Oam = JsonUtils.getJsonValue(requestPayload, "ipaddressV4Oam");
124 upgradePreCheckPayload.setIpaddressV4Oam(ipaddressV4Oam);
126 String oldSwVersion = JsonUtils.getJsonValue(requestPayload, "oldSwVersion");
127 upgradePreCheckPayload.setOldSwVersion(oldSwVersion);
129 String targetSwVersion = String.valueOf(execution.getVariable(SoPropertyConstants.TARGET_SOFTWARE_VERSION));
130 if (targetSwVersion == null) {
131 targetSwVersion = JsonUtils.getJsonValue(requestPayload, "targetSwVersion");
133 upgradePreCheckPayload.setTargetSwVersion(targetSwVersion);
135 String ruleName = JsonUtils.getJsonValue(requestPayload, "preCheckRuleName");
136 upgradePreCheckPayload.setRuleName(ruleName);
138 String additionalData = JsonUtils.getJsonValue(requestPayload, "preCheckAdditionalData");
139 upgradePreCheckPayload.setAdditionalData(additionalData);
141 String playbookName = JsonUtils.getJsonValue(requestPayload, "preCheckPlaybook");
142 if (playbookName != null) {
143 upgradePreCheckPayload.setPlaybookName(playbookName);
146 return upgradePreCheckPayload;
149 public static String convertToSting(Object msgObject) throws JsonProcessingException {
150 ObjectMapper mapper = new ObjectMapper();
151 return mapper.writeValueAsString(msgObject);