Merge "Fixed the SDK Junits and cleaned unused code"
authorJorge Hernandez <jh1730@att.com>
Tue, 13 Mar 2018 19:01:49 +0000 (19:01 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 13 Mar 2018 19:01:49 +0000 (19:01 +0000)
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java
POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java

index 650713c..84cd72f 100644 (file)
@@ -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();
index 91530c7..43eb434 100644 (file)
@@ -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());
             }
index 4de65fd..2a13fb0 100644 (file)
@@ -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;
index d95b367..6e46ab1 100644 (file)
@@ -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);
index 7001aa9..3e24dc7 100644 (file)
@@ -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(",")){     
index 6f8eea8..5ff20b6 100644 (file)
@@ -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<attributeList.size() ; i++){
                                                                                Map<String, String> map = (Map<String,String>)attributeList.get(i);