From a42ee1fd4ff659284057a832aecbf5bc10f44dbe Mon Sep 17 00:00:00 2001 From: ajay priyadarshi Date: Thu, 22 Mar 2018 14:16:25 +0530 Subject: [PATCH] Code Smells in emsdriver conf configmgr/ConfigurationManager.java file name:ConfigurationImp.java Change-Id: I03caeff75fb1d32086034545c20213f479772e0f Issue-ID: VFC-837 Signed-off-by: ajay priyadarshi --- .../vfc/nfvo/emsdriver/EmsDriverApplication.java | 6 +- .../vfc/nfvo/emsdriver/collector/TaskThread.java | 24 ++++---- .../emsdriver/collector/alarm/AlarmManager.java | 10 ++-- .../emsdriver/commons/utils/VarExprParser.java | 4 +- .../vfc/nfvo/emsdriver/commons/utils/XmlUtil.java | 1 - .../onap/vfc/nfvo/emsdriver/commons/utils/Zip.java | 9 +-- .../nfvo/emsdriver/configmgr/ConfigurationImp.java | 8 +-- .../emsdriver/configmgr/ConfigurationManager.java | 69 +++++++++++----------- 8 files changed, 61 insertions(+), 70 deletions(-) diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java index 7917d67..952ac5f 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java @@ -109,7 +109,7 @@ public class EmsDriverApplication extends Application { 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 { } 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 nodeList = new ArrayList(); + List nodeList = new ArrayList<>(); nodeList.add(serviceNode); registerVo.setServiceName("emsdriver"); registerVo.setUrl("/api/emsdriver/v1"); diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java index 94d9c56..bb97b32 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java @@ -667,7 +667,7 @@ public class TaskThread implements Runnable { } public List decompressed(String fileName) { - List filelist = new ArrayList(); + List 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 ftpDownload(CollectVo collectVo) { - List fileList = new ArrayList(); + List fileList = new ArrayList<>(); // IP String ip = collectVo.getIP(); // port @@ -747,11 +745,11 @@ public class TaskThread implements Runnable { // download String dir = collectVo.getRemotepath(); - List searchExprList = new ArrayList(); - String[] FPath = dir.split(";"); - for (int i = 0; i < FPath.length; i++) { + List 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 varMap = new HashMap<>(); long collectPeriod = 900; try { @@ -774,10 +772,10 @@ public class TaskThread implements Runnable { log.error(" collect fail ", e1); return fileList; } - List remoteFiles = new ArrayList(); + List 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 getPathNoRegular(List searchExprList, FTPInterface ftpCache) throws IOException { boolean isregular = false; - List regularList = new ArrayList(); + List 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; diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java index b6ca83f..22224e7 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java @@ -45,13 +45,13 @@ public class AlarmManager extends DriverThread { } } } - List collectVos = new ArrayList(); + List 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); } diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java index 5ea9a90..4a18e85 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java @@ -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; diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java index c08d8b0..4e55126 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java @@ -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; diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java index b48287d..cb6d57b 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java @@ -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 { diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImp.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImp.java index 62cc732..aaded64 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImp.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImp.java @@ -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 getAllEMSInfo() { - List 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(); } diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java index 5b7a2c1..320d33c 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java @@ -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 emsInfoCache = new ConcurrentHashMap(); + static Map emsInfoCache = new ConcurrentHashMap<>(); @VisibleForTesting static Properties properties = null; - private static Map emsCrontab = new ConcurrentHashMap(); - private static List emsIdList = new ArrayList(); + private static Map emsCrontab = new ConcurrentHashMap<>(); + private static List emsIdList = new ArrayList<>(); public static synchronized List getAllEMSInfos() { - List list = new ArrayList(); + List 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 tmpcache = new HashMap(); + Map 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 getEmsInfo(String emsId) { - Map tmpcache = new ConcurrentHashMap(); + Map 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 it = esr_system_info.iterator(); + JSONObject esrSystemInfoList = reagobj.getJSONObject("esr-system-info-list"); + JSONArray esrSystemInfo = esrSystemInfoList.getJSONArray("esr-system-info"); + Iterator 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 getEmsIdList() { - List emsIds = new ArrayList(); + List 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 it = esr_emsIds.iterator(); + JSONArray esrEmsIds = reagobj.getJSONArray("esr-ems"); + Iterator it = esrEmsIds.iterator(); while (it.hasNext()) { Object obj = it.next(); JSONObject emsId = (JSONObject) obj; -- 2.16.6