diff options
author | zhangab <zhanganbing@chinamobile.com> | 2018-04-27 20:25:50 +0800 |
---|---|---|
committer | zhangab <zhanganbing@chinamobile.com> | 2018-04-27 20:25:54 +0800 |
commit | 8af200280c3f66d8b9e0688629247e95c0142dec (patch) | |
tree | 09922eaee530d78aa29ecd2fabbe57a033d40bc0 | |
parent | c804509ad509dead6eab1813d7d6ad0274706c3b (diff) |
fix sonar-run bugs
Change-Id: Ifd0224aedc695971aefc6af47bc6c19e38a2ac26
Issue-ID: USECASEUI-110
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
7 files changed, 16 insertions, 200 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java index e41ec80d..f89585bf 100755 --- a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java @@ -26,7 +26,6 @@ import org.onap.usecaseui.server.bo.AlarmBo; import org.onap.usecaseui.server.constant.Constant;
import org.onap.usecaseui.server.service.AlarmsHeaderService;
import org.onap.usecaseui.server.service.AlarmsInformationService;
-import org.onap.usecaseui.server.util.CSVUtils;
import org.onap.usecaseui.server.util.DateUtils;
import org.onap.usecaseui.server.util.Page;
import org.onap.usecaseui.server.util.ResponseUtil;
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java index 2f0b9722..ec97252a 100755 --- a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java @@ -24,7 +24,6 @@ import org.onap.usecaseui.server.bo.PerformanceBo; import org.onap.usecaseui.server.constant.Constant; import org.onap.usecaseui.server.service.PerformanceHeaderService; import org.onap.usecaseui.server.service.PerformanceInformationService; -import org.onap.usecaseui.server.util.CSVUtils; import org.onap.usecaseui.server.util.DateUtils; import org.onap.usecaseui.server.util.Page; import org.onap.usecaseui.server.util.ResponseUtil; @@ -69,12 +68,9 @@ public class PerformanceController { @PathVariable int pageSize,@PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName,@PathVariable(required = false) String priority, @PathVariable(required = false) String startTime,@PathVariable(required = false) String endTime) throws JsonProcessingException { - logger.info("transfer getAlarmData Apis, " + - "Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " + - "sourceName : {} , priority : {} , startTime :{} , endTime : {} ]" - ,currentPage,pageSize,sourceId,sourceName,priority,startTime,endTime); + logger.info("API Parameter: [currentPage:{}, pageSize:{}, sourceId:{}, sourceName:{}, priority:{}, startTime:{}, endTime:{}]" ,currentPage, pageSize, sourceId, sourceName, priority, startTime, endTime); List<Object> list = new ArrayList<>(); - Page pa = null; + Page<PerformanceHeader> pa = new Page<PerformanceHeader>(); if (null != sourceId || null != sourceName || null != priority || null != startTime || null != endTime){ PerformanceHeader performanceHeader = new PerformanceHeader(); performanceHeader.setSourceId(!"null".equals(sourceId)?sourceId:null); @@ -130,69 +126,6 @@ public class PerformanceController { } } - @RequestMapping(value = {"/performance/genCsv/{eventId}"}, method = RequestMethod.GET, produces = "application/json") - public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId) throws JsonProcessingException { - String csvFile = "csvFiles/vnf_performance_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv"; - List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryId(eventId); - if (null == performanceHeaders || performanceHeaders.size() <= 0) - return new ObjectMapper().writeValueAsString("selected eventId don't exist"); - List<String[]> csvData = new ArrayList<>(); - performanceHeaders.forEach(s ->{ - List<PerformanceInformation> information = performanceInformationService.queryPerformanceInformation(new PerformanceInformation(s.getEventId()),1,100).getList(); - String names = ""; - String values = ""; - if (0 < information.size() && null != information){ - for (PerformanceInformation a : information){ - names += a.getName()+","; - values += a.getValue()+","; - } - names = names.substring(0,names.lastIndexOf(',')); - values = values.substring(0,values.lastIndexOf(',')); - } - csvData.add(new String[]{ - s.getVersion(),s.getEventName(),s.getDomain(),s.getEventId(),s.getEventType(),s.getNfcNamingCode(),s.getNfNamingCode(), - s.getSourceId(),s.getSourceName(),s.getReportingEntityId(),s.getReportingEntityName(),s.getPriority(), - s.getStartEpochMicrosec(),s.getLastEpochMicroSec(),s.getSequence(),s.getMeasurementsForVfScalingVersion(), - s.getMeasurementInterval(),DateUtils.dateToString(s.getCreateTime()),DateUtils.dateToString(s.getUpdateTime()), - names,values - }); - }); - CSVUtils.writeCsv(PerformanceCSVHeaders,csvData,csvFile); - if (ResponseUtil.responseDownload(csvFile,response)){ - return omPerformance.writeValueAsString("success"); - }else{ - return omPerformance.writeValueAsString("failed"); - } - } - - @RequestMapping(value = {"/performance/genDiaCsv/{dataJson}"}, method = RequestMethod.GET, produces = "application/json") - public String generateDiaCsvFile(HttpServletResponse response,@PathVariable String dataJson) throws IOException { - List<Map<String,Object>> dataList = omPerformance.readValue(dataJson,List.class); - String csvFileName = "csvFiles/"+dataList.get(0).get("name")+"_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv"; - try{ - String[] headers = new String[]{"eventId","name","dateUnit","value"}; - List<String[]> csvDatas = new ArrayList<>(); - if (null != dataList){ - dataList.forEach((l)->{ - StringBuffer fileData = new StringBuffer(); - l.forEach((k,v)->{ - logger.info(v.toString()); - fileData.append(v.toString()+","); - }); - csvDatas.add(fileData.toString().split(",")); - }); - } - CSVUtils.writeCsv(headers,csvDatas,csvFileName); - }catch (Exception pe){ - logger.error(pe.getMessage()); - } - if (ResponseUtil.responseDownload(csvFileName,response)){ - return omPerformance.writeValueAsString("success"); - }else{ - return omPerformance.writeValueAsString("failed"); - } - } - @ResponseBody @RequestMapping(value = {"/performance/diagram/{unit}/{eventId}"}, method = RequestMethod.GET, produces = "application/json") public String generateDiagram(@PathVariable String unit,@PathVariable String eventId) throws ParseException, JsonProcessingException { diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java index b85ff546..7d6b0afc 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java @@ -57,6 +57,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { try(Session session = getSession()){
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");
+ return "0";
}
logger.info("AlarmsHeaderServiceImpl saveAlarmsHeader: alarmsHeader={}", alarmsHeader);
Transaction tx = session.beginTransaction();
@@ -75,6 +76,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { try(Session session = getSession()){
if (null == alarmsHeader){
logger.error("AlarmsHeaderServiceImpl updateAlarmsHeader alarmsHeader is null!");
+ return "0";
}
logger.info("AlarmsHeaderServiceImpl updateAlarmsHeader: alarmsHeader={}", alarmsHeader);
Transaction tx = session.beginTransaction();
@@ -93,6 +95,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
+ return -1;
}else {
if(null!=alarmsHeader.getVersion()) {
String ver=alarmsHeader.getVersion();
@@ -218,7 +221,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { try(Session session = getSession()){
StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
- //logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
+ logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
+ return null;
}else {
if(null!=alarmsHeader.getVersion()) {
String ver=alarmsHeader.getVersion();
@@ -345,10 +349,11 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { @Override
public List<AlarmsHeader> queryId(String[] id) {
try(Session session = getSession()){
+ List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();
if(id.length==0) {
logger.error("AlarmsHeaderServiceImpl queryId is null!");
+ return list;
}
- List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();
Query query = session.createQuery("from AlarmsHeader a where a.eventName IN (:alist)");
list = query.setParameterList("alist", id).list();
return list;
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java index 6abc2012..fccee3d7 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java @@ -56,6 +56,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { try(Session session = getSession()){
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");
+ return "0";
}
logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder);
Transaction tx = session.beginTransaction();
@@ -74,6 +75,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { try(Session session = getSession()){
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");
+ return "0";
}
logger.info("PerformanceHeaderServiceImpl updatePerformanceHeader: performanceHeder={}", performanceHeder);
Transaction tx = session.beginTransaction();
@@ -92,6 +94,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!");
+ return 0;
}else {
if(null!=performanceHeder.getVersion()) {
String ver=performanceHeder.getVersion();
@@ -188,7 +191,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { try(Session session = getSession()){
StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
- //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");
+ logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");
+ return page;
}else {
if(null!=performanceHeder.getVersion()) {
String ver=performanceHeder.getVersion();
@@ -286,10 +290,11 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { @Override
public List<PerformanceHeader> queryId(String[] id) {
try(Session session = getSession()) {
+ List<PerformanceHeader> list = new ArrayList<PerformanceHeader>();
if(id.length==0) {
logger.error("PerformanceHeaderServiceImpl queryId is null!");
+ return list;
}
- List<PerformanceHeader> list = new ArrayList<PerformanceHeader>();
Query query = session.createQuery("from PerformanceHeader a where a.eventName IN (:alist)");
list = query.setParameterList("alist", id).list();
return list;
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/CSVUtils.java b/server/src/main/java/org/onap/usecaseui/server/util/CSVUtils.java deleted file mode 100644 index 8c850795..00000000 --- a/server/src/main/java/org/onap/usecaseui/server/util/CSVUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved. - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.usecaseui.server.util; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVPrinter; -import org.apache.commons.csv.CSVRecord; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.util.List; - - -public class CSVUtils { - - private static Logger logger = LoggerFactory.getLogger(CSVUtils.class); - - public static void writeCsv(String[] headers,List<String[]> data,String filePath) { - try{ - CSVFormat formator = CSVFormat.DEFAULT.withHeader(headers); - String dir = filePath.substring(0,filePath.lastIndexOf('/')); - File file = new File(dir); - if (!file.exists()) - file.mkdirs(); - try(Writer writer = new FileWriter(filePath); - CSVPrinter printer = new CSVPrinter(writer,formator)){ - for(String[] str : data){ - printer.printRecord(str); - } - } - - logger.info("CSV File Generate Success,FilePath:"+filePath); - }catch (IOException e){ - logger.error("CSV File Generate Failure:"+e.getMessage()); - } - } - - - public static boolean wCsv(){ - - return false; - } - - public static List<CSVRecord> readCSV(String filePath, String[] headers) throws IOException{ - //创建CSVFormat - CSVFormat formator = CSVFormat.DEFAULT.withHeader(headers); - FileReader fileReader=new FileReader(filePath); - //创建CSVParser对象 - CSVParser parser=new CSVParser(fileReader,formator); - List<CSVRecord> records=parser.getRecords(); - parser.close(); - fileReader.close(); - return records; - } - -} diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java index 199bc7e4..df96bd6c 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java @@ -150,11 +150,6 @@ public class DmaapSubscriber implements Runnable { subscribe(performanceTopic); } } catch (Exception e) { - try { - Thread.sleep(10000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } logger.error("subscribe raise error :" + e.getCause()); } } diff --git a/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java b/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java deleted file mode 100755 index d192b771..00000000 --- a/server/src/test/java/org/onap/usecaseui/server/util/CSVUtilsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved. - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.usecaseui.server.util; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class CSVUtilsTest { - - @Test - public void CSVTest(){ - String[] headers = new String[]{"name","age","birthday"}; - List<String[]> data = new ArrayList<>(); - data.add(new String[]{"Tom","15","2001-1-12"}); - data.add(new String[]{"Jerry","18","2005-1-12"}); - data.add(new String[]{"John","20","2011-1-12"}); - String csvPath = "csvFiles/data.csv"; - CSVUtils.writeCsv(headers,data,csvPath); - } - - @Test - public void CSVRead(){ - String[] headers = new String[]{"name","age","birthday"}; - String csvPath = "csvFiles/data.csv"; - try { - CSVUtils.readCSV(csvPath,headers); - } catch (IOException e) { - e.printStackTrace(); - } - } -} |