2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts;
24 import static org.apache.commons.lang3.StringUtils.*;
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.common.scripts.VidUtils
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.domain.CompareModelsResult
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
43 * This groovy class supports the <class>CompareModelofE2EServiceInstance.bpmn</class> process.
46 * @param - msoRequestId
47 * @param - globalSubscriberId
48 * @param - subscriptionServiceType
49 * @param - serviceInstanceId
50 * @param - modelInvariantIdTarget
51 * @param - modelVersionIdTarget
55 * @param - WorkflowException
57 public class CompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
58 private static final Logger logger = LoggerFactory.getLogger( CompareModelofE2EServiceInstance.class);
60 String Prefix="CMPMDSI_"
61 private static final String DebugFlag = "isDebugEnabled"
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 JsonUtils jsonUtil = new JsonUtils()
65 VidUtils vidUtils = new VidUtils()
67 public void preProcessRequest (DelegateExecution execution) {
68 execution.setVariable("prefix",Prefix)
71 logger.trace("preProcessRequest Request ")
74 // check for incoming json message/input
75 String siRequest = execution.getVariable("bpmnRequest")
76 logger.debug(siRequest)
79 String requestId = execution.getVariable("mso-request-id")
80 execution.setVariable("msoRequestId", requestId)
81 logger.info("Input Request:" + siRequest + " reqId:" + requestId)
83 String serviceInstanceId = execution.getVariable("serviceInstanceId")
84 if (isBlank(serviceInstanceId)) {
85 msg = "Input serviceInstanceId' is null"
86 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
90 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
91 if (isBlank(globalSubscriberId)) {
92 msg = "Input globalSubscriberId' is null"
95 execution.setVariable("globalSubscriberId", globalSubscriberId)
98 //subscriptionServiceType
99 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
100 if (isBlank(subscriptionServiceType)) {
101 msg = "Input subscriptionServiceType is null"
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
105 execution.setVariable("serviceType", subscriptionServiceType)
108 //modelInvariantIdTarget
109 String modelInvariantIdTarget = jsonUtil.getJsonValue(siRequest, "modelInvariantIdTarget")
110 if (isBlank(modelInvariantIdTarget)) {
111 msg = "Input modelInvariantIdTarget' is null"
113 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
115 execution.setVariable("modelInvariantIdTarget", modelInvariantIdTarget)
118 //modelVersionIdTarget
119 String modelVersionIdTarget = jsonUtil.getJsonValue(siRequest, "modelVersionIdTarget")
120 if (isBlank(modelVersionIdTarget)) {
121 msg = "Input modelVersionIdTarget is null"
123 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
125 execution.setVariable("modelVersionIdTarget", modelVersionIdTarget)
128 execution.setVariable("operationType", "CompareModel")
130 } catch (BpmnError e) {
132 } catch (Exception ex){
133 msg = "Exception in preProcessRequest " + ex.getMessage()
135 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
137 logger.trace("Exit preProcessRequest ")
140 public void sendSyncResponse (DelegateExecution execution) {
141 logger.trace("sendSyncResponse ")
144 CompareModelsResult compareModelsResult = execution.getVariable("compareModelsResult")
146 // RESTResponse (for API Handler(APIH) Reply Task)
147 String syncResponse = compareModelsResult.toJsonStringNoRootName()
148 logger.info(" sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
149 sendWorkflowResponse(execution, 202, syncResponse)
151 } catch (Exception ex) {
152 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
155 logger.trace("Exit sendSyncResopnse ")
158 public void sendSyncError (DelegateExecution execution) {
159 logger.trace("sendSyncError ")
162 String errorMessage = ""
163 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
164 WorkflowException wfe = execution.getVariable("WorkflowException")
165 errorMessage = wfe.getErrorMessage()
167 errorMessage = "Sending Sync Error."
170 String buildworkflowException =
171 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
172 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
173 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
174 </aetgt:WorkflowException>"""
176 logger.debug(buildworkflowException)
177 sendWorkflowResponse(execution, 500, buildworkflowException)
179 } catch (Exception ex) {
180 logger.info(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
185 public void prepareCompletionRequest (DelegateExecution execution) {
186 logger.trace("prepareCompletion ")
189 String requestId = execution.getVariable("msoRequestId")
190 String source = execution.getVariable("source")
191 String msoCompletionRequest =
192 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
193 xmlns:ns="http://org.onap/so/request/types/v1">
194 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
195 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
196 <action>COMPAREMODEL</action>
197 <source>${MsoUtils.xmlEscape(source)}</source>
199 <aetgt:status-message>E2E Service Instance Compare model successfully.</aetgt:status-message>
200 <aetgt:mso-bpel-name>CompareModelofE2EServiceInstance</aetgt:mso-bpel-name>
201 </aetgt:MsoCompletionRequest>"""
204 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
206 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
207 logger.info(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
209 } catch (Exception ex) {
210 String msg = " Exception in prepareCompletion:" + ex.getMessage()
212 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
214 logger.trace("Exit prepareCompletionRequest ")
217 public void prepareFalloutRequest(DelegateExecution execution){
218 logger.trace("prepareFalloutRequest ")
221 WorkflowException wfex = execution.getVariable("WorkflowException")
222 logger.info(" Input Workflow Exception: " + wfex.toString())
223 String requestId = execution.getVariable("msoRequestId")
224 String source = execution.getVariable("source")
226 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
227 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
228 <action>COMPAREMODEL</action>
229 <source>${MsoUtils.xmlEscape(source)}</source>
232 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
233 execution.setVariable("falloutRequest", falloutRequest)
234 } catch (Exception ex) {
235 logger.info("Exception prepareFalloutRequest:" + ex.getMessage())
236 String errorException = " Bpmn error encountered in CompareModelofE2EServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
237 String requestId = execution.getVariable("msoRequestId")
238 String falloutRequest =
239 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
240 xmlns:ns="http://org.onap/so/request/types/v1"
241 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
242 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
243 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
244 <action>COMPAREMODEL</action>
247 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
248 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
249 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
250 </aetgt:WorkflowException>
251 </aetgt:FalloutHandlerRequest>"""
253 execution.setVariable("falloutRequest", falloutRequest)
255 logger.trace("Exit prepareFalloutRequest ")