2 * ============LICENSE_START=======================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.openecomp.mso.bpmn.common.scripts
\r
23 import org.apache.commons.lang3.StringEscapeUtils
\r
24 import org.camunda.bpm.engine.delegate.BpmnError
\r
25 import org.camunda.bpm.engine.runtime.Execution
\r
26 import org.openecomp.mso.rest.APIResponse
\r
27 import org.springframework.web.util.UriUtils
\r
29 import static org.apache.commons.lang3.StringUtils.isBlank
\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
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
44 * When using to Get a Service-Subscription:
\r
45 * The global-customer-id and service-type must be
\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
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
64 * Variable Mapping Below:
\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
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
80 * For Service-Subscription:
\r
81 * @param - GENGS_type
\r
82 * @param - GENGS_serviceType
\r
83 * @param - GENGS_globalCustomerId
\r
86 * Out Mapping Variables:
\r
87 * @param - GENGS_service
\r
88 * @param - GENGS_FoundIndicator
\r
89 * @param - WorkflowException
\r
91 class GenericGetService extends AbstractServiceTaskProcessor{
\r
93 String Prefix = "GENGS_"
\r
94 ExceptionUtil exceptionUtil = new ExceptionUtil()
\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
101 * @param - execution
\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
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
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
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
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
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
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
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
154 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
155 utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
\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
163 utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
\r
164 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
167 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Type is Invalid. Please Specify Type as service-instance or service-subscription")
\r
170 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Incoming GENGS_type is null. Variable is Required.")
\r
173 }catch(BpmnError b){
\r
174 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\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
181 utils.log("DEBUG", "*** COMPLETED GenericGetService PreProcessRequest Process ***", isDebugEnabled)
\r
185 * This method obtains the Url to the provided service instance
\r
186 * using the Service Instance Id.
\r
188 * @param - execution
\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
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
199 String type = execution.getVariable("GENGS_type")
\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
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
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
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
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
244 utils.log("DEBUG", "Generic Query Response Does NOT Contains Data" , isDebugEnabled)
\r
245 execution.setVariable("WorkflowResponse", " ") //for junits
\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
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
256 }catch(BpmnError b){
\r
257 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\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
263 utils.log("DEBUG", " *** COMPLETED GenericGetService ObtainServiceInstanceUrlById Process*** ", isDebugEnabled)
\r
267 * This method obtains the Url to the provided service instance
\r
268 * using the Service Instance Name.
\r
270 * @param - execution
\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
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
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
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
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
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
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 String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")
\r
305 boolean nodeExists = isBlank(globalCustomerId) ? utils.nodeExists(aaiResponse, "result-data") : hasCustomerServiceInstance(aaiResponse, globalCustomerId)
\r
307 utils.log("DEBUG", "Query for Service Instance Url Response Does Contain Data" , isDebugEnabled)
\r
308 execution.setVariable("GENGS_FoundIndicator", true)
\r
309 String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")
\r
310 execution.setVariable("GENGS_resourceLink", resourceLink)
\r
311 execution.setVariable("GENGS_siResourceLink", resourceLink)
\r
313 utils.log("DEBUG", "Query for Service Instance Url Response Does NOT Contains Data" , isDebugEnabled)
\r
314 execution.setVariable("WorkflowResponse", " ") //for junits
\r
316 }else if(responseCode == 404){
\r
317 utils.log("DEBUG", " Query for Service Instance Received a Not Found (404) Response", isDebugEnabled)
\r
318 execution.setVariable("GENGS_SuccessIndicator", true)
\r
319 execution.setVariable("WorkflowResponse", " ") //for junits
\r
321 utils.log("DEBUG", "Query for Service Instance Received a BAD REST Response: \n" + aaiResponse, isDebugEnabled)
\r
322 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
\r
323 throw new BpmnError("MSOWorkflowException")
\r
325 }catch(BpmnError b){
\r
326 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
328 }catch(Exception e){
\r
329 utils.log("ERROR", " Error encountered within GenericGetService ObtainServiceInstanceUrlByName method!" + e, isDebugEnabled)
\r
330 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During ObtainServiceInstanceUrlByName")
\r
332 utils.log("DEBUG", " *** COMPLETED GenericGetService ObtainServiceInstanceUrlByName Process*** ", isDebugEnabled)
\r
337 * This method executes a GET call to AAI to obtain the
\r
338 * service-instance or service-subscription
\r
340 * @param - execution
\r
342 public void getServiceObject(Execution execution){
\r
343 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
344 execution.setVariable("prefix",Prefix)
\r
345 utils.log("DEBUG", " *** STARTED GenericGetService GetServiceObject Process*** ", isDebugEnabled)
\r
347 String type = execution.getVariable("GENGS_type")
\r
348 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
349 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
\r
350 String serviceEndpoint = ""
\r
352 utils.logAudit("GenericGetService getServiceObject AAI Endpoint: " + aai_endpoint)
\r
353 if(type.equalsIgnoreCase("service-instance")){
\r
354 String siResourceLink = execution.getVariable("GENGS_resourceLink")
\r
355 if(isBlank(siResourceLink)){
\r
356 String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")
\r
357 utils.log("DEBUG", " Incoming GENGS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
\r
358 String serviceType = execution.getVariable("GENGS_serviceType")
\r
359 utils.log("DEBUG", " Incoming GENGS_serviceType is: " + serviceType, isDebugEnabled)
\r
360 String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")
\r
361 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
363 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
364 logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
\r
365 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
367 utils.log("DEBUG", "Incoming Service Instance Url is: " + siResourceLink, isDebugEnabled)
\r
368 String[] split = siResourceLink.split("/aai/")
\r
369 serviceEndpoint = "/aai/" + split[1]
\r
371 }else if(type.equalsIgnoreCase("allotted-resource")){
\r
372 String siResourceLink = execution.getVariable("GENGS_resourceLink")
\r
373 if(isBlank(siResourceLink)){
\r
374 String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")
\r
375 utils.log("DEBUG", " Incoming GENGS_allottedResourceId is: " + allottedResourceId, isDebugEnabled)
\r
376 String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")
\r
377 utils.log("DEBUG", " Incoming GENGS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
\r
378 String serviceType = execution.getVariable("GENGS_serviceType")
\r
379 utils.log("DEBUG", " Incoming GENGS_serviceType is: " + serviceType, isDebugEnabled)
\r
380 String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")
\r
381 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
383 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
384 logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
\r
385 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
387 utils.log("DEBUG", "Incoming Allotted-Resource Url is: " + siResourceLink, isDebugEnabled)
\r
388 String[] split = siResourceLink.split("/aai/")
\r
389 serviceEndpoint = "/aai/" + split[1]
\r
391 }else if(type.equalsIgnoreCase("service-subscription")){
\r
392 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
393 String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")
\r
394 String serviceType = execution.getVariable("GENGS_serviceType")
\r
395 serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8")
\r
398 String serviceUrl = "${aai_endpoint}" + serviceEndpoint
\r
400 execution.setVariable("GENGS_getServiceUrl", serviceUrl)
\r
401 utils.log("DEBUG", "GET Service AAI Path is: \n" + serviceUrl, isDebugEnabled)
\r
403 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, serviceUrl)
\r
404 int responseCode = response.getStatusCode()
\r
405 execution.setVariable("GENGS_getServiceResponseCode", responseCode)
\r
406 utils.log("DEBUG", " GET Service response code is: " + responseCode, isDebugEnabled)
\r
407 utils.logAudit("GenericGetService AAI Response Code: " + responseCode)
\r
409 String aaiResponse = response.getResponseBodyAsString()
\r
410 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
\r
411 execution.setVariable("GENGS_getServiceResponse", aaiResponse)
\r
412 utils.logAudit("GenericGetService AAI Response: " + aaiResponse)
\r
414 if(responseCode == 200 || responseCode == 202){
\r
415 utils.log("DEBUG", "GET Service Received a Good Response Code", isDebugEnabled)
\r
416 if(utils.nodeExists(aaiResponse, "service-instance") || utils.nodeExists(aaiResponse, "service-subscription")){
\r
417 utils.log("DEBUG", "GET Service Response Contains a service-instance" , isDebugEnabled)
\r
418 execution.setVariable("GENGS_FoundIndicator", true)
\r
419 execution.setVariable("GENGS_service", aaiResponse)
\r
420 execution.setVariable("WorkflowResponse", aaiResponse)
\r
423 utils.log("DEBUG", "GET Service Response Does NOT Contain Data" , isDebugEnabled)
\r
425 }else if(responseCode == 404){
\r
426 utils.log("DEBUG", "GET Service Received a Not Found (404) Response", isDebugEnabled)
\r
427 execution.setVariable("WorkflowResponse", " ") //for junits
\r
430 utils.log("DEBUG", " GET Service Received a Bad Response: \n" + aaiResponse, isDebugEnabled)
\r
431 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
\r
432 throw new BpmnError("MSOWorkflowException")
\r
434 }catch(BpmnError b){
\r
435 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
437 }catch(Exception e){
\r
438 utils.log("DEBUG", " Error encountered within GenericGetService GetServiceObject method!" + e, isDebugEnabled)
\r
439 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During GenericGetService")
\r
441 utils.log("DEBUG", " *** COMPLETED GenericGetService GetServiceObject Process*** ", isDebugEnabled)
\r
445 * An utility method which check whether a service(by name) is already present within a globalCustomerId or not.
\r
446 * @param jsonResponse raw response received from AAI by searching ServiceInstance by Name.
\r
447 * @param globalCustomerId
\r
448 * @return {@code true} if globalCustomerId is found at 6th position within "resource-link", {@code false} in any other cases.
\r
450 public boolean hasCustomerServiceInstance(String aaiResponse, final String globalCustomerId) {
\r
451 if (isBlank(aaiResponse)) {
\r
454 aaiResponse = utils.removeXmlNamespaces(aaiResponse)
\r
455 ArrayList<String> linksArray = utils.getMultNodeObjects(aaiResponse, "resource-link")
\r
456 if (linksArray == null || linksArray.size() == 0) {
\r
459 for (String resourceLink : linksArray) {
\r
460 int custStart = resourceLink.indexOf("customer/")
\r
461 int custEnd = resourceLink.indexOf("/service-subscriptions/")
\r
462 String receivedCustomerId = resourceLink.substring(custStart + 9, custEnd)
\r
463 if (globalCustomerId.equals(receivedCustomerId)) {
\r