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