Code Smells in emsdriver conf 09/37709/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Thu, 22 Mar 2018 08:46:25 +0000 (14:16 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Thu, 22 Mar 2018 08:46:25 +0000 (14:16 +0530)
configmgr/ConfigurationManager.java
file name:ConfigurationImp.java

Change-Id: I03caeff75fb1d32086034545c20213f479772e0f
Issue-ID: VFC-837
Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImp.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java

index 7917d67..952ac5f 100644 (file)
@@ -109,7 +109,7 @@ public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
         String basePath = simpleServerFactory.getApplicationContextPath();
         String rootPath = simpleServerFactory.getJerseyRootPath().get();
         rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
-        basePath = basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
+        basePath ="/".equals(basePath) ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
         config.setBasePath(basePath);
         config.setScan(true);
     }
@@ -125,14 +125,14 @@ public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
         } catch (UnknownHostException e) {
             log.error("Unable to get host ip: ", e);
         }
-        if (ip.equals("")) {
+        if ("".equals(ip)) {
             ip = connector.getBindHost();
         }
         serviceNode.setIp(ip);
         serviceNode.setPort(String.valueOf(connector.getPort()));
         serviceNode.setTtl(0);
 
-        List<ServiceNodeVo> nodeList = new ArrayList<ServiceNodeVo>();
+        List<ServiceNodeVo> nodeList = new ArrayList<>();
         nodeList.add(serviceNode);
         registerVo.setServiceName("emsdriver");
         registerVo.setUrl("/api/emsdriver/v1");
index 94d9c56..bb97b32 100644 (file)
@@ -667,7 +667,7 @@ public class TaskThread implements Runnable {
        }
 
        public List<File> decompressed(String fileName) {
-               List<File> filelist = new ArrayList<File>();
+               List<File> filelist = new ArrayList<>();
 
                if (fileName.indexOf(".gz") > 1) {
                        try {
@@ -712,15 +712,13 @@ public class TaskThread implements Runnable {
                        unzip.deCompress();
                        file = new File(orgFile);
                }
-               File[] files = file.listFiles();
-
-               return files;
+               return file.listFiles();
 
        }
 
        private List<String> ftpDownload(CollectVo collectVo) {
 
-               List<String> fileList = new ArrayList<String>();
+               List<String> fileList = new ArrayList<>();
                // IP
                String ip = collectVo.getIP();
                // port
@@ -747,11 +745,11 @@ public class TaskThread implements Runnable {
 
                // download
                String dir = collectVo.getRemotepath();
-               List<String> searchExprList = new ArrayList<String>();
-               String[] FPath = dir.split(";");
-               for (int i = 0; i < FPath.length; i++) {
+               List<String> searchExprList = new ArrayList<>();
+               String[] fPath = dir.split(";");
+               for (int i = 0; i < fPath.length; i++) {
                        int oldSize = searchExprList.size();
-                       String conpath = FPath[i] + collectVo.getMatch();
+                       String conpath = fPath[i] + collectVo.getMatch();
                        HashMap<String, String> varMap = new HashMap<>();
                        long collectPeriod = 900;
                        try {
@@ -774,10 +772,10 @@ public class TaskThread implements Runnable {
                        log.error(" collect fail ", e1);
                        return fileList;
                }
-               List<AFtpRemoteFile> remoteFiles = new ArrayList<AFtpRemoteFile>();
+               List<AFtpRemoteFile> remoteFiles = new ArrayList<>();
                for (String expr : searchExprList) {
                        ftpClient.chdir(nowdir);
-                       String keys[] = parseExprKeys(expr);
+                       String[] keys = parseExprKeys(expr);
                        String ftpRegular = keys[1];
                        String ftpDir = keys[0];
 
@@ -879,7 +877,7 @@ public class TaskThread implements Runnable {
 
        public List<String> getPathNoRegular(List<String> searchExprList, FTPInterface ftpCache) throws IOException {
                boolean isregular = false;
-               List<String> regularList = new ArrayList<String>();
+               List<String> regularList = new ArrayList<>();
                for (String regular : searchExprList) {
                        Pattern lpattern = null;
                        try {
@@ -919,7 +917,7 @@ public class TaskThread implements Runnable {
                                regularList.add(regular);
                        }
                }
-               if (isregular == true) {
+               if (isregular) {
                        getPathNoRegular(regularList, ftpCache);
                }
                return regularList;
index b6ca83f..22224e7 100644 (file)
@@ -45,13 +45,13 @@ public class AlarmManager extends DriverThread {
                 }
             }
         }
-        List<CollectVo> collectVos = new ArrayList<CollectVo>();
+        List<CollectVo> collectVos = new ArrayList<>();
         for (EMSInfo emsInfo : emsInfos) {
             //alarm
-            CollectVo CollectVo = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_ALARM);
-            if (CollectVo != null) {
-                CollectVo.setEmsName(emsInfo.getName());
-                collectVos.add(CollectVo);
+            CollectVo collectVo = emsInfo.getCollectVoByType(Constant.COLLECT_TYPE_ALARM);
+            if (collectVo != null) {
+                collectVo.setEmsName(emsInfo.getName());
+                collectVos.add(collectVo);
             } else {
                 log.error("emsInfo.getCollectVoByType(EMS_RESOUCE) result CollectVo = null emsInfo =" + emsInfo);
             }
index 5ea9a90..4a18e85 100644 (file)
@@ -46,7 +46,9 @@ import java.util.regex.Pattern;
         str = str.replace("${e_hour}", "${SCAN_STOP_TIME,HH}");
         str = str.replace("${e_min}", "${SCAN_STOP_TIME,mm}");
 
-        String expr, varName, value ;
+        String expr;
+       String varName;
+       String value ;
         Matcher matcher = varPattern.matcher(str);
         while (matcher.find()) {
             value = null;
index c08d8b0..4e55126 100644 (file)
@@ -19,7 +19,6 @@ import org.jdom.Document;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 
-import javax.xml.stream.XMLStreamException;
 import java.io.IOException;
 import java.io.InputStream;
 
index b48287d..cb6d57b 100644 (file)
@@ -39,14 +39,7 @@ public class Zip {
         this.zipFilePath = zipFilePath;
         this.compressPath = compressFile.getAbsolutePath();
 
-        /*if (this.zipFilePath == null) {
-            StringBuffer zipFilePathBuf = new StringBuffer(this.compressPath);
-            int bufLen = zipFilePathBuf.length();
-            if (zipFilePathBuf.charAt(bufLen - 1) == '/')
-                zipFilePathBuf.deleteCharAt(bufLen - 1);
-            this.zipFilePath = zipFilePathBuf.append(".zip").toString();
-        }*/
-        relativeAddrIdx = this.compressPath.lastIndexOf(File.separator) + 1;
+       relativeAddrIdx = this.compressPath.lastIndexOf(File.separator) + 1;
     }
 
     public void compress() throws IOException {
index 62cc732..aaded64 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/**
  * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,8 +30,7 @@ public class ConfigurationImp implements ConfigurationInterface {
 
     @Override
     public List<EMSInfo> getAllEMSInfo() {
-        List<EMSInfo> emsInfos = ConfigurationManager.getAllEMSInfos();
-        return emsInfos;
+        return ConfigurationManager.getAllEMSInfos();
     }
 
     @Override
@@ -49,8 +48,7 @@ public class ConfigurationImp implements ConfigurationInterface {
 
     @Override
     public Properties getProperties() {
-        Properties p = ConfigurationManager.getProperties();
-        return p;
+        return ConfigurationManager.getProperties();
     }
 
 
index 5b7a2c1..320d33c 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
+/**
+ * Copyright 2017 BOCO Corporation 
+ * Copyright 2018 CMCC Technologies Co. Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,20 +40,20 @@ import java.util.concurrent.ConcurrentHashMap;
 
 
 public class ConfigurationManager extends DriverThread {
-    public final static String CONFIG_PROPERTIES_LOCATION = Constant.SYS_CFG + "config.properties";
-    protected static Log log = LogFactory.getLog(ConfigurationManager.class);
+    public static final String CONFIG_PROPERTIES_LOCATION = Constant.SYS_CFG + "config.properties";
+    protected static final Log log = LogFactory.getLog(ConfigurationManager.class);
     /**
      * ESM Cache
      */
     @VisibleForTesting
-    static Map<String, EMSInfo> emsInfoCache = new ConcurrentHashMap<String, EMSInfo>();
+    static Map<String, EMSInfo> emsInfoCache = new ConcurrentHashMap<>();
     @VisibleForTesting
     static Properties properties = null;
-    private static Map<String, CrontabVo> emsCrontab = new ConcurrentHashMap<String, CrontabVo>();
-    private static List<String> emsIdList = new ArrayList<String>();
+    private static Map<String, CrontabVo> emsCrontab = new ConcurrentHashMap<>();
+    private static List<String> emsIdList = new ArrayList<>();
 
     public static synchronized List<EMSInfo> getAllEMSInfos() {
-        List<EMSInfo> list = new ArrayList<EMSInfo>();
+        List<EMSInfo> list = new ArrayList<>();
         for (EMSInfo emsinfo : emsInfoCache.values()) {
             list.add(emsinfo);
         }
@@ -60,8 +61,7 @@ public class ConfigurationManager extends DriverThread {
     }
 
     public static synchronized EMSInfo getEMSInfoByName(String emsName) {
-        EMSInfo emsInfo = emsInfoCache.get(emsName);
-        return emsInfo;
+        return emsInfoCache.get(emsName);
     }
 
     public static synchronized Properties getProperties() {
@@ -97,7 +97,7 @@ public class ConfigurationManager extends DriverThread {
             log.debug("not exists " + path);
             return null;
         }
-        Map<String, CrontabVo> tmpcache = new HashMap<String, CrontabVo>();
+        Map<String, CrontabVo> tmpcache = new HashMap<>();
 
         try (
             InputStream is = new FileInputStream(cfg)){
@@ -146,7 +146,8 @@ public class ConfigurationManager extends DriverThread {
 
     class ReceiveSource extends Thread {
         long timeStamp = System.currentTimeMillis();
-
+       
+       @Override
         public void run() {
             while (true) {
 
@@ -185,7 +186,7 @@ public class ConfigurationManager extends DriverThread {
         }
 
         private Map<String, EMSInfo> getEmsInfo(String emsId) {
-            Map<String, EMSInfo> tmpcache = new ConcurrentHashMap<String, EMSInfo>();
+            Map<String, EMSInfo> tmpcache = new ConcurrentHashMap<>();
             String msbAddress = properties.getProperty("msbAddress");
             String emstUrl = properties.getProperty("esr_emsUrl");
             //set emsId to url
@@ -195,21 +196,21 @@ public class ConfigurationManager extends DriverThread {
             log.debug(getemstUrl + " result=" + emsResult);
             JSONObject reagobj = JSONObject.parseObject(emsResult);
 
-            JSONObject esr_system_info_list = reagobj.getJSONObject("esr-system-info-list");
-            JSONArray esr_system_info = esr_system_info_list.getJSONArray("esr-system-info");
-            Iterator<Object> it = esr_system_info.iterator();
+            JSONObject esrSystemInfoList = reagobj.getJSONObject("esr-system-info-list");
+            JSONArray esrSystemInfo = esrSystemInfoList.getJSONArray("esr-system-info");
+            Iterator<Object> it = esrSystemInfo.iterator();
             EMSInfo emsInfo = new EMSInfo();
             emsInfo.setName(emsId);
             tmpcache.put(emsId, emsInfo);
             while (it.hasNext()) {
                 Object obj = it.next();
                 JSONObject collect = (JSONObject) obj;
-                String system_type = (String) collect.get("system-type");
+                String systemType = (String) collect.get("system-type");
                 CollectVo collectVo = new CollectVo();
-                if (Constant.COLLECT_TYPE_CM.equalsIgnoreCase(system_type)) {
-                    CrontabVo crontabVo = emsCrontab.get(system_type);
+                if (Constant.COLLECT_TYPE_CM.equalsIgnoreCase(systemType)) {
+                    CrontabVo crontabVo = emsCrontab.get(systemType);
                     if (crontabVo != null) {
-                        collectVo.setType(system_type);
+                        collectVo.setType(systemType);
                         collectVo.setCrontab(crontabVo.getCrontab());
                         collectVo.setIP(collect.getString("ip-address"));
                         collectVo.setPort(collect.getString("port"));
@@ -221,14 +222,14 @@ public class ConfigurationManager extends DriverThread {
                         collectVo.setPassive(collect.getString("passive"));
                         collectVo.setGranularity(crontabVo.getGranularity());
                     } else {
-                        log.error("emsCrontab.get(system_type) result crontabVo is null system_type=[" + system_type + "] emsCrontabMap=" + emsCrontab);
+                        log.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "] emsCrontabMap=" + emsCrontab);
                     }
 
 
-                } else if (Constant.COLLECT_TYPE_PM.equalsIgnoreCase(system_type)) {
-                    CrontabVo crontabVo = emsCrontab.get(system_type);
+                } else if (Constant.COLLECT_TYPE_PM.equalsIgnoreCase(systemType)) {
+                    CrontabVo crontabVo = emsCrontab.get(systemType);
                     if (crontabVo != null) {
-                        collectVo.setType(system_type);
+                        collectVo.setType(systemType);
                         collectVo.setCrontab(crontabVo.getCrontab());
                         collectVo.setIP(collect.getString("ip-address"));
                         collectVo.setPort(collect.getString("port"));
@@ -240,34 +241,34 @@ public class ConfigurationManager extends DriverThread {
                         collectVo.setPassive(collect.getString("passive"));
                         collectVo.setGranularity(crontabVo.getGranularity());
                     } else {
-                        log.error("emsCrontab.get(system_type) result crontabVo is null system_type=[" + system_type + "]");
+                        log.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "]");
                     }
-                } else if (Constant.COLLECT_TYPE_ALARM.equalsIgnoreCase(system_type)) {
-                    CrontabVo crontabVo = emsCrontab.get(system_type);
+                } else if (Constant.COLLECT_TYPE_ALARM.equalsIgnoreCase(systemType)) {
+                    CrontabVo crontabVo = emsCrontab.get(systemType);
                     if (crontabVo != null) {
                         collectVo.setIscollect(crontabVo.isIscollect());
-                        collectVo.setType(system_type);
+                        collectVo.setType(systemType);
                         collectVo.setIP(collect.getString("ip-address"));
                         collectVo.setPort(collect.getString("port"));
                         collectVo.setUser(collect.getString("user-name"));
                         collectVo.setPassword(collect.getString("password"));
                         collectVo.setReadTimeout(crontabVo.getReadTimeout());
                     } else {
-                        log.error("emsCrontab.get(system_type) result crontabVo is null system_type=[" + system_type + "]");
+                        log.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "]");
                     }
 
 
                 } else {
-                    log.error("ems system-type =" + system_type + " ");
+                    log.error("ems system-type =" + systemType + " ");
                 }
 
-                emsInfo.putCollectMap(system_type, collectVo);
+                emsInfo.putCollectMap(systemType, collectVo);
             }
             return tmpcache;
         }
 
         private List<String> getEmsIdList() {
-            List<String> emsIds = new ArrayList<String>();
+            List<String> emsIds = new ArrayList<>();
             //http
             String msbAddress = properties.getProperty("msbAddress");
             String url = properties.getProperty("esr_ems_listUrl");
@@ -276,8 +277,8 @@ public class ConfigurationManager extends DriverThread {
             String result = HttpClientUtil.doGet(getemsListUrl, Constant.ENCODING_UTF8);
             log.debug(getemsListUrl + " result=" + result);
             JSONObject reagobj = JSONObject.parseObject(result);
-            JSONArray esr_emsIds = reagobj.getJSONArray("esr-ems");
-            Iterator<Object> it = esr_emsIds.iterator();
+            JSONArray esrEmsIds = reagobj.getJSONArray("esr-ems");
+            Iterator<Object> it = esrEmsIds.iterator();
             while (it.hasNext()) {
                 Object obj = it.next();
                 JSONObject emsId = (JSONObject) obj;