summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/groovy
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2018-12-13 15:19:55 +0000
committerGerrit Code Review <gerrit@onap.org>2018-12-13 15:19:55 +0000
commit90d8bdc280619c6036185a37d4556899b2181e29 (patch)
tree6fa34a30c0baf972f63b9247b0e90fc27f0d49ae /bpmn/MSOCommonBPMN/src/main/groovy
parent6e071febcb82bab59c65a0bb0af171fb05cbc222 (diff)
parent516b8f0c8b4ed43532abfaca95d2ca014bde885f (diff)
Merge "Add junit tests for CatalogDBUtils"
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/groovy')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy84
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy31
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy5
3 files changed, 58 insertions, 62 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy
index 103326a693..22b5de2e4b 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy
@@ -20,24 +20,22 @@
package org.onap.so.bpmn.common.scripts
-import org.json.JSONObject;
-import org.json.JSONArray;
+import org.apache.commons.lang3.StringUtils
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.json.JSONArray
+import org.json.JSONObject
import org.onap.logging.ref.slf4j.ONAPLogConstants
-import org.onap.so.bpmn.core.UrnPropertiesReader;
-import org.springframework.web.util.UriUtils;
-
+import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.logger.MessageEnum
+import org.onap.so.logger.MsoLogger
+import org.onap.so.utils.TargetEntity
+import org.springframework.web.util.UriUtils
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response
-import org.camunda.bpm.engine.delegate.DelegateExecution
-
-import org.onap.so.logger.MsoLogger;
-import org.onap.so.utils.TargetEntity
-import org.onap.so.logger.MessageEnum
-
-
/***
* Utilities for accessing Catalog DB Adapter to retrieve Networks, VNF/VFModules, AllottedResources and complete ServiceResources information
@@ -47,29 +45,15 @@ import org.onap.so.logger.MessageEnum
class CatalogDbUtils {
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CatalogDbUtils.class);
-
- MsoUtils utils = new MsoUtils()
- JsonUtils jsonUtils = new JsonUtils()
+ private HttpClientFactory httpClientFactory
+ private MsoUtils msoUtils
+ private JsonUtils jsonUtils
static private String defaultDbAdapterVersion = "v2"
- public JSONArray getAllVnfsByVnfModelCustomizationUuid(DelegateExecution execution, String vnfModelCustomizationUuid) {
- JSONArray vnfsList = null
- String endPoint = "/serviceVnfs?vnfModelCustomizationUuid=" + UriUtils.encode(vnfModelCustomizationUuid, "UTF-8")
- try {
- msoLogger.debug("ENDPOINT: " + endPoint)
- String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
-
- if (catalogDbResponse != null) {
- vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", "v1")
- }
-
- }
- catch (Exception e) {
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
- throw e
- }
-
- return vnfsList
+ CatalogDbUtils(HttpClientFactory httpClientFactory, MsoUtils msoUtils, JsonUtils jsonUtils) {
+ this.httpClientFactory = httpClientFactory
+ this.msoUtils = msoUtils
+ this.jsonUtils = jsonUtils
}
public JSONArray getAllVnfsByVnfModelCustomizationUuid(DelegateExecution execution, String vnfModelCustomizationUuid, String catalogUtilsVersion) {
@@ -114,7 +98,7 @@ class CatalogDbUtils {
}
}
catch (Exception e) {
- utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
+ msoUtils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
throw e
}
@@ -122,23 +106,14 @@ class CatalogDbUtils {
}
public String getServiceResourcesByServiceModelInvariantUuidString(DelegateExecution execution, String serviceModelInvariantUuid) {
- String resources = null
String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8")
try {
- String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint)
-
- if (catalogDbResponse != null) {
-
- resources = catalogDbResponse
- }
-
+ return getResponseFromCatalogDb(execution, endPoint)
}
catch (Exception e) {
msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message);
throw e
}
-
- return resources
}
public JSONObject getServiceResourcesByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid, String catalogUtilsVersion) {
@@ -443,19 +418,12 @@ class CatalogDbUtils {
String catalogDbEndpoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint",execution)
String queryEndpoint = catalogDbEndpoint + "/" + defaultDbAdapterVersion + endPoint
def responseData = ''
- def bpmnRequestId = UUID.randomUUID().toString()
-
- URL url = new URL(queryEndpoint)
- HttpClient client = new HttpClient(url, MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB)
- client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, bpmnRequestId)
+ HttpClient client = httpClientFactory.create(new URL(queryEndpoint), MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB)
+ client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, UUID.randomUUID().toString())
client.addAdditionalHeader('X-FromAppId', "BPMN")
client.addAdditionalHeader('Accept', MediaType.APPLICATION_JSON)
String basicAuthCred = execution.getVariable("BasicAuthHeaderValueDB")
- if (basicAuthCred != null && !"".equals(basicAuthCred)) {
- client.addAdditionalHeader("Authorization", basicAuthCred)
- }else {
- client.addAdditionalHeader("Authorization", getBasicDBAuthHeader(execution))
- }
+ client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution)))
msoLogger.debug('sending GET to Catalog DB endpoint: ' + endPoint)
Response response = client.get()
@@ -497,7 +465,7 @@ class CatalogDbUtils {
}
}
catch (Exception e) {
- utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
+ msoUtils.log("ERROR", "Exception in Querying Catalog DB: " + e.message)
throw e
}
@@ -509,13 +477,13 @@ class CatalogDbUtils {
String encodedString = null
try {
String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution)
- utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB)
+ msoUtils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB)
- encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution))
+ encodedString = msoUtils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution))
execution.setVariable("BasicAuthHeaderValueDB",encodedString)
} catch (IOException ex) {
String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
- utils.log("ERROR", dataErrorMessage)
+ msoUtils.log("ERROR", dataErrorMessage)
}
return encodedString
}
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy
new file mode 100644
index 0000000000..faa0037169
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.scripts
+
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.HttpClientFactory
+
+public class CatalogDbUtilsFactory {
+
+ CatalogDbUtils create() {
+ return new CatalogDbUtils(new HttpClientFactory(), new MsoUtils(), new JsonUtils())
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy
index 739bc4b7ed..1c1d5eb0e3 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy
@@ -20,9 +20,6 @@
package org.onap.so.bpmn.common.scripts
-import static org.apache.commons.lang3.StringUtils.*;
-
-import org.apache.commons.lang3.*
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.json.JSONObject;
@@ -56,7 +53,7 @@ public class DecomposeService extends AbstractServiceTaskProcessor {
String Prefix="DDS_"
ExceptionUtil exceptionUtil = new ExceptionUtil()
- CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
+ CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
JsonUtils jsonUtils = new JsonUtils()
public void preProcessRequest (DelegateExecution execution) {