Initial OpenECOMP MSO commit
[so.git] / bpmn / MSOGammaBPMN / src / main / groovy / com / att / bpm / scripts / VnfAdapterUtils.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package com.att.bpm.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.runtime.Execution;
25
26 class VnfAdapterUtils {
27
28         private AbstractServiceTaskProcessor taskProcessor
29
30         public VnfAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
31                 this.taskProcessor = taskProcessor
32         }
33
34         ExceptionUtil exceptionUtil = new ExceptionUtil()
35
36         public void validateVnfResponse(Execution execution, String responseVar, String responseCodeVar, String errorResponseVar) {
37                 def method = getClass().getSimpleName() + '.validateVnfResponse(' +
38                         'execution=' + execution.getId() +
39                         ', responseVar=' + responseVar +
40                         ', responseCodeVar=' + responseCodeVar +
41                         ', errorResponseVar=' + errorResponseVar +
42                         ')'
43                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
44                 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
45
46                 try {
47                         def prefix = execution.getVariable('prefix')
48
49                         def response = execution.getVariable(responseVar)
50                         def responseCode = execution.getVariable(responseCodeVar)
51                         def errorResponse = execution.getVariable(errorResponseVar)
52
53                         if (response.contains("WorkflowException")) {
54                                 execution.setVariable(prefix + "ErrorResponse", response)
55                                 //execution.setVariable(prefix + "ResponseCode", responseCode)
56                                 taskProcessor.logDebug(" Sub Vnf flow Error WorkflowException Response - " + "\n" + response, isDebugLogEnabled)
57                                 throw new BpmnError("MSOWorkflowException")
58                         }
59                 } catch (BpmnError e) {
60                         throw e;
61                 } catch (Exception e) {
62                         taskProcessor.logError('Caught exception in ' + method, e)
63                         taskProcessor.workflowException(execution, 'Internal Error- Unable to validate VNF Response ' + e.getMessage(), 500)
64                 }
65         }
66
67 }