aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguochuyicmri <guochuyi@chinamobile.com>2018-11-08 14:04:37 +0800
committerguochuyicmri <guochuyi@chinamobile.com>2018-11-08 14:04:52 +0800
commit672ca1d0ec9dfd237612b091200fd950d3ba833a (patch)
tree27813c609d125429d5058a5c616dfea2d1ed0792
parent216f7e8ca6fd6fa2c9eeed41173048afad8675ed (diff)
Fix VNF Alarm Query Bugs
Change-Id: Icb4d795bed9758f90aeb643f83b7af0c1b857bb9 Issue-ID: USECASEUI-165 Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java30
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java109
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java4
3 files changed, 27 insertions, 116 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 470890e0..be72cc70 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
@@ -29,8 +29,6 @@ import javax.annotation.Resource;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.AlarmsInformation;
-import org.onap.usecaseui.server.bean.maxAndMinTimeBean;
-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;
@@ -100,12 +98,11 @@ public class AlarmController
* test commit
* @throws ParseException
*/
- @RequestMapping(value = {"/alarm/{currentPage}/{pageSize}",
- "/alarm/{currentPage}/{pageSize}/{sourceName}/{priority}/{startTime}/{endTime}/{vfStatus}"},
+ @RequestMapping(value = {"/alarm/{currentPage}/{pageSize}"},
method = RequestMethod.GET , produces = "application/json")
- public String getAlarmData(@PathVariable(required = false) String sourceName,
- @PathVariable(required = false) String priority,@PathVariable(required = false) String startTime,
- @PathVariable(required = false) String endTime,@PathVariable(required = false) String vfStatus,
+ 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);
@@ -170,8 +167,8 @@ public class AlarmController
return omAlarm.writeValueAsString(sourceNames);
}
- @RequestMapping(value = {"/alarm/diagram"},method = RequestMethod.POST,produces = "application/json")
- public String diagram(@RequestParam String sourceName, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String format) {
+ @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) {
long timeInterval = 0;
try {
if("month".equals(format)){//alarm day month year
@@ -182,13 +179,6 @@ public class AlarmController
formatDate="yyyy-MM-dd";
timeInterval =86400000;
}
- List<maxAndMinTimeBean> list = alarmsInformationService.queryMaxAndMinTime();
- if(!UuiCommonUtil.isNotNullOrEmpty(startTime)&&list.size()>0){
- startTime=list.get(0).getMinTime();
- }
- if(!UuiCommonUtil.isNotNullOrEmpty(endTime)&&list.size()>0){
- endTime=list.get(0).getMaxTime();
- }
sdf = new SimpleDateFormat(formatDate);
long startTimel = sdf.parse(startTime).getTime();
long endTimel = sdf.parse(endTime).getTime();
@@ -219,10 +209,14 @@ public class AlarmController
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));
- int maxDay2 = DateUtils.MonthOfDay(sdf.format(new Date(tmpEndTimeL)), formatDate);
- int maxDay = DateUtils.MonthOfDay(sdf.format(new Date(startTimeL)), formatDate);
+ if("month".equals(format)){
+ maxDay2 = DateUtils.MonthOfDay(sdf.format(new Date(tmpEndTimeL)), formatDate);
+ maxDay = DateUtils.MonthOfDay(sdf.format(new Date(startTimeL)), formatDate);
+ }
numList.add(num);
startTimeL += 86400000L*maxDay;
tmpEndTimeL += 86400000L*maxDay2;
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 cf5d4f6d..71a0faf7 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
@@ -29,6 +29,7 @@ import org.hibernate.Transaction;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.service.AlarmsHeaderService;
import org.onap.usecaseui.server.util.Page;
+import org.onap.usecaseui.server.util.UuiCommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -95,108 +96,24 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
return -1;
}else {
- if(null!=alarmsHeader.getVersion()) {
- String ver=alarmsHeader.getVersion();
- count.append(" and a.version like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getEventName()) {
- String ver=alarmsHeader.getEventName();
- count.append(" and a.eventName like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getAlarmCondition()) {
- String ver=alarmsHeader.getAlarmCondition();
- count.append(" and a.alarmCondition like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getDomain()) {
- String ver=alarmsHeader.getDomain();
- count.append(" and a.domain like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getEventId()) {
- String ver=alarmsHeader.getEventId();
- count.append(" and a.eventId = '"+ver+"'");
- }
- if(null!=alarmsHeader.getNfcNamingCode()) {
- String ver=alarmsHeader.getNfcNamingCode();
- count.append(" and a.nfcNamingCode like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getNfNamingCode()) {
- String ver=alarmsHeader.getNfNamingCode();
- count.append(" and a.nfNamingCode like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getSourceId()) {
- String ver =alarmsHeader.getSourceId();
- count.append(" and a.sourceId like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getSourceName()) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getSourceName())) {
String ver =alarmsHeader.getSourceName();
count.append(" and a.sourceName like '%"+ver+"%'");
}
- if(null!=alarmsHeader.getReportingEntityId()) {
- String ver =alarmsHeader.getReportingEntityId();
- count.append(" and a.reportingEntityId like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getReportingEntityName()) {
- String ver =alarmsHeader.getReportingEntityName();
- count.append(" and a.reportingEntityName like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getPriority()) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getPriority())) {
String ver =alarmsHeader.getPriority();
count.append(" and a.priority like '%"+ver+"%'");
}
- if(null!=alarmsHeader.getStartEpochMicrosec()) {
- String ver =alarmsHeader.getStartEpochMicrosec();
- count.append(" and a.startEpochMicrosec like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getLastEpochMicroSec()) {
- String ver =alarmsHeader.getLastEpochMicroSec();
- count.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getSequence()) {
- String ver =alarmsHeader.getSequence();
- count.append(" and a.sequence like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getFaultFieldsVersion()) {
- String ver =alarmsHeader.getFaultFieldsVersion();
- count.append(" and a.faultFieldsVersion like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getEventServrity()) {
- String ver =alarmsHeader.getEventServrity();
- count.append(" and a.eventServrity like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getEventType()) {
- String ver =alarmsHeader.getEventType();
- count.append(" and a.eventSourceType like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getEventCategory()) {
- String ver =alarmsHeader.getEventCategory();
- count.append(" and a.eventCategory like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getAlarmCondition()) {
- String ver =alarmsHeader.getAlarmCondition();
- count.append(" and a.alarmCondition like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getSpecificProblem()) {
- String ver =alarmsHeader.getSpecificProblem();
- count.append(" and a.specificProblem like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getVfStatus()) {
- String ver =alarmsHeader.getVfStatus();
- count.append(" and a.vfStatus = '"+ver+"'");
- }
- if(null!=alarmsHeader.getAlarmInterfaceA()) {
- String ver =alarmsHeader.getAlarmInterfaceA();
- count.append(" and a.alarmInterfaceA like '%"+ver+"%'");
- }
- if(null!=alarmsHeader.getStatus()) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getStatus())) {
String ver =alarmsHeader.getStatus();
count.append(" and a.status = '"+ver+"'");
}
- if(null!=alarmsHeader.getStartEpochMicrosec() || alarmsHeader.getLastEpochMicroSec()!= null) {
- count.append(" and a.startEpochMicrosec between :startTime and :endTime");
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getStartEpochMicrosec())&&UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getLastEpochMicroSec())) {
+ count.append(" and (CASE WHEN a.startEpochMicrosec=0 THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ");
}
}
Query query = session.createQuery(count.toString());
- if(null!=alarmsHeader.getStartEpochMicrosec() || alarmsHeader.getLastEpochMicroSec()!= null) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getStartEpochMicrosec())&&UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getLastEpochMicroSec())) {
query.setString("startTime",alarmsHeader.getStartEpochMicrosec());
query.setString("endTime",alarmsHeader.getLastEpochMicroSec());
}
@@ -222,25 +139,25 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
return null;
}else {
- if(null!=alarmsHeader.getSourceName()) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getSourceName())) {
String ver =alarmsHeader.getSourceName();
hql.append(" and a.sourceName like '%"+ver+"%'");
}
- if(null!=alarmsHeader.getVfStatus()) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getVfStatus())) {
String ver =alarmsHeader.getVfStatus();
hql.append(" and a.vfStatus = '"+ver+"'");
}
- if(null!=alarmsHeader.getStatus()) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getStatus())) {
String ver =alarmsHeader.getStatus();
hql.append(" and a.status = '"+ver+"'");
}
- if(null!=alarmsHeader.getStartEpochMicrosec() || alarmsHeader.getLastEpochMicroSec()!= null) {
- hql.append(" and a.startEpochMicrosec between :startTime and :endTime");
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getStartEpochMicrosec())&&UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getLastEpochMicroSec())) {
+ hql.append(" and (CASE WHEN a.startEpochMicrosec=0 THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ");
}
}
logger.info("AlarmsHeaderServiceImpl queryAlarmsHeader: alarmsHeader={}", alarmsHeader);
Query query = session.createQuery(hql.toString());
- if(null!=alarmsHeader.getStartEpochMicrosec() || alarmsHeader.getLastEpochMicroSec()!= null) {
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getStartEpochMicrosec())&&UuiCommonUtil.isNotNullOrEmpty(alarmsHeader.getLastEpochMicroSec())) {
query.setString("startTime",alarmsHeader.getStartEpochMicrosec());
query.setString("endTime",alarmsHeader.getLastEpochMicroSec());
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java b/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java
index 33577e90..3a90e713 100644
--- a/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java
+++ b/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java
@@ -130,8 +130,8 @@ public class UuiCommonUtil {
List listPages = new ArrayList();
int currIdx = (currentPage > 1 ? (currentPage -1) * pageSize : 0);
- for (int i = 0; i < pageSize && i < listPages.size() - currIdx; i++) {
- Object listPage= listPages.get(currIdx + i);
+ for (int i = 0; i < pageSize && i < list.size() - currIdx; i++) {
+ Object listPage= list.get(currIdx + i);
listPages.add(listPage);
}
return listPages;