X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FPolicyDBDao.java;h=60b35fb09e07505ddd4d9c6de251aa4bc51b5d68;hb=a97e1eafd731937aab373213ab04c3296cc97595;hp=71eb1156fba91c62076f2e88f207e29cf7b2efc3;hpb=4e9205fe5586a33461e8207e446147948d3fd309;p=policy%2Fengine.git 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..60b35fb09 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 @@ -127,7 +127,7 @@ public class PolicyDBDao { public static final String duplicatePolicyId = "Somehow, more than one policy with the id "; public static final String foundInDB = " were found in the database"; - public static boolean isJunit = false; + private static boolean isJunit = false; public static void setJunit(boolean isJunit) { PolicyDBDao.isJunit = isJunit; @@ -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; @@ -1247,6 +1250,9 @@ public class PolicyDBDao { for(PDPPolicy policy : policies){ try{ String[] stringArray = getNameScopeAndVersionFromPdpPolicy(policy.getId()); + if(stringArray == null) { + throw new IllegalArgumentException("Invalid input - policyID must contain name, scope and version"); + } List policyEntityList; Query getPolicyEntitiesQuery = em.createNamedQuery("PolicyEntity.findByNameAndScope"); getPolicyEntitiesQuery.setParameter("name", stringArray[0]); @@ -1315,8 +1321,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 +1370,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 +1534,7 @@ public class PolicyDBDao { } } } - if(transactionTimer instanceof Thread){ + if(transactionTimer != null){ transactionTimer.interrupt(); } } @@ -1563,7 +1565,7 @@ public class PolicyDBDao { } } - if(transactionTimer instanceof Thread){ + if(transactionTimer != null){ transactionTimer.interrupt(); } } @@ -1768,7 +1770,7 @@ public class PolicyDBDao { policyId = policyName; policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:name AND p.scope=:scope"); policyQuery.setParameter("name", policyId); - policyQuery.setParameter(scope, scope); + policyQuery.setParameter("scope", scope); } else{ policyId = String.valueOf(policyID); policyQuery = em.createNamedQuery("PolicyEntity.FindById"); @@ -1921,18 +1923,15 @@ public class PolicyDBDao { private String readConfigFile(String configPath){ String configDataString = null; - InputStream configContentStream = null; - try { - configContentStream = new FileInputStream(configPath); + + try(InputStream configContentStream = new FileInputStream(configPath)) { configDataString = IOUtils.toString(configContentStream); } catch (FileNotFoundException e) { logger.error("Caught FileNotFoundException on new FileInputStream("+configPath+")",e); throw new IllegalArgumentException("The config file path does not exist"); } catch(IOException e2){ - logger.error("Caught IOException on newIOUtils.toString("+configContentStream+")",e2); + logger.error("Caught IOException on newIOUtils.toString(configContentStream)",e2); throw new IllegalArgumentException("The config file path cannot be read"); - } finally { - IOUtils.closeQuietly(configContentStream); } if(configDataString == null){ throw new IllegalArgumentException("The config file path cannot be read"); @@ -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]);