Added Groovy for E2E svc
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / CustomE2EGetService.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. \r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  * \r
12  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * \r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  */\r
21 \r
22 package org.openecomp.mso.bpmn.common.scripts\r
23 \r
24 import static org.apache.commons.lang3.StringUtils.*\r
25 \r
26 import org.apache.commons.lang3.*\r
27 import org.camunda.bpm.engine.delegate.BpmnError\r
28 import org.camunda.bpm.engine.runtime.Execution\r
29 import org.openecomp.mso.rest.APIResponse\r
30 import org.springframework.web.util.UriUtils\r
31 \r
32 \r
33 /**\r
34  * This class supports the GenericGetService Sub Flow.\r
35  * This Generic sub flow can be used by any flow for accomplishing\r
36  * the goal of getting a Service-Instance or Service-Subscription (from AAI).\r
37  * The calling flow must set the GENGS_type variable as "service-instance"\r
38  * or "service-subscription".\r
39  *\r
40  * When using to Get a Service-Instance:\r
41  * If the global-customer-id and service-type are not provided\r
42  * this flow executes a query to get the service- Url using the\r
43  * Service  Id or Name (whichever is provided).\r
44  *\r
45  * When using to Get a Service-Subscription:\r
46  * The global-customer-id and service-type must be\r
47  * provided.\r
48  *\r
49  * Upon successful completion of this sub flow the\r
50  * GENGS_SuccessIndicator will be true and the query response payload\r
51  * will be set to GENGS_service.  An MSOWorkflowException will\r
52  * be thrown upon unsuccessful completion or if an error occurs\r
53  * at any time during this sub flow. Please map variables\r
54  * to the corresponding variable names below.\r
55  *\r
56  * Note - If this sub flow receives a Not Found (404) response\r
57  * from AAI at any time this will be considered an acceptable\r
58  * successful response however the GENGS_FoundIndicator\r
59  * will be set to false. This variable will allow the calling flow\r
60  * to distinguish between the two Success scenarios,\r
61  * "Success where service- is found" and\r
62  * "Success where service- is NOT found".\r
63  *\r
64  *\r
65  * Variable Mapping Below:\r
66  *\r
67  * In Mapping Variables:\r
68  *   For Allotted-Resource:\r
69  *     @param - GENGS_allottedResourceId\r
70  *     @param - GENGS_type\r
71  *     @param (Optional) - GENGS_serviceInstanceId\r
72  *     @param (Optional) - GENGS_serviceType\r
73  *     @param (Optional) - GENGS_globalCustomerId\r
74  *\r
75  *   For Service-Instance:\r
76  *     @param - GENGS_serviceInstanceId or @param - GENGS_serviceInstanceName\r
77  *     @param - GENGS_type\r
78  *     @param (Optional) - GENGS_serviceType\r
79  *     @param (Optional) - GENGS_globalCustomerId\r
80  *\r
81  *   For Service-Subscription:\r
82  *     @param - GENGS_type\r
83  *     @param - GENGS_serviceType\r
84  *     @param - GENGS_globalCustomerId\r
85  *\r
86  *\r
87  * Out Mapping Variables:\r
88  *    @param - GENGS_service\r
89  *    @param - GENGS_FoundIndicator\r
90  *    @param - WorkflowException\r
91  */\r
92 class CustomE2EGetService extends AbstractServiceTaskProcessor{\r
93 \r
94         String Prefix = "GENGS_"\r
95         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
96 \r
97         /**\r
98          * This method validates the incoming variables and\r
99          * determines the subsequent event based on which\r
100          * variables the calling flow provided.\r
101          *\r
102          * @param - execution\r
103          *\r
104          */\r
105         public void preProcessRequest(Execution execution) {\r
106                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
107                 execution.setVariable("prefix",Prefix)\r
108                 utils.log("DEBUG", " *** STARTED GenericGetService PreProcessRequest Process*** ", isDebugEnabled)\r
109 \r
110                 execution.setVariable("GENGS_obtainObjectsUrl", false)\r
111                 execution.setVariable("GENGS_obtainServiceInstanceUrlByName", false)\r
112                 execution.setVariable("GENGS_SuccessIndicator", false)\r
113                 execution.setVariable("GENGS_FoundIndicator", false)\r
114                 execution.setVariable("GENGS_resourceLink", null)\r
115                 execution.setVariable("GENGS_siResourceLink", null)\r
116 \r
117                 try{\r
118                         // Get Variables\r
119                         String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")\r
120                         String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
121                         String serviceInstanceName = execution.getVariable("GENGS_serviceInstanceName")\r
122                         String serviceType = execution.getVariable("GENGS_serviceType")\r
123                         String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
124                         String type = execution.getVariable("GENGS_type")\r
125 \r
126                         if(type != null){\r
127                                 utils.log("DEBUG", "Incoming GENGS_type is: " + type, isDebugEnabled)\r
128                                 if(type.equalsIgnoreCase("allotted-resource")){\r
129                                         if(isBlank(allottedResourceId)){\r
130                                                 utils.log("DEBUG", "Incoming allottedResourceId is null. Allotted Resource Id is required to Get an allotted-resource.", isDebugEnabled)\r
131                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming allottedResourceId is null. Allotted Resource Id is required to Get an allotted-resource.")\r
132                                         }else{\r
133                                                 utils.log("DEBUG", "Incoming Allotted Resource Id is: " + allottedResourceId, isDebugEnabled)\r
134                                                 if(isBlank(globalCustomerId) || isBlank(serviceType) || isBlank(serviceInstanceId)){\r
135                                                         execution.setVariable("GENGS_obtainObjectsUrl", true)\r
136                                                 }else{\r
137                                                         utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)\r
138                                                         utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)\r
139                                                         utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
140                                                 }\r
141                                         }\r
142                                 }else if(type.equalsIgnoreCase("service-instance")){\r
143                                         if(isBlank(serviceInstanceId) && isBlank(serviceInstanceName)){\r
144                                                 utils.log("DEBUG", "Incoming serviceInstanceId and serviceInstanceName are null. ServiceInstanceId or ServiceInstanceName is required to Get a service-instance.", isDebugEnabled)\r
145                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming serviceInstanceId and serviceInstanceName are null. ServiceInstanceId or ServiceInstanceName is required to Get a service-instance.")\r
146                                         }else{\r
147                                                 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)\r
148                                                 utils.log("DEBUG", "Incoming Service Instance Name is: " + serviceInstanceName, isDebugEnabled)\r
149                                                 if(isBlank(globalCustomerId) || isBlank(serviceType)){\r
150                                                         execution.setVariable("GENGS_obtainObjectsUrl", true)\r
151                                                         if(isBlank(serviceInstanceId)){\r
152                                                                 execution.setVariable("GENGS_obtainServiceInstanceUrlByName", true)\r
153                                                         }\r
154                                                 }else{\r
155                                                         utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
156                                                         utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)\r
157                                                 }\r
158                                         }\r
159                                 }else if(type.equalsIgnoreCase("service-subscription")){\r
160                                         if(isBlank(serviceType) || isBlank(globalCustomerId)){\r
161                                                 utils.log("DEBUG", "Incoming ServiceType or GlobalCustomerId is null. These variables are required to Get a service-subscription.", isDebugEnabled)\r
162                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming ServiceType or GlobalCustomerId is null. These variables are required to Get a service-subscription.")\r
163                                         }else{\r
164                                                 utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)\r
165                                                 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
166                                         }\r
167                                 }else{\r
168                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Type is Invalid. Please Specify Type as service-instance or service-subscription")\r
169                                 }\r
170                         }else{\r
171                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Incoming GENGS_type is null. Variable is Required.")\r
172                         }\r
173 \r
174                 }catch(BpmnError b){\r
175                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
176                         throw b\r
177                 }catch(Exception e){\r
178                         utils.log("DEBUG", "Internal Error encountered within GenericGetService PreProcessRequest method!" + e, isDebugEnabled)\r
179                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in GenericGetService PreProcessRequest")\r
180 \r
181                 }\r
182                 utils.log("DEBUG", "*** COMPLETED GenericGetService PreProcessRequest Process ***", isDebugEnabled)\r
183         }\r
184 \r
185         /**\r
186          * This method obtains the Url to the provided service instance\r
187          * using the Service Instance Id.\r
188          *\r
189          * @param - execution\r
190          */\r
191         public void obtainServiceInstanceUrlById(Execution execution){\r
192                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
193                 execution.setVariable("prefix",Prefix)\r
194                 utils.log("DEBUG", " *** STARTED GenericGetService ObtainServiceInstanceUrlById Process*** ", isDebugEnabled)\r
195                 try {\r
196                         AaiUtil aaiUriUtil = new AaiUtil(this)\r
197                         String aai_uri = aaiUriUtil.getSearchNodesQueryEndpoint(execution)\r
198                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")\r
199 \r
200                         String type = execution.getVariable("GENGS_type")\r
201                         String path = ""\r
202                         if(type.equalsIgnoreCase("service-instance")){\r
203                                 String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
204                                 utils.log("DEBUG", " Querying Node for Service-Instance URL by using Service-Instance Id: " + serviceInstanceId, isDebugEnabled)\r
205                                 path = "${aai_uri}?search-node-type=service-instance&filter=service-instance-id:EQUALS:${serviceInstanceId}"\r
206                                 utils.logAudit("Service Instance Node Query Url is: " + path)\r
207                                 utils.log("DEBUG", "Service Instance Node Query Url is: " + path, isDebugEnabled)\r
208                         }else if(type.equalsIgnoreCase("allotted-resource")){\r
209                                 String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")\r
210                                 utils.log("DEBUG", " Querying Node for Service-Instance URL by using Allotted Resource Id: " + allottedResourceId, isDebugEnabled)\r
211                                 path = "${aai_uri}?search-node-type=allotted-resource&filter=id:EQUALS:${allottedResourceId}"\r
212                                 utils.logAudit("Allotted Resource Node Query Url is: " + path)\r
213                                 utils.log("DEBUG", "Allotted Resource Node Query Url is: " + path, isDebugEnabled)\r
214                         }\r
215 \r
216                         //String url = "${aai_endpoint}${path}"  host name needs to be removed from property\r
217                         String url = "${path}"\r
218                         execution.setVariable("GENGS_genericQueryPath", url)\r
219 \r
220                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, url)\r
221                         int responseCode = response.getStatusCode()\r
222                         execution.setVariable("GENGS_genericQueryResponseCode", responseCode)\r
223                         utils.log("DEBUG", "  GET Service Instance response code is: " + responseCode, isDebugEnabled)\r
224                         utils.logAudit("GenericGetService AAI GET Response Code: " + responseCode)\r
225 \r
226                         String aaiResponse = response.getResponseBodyAsString()\r
227                         execution.setVariable("GENGS_obtainSIUrlResponseBeforeUnescaping", aaiResponse)\r
228                         utils.log("DEBUG", "GenericGetService AAI Response before unescaping: " + aaiResponse, isDebugEnabled)\r
229                         aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
230                         execution.setVariable("GENGS_genericQueryResponse", aaiResponse)\r
231                         utils.logAudit("GenericGetService AAI Response: " + aaiResponse)\r
232                         utils.log("DEBUG", "GenericGetService AAI Response: " + aaiResponse, isDebugEnabled)\r
233 \r
234                         //Process Response\r
235                         if(responseCode == 200){\r
236                                 utils.log("DEBUG", "Generic Query Received a Good Response Code", isDebugEnabled)\r
237                                 execution.setVariable("GENGS_SuccessIndicator", true)\r
238                                 if(utils.nodeExists(aaiResponse, "result-data")){\r
239                                         utils.log("DEBUG", "Generic Query Response Does Contain Data" , isDebugEnabled)\r
240                                         execution.setVariable("GENGS_FoundIndicator", true)\r
241                                         String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")\r
242                                         execution.setVariable("GENGS_resourceLink", resourceLink)\r
243                                         execution.setVariable("GENGS_siResourceLink", resourceLink)\r
244                                 }else{\r
245                                         utils.log("DEBUG", "Generic Query Response Does NOT Contains Data" , isDebugEnabled)\r
246                                         execution.setVariable("WorkflowResponse", "  ") //for junits\r
247                                 }\r
248                         }else if(responseCode == 404){\r
249                                 utils.log("DEBUG", "Generic Query Received a Not Found (404) Response", isDebugEnabled)\r
250                                 execution.setVariable("GENGS_SuccessIndicator", true)\r
251                                 execution.setVariable("WorkflowResponse", "  ") //for junits\r
252                         }else{\r
253                                 utils.log("DEBUG", "Generic Query Received a BAD REST Response: \n" + aaiResponse, isDebugEnabled)\r
254                                 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
255                                 throw new BpmnError("MSOWorkflowException")\r
256                         }\r
257                 }catch(BpmnError b){\r
258                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
259                         throw b\r
260                 }catch(Exception e){\r
261                         utils.log("ERROR", " Error encountered within GenericGetService ObtainServiceInstanceUrlById method!" + e, isDebugEnabled)\r
262                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During ObtainServiceInstanceUrlById")\r
263                 }\r
264                 utils.log("DEBUG", " *** COMPLETED GenericGetService ObtainServiceInstanceUrlById Process*** ", isDebugEnabled)\r
265         }\r
266 \r
267         /**\r
268          * This method obtains the Url to the provided service instance\r
269          * using the Service Instance Name.\r
270          *\r
271          * @param - execution\r
272          */\r
273         public void obtainServiceInstanceUrlByName(Execution execution){\r
274                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
275                 execution.setVariable("prefix",Prefix)\r
276                 utils.log("DEBUG", " *** STARTED GenericGetService ObtainServiceInstanceUrlByName Process*** ", isDebugEnabled)\r
277                 try {\r
278                         String serviceInstanceName = execution.getVariable("GENGS_serviceInstanceName")\r
279                         utils.log("DEBUG", " Querying Node for Service-Instance URL by using Service-Instance Name " + serviceInstanceName, isDebugEnabled)\r
280 \r
281                         AaiUtil aaiUriUtil = new AaiUtil(this)\r
282                         String aai_uri = aaiUriUtil.getSearchNodesQueryEndpoint(execution)\r
283                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")\r
284                         String path = "${aai_uri}?search-node-type=service-instance&filter=service-instance-name:EQUALS:${serviceInstanceName}"\r
285 \r
286                         //String url = "${aai_endpoint}${path}"  host name needs to be removed from property\r
287                         String url = "${path}"\r
288                         execution.setVariable("GENGS_obtainSIUrlPath", url)\r
289 \r
290                         utils.logAudit("GenericGetService AAI Endpoint: " + aai_endpoint)\r
291                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, url)\r
292                         int responseCode = response.getStatusCode()\r
293                         execution.setVariable("GENGS_obtainSIUrlResponseCode", responseCode)\r
294                         utils.log("DEBUG", "  GET Service Instance response code is: " + responseCode, isDebugEnabled)\r
295                         utils.logAudit("GenericGetService AAI Response Code: " + responseCode)\r
296 \r
297                         String aaiResponse = response.getResponseBodyAsString()\r
298                         aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
299                         execution.setVariable("GENGS_obtainSIUrlResponse", aaiResponse)\r
300                         utils.logAudit("GenericGetService AAI Response: " + aaiResponse)\r
301                         //Process Response\r
302                         if(responseCode == 200){\r
303                                 utils.log("DEBUG", "  Query for Service Instance Url Received a Good Response Code", isDebugEnabled)\r
304                                 execution.setVariable("GENGS_SuccessIndicator", true)\r
305                                 if(utils.nodeExists(aaiResponse, "result-data")){\r
306                                         utils.log("DEBUG", "Query for Service Instance Url Response Does Contain Data" , isDebugEnabled)\r
307                                         execution.setVariable("GENGS_FoundIndicator", true)\r
308                                         String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")\r
309                                         execution.setVariable("GENGS_resourceLink", resourceLink)\r
310                                         execution.setVariable("GENGS_siResourceLink", resourceLink)\r
311                                 }else{\r
312                                         utils.log("DEBUG", "Query for Service Instance Url Response Does NOT Contains Data" , isDebugEnabled)\r
313                                         execution.setVariable("WorkflowResponse", "  ") //for junits\r
314                                 }\r
315                         }else if(responseCode == 404){\r
316                                 utils.log("DEBUG", "  Query for Service Instance Received a Not Found (404) Response", isDebugEnabled)\r
317                                 execution.setVariable("GENGS_SuccessIndicator", true)\r
318                                 execution.setVariable("WorkflowResponse", "  ") //for junits\r
319                         }else{\r
320                                 utils.log("DEBUG", "Query for Service Instance Received a BAD REST Response: \n" + aaiResponse, isDebugEnabled)\r
321                                 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
322                                 throw new BpmnError("MSOWorkflowException")\r
323                         }\r
324                 }catch(BpmnError b){\r
325                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
326                         throw b\r
327                 }catch(Exception e){\r
328                         utils.log("ERROR", " Error encountered within GenericGetService ObtainServiceInstanceUrlByName method!" + e, isDebugEnabled)\r
329                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During ObtainServiceInstanceUrlByName")\r
330                 }\r
331                 utils.log("DEBUG", " *** COMPLETED GenericGetService ObtainServiceInstanceUrlByName Process*** ", isDebugEnabled)\r
332         }\r
333 \r
334 \r
335         /**\r
336          * This method executes a GET call to AAI to obtain the\r
337          * service-instance or service-subscription\r
338          *\r
339          * @param - execution\r
340          */\r
341         public void getServiceObject(Execution execution){\r
342                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
343                 execution.setVariable("prefix",Prefix)\r
344                 utils.log("DEBUG", " *** STARTED GenericGetService GetServiceObject Process*** ", isDebugEnabled)\r
345                 try {\r
346                         String type = execution.getVariable("GENGS_type")\r
347                         AaiUtil aaiUriUtil = new AaiUtil(this)\r
348                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")\r
349                         String serviceEndpoint = ""\r
350 \r
351                         utils.logAudit("GenericGetService getServiceObject AAI Endpoint: " + aai_endpoint)\r
352                         if(type.equalsIgnoreCase("service-instance")){\r
353                                 String siResourceLink = execution.getVariable("GENGS_resourceLink")\r
354                                 if(isBlank(siResourceLink)){\r
355                                         String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
356                                         utils.log("DEBUG", " Incoming GENGS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)\r
357                                         String serviceType = execution.getVariable("GENGS_serviceType")\r
358                                         utils.log("DEBUG", " Incoming GENGS_serviceType is: " + serviceType, isDebugEnabled)\r
359                                         String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
360                                         utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
361 \r
362                                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
363                                         logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)\r
364                                         serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8")\r
365                                 }else{\r
366                                         utils.log("DEBUG", "Incoming Service Instance Url is: " + siResourceLink, isDebugEnabled)\r
367                                         String[] split = siResourceLink.split("/aai/")\r
368                                         serviceEndpoint = "/aai/" + split[1]\r
369                                 }\r
370                         }else if(type.equalsIgnoreCase("allotted-resource")){\r
371                                 String siResourceLink = execution.getVariable("GENGS_resourceLink")\r
372                                 if(isBlank(siResourceLink)){\r
373                                         String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")\r
374                                         utils.log("DEBUG", " Incoming GENGS_allottedResourceId is: " + allottedResourceId, isDebugEnabled)\r
375                                         String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
376                                         utils.log("DEBUG", " Incoming GENGS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)\r
377                                         String serviceType = execution.getVariable("GENGS_serviceType")\r
378                                         utils.log("DEBUG", " Incoming GENGS_serviceType is: " + serviceType, isDebugEnabled)\r
379                                         String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
380                                         utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
381 \r
382                                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
383                                         logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)\r
384                                         serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8") +  "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8")\r
385                                 }else{\r
386                                         utils.log("DEBUG", "Incoming Allotted-Resource Url is: " + siResourceLink, isDebugEnabled)\r
387                                         String[] split = siResourceLink.split("/aai/")\r
388                                         serviceEndpoint = "/aai/" + split[1]\r
389                                 }\r
390                         }else if(type.equalsIgnoreCase("service-subscription")){\r
391                                 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
392                                 String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
393                                 String serviceType = execution.getVariable("GENGS_serviceType")\r
394                                 serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8")\r
395                         }\r
396 \r
397                         String serviceUrl = "${aai_endpoint}" + serviceEndpoint\r
398 \r
399                         execution.setVariable("GENGS_getServiceUrl", serviceUrl)\r
400                         utils.log("DEBUG", "GET Service AAI Path is: \n" + serviceUrl, isDebugEnabled)\r
401 \r
402                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, serviceUrl)\r
403                         int responseCode = response.getStatusCode()\r
404                         execution.setVariable("GENGS_getServiceResponseCode", responseCode)\r
405                         utils.log("DEBUG", "  GET Service response code is: " + responseCode, isDebugEnabled)\r
406                         utils.logAudit("GenericGetService AAI Response Code: " + responseCode)\r
407 \r
408                         String aaiResponse = response.getResponseBodyAsString()\r
409                         aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
410                         execution.setVariable("GENGS_getServiceResponse", aaiResponse)\r
411                         utils.logAudit("GenericGetService AAI Response: " + aaiResponse)\r
412                         //Process Response\r
413                         if(responseCode == 200 || responseCode == 202){\r
414                                 utils.log("DEBUG", "GET Service Received a Good Response Code", isDebugEnabled)\r
415                                 if(utils.nodeExists(aaiResponse, "service-instance") || utils.nodeExists(aaiResponse, "service-subscription")){\r
416                                         utils.log("DEBUG", "GET Service Response Contains a service-instance" , isDebugEnabled)\r
417                                         execution.setVariable("GENGS_FoundIndicator", true)\r
418                                         execution.setVariable("GENGS_service", aaiResponse)\r
419                                         execution.setVariable("WorkflowResponse", aaiResponse)\r
420 \r
421                                 }else{\r
422                                         utils.log("DEBUG", "GET Service Response Does NOT Contain Data" , isDebugEnabled)\r
423                                 }\r
424                         }else if(responseCode == 404){\r
425                                 utils.log("DEBUG", "GET Service Received a Not Found (404) Response", isDebugEnabled)\r
426                                 execution.setVariable("WorkflowResponse", "  ") //for junits\r
427                         }\r
428                         else{\r
429                                 utils.log("DEBUG", "  GET Service Received a Bad Response: \n" + aaiResponse, isDebugEnabled)\r
430                                 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
431                                 throw new BpmnError("MSOWorkflowException")\r
432                         }\r
433                 }catch(BpmnError b){\r
434                         utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
435                         throw b\r
436                 }catch(Exception e){\r
437                         utils.log("DEBUG", " Error encountered within GenericGetService GetServiceObject method!" + e, isDebugEnabled)\r
438                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During GenericGetService")\r
439                 }\r
440                 utils.log("DEBUG", " *** COMPLETED GenericGetService GetServiceObject Process*** ", isDebugEnabled)\r
441         }\r
442 \r
443 }