aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
diff options
context:
space:
mode:
authoreramkve <ram.krishna.verma@ericsson.com>2018-03-16 15:44:07 +0000
committereramkve <ram.krishna.verma@ericsson.com>2018-03-20 15:28:04 +0000
commiteef3c224cb6cad4b82a96938ade1e42ca881eea2 (patch)
tree37fc08a9b229e5634c0ffb983227f9f563ac7766 /ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
parent44fd25bcbb86f8600ec88eeeac6bb8312672c470 (diff)
Fix all bugs reported by Sonar in policy/engine
Code fixes for 27 bugs reported by Sonar in policy/engine Change-Id: I96da96b38a2e2954ec549e5cdf6ed3ad1d76722c Issue-ID: POLICY-662 Signed-off-by: eramkve <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index 71eb1156f..9ac858277 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -479,11 +479,14 @@ public class PolicyDBDao {
HttpURLConnection connection = null;
UUID requestID = UUID.randomUUID();
URL url;
+ String papUrl;
try {
- String papUrl = getPapUrlUserPass()[0];
- if(papUrl == null){
- papUrl = "undefined";
- }
+ String[] papUrlUserPass = getPapUrlUserPass();
+ if(papUrlUserPass == null ){
+ papUrl = "undefined";
+ } else {
+ papUrl = papUrlUserPass[0];
+ }
logger.debug("We are going to try to notify "+o);
//is this our own url?
String ourUrl = o;
@@ -1315,8 +1318,7 @@ public class PolicyDBDao {
private String[] getNameScopeAndVersionFromPdpPolicy(String fileName){
String[] splitByDots = fileName.split("\\.");
if(splitByDots.length < 3){
- //should we throw something
- return null;
+ return null;
}
String policyName = splitByDots[splitByDots.length-3];
String version = splitByDots[splitByDots.length-2];
@@ -1365,10 +1367,7 @@ public class PolicyDBDao {
*/
private static boolean isNullOrEmpty(String... strings){
for(String s : strings){
- if(!(s instanceof String)){
- return true;
- }
- if("".equals(s)){
+ if(s == null || "".equals(s)){
return true;
}
}
@@ -1532,7 +1531,7 @@ public class PolicyDBDao {
}
}
}
- if(transactionTimer instanceof Thread){
+ if(transactionTimer != null){
transactionTimer.interrupt();
}
}
@@ -1563,7 +1562,7 @@ public class PolicyDBDao {
}
}
- if(transactionTimer instanceof Thread){
+ if(transactionTimer != null){
transactionTimer.interrupt();
}
}
@@ -2042,7 +2041,7 @@ public class PolicyDBDao {
}
em.close();
}
- if(transactionTimer instanceof Thread){
+ if(transactionTimer != null){
transactionTimer.interrupt();
}
}
@@ -2544,7 +2543,10 @@ public class PolicyDBDao {
//we need to convert the form of the policy id that is used groups into the form that is used
//for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml)
- String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
+ String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
+ if(policyNameScopeAndVersion == null) {
+ throw new IllegalArgumentException("Invalid input - policyID must contain name, scope and version");
+ }
Query policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p.deleted=:deleted");
policyQuery.setParameter("policyName", policyNameScopeAndVersion[0]);
policyQuery.setParameter(scope, policyNameScopeAndVersion[1]);