aboutsummaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-design-services
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-06 15:56:15 +0100
committerPatrick Brady <pb071s@att.com>2018-02-07 17:17:20 +0000
commit972c29789738964ef7a92cffce4b4fccf2527807 (patch)
treeed878f66c8b57527a32f437365f84cdcb253ed06 /appc-inbound/appc-design-services
parent9f387dc0c254b1ca6aca6846c4524bc79dcc9a15 (diff)
DbService sonar fixes
Change-Id: I3e9ed180c1c0d6be9182e65afc84dd2947404980 Issue-ID: APPC-570 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-inbound/appc-design-services')
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBDesignException.java8
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBException.java12
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java74
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java20
4 files changed, 58 insertions, 56 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBDesignException.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBDesignException.java
deleted file mode 100644
index f7ae77cb4..000000000
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBDesignException.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.onap.appc.design.dbervices;
-
-public class DBDesignException extends Exception {
-
- public DBDesignException(String message) {
- super(message);
- }
-}
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBException.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBException.java
new file mode 100644
index 000000000..6ee961aa4
--- /dev/null
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DBException.java
@@ -0,0 +1,12 @@
+package org.onap.appc.design.dbervices;
+
+public class DBException extends Exception {
+
+ public DBException(String message) {
+ super(message);
+ }
+
+ public DBException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java
index 888e76a45..b09ef0d8c 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java
@@ -24,12 +24,13 @@
package org.onap.appc.design.dbervices;
-import java.sql.ResultSet;
-import java.util.ArrayList;
+import static com.google.common.collect.Lists.newArrayList;
-import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import java.sql.ResultSet;
+import java.util.List;
import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.onap.ccsdk.sli.core.dblib.DbLibService;
+import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
@@ -41,102 +42,99 @@ public class DbService {
private static final Logger Log = LoggerFactory.getLogger(DbService.class);
private static final String DBLIB_SERVICE = "org.onap.ccsdk.sli.core.dblib.DBResourceManager";
- DbLibService dblibSvc = null;
- String errorMsg = null;
+ private DbLibService dbLibSvc = null;
- public DbService() throws Exception {
- DbLibService dblibSvc = null;
+ public DbService() throws DBException {
Log.info("Initializing DbService service");
try
{
- dblibSvc = getDbLibService();
- if (dblibSvc == null) {
+ dbLibSvc = getDbLibService();
+ if (dbLibSvc == null) {
Log.error("Got Exception While getting DB Connection");
- throw new Exception("Got Exception While getting DB Connection");
+ throw new DBException("Got Exception While getting DB Connection");
}
- this.dblibSvc = dblibSvc;
}
catch (Exception e) {
Log.error(e.getMessage());
- throw e;
+ throw new DBException("An error occurred when instantiating DB service", e);
}
}
private static DbLibService getDbLibService() {
- DbLibService dblibSvc = null;
- BundleContext bctx = null;
- ServiceReference sref = null;
+ DbLibService dbLibService = null;
+ BundleContext bundleContext = null;
+ ServiceReference serviceRef = null;
Bundle bundle = FrameworkUtil.getBundle(SvcLogicService.class);
if (bundle != null) {
- bctx = bundle.getBundleContext();
+ bundleContext = bundle.getBundleContext();
}
- if (bctx != null) {
+ if (bundleContext != null) {
Log.debug("Getting bundle Context");
- sref = bctx.getServiceReference(DBLIB_SERVICE);
+ serviceRef = bundleContext.getServiceReference(DBLIB_SERVICE);
}
- if (sref == null) {
+ if (serviceRef == null) {
Log.warn("Could not find service reference for DBLib service");
} else {
- dblibSvc = (DbLibService) bctx.getService(sref);
- if (dblibSvc == null) {
+ dbLibService = (DbLibService)bundleContext.getService(serviceRef);
+ if (dbLibService == null) {
Log.warn("DBLIB_SERVICE is null");
}
}
- if (dblibSvc == null) {
+ if (dbLibService == null) {
try {
- dblibSvc = new DBResourceManager(System.getProperties());
+ dbLibService = new DBResourceManager(System.getProperties());
} catch (Exception e) {
Log.error("Caught exception trying to create db service", e);
}
- if (dblibSvc == null) {
+ if (dbLibService == null) {
Log.warn("Could not create new DBResourceManager");
}
}
- return (dblibSvc);
+ return dbLibService;
}
- public ResultSet getDBData(String query) throws Exception {
+ public ResultSet getDBData(String query) throws DBException{
ResultSet resultSet;
StringBuilder sqlBuilder = new StringBuilder(query);
Log.info("Query: " + sqlBuilder.toString());
try {
- resultSet = dblibSvc.getData(sqlBuilder.toString(), null, null);
+ resultSet = dbLibSvc.getData(sqlBuilder.toString(), null, null);
} catch (Exception e) {
Log.error("SQL query "+sqlBuilder+" :: " + e.getMessage());
- throw e;
+ throw new DBException("An error occurred when reading DB data", e);
}
return resultSet;
}
- public ResultSet getDBData(String query, ArrayList<String> paramList) throws Exception {
+ public ResultSet getDBData(String query, List<String> paramList) throws DBException {
ResultSet resultSet;
StringBuilder sqlBuilder = new StringBuilder(query);
Log.info("Query :" + sqlBuilder.toString());
try {
- resultSet = dblibSvc.getData(sqlBuilder.toString(), paramList, null);
- } catch (Exception expObj) {
- Log.error("query "+sqlBuilder+" :: " + expObj.getMessage());
- throw expObj;
+ resultSet = dbLibSvc.getData(sqlBuilder.toString(), newArrayList(paramList), null);
+ } catch (Exception e) {
+ Log.error("query "+sqlBuilder+" :: " + e.getMessage());
+ throw new DBException("An error occurred when reading DB data", e);
}
return resultSet;
}
- public boolean updateDBData(String query, ArrayList<String> paramList) throws Exception {
+ public boolean updateDBData(String query, List<String> paramList) throws DBException{
boolean update;
StringBuilder sqlBuilder = new StringBuilder(query);
Log.info("Query :" + sqlBuilder.toString());
try {
- update = dblibSvc.writeData(sqlBuilder.toString(), paramList, null);
- } catch (Exception expObj) {
- Log.error("query "+sqlBuilder+" :: " + expObj.getMessage());
- throw expObj;
+ update = dbLibSvc.writeData(sqlBuilder.toString(), newArrayList(paramList), null);
+ } catch (Exception e) {
+ Log.error("query "+sqlBuilder+" :: " + e.getMessage());
+ throw new DBException("An error occurred when updating DB data", e);
}
return update;
}
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java
index 5a20c063f..02de3609c 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java
@@ -106,7 +106,7 @@ public class DesignDBService {
response = setProtocolReference(payload, requestID);
break;
default:
- throw new DBDesignException(" Action " + action + " not found while processing request ");
+ throw new DBException(" Action " + action + " not found while processing request ");
}
return response;
@@ -135,7 +135,7 @@ public class DesignDBService {
boolean data = dbservice.updateDBData(queryString, argList);
if (!data) {
- throw new DBDesignException("Error while updating ProtocolReference");
+ throw new DBException("Error while updating ProtocolReference");
}
return SUCCESS_JSON;
}
@@ -177,7 +177,7 @@ public class DesignDBService {
data = dbservice.updateDBData(queryString, argList);
if (!data) {
- throw new DBDesignException("Error while updating ProtocolReference");
+ throw new DBException("Error while updating ProtocolReference");
}
return SUCCESS_JSON;
}
@@ -235,7 +235,7 @@ public class DesignDBService {
boolean data = dbservice.updateDBData(queryString, argList);
if (!data) {
- throw new DBDesignException("Error while updating RelationShip table");
+ throw new DBException("Error while updating RelationShip table");
}
}
@@ -324,7 +324,7 @@ public class DesignDBService {
boolean updateStatus = dbservice.updateDBData(insertQuery, argList);
if (!updateStatus)
- throw new DBDesignException("Error while updating Action Status");
+ throw new DBException("Error while updating Action Status");
}
private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId)
@@ -356,7 +356,7 @@ public class DesignDBService {
log.info(QUERY_STR + queryString);
boolean data = dbservice.updateDBData(queryString, argList);
if (!data) {
- throw new DBDesignException("Error Updating DT_ARTIFACT_TRACKING ");
+ throw new DBException("Error Updating DT_ARTIFACT_TRACKING ");
}
}
@@ -404,7 +404,7 @@ public class DesignDBService {
}
}
if (artifactContent == null || artifactContent.isEmpty()) {
- throw new DBDesignException(
+ throw new DBException(
"Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue());
}
DesignResponse designResponse = new DesignResponse();
@@ -454,7 +454,7 @@ public class DesignDBService {
designResponse.setUserId(payloadObject.get(USER_ID).textValue());
boolean update = dbservice.updateDBData(queryString, argList);
if (!update) {
- throw new DBDesignException("Sorry .....Something went wrong while updating the Status");
+ throw new DBException("Sorry .....Something went wrong while updating the Status");
}
ObjectMapper mapper = new ObjectMapper();
@@ -511,7 +511,7 @@ public class DesignDBService {
}
if (statusInfoList.isEmpty()) {
- throw new DBDesignException(
+ throw new DBException(
"OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID);
}
designResponse.setStatusInfoList(statusInfoList);
@@ -587,7 +587,7 @@ public class DesignDBService {
designInfoList.add(designInfo);
}
if (designInfoList.isEmpty()) {
- throw new DBDesignException(
+ throw new DBException(
" Welcome to CDT, Looks like you dont have Design Yet... Lets create some....");
}
designResponse.setDesignInfoList(designInfoList);