From cd805e236b7e7ae75164c245e0366878c484503d Mon Sep 17 00:00:00 2001 From: Chittaranjan Sardar Date: Wed, 24 Jan 2018 12:57:55 +0530 Subject: Same Service names under two different Customers SO is not allowing to create services with same name with in different customers. Change-Id: I2ce83f3d6c8d999f88154a1ac50330a8b6d50118 Issue-ID: SO-382 Signed-off-by: Chittaranjan Sardar --- .../bpmn/common/scripts/GenericGetService.groovy | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy index 14f9135826..cfc5171dca 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy @@ -20,14 +20,14 @@ package org.openecomp.mso.bpmn.common.scripts -import static org.apache.commons.lang3.StringUtils.* - -import org.apache.commons.lang3.* +import org.apache.commons.lang3.StringEscapeUtils import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.runtime.Execution import org.openecomp.mso.rest.APIResponse import org.springframework.web.util.UriUtils +import static org.apache.commons.lang3.StringUtils.isBlank + /** * This class supports the GenericGetService Sub Flow. @@ -301,7 +301,9 @@ class GenericGetService extends AbstractServiceTaskProcessor{ if(responseCode == 200){ utils.log("DEBUG", " Query for Service Instance Url Received a Good Response Code", isDebugEnabled) execution.setVariable("GENGS_SuccessIndicator", true) - if(utils.nodeExists(aaiResponse, "result-data")){ + String globalCustomerId = execution.getVariable("GENGS_globalCustomerId") + boolean nodeExists = isBlank(globalCustomerId) ? utils.nodeExists(aaiResponse, "result-data") : hasCustomerServiceInstance(aaiResponse, globalCustomerId) + if(nodeExists){ utils.log("DEBUG", "Query for Service Instance Url Response Does Contain Data" , isDebugEnabled) execution.setVariable("GENGS_FoundIndicator", true) String resourceLink = utils.getNodeText1(aaiResponse, "resource-link") @@ -439,4 +441,30 @@ class GenericGetService extends AbstractServiceTaskProcessor{ utils.log("DEBUG", " *** COMPLETED GenericGetService GetServiceObject Process*** ", isDebugEnabled) } + /** + * An utility method which check whether a service(by name) is already present within a globalCustomerId or not. + * @param jsonResponse raw response received from AAI by searching ServiceInstance by Name. + * @param globalCustomerId + * @return {@code true} if globalCustomerId is found at 6th position within "resource-link", {@code false} in any other cases. + */ + public boolean hasCustomerServiceInstance(String aaiResponse, final String globalCustomerId) { + if (isBlank(aaiResponse)) { + return false + } + aaiResponse = utils.removeXmlNamespaces(aaiResponse) + ArrayList linksArray = utils.getMultNodeObjects(aaiResponse, "resource-link") + if (linksArray == null || linksArray.size() == 0) { + return false + } + for (String resourceLink : linksArray) { + int custStart = resourceLink.indexOf("customer/") + int custEnd = resourceLink.indexOf("/service-subscriptions/") + String receivedCustomerId = resourceLink.substring(custStart + 9, custEnd) + if (globalCustomerId.equals(receivedCustomerId)) { + return true + } + } + return false + } + } \ No newline at end of file -- cgit 1.2.3-korg