Fix all bugs reported by Sonar in policy/engine
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / CreateClosedLoopPerformanceMetrics.java
index ada7044..456924a 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.rest.adapter.PolicyRestAdapter;
 
+import com.att.research.xacml.api.pap.PAPException;
 import com.att.research.xacml.std.IdentifierImpl;
 
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
@@ -66,23 +67,15 @@ public class CreateClosedLoopPerformanceMetrics extends Policy {
        }
 
        //save configuration of the policy based on the policyname
-       private void saveConfigurations(String policyName, String jsonBody) {
-               try {
-                       String body = null;
-                       try {
-                               body = jsonBody;
-                       } catch (Exception e) {
-                               LOGGER.error("Exception Occured"+e);
-                       }
-                       if(policyName.endsWith(".xml")){
-                               policyName       = policyName.substring(0, policyName.lastIndexOf(".xml"));     
-                       }
-                       PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + "."+ policyName +".json");
-                       out.println(body);
-                       policyAdapter.setJsonBody(body);
-                       policyAdapter.setConfigBodyData(body);
-                       out.close();
-
+       private void saveConfigurations(String policyName, final String jsonBody) {
+           
+               if(policyName.endsWith(".xml")){
+                   policyName   = policyName.substring(0, policyName.lastIndexOf(".xml"));
+               }
+               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + "."+ policyName +".json")){
+                       out.println(jsonBody);
+                       policyAdapter.setJsonBody(jsonBody);
+                       policyAdapter.setConfigBodyData(jsonBody);
                } catch (Exception e) {
                        LOGGER.error("Exception Occured"+e);
                }
@@ -99,7 +92,7 @@ public class CreateClosedLoopPerformanceMetrics extends Policy {
        }
        
        @Override
-       public Map<String, String> savePolicies() throws Exception {
+       public Map<String, String> savePolicies() throws PAPException {
 
                Map<String, String> successMap = new HashMap<>();
                if(isPolicyExists()){
@@ -124,7 +117,7 @@ public class CreateClosedLoopPerformanceMetrics extends Policy {
        //This is the method for preparing the policy for saving.  We have broken it out
        //separately because the fully configured policy is used for multiple things
        @Override
-       public boolean prepareToSave() throws Exception{
+       public boolean prepareToSave() throws PAPException{
 
                if(isPreparedToSave()){
                        //we have already done this