2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts;
22 import static org.apache.commons.lang3.StringUtils.*;
24 import org.apache.commons.lang3.*
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.VidUtils
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.so.bpmn.core.domain.CompareModelsResult
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.logger.MsoLogger
40 * This groovy class supports the <class>CompareModelofE2EServiceInstance.bpmn</class> process.
43 * @param - msoRequestId
44 * @param - globalSubscriberId
45 * @param - subscriptionServiceType
46 * @param - serviceInstanceId
47 * @param - modelInvariantIdTarget
48 * @param - modelVersionIdTarget
52 * @param - WorkflowException
54 public class CompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
55 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CompareModelofE2EServiceInstance.class);
57 String Prefix="CMPMDSI_"
58 private static final String DebugFlag = "isDebugEnabled"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
61 JsonUtils jsonUtil = new JsonUtils()
62 VidUtils vidUtils = new VidUtils()
64 public void preProcessRequest (DelegateExecution execution) {
65 execution.setVariable("prefix",Prefix)
68 msoLogger.trace("preProcessRequest Request ")
71 // check for incoming json message/input
72 String siRequest = execution.getVariable("bpmnRequest")
73 msoLogger.debug(siRequest)
76 String requestId = execution.getVariable("mso-request-id")
77 execution.setVariable("msoRequestId", requestId)
78 msoLogger.info("Input Request:" + siRequest + " reqId:" + requestId)
80 String serviceInstanceId = execution.getVariable("serviceInstanceId")
81 if (isBlank(serviceInstanceId)) {
82 msg = "Input serviceInstanceId' is null"
83 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
87 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
88 if (isBlank(globalSubscriberId)) {
89 msg = "Input globalSubscriberId' is null"
90 utils.log("INFO", msg, isDebugEnabled)
92 execution.setVariable("globalSubscriberId", globalSubscriberId)
95 //subscriptionServiceType
96 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
97 if (isBlank(subscriptionServiceType)) {
98 msg = "Input subscriptionServiceType is null"
99 utils.log("DEBUG", msg, isDebugEnabled)
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 execution.setVariable("serviceType", subscriptionServiceType)
105 //modelInvariantIdTarget
106 String modelInvariantIdTarget = jsonUtil.getJsonValue(siRequest, "modelInvariantIdTarget")
107 if (isBlank(modelInvariantIdTarget)) {
108 msg = "Input modelInvariantIdTarget' is null"
109 utils.log("INFO", msg, isDebugEnabled)
110 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
112 execution.setVariable("modelInvariantIdTarget", modelInvariantIdTarget)
115 //modelVersionIdTarget
116 String modelVersionIdTarget = jsonUtil.getJsonValue(siRequest, "modelVersionIdTarget")
117 if (isBlank(modelVersionIdTarget)) {
118 msg = "Input modelVersionIdTarget is null"
119 utils.log("DEBUG", msg, isDebugEnabled)
120 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
122 execution.setVariable("modelVersionIdTarget", modelVersionIdTarget)
125 execution.setVariable("operationType", "CompareModel")
127 } catch (BpmnError e) {
129 } catch (Exception ex){
130 msg = "Exception in preProcessRequest " + ex.getMessage()
132 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
134 msoLogger.trace("Exit preProcessRequest ")
137 public void sendSyncResponse (DelegateExecution execution) {
138 msoLogger.trace("sendSyncResponse ")
141 CompareModelsResult compareModelsResult = execution.getVariable("compareModelsResult")
143 // RESTResponse (for API Handler(APIH) Reply Task)
144 String syncResponse = compareModelsResult.toJsonStringNoRootName()
145 msoLogger.info(" sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
146 sendWorkflowResponse(execution, 202, syncResponse)
148 } catch (Exception ex) {
149 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
150 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
152 msoLogger.trace("Exit sendSyncResopnse ")
155 public void sendSyncError (DelegateExecution execution) {
156 msoLogger.trace("sendSyncError ")
159 String errorMessage = ""
160 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
161 WorkflowException wfe = execution.getVariable("WorkflowException")
162 errorMessage = wfe.getErrorMessage()
164 errorMessage = "Sending Sync Error."
167 String buildworkflowException =
168 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
169 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
170 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
171 </aetgt:WorkflowException>"""
173 msoLogger.debug(buildworkflowException)
174 sendWorkflowResponse(execution, 500, buildworkflowException)
176 } catch (Exception ex) {
177 msoLogger.info(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
182 public void prepareCompletionRequest (DelegateExecution execution) {
183 msoLogger.trace("prepareCompletion ")
186 String requestId = execution.getVariable("msoRequestId")
187 String source = execution.getVariable("source")
188 String msoCompletionRequest =
189 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
190 xmlns:ns="http://org.onap/so/request/types/v1">
191 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
192 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
193 <action>COMPAREMODEL</action>
194 <source>${MsoUtils.xmlEscape(source)}</source>
196 <aetgt:status-message>E2E Service Instance Compare model successfully.</aetgt:status-message>
197 <aetgt:mso-bpel-name>CompareModelofE2EServiceInstance</aetgt:mso-bpel-name>
198 </aetgt:MsoCompletionRequest>"""
201 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
203 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
204 msoLogger.info(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
206 } catch (Exception ex) {
207 String msg = " Exception in prepareCompletion:" + ex.getMessage()
209 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
211 msoLogger.trace("Exit prepareCompletionRequest ")
214 public void prepareFalloutRequest(DelegateExecution execution){
215 msoLogger.trace("prepareFalloutRequest ")
218 WorkflowException wfex = execution.getVariable("WorkflowException")
219 msoLogger.info(" Input Workflow Exception: " + wfex.toString())
220 String requestId = execution.getVariable("msoRequestId")
221 String source = execution.getVariable("source")
223 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
224 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
225 <action>COMPAREMODEL</action>
226 <source>${MsoUtils.xmlEscape(source)}</source>
229 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
230 execution.setVariable("falloutRequest", falloutRequest)
231 } catch (Exception ex) {
232 msoLogger.info("Exception prepareFalloutRequest:" + ex.getMessage())
233 String errorException = " Bpmn error encountered in CompareModelofE2EServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
234 String requestId = execution.getVariable("msoRequestId")
235 String falloutRequest =
236 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
237 xmlns:ns="http://org.onap/so/request/types/v1"
238 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
239 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
240 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
241 <action>COMPAREMODEL</action>
244 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
245 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
246 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
247 </aetgt:WorkflowException>
248 </aetgt:FalloutHandlerRequest>"""
250 execution.setVariable("falloutRequest", falloutRequest)
252 msoLogger.trace("Exit prepareFalloutRequest ")