diff options
author | Arindam Mondal <arind.mondal@samsung.com> | 2019-03-20 10:32:02 +0900 |
---|---|---|
committer | arind.mondal <arind.mondal@samsung.com> | 2019-03-20 10:32:25 +0900 |
commit | f65f53ebc6b96eb76675d795b69937274e4ef533 (patch) | |
tree | 1df0abda45b5796544f44e4815dc67b883982cd3 | |
parent | c946ee87d556ed36df4d7cb028399869815574db (diff) |
Sonar bug fix
+ Fix too many method param
++ Code format
Issue-ID: USECASEUI-246
Change-Id: Ic114cd1615270cd8ea1d7147ae806085d4fd7e31
Signed-off-by: Arindam Mondal <arind.mondal@samsung.com>
-rwxr-xr-x | server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java | 127 | ||||
-rw-r--r-- | server/src/main/java/org/onap/usecaseui/server/util/DateProcessDataObject.java | 106 |
2 files changed, 180 insertions, 53 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 be72cc70..e217fe77 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 @@ -32,6 +32,7 @@ import org.onap.usecaseui.server.bean.AlarmsInformation; 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.DateProcessDataObject;
import org.onap.usecaseui.server.util.DateUtils;
import org.onap.usecaseui.server.util.Page;
import org.onap.usecaseui.server.util.UuiCommonUtil;
@@ -98,26 +99,30 @@ public class AlarmController * test commit
* @throws ParseException
*/
- @RequestMapping(value = {"/alarm/{currentPage}/{pageSize}"},
- method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/alarm/{currentPage}/{pageSize}"}, method = RequestMethod.GET,
+ produces = "application/json")
public String getAlarmData(@RequestParam(required = false) String sourceName,
- @RequestParam(required = false) String priority,@RequestParam(required = false) String startTime,
- @RequestParam(required = false) String endTime,@RequestParam(required = false) String vfStatus,
- @PathVariable String currentPage, @PathVariable String pageSize) throws JsonProcessingException, ParseException {
- AlarmsHeader alarm = new AlarmsHeader();
- alarm.setSourceName(sourceName);
- alarm.setStatus(vfStatus);
- alarm.setStartEpochMicrosec(!UuiCommonUtil.isNotNullOrEmpty(startTime)?null:new SimpleDateFormat(Constant.DATE_FORMAT).parse(startTime).getTime()+"");
- alarm.setLastEpochMicroSec(!UuiCommonUtil.isNotNullOrEmpty(endTime)?null:new SimpleDateFormat(Constant.DATE_FORMAT).parse(endTime).getTime()+"");
- Page pa = alarmsHeaderService.queryAlarmsHeader(alarm,Integer.parseInt(currentPage),Integer.parseInt(pageSize));
+ @RequestParam(required = false) String priority, @RequestParam(required = false) String startTime,
+ @RequestParam(required = false) String endTime, @RequestParam(required = false) String vfStatus,
+ @PathVariable String currentPage, @PathVariable String pageSize)
+ throws JsonProcessingException, ParseException {
+ AlarmsHeader alarm = new AlarmsHeader();
+ alarm.setSourceName(sourceName);
+ alarm.setStatus(vfStatus);
+ alarm.setStartEpochMicrosec(!UuiCommonUtil.isNotNullOrEmpty(startTime) ? null
+ : new SimpleDateFormat(Constant.DATE_FORMAT).parse(startTime).getTime() + "");
+ alarm.setLastEpochMicroSec(!UuiCommonUtil.isNotNullOrEmpty(endTime) ? null
+ : new SimpleDateFormat(Constant.DATE_FORMAT).parse(endTime).getTime() + "");
+ Page pa =
+ alarmsHeaderService.queryAlarmsHeader(alarm, Integer.parseInt(currentPage), Integer.parseInt(pageSize));
try {
- Map<String,Object> map = new HashMap<>();
- map.put("alarms",pa.getList());
- map.put("totalRecords",pa.getTotalRecords());
+ Map<String, Object> map = new HashMap<>();
+ map.put("alarms", pa.getList());
+ map.put("totalRecords", pa.getTotalRecords());
omAlarm.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
return omAlarm.writeValueAsString(map);
} catch (JsonProcessingException e) {
- logger.debug("JsonProcessingException :"+e.getMessage());
+ logger.debug("JsonProcessingException :" + e.getMessage());
return omAlarm.writeValueAsString("failed");
}
}
@@ -168,59 +173,75 @@ public class AlarmController }
@RequestMapping(value = {"/alarm/diagram"},method = RequestMethod.GET,produces = "application/json")
- public String diagram(@RequestParam String sourceName, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam String format) {
+ public String diagram(@RequestParam String sourceName, @RequestParam(required = false) String startTime,
+ @RequestParam(required = false) String endTime, @RequestParam String format) {
long timeInterval = 0;
- try {
- if("month".equals(format)){//alarm day month year
- formatDate="yyyy-MM";
- int maxDay= DateUtils.MonthOfDay(startTime, formatDate);
- timeInterval =86400000L*maxDay;
- }else{
- formatDate="yyyy-MM-dd";
- timeInterval =86400000;
- }
- sdf = new SimpleDateFormat(formatDate);
+ try {
+ if ("month".equals(format)) {// alarm day month year
+ formatDate = "yyyy-MM";
+ int maxDay = DateUtils.MonthOfDay(startTime, formatDate);
+ timeInterval = 86400000L * maxDay;
+ } else {
+ formatDate = "yyyy-MM-dd";
+ timeInterval = 86400000;
+ }
+ sdf = new SimpleDateFormat(formatDate);
long startTimel = sdf.parse(startTime).getTime();
long endTimel = sdf.parse(endTime).getTime();
- return getDiagram(sourceName, startTimel, endTimel+timeInterval, timeInterval, 1, 1,format);
+ return getDiagram(sourceName, startTimel, endTimel + timeInterval, timeInterval, 1, 1, format);
} catch (Exception e) {
- logger.error("alarmController diagram occured exception:"+e.getMessage());
+ logger.error("alarmController diagram occured exception:" + e.getMessage());
e.printStackTrace();
}
return null;
}
@SuppressWarnings("rawtypes")
- private String getDiagram(String sourceName, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal, long keyValIteraVal,String format) throws JsonProcessingException{
- Map<String,List> result = new HashMap<String,List>();
-
- Map<String,List> allMaps = dateProcess(sourceName, startTimeL, endTimeL, timeIteraPlusVal, keyVal, keyValIteraVal,format,"");
- Map<String,List> closedMaps = dateProcess(sourceName, startTimeL, endTimeL, timeIteraPlusVal, 1, 1,format,"closed");
- Map<String,List> activeMaps = dateProcess(sourceName, startTimeL, endTimeL, timeIteraPlusVal, 1, 1,format,"active");
- result.put("dateList", allMaps.get("dateTime"));
- result.put("allList", allMaps.get("dataList"));
- result.put("closedList",closedMaps.get("dataList"));
- result.put("ActiveList",activeMaps.get("dataList"));
- return omAlarm.writeValueAsString(result);
+ private String getDiagram(String sourceName, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal,
+ long keyValIteraVal, String format) throws JsonProcessingException {
+ Map<String, List> result = new HashMap<String, List>();
+
+ Map<String, List> allMaps = dateProcess(new DateProcessDataObject().setSourceName(sourceName)
+ .setStartTimeL(startTimeL).setEndTimeL(endTimeL).setTimeIteraPlusVal(timeIteraPlusVal).setKeyVal(keyVal)
+ .setKeyValIteraVal(keyValIteraVal).setFormat(format).setLevel(""));
+
+ Map<String, List> closedMaps = dateProcess(new DateProcessDataObject().setSourceName(sourceName)
+ .setStartTimeL(startTimeL).setEndTimeL(endTimeL).setTimeIteraPlusVal(timeIteraPlusVal).setKeyVal(1)
+ .setKeyValIteraVal(1).setFormat(format).setLevel("closed"));
+
+ Map<String, List> activeMaps = dateProcess(new DateProcessDataObject().setSourceName(sourceName)
+ .setStartTimeL(startTimeL).setEndTimeL(endTimeL).setTimeIteraPlusVal(timeIteraPlusVal).setKeyVal(1)
+ .setKeyValIteraVal(1).setFormat(format).setLevel("active"));
+
+ result.put("dateList", allMaps.get("dateTime"));
+ result.put("allList", allMaps.get("dataList"));
+ result.put("closedList", closedMaps.get("dataList"));
+ result.put("ActiveList", activeMaps.get("dataList"));
+ return omAlarm.writeValueAsString(result);
}
- private Map<String,List> dateProcess(String sourceName, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal, long keyValIteraVal,String format,String level) {
- Map<String,List> result = new HashMap<String,List>();
+
+ private Map<String, List> dateProcess(DateProcessDataObject dataObject) {
+ Map<String, List> result = new HashMap<String, List>();
List<String> dateList = new ArrayList<String>();
List<Integer> numList = new ArrayList<Integer>();
- long tmpEndTimeL = startTimeL + timeIteraPlusVal;
- while (endTimeL >= tmpEndTimeL) {
- int maxDay2 = 1;
- int maxDay = 1;
- int num = alarmsInformationService.queryDateBetween(sourceName,startTimeL+"",tmpEndTimeL+"",level);
- dateList.add(DateUtils.getResultDate(startTimeL, format));
- if("month".equals(format)){
- maxDay2 = DateUtils.MonthOfDay(sdf.format(new Date(tmpEndTimeL)), formatDate);
- maxDay = DateUtils.MonthOfDay(sdf.format(new Date(startTimeL)), formatDate);
+ long tmpEndTimeL = dataObject.getStartTimeL() + dataObject.getTimeIteraPlusVal();
+ while (dataObject.getEndTimeL() >= tmpEndTimeL) {
+ int maxDay2 = 1;
+ int maxDay = 1;
+ int num = alarmsInformationService.queryDateBetween(dataObject.getSourceName(),
+ dataObject.getStartTimeL() + "", tmpEndTimeL + "", dataObject.getLevel());
+ dateList.add(DateUtils.getResultDate(dataObject.getStartTimeL(), dataObject.getFormat()));
+ if ("month".equals(dataObject.getFormat())) {
+ maxDay2 = DateUtils.MonthOfDay(sdf.format(new Date(tmpEndTimeL)), formatDate);
+ maxDay = DateUtils.MonthOfDay(sdf.format(new Date(dataObject.getStartTimeL())), formatDate);
}
numList.add(num);
- startTimeL += 86400000L*maxDay;
- tmpEndTimeL += 86400000L*maxDay2;
- keyVal += keyValIteraVal;
+ long startTimeL1 = dataObject.getStartTimeL();
+ startTimeL1 += 86400000L * maxDay;
+ tmpEndTimeL += 86400000L * maxDay2;
+ long keyVal1 = dataObject.getKeyVal();
+ long keyValIteraVal1 = dataObject.getKeyValIteraVal();
+ keyVal1 += keyValIteraVal1;
}
result.put("dateTime", dateList);
result.put("dataList", numList);
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DateProcessDataObject.java b/server/src/main/java/org/onap/usecaseui/server/util/DateProcessDataObject.java new file mode 100644 index 00000000..9ee0024b --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/util/DateProcessDataObject.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung Electronics Co., Ltd. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.usecaseui.server.util; + +public class DateProcessDataObject { + private String sourceName; + private long startTimeL; + private long endTimeL; + private long timeIteraPlusVal; + private long keyVal; + private long keyValIteraVal; + private String format; + private String level; + + + public String getSourceName() { + return sourceName; + } + + public DateProcessDataObject setSourceName(String sourceName) { + this.sourceName = sourceName; + return this; + } + + public long getStartTimeL() { + return startTimeL; + } + + public DateProcessDataObject setStartTimeL(long startTimeL) { + this.startTimeL = startTimeL; + return this; + } + + public long getEndTimeL() { + return endTimeL; + } + + public DateProcessDataObject setEndTimeL(long endTimeL) { + this.endTimeL = endTimeL; + return this; + } + + public long getTimeIteraPlusVal() { + return timeIteraPlusVal; + } + + public DateProcessDataObject setTimeIteraPlusVal(long timeIteraPlusVal) { + this.timeIteraPlusVal = timeIteraPlusVal; + return this; + } + + public long getKeyVal() { + return keyVal; + } + + public DateProcessDataObject setKeyVal(long keyVal) { + this.keyVal = keyVal; + return this; + } + + public long getKeyValIteraVal() { + return keyValIteraVal; + } + + public DateProcessDataObject setKeyValIteraVal(long keyValIteraVal) { + this.keyValIteraVal = keyValIteraVal; + return this; + } + + public String getFormat() { + return format; + } + + public DateProcessDataObject setFormat(String format) { + this.format = format; + return this; + } + + public String getLevel() { + return level; + } + + public DateProcessDataObject setLevel(String level) { + this.level = level; + return this; + } + + +} |