Removing code smells
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / NodeConfigManager.java
index 90aaf0a..0283f5c 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import static java.lang.System.exit;
+
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
+import java.nio.file.Files;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.Timer;
 import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
@@ -134,13 +139,12 @@ public class NodeConfigManager implements DeliveryQueueHelper {
          */
         //Disable and enable protocols*/
         enabledprotocols = ((drNodeProperties.getProperty("NodeHttpsProtocols")).trim()).split("\\|");
-
         try {
             provhost = (new URL(provurl)).getHost();
         } catch (Exception e) {
             NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
             eelfLogger.error(EelfMsgs.MESSAGE_BAD_PROV_URL, e, provurl);
-            System.exit(1);
+            exit(1);
         }
         eelfLogger.debug("NODE0303 Provisioning server is " + provhost);
         eventlogurl = drNodeProperties.getProperty("LogUploadURL", "https://feeds-drtr.web.att.com/internal/logs");
@@ -151,9 +155,11 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         spooldir = drNodeProperties.getProperty("SpoolDir", "spool");
         File fdir = new File(spooldir + "/f");
         fdir.mkdirs();
-        for (File junk : fdir.listFiles()) {
-            if (junk.isFile()) {
-                junk.delete();
+        for (File junk : Objects.requireNonNull(fdir.listFiles())) {
+            try {
+                Files.deleteIfExists(junk.toPath());
+            } catch (IOException e) {
+                eelfLogger.error("NODE0313 Failed to clear junk files from " + fdir.getPath(), e);
             }
         }
         logdir = drNodeProperties.getProperty("LogDir", "logs");
@@ -181,7 +187,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
             NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
             eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_FETCH_ERROR, ksfile);
             eelfLogger.error("NODE0309 Unable to fetch canonical name from keystore file " + ksfile);
-            System.exit(1);
+            exit(1);
         }
         eelfLogger.debug("NODE0304 My certificate says my name is " + myname);
         pid = new PublishId(myname);
@@ -496,13 +502,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (purl + "/" + fileid);
     }
 
-    /**
-     * Is a destination redirected.
-     */
-    public boolean isDestRedirected(DestInfo destinfo) {
-        return (followredirects && rdmgr.isRedirected(destinfo.getSubId()));
-    }
-
     /**
      * Set up redirection on receipt of a 3XX from a target URL.
      */
@@ -520,23 +519,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (false);
     }
 
-    /**
-     * Set up redirection on receipt of a 3XX from a target URL.
-     */
-    public boolean handleRedirectionSubLevel(DeliveryTask task, DestInfo destinfo, String redirto, String fileid) {
-        fileid = "/" + fileid;
-        String subid = destinfo.getSubId();
-        String purl = destinfo.getURL();
-        if (task.getFollowRedirects() && subid != null && redirto.endsWith(fileid)) {
-            redirto = redirto.substring(0, redirto.length() - fileid.length());
-            if (!redirto.equals(purl)) {
-                rdmgr.redirect(subid, purl, redirto);
-                return true;
-            }
-        }
-        return false;
-    }
-
     /**
      * Handle unreachable target URL.
      */
@@ -606,16 +588,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (config.getTargets(feedid));
     }
 
-    /**
-     * Get the creation date for a feed.
-     *
-     * @param feedid The feed ID
-     * @return the timestamp of creation date of feed id passed
-     */
-    public String getCreatedDate(String feedid) {
-        return (config.getCreatedDate(feedid));
-    }
-
     /**
      * Get the spool directory for temporary files.
      */
@@ -811,30 +783,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return enabledprotocols;
     }
 
-    public void setEnabledprotocols(String[] enabledprotocols) {
-        this.enabledprotocols = enabledprotocols.clone();
-    }
-
     public String getAafType() {
         return aafType;
     }
 
-    public void setAafType(String aafType) {
-        this.aafType = aafType;
-    }
-
-    public void setAafInstance(String aafInstance) {
-        this.aafInstance = aafInstance;
-    }
-
     public String getAafAction() {
         return aafAction;
     }
 
-    public void setAafAction(String aafAction) {
-        this.aafAction = aafAction;
-    }
-
     /*
      * Get aafURL from SWM variable
      * */
@@ -842,18 +798,10 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return aafURL;
     }
 
-    public void setAafURL(String aafURL) {
-        this.aafURL = aafURL;
-    }
-
     public boolean getCadiEnabled() {
         return cadiEnabled;
     }
 
-    public void setCadiEnabled(boolean cadiEnabled) {
-        this.cadiEnabled = cadiEnabled;
-    }
-
     /**
      * Builds the permissions string to be verified.
      *