Remove Swagger UI
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateServiceInstanceRollback.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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 org.onap.so.bpmn.infrastructure.scripts
22
23
24 import static org.apache.commons.lang3.StringUtils.*;
25 import groovy.xml.XmlUtil
26 import groovy.json.*
27
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.logger.MsoLogger
34 import org.onap.so.logger.MessageEnum
35
36 import java.util.UUID;
37
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.delegate.DelegateExecution
40 import org.json.JSONObject;
41 import org.apache.commons.lang3.*
42 import org.apache.commons.codec.binary.Base64;
43 import org.springframework.web.util.UriUtils;
44 /**
45  * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
46  *
47  * Inputs:
48  * @param - msoRequestId
49  * @param - rollbackData with
50  *          globalCustomerId
51  *                      subscriptionServiceType
52  *                      serviceInstanceId
53  *                      disableRollback
54  *                      rollbackAAI
55  *                      rollbackSDNC
56  *                      sdncRollbackRequest
57  *
58  *
59  * Outputs:
60  * @param - rollbackError
61  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
62  *
63  */
64 public class DoCreateServiceInstanceRollback extends AbstractServiceTaskProcessor{
65         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstanceRollback.class);
66
67
68         String Prefix="DCRESIRB_"
69
70         public void preProcessRequest(DelegateExecution execution) {
71                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
72                 execution.setVariable("prefix",Prefix)
73                 String msg = ""
74                 msoLogger.trace("preProcessRequest")
75                 execution.setVariable("rollbackAAI",false)
76                 execution.setVariable("rollbackSDNC",false)
77
78                 try {
79                         def rollbackData = execution.getVariable("rollbackData")
80                         msoLogger.debug("RollbackData:" + rollbackData)
81
82                         if (rollbackData != null) {
83                                 if (rollbackData.hasType("SERVICEINSTANCE")) {
84
85                                         def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
86                                         execution.setVariable("serviceInstanceId", serviceInstanceId)
87
88                                         def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
89                                         execution.setVariable("subscriptionServiceType", subscriptionServiceType)
90
91                                         def globalSubscriberId  = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
92                                         execution.setVariable("globalSubscriberId", globalSubscriberId)
93
94                                         def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
95                                         if ("true".equals(rollbackAAI))
96                                         {
97                                                 execution.setVariable("rollbackAAI",true)
98                                         }
99
100                                         def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
101                                         if ("true".equals(rollbackSDNC))
102                                         {
103                                                 execution.setVariable("rollbackSDNC", true)
104                                         }
105
106                                         if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
107                                         {
108                                                 execution.setVariable("skipRollback", true)
109                                         }
110
111                                         def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
112                                         execution.setVariable("sdncDelete", sdncDelete)
113                                         def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
114                                         execution.setVariable("sdncDeactivate", sdncDeactivate)
115                                         msoLogger.debug("sdncDeactivate:\n" + sdncDeactivate)
116                                         msoLogger.debug("sdncDelete:\n" + sdncDelete)
117                                 }
118                                 else {
119                                         execution.setVariable("skipRollback", true)
120                                 }
121                         }
122                         else {
123                                 execution.setVariable("skipRollback", true)
124                         }
125                         if (execution.getVariable("disableRollback").equals("true" ))
126                         {
127                                 execution.setVariable("skipRollback", true)
128                         }
129
130                 } catch (BpmnError e) {
131                         throw e;
132                 } catch (Exception ex){
133                         msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
134                         msoLogger.debug(msg)
135                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
136                 }
137                 msoLogger.trace("Exit preProcessRequest")
138         }
139
140         public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
141
142                 msoLogger.trace("validateSDNCResponse")
143                 String msg = ""
144                 try {
145                         WorkflowException workflowException = execution.getVariable("WorkflowException")
146                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
147                         msoLogger.debug("SDNCResponse: " + response)
148                         msoLogger.debug("workflowException: " + workflowException)
149
150                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
151                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
152
153                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
154                                 msg = "SDNC Adapter service-instance rollback successful for " + method
155                                 msoLogger.debug(msg)
156                         }else{
157                                 execution.setVariable("rolledBack", false)
158                                 msg =  "Error Response from SDNC Adapter service-instance rollback for " + method
159                                 execution.setVariable("rollbackError", msg)
160                                 msoLogger.debug(msg)
161                                 throw new BpmnError("MSOWorkflowException")
162                         }
163                 } catch (BpmnError e) {
164                         throw e;
165                 } catch (Exception ex){
166                         msg = "Exception in Create ServiceInstance rollback for "  + method  + " Exception:" + ex.getMessage()
167                         msoLogger.debug(msg)
168                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
169                 }
170                 msoLogger.trace("Exit validateSDNCResponse")
171         }
172
173         public void postProcessRequest(DelegateExecution execution) {
174
175                 msoLogger.trace("postProcessRequest")
176                 String msg = ""
177                 try {
178                         execution.setVariable("rollbackData", null)
179                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
180                         boolean rollbackAAI = execution.getVariable("rollbackAAI")
181                         boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
182                         if (rollbackAAI || rollbackSDNC)
183                         {
184                                 execution.setVariable("rolledBack", true)
185                         }
186                         if (rollbackAAI)
187                         {
188                                 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
189                                 if(!succInAAI){
190                                         execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
191                                         execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
192                                         msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
193                                 }
194                         }
195                         msoLogger.trace("Exit postProcessRequest")
196
197                 } catch (BpmnError e) {
198                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
199                         msoLogger.debug(msg)
200                 } catch (Exception ex) {
201                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
202                         msoLogger.debug(msg)
203                 }
204
205         }
206
207         public void processRollbackException(DelegateExecution execution){
208
209                 msoLogger.trace("processRollbackException")
210                 try{
211                         msoLogger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
212                         execution.setVariable("rollbackData", null)
213                         execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
214                         execution.setVariable("WorkflowException", null)
215
216                 }catch(BpmnError b){
217                         msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
218                 }catch(Exception e){
219                         msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
220                 }
221
222                 msoLogger.debug("Exit processRollbackException")
223         }
224
225         public void processRollbackJavaException(DelegateExecution execution){
226
227                 msoLogger.trace("processRollbackJavaException")
228                 try{
229                         execution.setVariable("rollbackData", null)
230                         execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
231                         msoLogger.debug("Caught Exception in processRollbackJavaException")
232
233                 }catch(Exception e){
234                         msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
235                 }
236                 msoLogger.trace("Exit processRollbackJavaException")
237         }
238
239 }