CHeckstyle and JUnit for base package in ONAP-REST
[policy/engine.git] / ONAP-PDP-REST / src / main / java / org / onap / policy / pdp / rest / XACMLPdpLoader.java
index 102d43f..52dcd96 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,8 +40,8 @@ import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
 import org.onap.policy.pdp.rest.notifications.NotificationController;
-import org.onap.policy.rest.XACMLRest;
-import org.onap.policy.rest.XACMLRestProperties;
+import org.onap.policy.rest.XacmlRest;
+import org.onap.policy.rest.XacmlRestProperties;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 
@@ -68,8 +68,8 @@ import com.google.common.base.Splitter;
 /**
  * Does the work for loading policy and PIP configurations sent from the PAP
  * servlet.
- * 
- * 
+ *
+ *
  *
  */
 public class XACMLPdpLoader {
@@ -167,7 +167,7 @@ public class XACMLPdpLoader {
                // Reset our official properties the PDP factory
                // uses to configure the PDP engine.
                //
-               XACMLRest.loadXacmlProperties(policyProperties, pipProperties);
+               XacmlRest.loadXacmlProperties(policyProperties, pipProperties);
                //
                // Dump ALL our properties that we are trying to load
                //
@@ -195,10 +195,11 @@ public class XACMLPdpLoader {
        }
 
        private static HashMap<String, PolicyDef> policyContainer = null;
-       
+
        public static synchronized void sendNotification(){
                Thread notify = new Thread(){
-                       public void run(){
+                       @Override
+            public void run(){
                                try{
                                        Thread.sleep(notifyDelay);
                                        NotificationController.sendNotification();
@@ -209,7 +210,7 @@ public class XACMLPdpLoader {
                };
                notify.start();
        }
-       
+
        public static synchronized void validatePolicies(Properties properties,
                        StdPDPStatus status) throws PAPException {
                Set<String> rootPolicies = XACMLProperties.getRootPolicyIDs(properties);
@@ -239,13 +240,13 @@ public class XACMLPdpLoader {
                policyContainer.clear();
        }
 
-       
+
        public static synchronized void loadPolicy(Properties properties,
                        StdPDPStatus status, String id, boolean isRoot) throws PAPException {
                PolicyDef policy = null;
                String location = null;
                URI locationURI = null;
-               boolean isFile = false;         
+               boolean isFile = false;
                boolean rougeFile = false;
                try {
                        location = properties.getProperty(id + ".file");
@@ -255,7 +256,7 @@ public class XACMLPdpLoader {
                                try (InputStream is = Files.newInputStream(Paths.get(location))) {
                                        policy = DOMPolicyDef.load(is);
                                } catch (Exception e){
-                                       // This Happens if a any issue with the error policyFile. Lets remove it. 
+                                       // This Happens if a any issue with the error policyFile. Lets remove it.
                                        try {
                                                LOGGER.error("Corrupted policy file, deleting: " + location + e);
                                                Files.delete(Paths.get(location));
@@ -296,8 +297,8 @@ public class XACMLPdpLoader {
                                                                papUrls.getNext();
                                                                break;
                                                        }
-                                                       urlConnection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID,
-                                                                                       XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID));
+                                                       urlConnection.setRequestProperty(XacmlRestProperties.PROP_PDP_HTTP_HEADER_ID,
+                                                                                       XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_ID));
                                                        urlConnection.setRequestProperty("Authorization", "Basic " + encoding);
                                                        //
                                                        // Now construct the output file name
@@ -343,7 +344,7 @@ public class XACMLPdpLoader {
                                                }
                                        }while(error && errorCount>2);
                                }
-                       } 
+                       }
                        if (policy != null) {
                                status.addLoadedPolicy(new StdPDPPolicy(id, isRoot,
                                                locationURI, properties));
@@ -373,7 +374,7 @@ public class XACMLPdpLoader {
                                try {
                                        LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Corrupted policy file, deleting: " + location);
                                        Files.delete(Paths.get(location));
-                                       
+
                                } catch (IOException e1) {
                                        LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e1);
                                }
@@ -424,10 +425,10 @@ public class XACMLPdpLoader {
         * the local directory; if so create a ".file" property for it. - if not,
         * get the "&lt;PolicyID&gt;.url" property and try to GET the policy from
         * that location (and set the ".file" property)
-        * 
+        *
         * If the ".file" property is created, then true is returned to tell the
         * caller that the props object changed.
-        * 
+        *
         * @param props
         * @return true/false if anything was changed in the props object
         * @throws PAPException
@@ -524,8 +525,8 @@ public class XACMLPdpLoader {
                                                                        // Open the connection
                                                                        //
                                                                        URLConnection urlConnection = url.openConnection();
-                                                                       urlConnection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID,
-                                                                                                       XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID));
+                                                                       urlConnection.setRequestProperty(XacmlRestProperties.PROP_PDP_HTTP_HEADER_ID,
+                                                                                                       XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_ID));
                                                                        urlConnection.setRequestProperty("Authorization", "Basic " + encoding);
                                                                        //
                                                                        // Copy it to disk
@@ -619,7 +620,7 @@ public class XACMLPdpLoader {
 
        public static synchronized Path getPDPConfig() throws PAPException {
                Path config = Paths.get(XACMLProperties
-                               .getProperty(XACMLRestProperties.PROP_PDP_CONFIG));
+                               .getProperty(XacmlRestProperties.PROP_PDP_CONFIG));
                if (Files.notExists(config)) {
                        LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + config.toAbsolutePath().toString() + " does NOT exist.");
                        //