From: Jorge Hernandez Date: Tue, 13 Mar 2018 19:01:49 +0000 (+0000) Subject: Merge "Fixed the SDK Junits and cleaned unused code" X-Git-Tag: v1.2.0~62 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=commitdiff_plain;h=1cb0fbfc4993c1f47f31b061d70b64f53247df95;hp=dbb838a594fde49ca337900e42a6e9b56bb2b60b Merge "Fixed the SDK Junits and cleaned unused code" --- diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java index 650713c1e..84cd72fe6 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java @@ -1176,7 +1176,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList PolicyLogger.audit("Transaction Ended Successfully"); im.endTransaction(); return; - } else if (apiflag != null && apiflag.equalsIgnoreCase("api")) { + } else if (apiflag != null && "api".equalsIgnoreCase(apiflag)) { // this request is from the Policy Creation API if(authorizeRequest(request)){ APIRequestHandler apiRequestHandler = new APIRequestHandler(); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java index 91530c7af..43eb4348e 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java @@ -256,15 +256,12 @@ public class ActionPolicy extends Policy { // Saving the json Configurations file if exists at server location for action policy. private void saveActionBody(String policyName, String actionBodyData) { - try { if(policyName.endsWith(".xml")){ policyName = policyName.replace(".xml", ""); } File file = new File(ACTION_HOME+ File.separator + policyName + ".json"); - FileWriter fw = new FileWriter(file.getAbsoluteFile()); - BufferedWriter bw = new BufferedWriter(fw); + try(BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()))) { bw.write(actionBodyData); - bw.close(); if (LOGGER.isInfoEnabled()) { LOGGER.info("Action Body is succesfully saved at " + file.getAbsolutePath()); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java index 4de65fd1e..2a13fb000 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java @@ -214,10 +214,8 @@ public class CreateBrmsParamPolicy extends Policy { comment = true; continue; } - if (line.contains("//")) { - if(!(line.contains("http://") || line.contains("https://"))){ + if (line.contains("//") && !(line.contains("http://") || line.contains("https://"))){ line = line.split("\\/\\/")[0]; - } } if (line.contains("/*")) { comment = true; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java index d95b36709..6e46ab1c0 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java @@ -98,32 +98,21 @@ public class FirewallConfigPolicy extends Policy { // Saving the Configurations file at server location for config policy. protected void saveConfigurations(String policyName, String jsonBody) { String configurationName = policyName; - FileWriter fw = null; - try{ - if(configurationName.endsWith(".xml")){ - configurationName = configurationName.replace(".xml", ""); - } - fw = new FileWriter(CONFIG_HOME + File.separator + configurationName + ".json"); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(jsonBody); - bw.close(); + if(configurationName.endsWith(".xml")){ + configurationName = configurationName.replace(".xml", ""); + } + String fileName = CONFIG_HOME + File.separator + configurationName + ".json"; + try(BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))){ + bw.write(jsonBody); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Configuration is succesfully saved"); } } catch (IOException e) { - LOGGER.error("Exception Occured"+e); - }finally{ - try{ - if(fw != null){ - fw.close(); - } - }catch(Exception e){ - LOGGER.error("Exception Occured"+e); - } + LOGGER.error("Save of configuration to file" +fileName+ "failed",e); } } - - //Utility to read json data from the existing file to a string + + //Utility to read json data from the existing file to a string static String readFile(String path, Charset encoding) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, encoding); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java index 7001aa9a8..3e24dc7c4 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java @@ -344,7 +344,7 @@ public class CreateFirewallController extends RestrictedBaseController { jpaTermList = (TermList) tmList.get(0); if (jpaTermList != null){ ruleSrcList= jpaTermList.getSrcIPList(); - if ((ruleSrcList!= null) && (!ruleSrcList.isEmpty()) && !ruleSrcList.equals("null")){ + if ((ruleSrcList!= null) && (!ruleSrcList.isEmpty()) && !"null".equals(ruleSrcList)){ displayString.append("Source IP List: " + jpaTermList.getSrcIPList()); displayString.append(" ; \t\n"); for(String srcList:ruleSrcList.split(",")){ diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java index 6f8eea8e7..5ff20b6fc 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java @@ -205,7 +205,7 @@ public class DecisionPolicyController extends RestrictedBaseController { ApplyType decisionApply = (ApplyType) condition.getExpression().getValue(); decisionApply = (ApplyType) decisionApply.getExpression().get(0).getValue(); ruleAlgoirthmTracker = new LinkedList<>(); - if(policyAdapter.getRuleProvider()!=null && ("GUARD_YAML".equals(policyAdapter.getRuleProvider())||(policyAdapter.getRuleProvider().equals("GUARD_BL_YAML")))){ + if(policyAdapter.getRuleProvider()!=null && ("GUARD_YAML".equals(policyAdapter.getRuleProvider())||("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())))){ YAMLParams yamlParams = new YAMLParams(); for(int i=0; i map = (Map)attributeList.get(i);