diff options
author | shentao <shentao@chinamobile.com> | 2017-10-31 10:27:24 +0800 |
---|---|---|
committer | shentao <shentao@chinamobile.com> | 2017-10-31 10:27:35 +0800 |
commit | 256b0e5eb968019c356eeeac06b5cd934e48cf44 (patch) | |
tree | f12e915a85f3e773f0b33960462748d0e3012d42 | |
parent | a3c2bbdf70af7e9c798ae6a285522c5b0a460be7 (diff) |
Fix monitor bug
Change-Id: Ife25671ad541732d2328fa46804bd006076e022b
Issue-Id: USECASEUI-50
Signed-off-by: shentao <shentao@chinamobile.com>
22 files changed, 812 insertions, 358 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java index a45a7ec9..c12bb24e 100644 --- a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java +++ b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java @@ -15,22 +15,12 @@ */ package org.onap.usecaseui.server; -import org.onap.msb.sdk.discovery.common.RouteException; -import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; -import org.onap.msb.sdk.discovery.entity.Node; -import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; -import org.onap.usecaseui.server.util.RestfulServices; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.client.RestTemplate; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.HashSet; -import java.util.Set; - @SpringBootApplication @ComponentScan(basePackages = "org.onap.usecaseui.server") public class UsecaseuiServerApplication { @@ -42,32 +32,6 @@ public class UsecaseuiServerApplication { public static void main(String[] args) { SpringApplication.run(UsecaseuiServerApplication.class, args); -// String msbUrl = RestfulServices.getMsbAddress(); -// if (msbUrl.contains(":")) { -// String[] ipAndPort = msbUrl.split(":"); -// MSBServiceClient msbClient = new MSBServiceClient(ipAndPort[0], Integer.parseInt(ipAndPort[1])); -// -// MicroServiceInfo msinfo = new MicroServiceInfo(); -// msinfo.setServiceName("usecase-ui-server"); -// msinfo.setVersion("v1"); -// msinfo.setUrl("/api/usecaseui/server/v1"); -// msinfo.setProtocol("REST"); -// msinfo.setVisualRange("0|1"); -// -// try { -// Set<Node> nodes = new HashSet<>(); -// Node node1 = new Node(); -// node1.setIp(InetAddress.getLocalHost().getHostAddress()); -// node1.setPort("8082"); -// nodes.add(node1); -// msinfo.setNodes(nodes); -// msbClient.registerMicroServiceInfo(msinfo, false); -// } catch (UnknownHostException e) { -// e.printStackTrace(); -// } catch (RouteException e) { -// e.printStackTrace(); -// } -// } } } diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java b/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java index ddb5ded8..d9745686 100644 --- a/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java @@ -23,11 +23,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; -/** - * - * @author xuekui - * - */ + @Entity @Table(name="alarms_commoneventheader") public class AlarmsHeader implements Serializable{ diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsInformation.java b/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsInformation.java index 5c447d61..ef3ae55f 100644 --- a/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsInformation.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsInformation.java @@ -33,13 +33,15 @@ import javax.persistence.Table; public class AlarmsInformation implements Serializable { @Id + @Column(name = "id") + private int id; + @Column(name = "name") private String name; @Column(name = "value") private String value; - @Id @Column(name = "eventId") private String eventId; @@ -103,6 +105,14 @@ public class AlarmsInformation implements Serializable { public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceInformation.java b/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceInformation.java index d2c71ade..c0da3ab5 100755 --- a/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceInformation.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceInformation.java @@ -29,13 +29,15 @@ import javax.persistence.Table; public class PerformanceInformation implements Serializable {
@Id
+ @Column(name = "id")
+ private int id;
+
@Column(name = "name")
private String name;
@Column(name = "value")
private String value;
- @Id
@Column(name = "eventId")
private String eventId;
@@ -99,6 +101,14 @@ public class PerformanceInformation implements Serializable { public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java b/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java index ab95eb2d..9a818e4e 100755 --- a/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java +++ b/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java @@ -19,6 +19,7 @@ package org.onap.usecaseui.server.constant; public final class Constant
{
- public static final String DATE_FROMAT= "yyyy-MM-dd HH:mm:ss";
-
+ public static final String DATE_FORMAT= "yyyy-MM-dd HH:mm:ss";
+
+
}
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 e01bf043..170d67da 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 @@ -16,28 +16,22 @@ package org.onap.usecaseui.server.controller;
import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.hibernate.annotations.Parameter;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.AlarmsInformation;
-import org.onap.usecaseui.server.bean.PerformanceHeader;
-import org.onap.usecaseui.server.bean.PerformanceInformation;
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.wrapper.AlarmWrapper;
+import org.onap.usecaseui.server.util.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@@ -65,12 +59,37 @@ public class AlarmController @Resource(name = "AlarmsInformationService")
private AlarmsInformationService alarmsInformationService;
+ private String[] AlarmCSVHeaders = new String[]{"version",
+ "eventName","domain","eventId","eventType","nfcNamingCode",
+ "nfNamingCode","sourceId","sourceName","reportingEntityId",
+ "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
+ "sequence","faultFieldsVersion","eventServrity","eventSourceType",
+ "eventCategory","alarmCondition","specificProblem","vfStatus",
+ "alarmInterfaceA","status",
+ "createTime","updateTime","name","value"};
+
+ private ObjectMapper omAlarm = new ObjectMapper();
+
+ private List<String> last_eventId = new ArrayList<>();
+
+ private List<String> last_status = new ArrayList<>();
+
+ private List<String> last_vfStatus = new ArrayList<>();
@RequestMapping(value = {"/usecase-ui"}, method = RequestMethod.GET)
public ModelAndView index(){
return new ModelAndView("index");
}
+ @RequestMapping(value = {"/alarm/{eventId}/{eventName}/{name}/{value}/{createTime}/{status}/{vfStatus}"})
+ public String getAlarmDateTotal(@PathVariable String eventId,@PathVariable String eventName,
+ @PathVariable String name,@PathVariable String value,
+ @PathVariable String createTime,@PathVariable String status,
+ @PathVariable String vfStatus) throws ParseException {
+
+ return "";
+ }
+
@RequestMapping(value = {"/alarm/{currentPage}/{pageSize}",
"/alarm/{currentPage}/{pageSize}/{eventId}/{eventName}/{name}/{value}/{createTime}/{status}/{vfStatus}"},
method = RequestMethod.GET , produces = "application/json")
@@ -78,9 +97,10 @@ public class AlarmController @PathVariable(required = false) String name,@PathVariable(required = false) String value,
@PathVariable(required = false) String createTime,@PathVariable(required = false) String status,
@PathVariable(required = false) String vfStatus,
- @PathVariable int currentPage, @PathVariable int pageSize) {
+ @PathVariable int currentPage, @PathVariable int pageSize) throws JsonProcessingException {
List<AlarmsHeader> alarmsHeaders = null;
- List<AlarmBo> maps = new ArrayList<>();
+ List<AlarmBo> list = new ArrayList<>();
+ Page pa = null;
if (null != eventId || null != eventName || null != name || null != value || null != createTime
|| null != status || null != vfStatus ){
AlarmsHeader alarm = new AlarmsHeader();
@@ -93,7 +113,8 @@ public class AlarmController } catch (ParseException e) {
logger.error("Parse date error :"+e.getMessage());
}
- alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(alarm,currentPage,pageSize).getList();
+ pa = alarmsHeaderService.queryAlarmsHeader(alarm,currentPage,pageSize);
+ alarmsHeaders = pa.getList();
if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
alarmsHeaders.forEach(a ->{
AlarmBo abo = new AlarmBo();
@@ -103,48 +124,43 @@ public class AlarmController information.setValue(!"null".equals(value)?value:null);
information.setEventId(a.getEventId());
abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(information,1,100).getList());
- maps.add(abo);
+ list.add(abo);
});
}
}else {
- alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(null, currentPage, pageSize).getList();
+ pa = alarmsHeaderService.queryAlarmsHeader(null, currentPage, pageSize);
+ alarmsHeaders = pa.getList();
if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
alarmsHeaders.forEach(a -> {
AlarmBo abo = new AlarmBo();
abo.setAlarmsHeader(a);
abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(a.getEventId()),currentPage,pageSize).getList());
- maps.add(abo);
+ list.add(abo);
});
}
}
try {
- ObjectMapper ojm = new ObjectMapper();
- ojm.setDateFormat(new SimpleDateFormat(Constant.DATE_FROMAT));
- return ojm.writeValueAsString(maps);
+ Map<String,Object> map = new HashMap<>();
+ map.put("alarms",list);
+ map.put("totalRecords",pa.getTotalRecords());
+ omAlarm.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
+ return omAlarm.writeValueAsString(map);
} catch (JsonProcessingException e) {
logger.debug("JsonProcessingException :"+e.getMessage());
- return "";
+ return omAlarm.writeValueAsString("failed");
}
}
@RequestMapping(value = { "/alarm/genCsv/{eventId}" } , method = RequestMethod.GET , produces = "application/json")
- public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId){
+ public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId) throws JsonProcessingException {
String csvFile = "csvFiles/vnf_alarm_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv";
- String[] headers = new String[]{"version",
- "eventName","domain","eventId","eventType","nfcNamingCode",
- "nfNamingCode","sourceId","sourceName","reportingEntityId",
- "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
- "sequence","faultFieldsVersion","eventServrity","eventSourceType",
- "eventCategory","alarmCondition","specificProblem","vfStatus",
- "alarmInterfaceA","status",
- "createTime","updateTime","name","value"};
List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eventId);
List<String[]> csvData = new ArrayList<>();
try{
alarmsHeaders.forEach(ala ->{
List<AlarmsInformation> information = alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(ala.getEventId()),1,100).getList();
- String names = new String();
- String values = new String();
+ String names = "";
+ String values = "";
if (0 < information.size() && null != information){
for (AlarmsInformation a : information){
names += a.getName()+",";
@@ -163,7 +179,7 @@ public class AlarmController DateUtils.dateToString(ala.getUpdateTime()),names,values
});
});
- CSVUtils.writeCsv(headers,csvData,csvFile);
+ CSVUtils.writeCsv(AlarmCSVHeaders,csvData,csvFile);
}catch (Exception e){
logger.error(e.getMessage());
}
@@ -178,20 +194,26 @@ public class AlarmController while ((length = is.read(b)) > 0) {
os.write(b, 0, length);
}
- return "{'result':'success'}";
+ return omAlarm.writeValueAsString("success");
}catch (IOException e){
logger.error("download csv File error :"+e.getMessage());
- return "{'result':'failed'}";
+ return omAlarm.writeValueAsString("failed");
}
}else
- return "csvFile generate success,response is null,don't download to local";
+ return omAlarm.writeValueAsString("csvFile generate success,response is null,don't download to local");
}
@RequestMapping(value = { "/alarm/{eventId}/{status}/{type}" } , method = RequestMethod.PUT )
- public String updateStatus(HttpServletResponse response,@PathVariable String[] eventId,@PathVariable String[] status,@PathVariable String type){
+ public String updateStatus(HttpServletResponse response,@PathVariable String[] eventId,@PathVariable String[] status,@PathVariable String type) throws JsonProcessingException {
List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eventId);
+ last_eventId.clear();
+ last_vfStatus.clear();
+ last_status.clear();
for (AlarmsHeader ala: alarmsHeaders) {
+ last_eventId.add(ala.getEventId());
+ last_status.add(ala.getStatus());
+ last_vfStatus.add(ala.getVfStatus());
if ("vf".equals(type))
ala.setVfStatus(status[0]);
else if ("many".equals(type)){
@@ -203,13 +225,34 @@ public class AlarmController if ("0".equals(alarmsHeaderService.updateAlarmsHeader(ala))) {
if (null != response)
response.setStatus(400);
- return "{'result':'update failed'}";
+ return omAlarm.writeValueAsString("failed");
}
}
- return "{'result':'update success'}";
+ return omAlarm.writeValueAsString("success");
}
-
+ @RequestMapping(value = {"/alarm/revoke"} , method = RequestMethod.GET)
+ public String revoke() throws JsonProcessingException {
+ String result ;
+ if (last_eventId.size() > 0 && last_vfStatus.size() > 0 && last_status.size() > 0){
+ String[] eids = new String[last_eventId.size()];
+ last_eventId.toArray(eids);
+ List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eids);
+ for (int i = 0;i<alarmsHeaders.size();i++){
+ AlarmsHeader ala = alarmsHeaders.get(i);
+ ala.setStatus(last_status.get(i));
+ ala.setVfStatus(last_vfStatus.get(i));
+ alarmsHeaderService.updateAlarmsHeader(ala);
+ }
+ last_eventId.clear();
+ last_status.clear();
+ last_vfStatus.clear();
+ result = "revoke success";
+ } else {
+ result = "nothing can revoke";
+ }
+ return omAlarm.writeValueAsString(result);
+ }
}
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 422074a7..2634d259 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 @@ -18,7 +18,6 @@ package org.onap.usecaseui.server.controller; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.usecaseui.server.bean.AlarmsHeader; import org.onap.usecaseui.server.bean.PerformanceHeader; import org.onap.usecaseui.server.bean.PerformanceInformation; import org.onap.usecaseui.server.bo.PerformanceBo; @@ -30,17 +29,12 @@ import org.onap.usecaseui.server.util.DateUtils; import org.onap.usecaseui.server.util.Page; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.xml.crypto.Data; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -63,12 +57,22 @@ public class PerformanceController { private Logger logger = LoggerFactory.getLogger(PerformanceController.class); + private final String[] PerformanceCSVHeaders = {"version", + "eventName","domain","eventId","eventType","nfcNamingCode", + "nfNamingCode","sourceId","sourceName","reportingEntityId", + "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec", + "sequence","measurementsForVfScalingVersion","measurementInterval", + "createTime","updateTime","value","name"}; + + private ObjectMapper omPerformance = new ObjectMapper(); + @RequestMapping(value = {"/performance/{currentPage}/{pageSize}","/performance/{currentPage}/{pageSize}/{eventId}/{eventName}/{name}/{value}/{createTime}"},method = RequestMethod.GET, produces = "application/json") public String getPerformanceData(HttpServletResponse response,@PathVariable int currentPage, @PathVariable int pageSize,@PathVariable(required = false) String eventId, @PathVariable(required = false) String eventName,@PathVariable(required = false) String name, - @PathVariable(required = false) String value,@PathVariable(required = false) String createTime) { + @PathVariable(required = false) String value,@PathVariable(required = false) String createTime) throws JsonProcessingException { List<Object> list = new ArrayList<>(); + Page pa = null; if (null != eventId || null != eventName || null != name || null != value || null != createTime){ PerformanceHeader performanceHeader = new PerformanceHeader(); performanceHeader.setEventId(!"null".equals(eventId)?eventId:null); @@ -81,7 +85,8 @@ public class PerformanceController { logger.error("ParseException["+createTime+"]:"+e.getMessage()); return "{'result':'error'}"; } - List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(performanceHeader,currentPage,pageSize).getList(); + pa = performanceHeaderService.queryPerformanceHeader(performanceHeader,currentPage,pageSize); + List<PerformanceHeader> performanceHeaders = pa.getList(); performanceHeaders.forEach( per ->{ PerformanceBo pbo = new PerformanceBo(); PerformanceInformation pe = new PerformanceInformation(); @@ -94,7 +99,7 @@ public class PerformanceController { list.add(pbo); }); }else{ - Page pa = performanceHeaderService.queryPerformanceHeader(null,currentPage,pageSize); + pa = performanceHeaderService.queryPerformanceHeader(null,currentPage,pageSize); List<PerformanceHeader> p = pa!=null?pa.getList():null; if (null != p && p.size() > 0) p.forEach( per ->{ @@ -105,32 +110,28 @@ public class PerformanceController { }); } try { - ObjectMapper ojm = new ObjectMapper(); - ojm.setDateFormat(new SimpleDateFormat(Constant.DATE_FROMAT)); - return ojm.writeValueAsString(list); + Map<String,Object> map = new HashMap<>(); + map.put("performances",list); + map.put("totalRecords",pa.getTotalRecords()); + omPerformance.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT)); + return omPerformance.writeValueAsString(map); } catch (JsonProcessingException e) { logger.error("JsonProcessingException"+e.getMessage()); - return "{'result':'error'}"; + return omPerformance.writeValueAsString("failed"); } } @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"; - String[] headers = new String[]{"version", - "eventName","domain","eventId","eventType","nfcNamingCode", - "nfNamingCode","sourceId","sourceName","reportingEntityId", - "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec", - "sequence","measurementsForVfScalingVersion","measurementInterval", - "createTime","updateTime","value","name"}; List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryId(eventId); - if (null == performanceHeaders || performanceHeaders.size() < 0) + 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 = new String(); - String values = new String(); + String names = ""; + String values = ""; if (0 < information.size() && null != information){ for (PerformanceInformation a : information){ names += a.getName()+","; @@ -147,7 +148,7 @@ public class PerformanceController { names,values }); }); - CSVUtils.writeCsv(headers,csvData,csvFile); + CSVUtils.writeCsv(PerformanceCSVHeaders,csvData,csvFile); if (null != response){ response.setCharacterEncoding("utf-8"); response.setContentType("application/csv"); @@ -159,18 +160,18 @@ public class PerformanceController { while ((length = is.read(b)) > 0) { os.write(b, 0, length); } - return "{'result':'success'}"; + return omPerformance.writeValueAsString("success"); }catch (IOException e){ logger.error("download csv File error :"+e.getMessage()); - return "{'result':'failed'}"; + return omPerformance.writeValueAsString("failed"); } }else - return "csvFile generate success,response is null,don't download to local"; + return omPerformance.writeValueAsString("csvFile generate success,but response is null,don't download to local"); } @RequestMapping(value = {"/performance/genDiaCsv"}, method = RequestMethod.POST, produces = "application/json") - public String generateDiaCsvFile(HttpServletResponse response,@RequestBody Map<String,String> p) { + public String generateDiaCsvFile(HttpServletResponse response,@RequestBody Map<String,String> p) throws JsonProcessingException { String csvFileName = "csvFiles/"+p.get("name")+"_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv"; try{ String[] headers = new String[]{"eventId","name","value","createTime","updateTime"}; @@ -196,40 +197,83 @@ public class PerformanceController { while ((length = is.read(b)) > 0) { os.write(b, 0, length); } - return "{'result':'success'}"; + return omPerformance.writeValueAsString("success"); }catch (IOException e){ logger.error("download csv File error :"+e.getMessage()); - return "{'result':'failed'}"; + return omPerformance.writeValueAsString("failed"); } }else - return "csvFile generate success,response is null,don't download to local"; + return omPerformance.writeValueAsString("csvFile generate success,but response is null,don't download to local"); } @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 { - String revDate = ""; + Map<String,List<Integer>> diagramSource = new HashMap<>(); + String[] names = {"cpu","network","disk","memory"}; switch (unit){ case "hour": - revDate = DateUtils.initDate(new Date(),1,1,1,-1,0,0); + for(int i = 0 ; i < 4 ; i++){ + Date startDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,-1,-1,0,0)); + Date endDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,-1,-1,0,0)); + endDateHour = DateUtils.stringToDate(DateUtils.addDate(endDateHour,"minute",15)); + List<Integer> values = new ArrayList<>(); + for (int j = 0 ; j < 4 ; j++){ + values.add(performanceInformationService.queryDataBetweenSum(eventId,names[i],startDateHour,endDateHour)); + startDateHour = DateUtils.stringToDate(DateUtils.addDate(startDateHour,"minute",15)); + endDateHour = DateUtils.stringToDate(DateUtils.addDate(endDateHour,"minute",15)); + } + diagramSource.put(names[i],values); + } break; case "day": - revDate = DateUtils.initDate(new Date(),1,1,-1,0,0,0); + for(int i = 0 ; i < 4 ; i++){ + Date startDateDay = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,-1,0,0,0)); + Date endDateDay = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,-1,0,0,0)); + endDateDay = DateUtils.stringToDate(DateUtils.addDate(endDateDay,"hour",1)); + List<Integer> values = new ArrayList<>(); + for (int j = 0 ; j < 24 ; j++){ + values.add(performanceInformationService.queryDataBetweenSum(eventId,names[i],startDateDay,endDateDay)); + startDateDay = DateUtils.stringToDate(DateUtils.addDate(startDateDay,"hour",1)); + endDateDay = DateUtils.stringToDate(DateUtils.addDate(endDateDay,"hour",1)); + } + diagramSource.put(names[i],values); + } break; case "month": - revDate = DateUtils.initDate(new Date(),1,-1,0,0,0,0); + for(int i = 0 ; i < 4 ; i++){ + Date startDateMonth = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,-1,0,0,0,0)); + Date endDateMonth = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,-1,0,0,0,0)); + endDateMonth = DateUtils.stringToDate(DateUtils.addDate(endDateMonth,"day",1)); + List<Integer> values = new ArrayList<>(); + for (int j = 0 ; j < 31 ; j++){ + values.add(performanceInformationService.queryDataBetweenSum(eventId,names[i],startDateMonth,endDateMonth)); + startDateMonth = DateUtils.stringToDate(DateUtils.addDate(startDateMonth,"day",1)); + endDateMonth = DateUtils.stringToDate(DateUtils.addDate(endDateMonth,"day",1)); + } + diagramSource.put(names[i],values); + } break; case "year": - revDate = DateUtils.initDate(new Date(),-1,0,0,0,0,0); + for(int i = 0 ; i < 4 ; i++){ + Date startDateYear = DateUtils.stringToDate(DateUtils.initDate(new Date(),-1,0,0,0,0,0)); + Date endDateYear = DateUtils.stringToDate(DateUtils.initDate(new Date(),-1,0,0,0,0,0)); + endDateYear = DateUtils.stringToDate(DateUtils.addDate(endDateYear,"month",1)); + List<Integer> values = new ArrayList<>(); + for (int j = 0 ; j < 12 ; j++){ + logger.info(names[i]); + logger.info(DateUtils.dateToString(startDateYear)); + logger.info(DateUtils.dateToString(endDateYear)); + values.add(performanceInformationService.queryDataBetweenSum(eventId,names[i],startDateYear,endDateYear)); + startDateYear = DateUtils.stringToDate(DateUtils.addDate(startDateYear,"month",1)); + endDateYear = DateUtils.stringToDate(DateUtils.addDate(endDateYear,"month",1)); + } + diagramSource.put(names[i],values); + } break; } - PerformanceInformation performanceInformation = new PerformanceInformation(); - performanceInformation.setEventId(eventId); - performanceInformation.setCreateTime(DateUtils.stringToDate(revDate)); - List<PerformanceInformation> informations = performanceInformationService.queryPerformanceInformation(performanceInformation,1,100).getList(); - ObjectMapper ojm = new ObjectMapper(); - ojm.setDateFormat(new SimpleDateFormat(Constant.DATE_FROMAT)); - return ojm.writeValueAsString(informations); + omPerformance.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT)); + return omPerformance.writeValueAsString(diagramSource); } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java index 1979115e..6bb8e6f7 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java @@ -27,7 +27,7 @@ public interface AlarmsHeaderService { String updateAlarmsHeader(AlarmsHeader alarmsHeader); - int getAllCount(); + int getAllCount(AlarmsHeader alarmsHeader, int currentPage, int pageSize); Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize); diff --git a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java index cc9aa6ec..58b9b6d0 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java @@ -28,7 +28,7 @@ public interface AlarmsInformationService { String updateAlarmsInformation(AlarmsInformation alarmsInformation); - int getAllCount(); + int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize); Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage, int pageSize); diff --git a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java index 5535aeb4..683903d3 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java @@ -28,7 +28,7 @@ public interface PerformanceHeaderService { String updatePerformanceHeader(PerformanceHeader performanceHeder); - int getAllCount(); + int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize); Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, int pageSize); diff --git a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java index 128966e7..d3060d8e 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java @@ -15,6 +15,7 @@ */ package org.onap.usecaseui.server.service; +import java.util.Date; import java.util.List; import org.onap.usecaseui.server.bean.AlarmsInformation; @@ -28,9 +29,13 @@ public interface PerformanceInformationService { String updatePerformanceInformation(PerformanceInformation performanceInformation); - int getAllCount(); + int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize); Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation, int currentPage, int pageSize); List<PerformanceInformation> queryId(String[] id); + + List<PerformanceInformation> queryDateBetween(String eventId, Date startDate, Date endDate); + + int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate); } 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 f4778b90..f918b22b 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 @@ -89,10 +89,119 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { }
}
- public int getAllCount() {
+ public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
try{
+ StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
+ if (null == alarmsHeader) {
+ //logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
+ }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()) {
+ 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()) {
+ 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()) {
+ String ver =alarmsHeader.getStatus();
+ count.append(" and a.status = '"+ver+"'");
+ }
+ if(null!=alarmsHeader.getCreateTime()) {
+ Date ver =alarmsHeader.getCreateTime();
+ count.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getUpdateTime()) {
+ Date ver =alarmsHeader.getUpdateTime();
+ count.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
Session session = sessionFactory.openSession();
- long q=(long)session.createQuery("select count(*) from AlarmsHeader").uniqueResult();
+ long q=(long)session.createQuery(count.toString()).uniqueResult();
session.flush();
session.close();
return (int)q;
@@ -106,91 +215,118 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService { @Override
public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
Page<AlarmsHeader> page = new Page<AlarmsHeader>();
- int allRow =this.getAllCount();
+ int allRow =this.getAllCount(alarmsHeader,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
try{
StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
- logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
- }else if(null!=alarmsHeader.getVersion()) {
- String ver=alarmsHeader.getVersion();
- hql.append(" and a.version like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getEventName()) {
- String ver=alarmsHeader.getEventName();
- hql.append(" and a.eventName like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getAlarmCondition()) {
- String ver=alarmsHeader.getAlarmCondition();
- hql.append(" and a.alarmCondition like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getDomain()) {
- String ver=alarmsHeader.getDomain();
- hql.append(" and a.domain like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getEventId()) {
- String ver=alarmsHeader.getEventId();
- hql.append(" and a.eventId = '"+ver+"'");
- }else if(null!=alarmsHeader.getNfcNamingCode()) {
- String ver=alarmsHeader.getNfcNamingCode();
- hql.append(" and a.nfcNamingCode like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getNfNamingCode()) {
- String ver=alarmsHeader.getNfNamingCode();
- hql.append(" and a.nfNamingCode like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getSourceId()) {
- String ver =alarmsHeader.getSourceId();
- hql.append(" and a.sourceId like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getSourceName()) {
- String ver =alarmsHeader.getSourceName();
- hql.append(" and a.sourceName like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getReportingEntityId()) {
- String ver =alarmsHeader.getReportingEntityId();
- hql.append(" and a.reportingEntityId like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getReportingEntityName()) {
- String ver =alarmsHeader.getReportingEntityName();
- hql.append(" and a.reportingEntityName like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getPriority()) {
- String ver =alarmsHeader.getPriority();
- hql.append(" and a.priority like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getStartEpochMicrosec()) {
- String ver =alarmsHeader.getStartEpochMicrosec();
- hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getLastEpochMicroSec()) {
- String ver =alarmsHeader.getLastEpochMicroSec();
- hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getSequence()) {
- String ver =alarmsHeader.getSequence();
- hql.append(" and a.sequence like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getFaultFieldsVersion()) {
- String ver =alarmsHeader.getFaultFieldsVersion();
- hql.append(" and a.faultFieldsVersion like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getEventServrity()) {
- String ver =alarmsHeader.getEventServrity();
- hql.append(" and a.eventServrity like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getEventType()) {
- String ver =alarmsHeader.getEventType();
- hql.append(" and a.eventSourceType like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getEventCategory()) {
- String ver =alarmsHeader.getEventCategory();
- hql.append(" and a.eventCategory like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getAlarmCondition()) {
- String ver =alarmsHeader.getAlarmCondition();
- hql.append(" and a.alarmCondition like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getSpecificProblem()) {
- String ver =alarmsHeader.getSpecificProblem();
- hql.append(" and a.specificProblem like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getVfStatus()) {
- String ver =alarmsHeader.getVfStatus();
- hql.append(" and a.vfStatus like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getAlarmInterfaceA()) {
- String ver =alarmsHeader.getAlarmInterfaceA();
- hql.append(" and a.alarmInterfaceA like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getStatus()) {
- String ver =alarmsHeader.getStatus();
- hql.append(" and a.status like '%"+ver+"%'");
- }else if(null!=alarmsHeader.getCreateTime()) {
- Date ver =alarmsHeader.getCreateTime();
- hql.append(" and a.createTime > '%"+ver+"%'");
- }else if(null!=alarmsHeader.getUpdateTime()) {
- Date ver =alarmsHeader.getUpdateTime();
- hql.append(" and a.updateTime like '%"+ver+"%'");
+ //logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
+ }else {
+ if(null!=alarmsHeader.getVersion()) {
+ String ver=alarmsHeader.getVersion();
+ hql.append(" and a.version like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getEventName()) {
+ String ver=alarmsHeader.getEventName();
+ hql.append(" and a.eventName like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getAlarmCondition()) {
+ String ver=alarmsHeader.getAlarmCondition();
+ hql.append(" and a.alarmCondition like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getDomain()) {
+ String ver=alarmsHeader.getDomain();
+ hql.append(" and a.domain like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getEventId()) {
+ String ver=alarmsHeader.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=alarmsHeader.getNfcNamingCode()) {
+ String ver=alarmsHeader.getNfcNamingCode();
+ hql.append(" and a.nfcNamingCode like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getNfNamingCode()) {
+ String ver=alarmsHeader.getNfNamingCode();
+ hql.append(" and a.nfNamingCode like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getSourceId()) {
+ String ver =alarmsHeader.getSourceId();
+ hql.append(" and a.sourceId like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getSourceName()) {
+ String ver =alarmsHeader.getSourceName();
+ hql.append(" and a.sourceName like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getReportingEntityId()) {
+ String ver =alarmsHeader.getReportingEntityId();
+ hql.append(" and a.reportingEntityId like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getReportingEntityName()) {
+ String ver =alarmsHeader.getReportingEntityName();
+ hql.append(" and a.reportingEntityName like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getPriority()) {
+ String ver =alarmsHeader.getPriority();
+ hql.append(" and a.priority like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getStartEpochMicrosec()) {
+ String ver =alarmsHeader.getStartEpochMicrosec();
+ hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getLastEpochMicroSec()) {
+ String ver =alarmsHeader.getLastEpochMicroSec();
+ hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getSequence()) {
+ String ver =alarmsHeader.getSequence();
+ hql.append(" and a.sequence like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getFaultFieldsVersion()) {
+ String ver =alarmsHeader.getFaultFieldsVersion();
+ hql.append(" and a.faultFieldsVersion like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getEventServrity()) {
+ String ver =alarmsHeader.getEventServrity();
+ hql.append(" and a.eventServrity like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getEventType()) {
+ String ver =alarmsHeader.getEventType();
+ hql.append(" and a.eventSourceType like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getEventCategory()) {
+ String ver =alarmsHeader.getEventCategory();
+ hql.append(" and a.eventCategory like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getAlarmCondition()) {
+ String ver =alarmsHeader.getAlarmCondition();
+ hql.append(" and a.alarmCondition like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getSpecificProblem()) {
+ String ver =alarmsHeader.getSpecificProblem();
+ hql.append(" and a.specificProblem like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getVfStatus()) {
+ String ver =alarmsHeader.getVfStatus();
+ hql.append(" and a.vfStatus = '"+ver+"'");
+ }
+ if(null!=alarmsHeader.getAlarmInterfaceA()) {
+ String ver =alarmsHeader.getAlarmInterfaceA();
+ hql.append(" and a.alarmInterfaceA like '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getStatus()) {
+ String ver =alarmsHeader.getStatus();
+ hql.append(" and a.status = '"+ver+"'");
+ }
+ if(null!=alarmsHeader.getCreateTime()) {
+ Date ver =alarmsHeader.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=alarmsHeader.getUpdateTime()) {
+ Date ver =alarmsHeader.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
}
logger.info("AlarmsHeaderServiceImpl queryAlarmsHeader: alarmsHeader={}", alarmsHeader);
Session session = sessionFactory.openSession();
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java index 6ef1cf46..dfd92d32 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java @@ -88,10 +88,35 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { }
- public int getAllCount() {
+ public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
try{
+ StringBuffer hql = new StringBuffer("select count(*) from AlarmsInformation a where 1=1");
+ if (null == alarmsInformation) {
+ //logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");
+ }else {
+ if(null!=alarmsInformation.getName()) {
+ String ver=alarmsInformation.getName();
+ hql.append(" and a.name like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getValue()) {
+ String ver=alarmsInformation.getValue();
+ hql.append(" and a.value like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getEventId()) {
+ String ver=alarmsInformation.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=alarmsInformation.getCreateTime()) {
+ Date ver =alarmsInformation.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getUpdateTime()) {
+ Date ver =alarmsInformation.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
Session session = sessionFactory.openSession();
- long q=(long)session.createQuery("select count(*) from AlarmsInformation").uniqueResult();
+ long q=(long)session.createQuery(hql.toString()).uniqueResult();
session.flush();
session.close();
return (int)q;
@@ -106,28 +131,34 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { public Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage,
int pageSize) {
Page<AlarmsInformation> page = new Page<AlarmsInformation>();
- int allRow =this.getAllCount();
+ int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
try{
StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
- logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
- }else if(null!=alarmsInformation.getName()) {
- String ver=alarmsInformation.getName();
- hql.append(" and a.name like '%"+ver+"%'");
- }else if(null!=alarmsInformation.getValue()) {
- String ver=alarmsInformation.getValue();
- hql.append(" and a.value like '%"+ver+"%'");
- }else if(null!=alarmsInformation.getEventId()) {
- String ver=alarmsInformation.getEventId();
- hql.append(" and a.eventId = '"+ver+"'");
- }else if(null!=alarmsInformation.getCreateTime()) {
- Date ver =alarmsInformation.getCreateTime();
- hql.append(" and a.createTime > '%"+ver+"%'");
- }else if(null!=alarmsInformation.getUpdateTime()) {
- Date ver =alarmsInformation.getUpdateTime();
- hql.append(" and a.updateTime like '%"+ver+"%'");
+ //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
+ }else {
+ if(null!=alarmsInformation.getName()) {
+ String ver=alarmsInformation.getName();
+ hql.append(" and a.name like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getValue()) {
+ String ver=alarmsInformation.getValue();
+ hql.append(" and a.value like '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getEventId()) {
+ String ver=alarmsInformation.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=alarmsInformation.getCreateTime()) {
+ Date ver =alarmsInformation.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=alarmsInformation.getUpdateTime()) {
+ Date ver =alarmsInformation.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
}
logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);
Session session = sessionFactory.openSession();
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 78205ec1..1dd783e0 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 @@ -91,10 +91,91 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { }
- public int getAllCount() {
+ public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {
try{
+ StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
+ if (null == performanceHeder) {
+ //logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!");
+ }else {
+ if(null!=performanceHeder.getVersion()) {
+ String ver=performanceHeder.getVersion();
+ hql.append(" and a.version like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getEventName()) {
+ String ver=performanceHeder.getEventName();
+ hql.append(" and a.eventName like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getDomain()) {
+ String ver=performanceHeder.getDomain();
+ hql.append(" and a.domain like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getEventId()) {
+ String ver=performanceHeder.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=performanceHeder.getNfcNamingCode()) {
+ String ver=performanceHeder.getNfcNamingCode();
+ hql.append(" and a.nfcNamingCode like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getNfNamingCode()) {
+ String ver=performanceHeder.getNfNamingCode();
+ hql.append(" and a.nfNamingCode like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getSourceId()) {
+ String ver =performanceHeder.getSourceId();
+ hql.append(" and a.sourceId like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getSourceName()) {
+ String ver =performanceHeder.getSourceName();
+ hql.append(" and a.sourceName like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getReportingEntityId()) {
+ String ver =performanceHeder.getReportingEntityId();
+ hql.append(" and a.reportingEntityId like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getReportingEntityName()) {
+ String ver =performanceHeder.getReportingEntityName();
+ hql.append(" and a.reportingEntityName like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getPriority()) {
+ String ver =performanceHeder.getPriority();
+ hql.append(" and a.priority like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getStartEpochMicrosec()) {
+ String ver =performanceHeder.getStartEpochMicrosec();
+ hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getLastEpochMicroSec()) {
+ String ver =performanceHeder.getLastEpochMicroSec();
+ hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getSequence()) {
+ String ver =performanceHeder.getSequence();
+ hql.append(" and a.sequence like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {
+ String ver =performanceHeder.getMeasurementsForVfScalingVersion();
+ hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getMeasurementInterval()) {
+ String ver =performanceHeder.getMeasurementInterval();
+ hql.append(" and a.measurementInterval like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getEventType()) {
+ String ver =performanceHeder.getEventType();
+ hql.append(" and a.eventType like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getCreateTime()) {
+ Date ver =performanceHeder.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getUpdateTime()) {
+ Date ver =performanceHeder.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
Session session = sessionFactory.openSession();
- long q=(long)session.createQuery("select count(*) from PerformanceHeader").uniqueResult();
+ long q=(long)session.createQuery(hql.toString()).uniqueResult();
session.flush();
session.close();
return (int)q;
@@ -109,70 +190,90 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService { public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage,
int pageSize) {
Page<PerformanceHeader> page = new Page<PerformanceHeader>();
- int allRow =this.getAllCount();
+ int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
try{
StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
- logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");
- }else if(null!=performanceHeder.getVersion()) {
- String ver=performanceHeder.getVersion();
- hql.append(" and a.version like '%"+ver+"%'");
- }else if(null!=performanceHeder.getEventName()) {
- String ver=performanceHeder.getEventName();
- hql.append(" and a.eventName like '%"+ver+"%'");
- }else if(null!=performanceHeder.getDomain()) {
- String ver=performanceHeder.getDomain();
- hql.append(" and a.domain like '%"+ver+"%'");
- }else if(null!=performanceHeder.getEventId()) {
- String ver=performanceHeder.getEventId();
- hql.append(" and a.eventId = '"+ver+"'");
- }else if(null!=performanceHeder.getNfcNamingCode()) {
- String ver=performanceHeder.getNfcNamingCode();
- hql.append(" and a.nfcNamingCode like '%"+ver+"%'");
- }else if(null!=performanceHeder.getNfNamingCode()) {
- String ver=performanceHeder.getNfNamingCode();
- hql.append(" and a.nfNamingCode like '%"+ver+"%'");
- }else if(null!=performanceHeder.getSourceId()) {
- String ver =performanceHeder.getSourceId();
- hql.append(" and a.sourceId like '%"+ver+"%'");
- }else if(null!=performanceHeder.getSourceName()) {
- String ver =performanceHeder.getSourceName();
- hql.append(" and a.sourceName like '%"+ver+"%'");
- }else if(null!=performanceHeder.getReportingEntityId()) {
- String ver =performanceHeder.getReportingEntityId();
- hql.append(" and a.reportingEntityId like '%"+ver+"%'");
- }else if(null!=performanceHeder.getReportingEntityName()) {
- String ver =performanceHeder.getReportingEntityName();
- hql.append(" and a.reportingEntityName like '%"+ver+"%'");
- }else if(null!=performanceHeder.getPriority()) {
- String ver =performanceHeder.getPriority();
- hql.append(" and a.priority like '%"+ver+"%'");
- }else if(null!=performanceHeder.getStartEpochMicrosec()) {
- String ver =performanceHeder.getStartEpochMicrosec();
- hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");
- }else if(null!=performanceHeder.getLastEpochMicroSec()) {
- String ver =performanceHeder.getLastEpochMicroSec();
- hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
- }else if(null!=performanceHeder.getSequence()) {
- String ver =performanceHeder.getSequence();
- hql.append(" and a.sequence like '%"+ver+"%'");
- }else if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {
- String ver =performanceHeder.getMeasurementsForVfScalingVersion();
- hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");
- }else if(null!=performanceHeder.getMeasurementInterval()) {
- String ver =performanceHeder.getMeasurementInterval();
- hql.append(" and a.measurementInterval like '%"+ver+"%'");
- }else if(null!=performanceHeder.getEventType()) {
- String ver =performanceHeder.getEventType();
- hql.append(" and a.eventType like '%"+ver+"%'");
- }else if(null!=performanceHeder.getCreateTime()) {
- Date ver =performanceHeder.getCreateTime();
- hql.append(" and a.createTime > '%"+ver+"%'");
- }else if(null!=performanceHeder.getUpdateTime()) {
- Date ver =performanceHeder.getUpdateTime();
- hql.append(" and a.updateTime like '%"+ver+"%'");
+ //logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");
+ }else {
+ if(null!=performanceHeder.getVersion()) {
+ String ver=performanceHeder.getVersion();
+ hql.append(" and a.version like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getEventName()) {
+ String ver=performanceHeder.getEventName();
+ hql.append(" and a.eventName like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getDomain()) {
+ String ver=performanceHeder.getDomain();
+ hql.append(" and a.domain like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getEventId()) {
+ String ver=performanceHeder.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=performanceHeder.getNfcNamingCode()) {
+ String ver=performanceHeder.getNfcNamingCode();
+ hql.append(" and a.nfcNamingCode like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getNfNamingCode()) {
+ String ver=performanceHeder.getNfNamingCode();
+ hql.append(" and a.nfNamingCode like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getSourceId()) {
+ String ver =performanceHeder.getSourceId();
+ hql.append(" and a.sourceId like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getSourceName()) {
+ String ver =performanceHeder.getSourceName();
+ hql.append(" and a.sourceName like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getReportingEntityId()) {
+ String ver =performanceHeder.getReportingEntityId();
+ hql.append(" and a.reportingEntityId like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getReportingEntityName()) {
+ String ver =performanceHeder.getReportingEntityName();
+ hql.append(" and a.reportingEntityName like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getPriority()) {
+ String ver =performanceHeder.getPriority();
+ hql.append(" and a.priority like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getStartEpochMicrosec()) {
+ String ver =performanceHeder.getStartEpochMicrosec();
+ hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getLastEpochMicroSec()) {
+ String ver =performanceHeder.getLastEpochMicroSec();
+ hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getSequence()) {
+ String ver =performanceHeder.getSequence();
+ hql.append(" and a.sequence like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getMeasurementsForVfScalingVersion()) {
+ String ver =performanceHeder.getMeasurementsForVfScalingVersion();
+ hql.append(" and a.measurementsForVfScalingVersion like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getMeasurementInterval()) {
+ String ver =performanceHeder.getMeasurementInterval();
+ hql.append(" and a.measurementInterval like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getEventType()) {
+ String ver =performanceHeder.getEventType();
+ hql.append(" and a.eventType like '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getCreateTime()) {
+ Date ver =performanceHeder.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=performanceHeder.getUpdateTime()) {
+ Date ver =performanceHeder.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
}
logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder);
Session session = sessionFactory.openSession();
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java index ecd697df..a1a9a0dd 100755 --- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java @@ -20,12 +20,10 @@ import java.util.ArrayList; import java.util.Date;
import java.util.List;
+import javax.persistence.Id;
import javax.transaction.Transactional;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
+import org.hibernate.*;
import org.onap.usecaseui.server.bean.PerformanceInformation;
import org.onap.usecaseui.server.service.PerformanceInformationService;
import org.onap.usecaseui.server.util.Page;
@@ -90,10 +88,35 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation }
- public int getAllCount() {
+ public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) {
try{
+ StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1");
+ if (null == performanceInformation) {
+ //logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!");
+ }else {
+ if(null!=performanceInformation.getName()) {
+ String ver=performanceInformation.getName();
+ hql.append(" and a.name like '%"+ver+"%'");
+ }
+ if(null!=performanceInformation.getValue()) {
+ String ver=performanceInformation.getValue();
+ hql.append(" and a.value like '%"+ver+"%'");
+ }
+ if(null!=performanceInformation.getEventId()) {
+ String ver=performanceInformation.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=performanceInformation.getCreateTime()) {
+ Date ver =performanceInformation.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=performanceInformation.getUpdateTime()) {
+ Date ver =performanceInformation.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
Session session = sessionFactory.openSession();
- long q=(long)session.createQuery("select count(*) from PerformanceInformation").uniqueResult();
+ long q=(long)session.createQuery(hql.toString()).uniqueResult();
session.flush();
session.close();
return (int)q;
@@ -108,35 +131,42 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation public Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation,
int currentPage, int pageSize) {
Page<PerformanceInformation> page = new Page<PerformanceInformation>();
- int allRow =this.getAllCount();
+ int allRow =this.getAllCount(performanceInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
try{
- StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1");
+ StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 ");
if (null == performanceInformation) {
- logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");
- }else if(null!=performanceInformation.getName()) {
- String ver=performanceInformation.getName();
- hql.append(" and a.name like '%"+ver+"%'");
- }else if(null!=performanceInformation.getValue()) {
- String ver=performanceInformation.getValue();
- hql.append(" and a.value like '%"+ver+"%'");
- }else if(null!=performanceInformation.getEventId()) {
- String ver=performanceInformation.getEventId();
- hql.append(" and a.eventId = '"+ver+"'");
- }else if(null!=performanceInformation.getCreateTime()) {
- Date ver =performanceInformation.getCreateTime();
- hql.append(" and a.createTime > '%"+ver+"%'");
- }else if(null!=performanceInformation.getUpdateTime()) {
- Date ver =performanceInformation.getUpdateTime();
- hql.append(" and a.updateTime like '%"+ver+"%'");
- }
+ //logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");
+ }else {
+ if(null!=performanceInformation.getName()) {
+ String ver=performanceInformation.getName();
+ hql.append(" and a.name like '%"+ver+"%'");
+ }
+ if(null!=performanceInformation.getValue()) {
+ String ver=performanceInformation.getValue();
+ hql.append(" and a.value like '%"+ver+"%'");
+ }
+ if(null!=performanceInformation.getEventId()) {
+ String ver=performanceInformation.getEventId();
+ hql.append(" and a.eventId = '"+ver+"'");
+ }
+ if(null!=performanceInformation.getCreateTime()) {
+ Date ver =performanceInformation.getCreateTime();
+ hql.append(" and a.createTime > '%"+ver+"%'");
+ }
+ if(null!=performanceInformation.getUpdateTime()) {
+ Date ver =performanceInformation.getUpdateTime();
+ hql.append(" and a.updateTime like '%"+ver+"%'");
+ }
+ }
logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation);
Session session = sessionFactory.openSession();
Query query = session.createQuery(hql.toString());
query.setFirstResult(offset);
query.setMaxResults(pageSize);
List<PerformanceInformation> list= query.list();
+
page.setPageNo(currentPage);
page.setPageSize(pageSize);
page.setTotalRecords(allRow);
@@ -171,7 +201,36 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation }
-
-
-
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<PerformanceInformation> queryDateBetween(String eventId,Date startDate, Date endDate) {
+ try {
+ List<PerformanceInformation> list = new ArrayList<>();
+ Session session = sessionFactory.openSession();
+ Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate");
+ list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();
+ session.close();
+ return list;
+ } catch (Exception e) {
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryId. Details:" + e.getMessage());
+ return null;
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate){
+
+ try(Session session = sessionFactory.openSession();) {
+ int sum = 0;
+ Query query = session.createQuery("select sum(a.value) from PerformanceInformation a where a.eventId = :eventId and a.name = :name and a.createTime BETWEEN :startDate and :endDate");
+ sum = Integer.parseInt(query.setParameter("eventId",eventId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());
+ return sum;
+ } catch (Exception e) {
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryId. Details:" + e.getMessage());
+ return 0;
+ }
+ }
+
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java b/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java index f61094ca..3184dc01 100755 --- a/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java @@ -52,7 +52,7 @@ public class DateUtils { ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()-1); if(hour >= 0){ if(hour == 0) - ldt = ldt.withHour(1); + ldt = ldt.withHour(0); } else ldt = ldt.withHour(ldt.getHour()-1); if(minute >= 0){ @@ -65,7 +65,7 @@ public class DateUtils { ldt = ldt.withSecond(0); } else ldt = ldt.withMinute(ldt.getSecond()-1); - return ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + return ldt.format(DateTimeFormatter.ofPattern(Constant.DATE_FORMAT)); } @@ -84,7 +84,7 @@ public class DateUtils { * @throws ParseException */ public static Date initProcessDate(Date d,int year,int month,int day,int hour,int minute,int second) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat(Constant.DATE_FORMAT); Calendar c = Calendar.getInstance(); c.setTime(d); if(year >= 0){ @@ -133,32 +133,51 @@ public class DateUtils { ZoneId zone = ZoneId.systemDefault(); LocalDateTime ldt = LocalDateTime.ofInstant(instant,zone); switch (unit.toLowerCase()){ + case "year": + ldt = ldt.withYear(ldt.getYear()+addVal); + break; case "month": - ldt = ldt.withMonth(ldt.getMonthValue()+addVal); + if (ldt.getMonthValue() + addVal < 13) { + ldt = ldt.withMonth(ldt.getMonthValue() + addVal); + }else{ + ldt = ldt.withYear(ldt.getYear()+1).withMonth(1); + } break; case "day": - ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()+addVal); + if(ldt.getDayOfMonth()+addVal <= ldt.getMonth().length((ldt.getYear()%4==0?true:false))){ + ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()+addVal); + }else{ + ldt = ldt.withMonth(ldt.getMonthValue()+1).withDayOfMonth(1); + } break; case "hour": - ldt = ldt.withHour(ldt.getHour()+addVal); + if (ldt.getHour()+addVal < 24) + ldt = ldt.withHour(ldt.getHour()+addVal); + else{ + ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()+1).withHour(1); + } break; case "minute": - ldt = ldt.withMinute(ldt.getMinute()+addVal); + if (ldt.getMinute()+addVal < 60) + ldt = ldt.withMinute(ldt.getMinute()+addVal); + else{ + ldt = ldt.withMinute(0).withHour(ldt.getHour()+1); + } break; } - return ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + return ldt.format(DateTimeFormatter.ofPattern(Constant.DATE_FORMAT)); } public static String dateToString(Date d){ - return new SimpleDateFormat(Constant.DATE_FROMAT).format(d); + return new SimpleDateFormat(Constant.DATE_FORMAT).format(d); } public static Date stringToDate(String d) throws ParseException { - return new SimpleDateFormat(Constant.DATE_FROMAT).parse(d); + return new SimpleDateFormat(Constant.DATE_FORMAT).parse(d); } public static Date now() throws ParseException { - return new SimpleDateFormat(Constant.DATE_FROMAT).parse(dateToString(new Date())); + return new SimpleDateFormat(Constant.DATE_FORMAT).parse(dateToString(new Date())); } } diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java index cc59616b..a674cf2e 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java @@ -15,6 +15,7 @@ */ package org.onap.usecaseui.server.controller; +import com.fasterxml.jackson.core.JsonProcessingException; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.usecaseui.server.bean.AlarmsHeader; @@ -41,22 +42,22 @@ public class AlarmControllerTest { AlarmController alarmController; @Test - public void getDataNotParam(){ + public void getDataNotParam() throws JsonProcessingException { System.out.println(alarmController.getAlarmData(null,null,null,null,null,null,null,1,100)); } @Test - public void getDataCarryParam(){ + public void getDataCarryParam() throws JsonProcessingException { System.out.println(alarmController.getAlarmData("110","a","drop","down","1506331166000","1","2",1,100)); } @Test - public void csvFile(){ + public void csvFile() throws JsonProcessingException { System.out.println(alarmController.generateCsvFile(null,new String[]{"110"})); } @Test - public void update(){ + public void update() throws JsonProcessingException { System.out.println(alarmController.updateStatus(null,new String[]{"110"},new String[]{"1"},"s")); System.out.println(alarmController.updateStatus(null,new String[]{"110","1101"},new String[]{"1","1"},"many")); System.out.println(alarmController.updateStatus(null,new String[]{"110"},new String[]{"1"},"vf")); diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java index c7461013..4b90e86e 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java @@ -46,7 +46,7 @@ public class PerformanceControllerTest { private PerformanceController performanceController; @Test - public void getPerformanceData(){ + public void getPerformanceData() throws JsonProcessingException { System.out.println(performanceController.getPerformanceData(null,1,100,null,null,null,null,null)); } @@ -64,7 +64,7 @@ public class PerformanceControllerTest { } @Test - public void generateDiaCsvFile() { + public void generateDiaCsvFile() throws JsonProcessingException { Map<String,String> p = new HashMap<>(); p.put("eventId","110"); p.put("name","110"); diff --git a/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java index f8f61b32..5616ef23 100755 --- a/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/AlarmsHeaderServiceTest.java @@ -38,7 +38,7 @@ public class AlarmsHeaderServiceTest { a.setEventName("a"); a.setStatus("1"); a.setVfStatus("1"); - a.setEventId("11011"); + a.setEventId("1119"); a.setDomain("asb"); a.setEventCategory("s"); a.setAlarmCondition("ea"); @@ -129,8 +129,11 @@ public class AlarmsHeaderServiceTest { @Test public void queryEventName() throws ParseException { AlarmsHeader a=new AlarmsHeader(); - a.setEventName("a"); - System.out.println(alarmsHeaderService.queryAlarmsHeader(a,1,100).getList().size()); + a.setEventId("110"); + a.setEventName("asdasds"); + // a.setVfStatus("2"); + System.out.println(alarmsHeaderService.queryAlarmsHeader(a,1,100).getList().size()); + alarmsHeaderService.queryAlarmsHeader(a,1,100).getList().forEach( as->System.out.println(as.toString())); } @Test diff --git a/server/src/test/java/org/onap/usecaseui/server/service/PerformanceHeaderServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/PerformanceHeaderServiceTest.java index 7d44315b..9705c6b6 100755 --- a/server/src/test/java/org/onap/usecaseui/server/service/PerformanceHeaderServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/PerformanceHeaderServiceTest.java @@ -38,7 +38,7 @@ public class PerformanceHeaderServiceTest { public void save() throws ParseException { PerformanceHeader p = new PerformanceHeader(); p.setCreateTime(DateUtils.now()); - p.setEventId("1101"); + p.setEventId("2202"); p.setEventName("fxc"); p.setDomain("asb"); p.setCreateTime(DateUtils.now()); @@ -109,7 +109,7 @@ public class PerformanceHeaderServiceTest { @Test public void get() throws ParseException { performanceHeaderService.queryId(new String[]{"110"}) - .forEach(pe -> System.out.println(pe)); + .forEach(pe -> System.out.println(pe.getCreateTime())); } @Test diff --git a/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java index 3c710e93..80f8743e 100755 --- a/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/PerformanceInformationServiceTest.java @@ -24,6 +24,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.text.ParseException; +import java.util.List; +import java.util.Random; @RunWith(SpringRunner.class) @SpringBootTest @@ -36,12 +38,24 @@ public class PerformanceInformationServiceTest { @Test public void save() throws ParseException { PerformanceInformation a = new PerformanceInformation(); - a.setEventId("112"); - a.setName("efw"); - a.setValue("fre"); - a.setCreateTime(DateUtils.now()); - a.setUpdateTime(DateUtils.now()); - System.out.println(performanceInformationService.savePerformanceInformation(a)); + for (int y = 1 ; y < 13 ; y++){ + for (int m = 1 ;m < 31 ; m++){ + for (int j = 0 ; j < 24 ;j++){ + for (int i = 14 ; i <= 59;i += 15){ + a.setEventId("2202"); + a.setName("memory"); + a.setValue((i+j+new Random().nextInt(60))+""); + a.setCreateTime(DateUtils.stringToDate("2016-"+y+"-"+m+" "+j+":"+i+":00")); + a.setUpdateTime(DateUtils.now()); + System.out.println(performanceInformationService.savePerformanceInformation(a)); + } + } + + } + + } + + } @Test @@ -57,25 +71,29 @@ public class PerformanceInformationServiceTest { @Test public void update1() throws ParseException { - PerformanceInformation a = new PerformanceInformation(); - a.setEventId("110"); - a.setName("efw"); - a.setValue("fko11"); - System.out.println(performanceInformationService.updatePerformanceInformation(a)); + List<PerformanceInformation> as = performanceInformationService.queryId(new String[]{"2202"}); + as.forEach( a ->{ + try { + a.setCreateTime(DateUtils.stringToDate(DateUtils.addDate(a.getCreateTime(),"day",1))); + } catch (ParseException e) { + e.printStackTrace(); + } + System.out.println(performanceInformationService.updatePerformanceInformation(a)); + }); } @Test public void get() throws ParseException { - performanceInformationService.queryId(new String[]{"110"}) - .forEach(ai -> System.out.println(ai)); + performanceInformationService.queryId(new String[]{"2202"}) + .forEach(ai -> System.out.println(ai.getCreateTime())); } @Test public void queryEventId() throws ParseException { PerformanceInformation a = new PerformanceInformation(); - a.setEventId("110"); + // a.setEventId("2202"); performanceInformationService.queryPerformanceInformation(a,1,100) - .getList().forEach( al -> System.out.println(al)); + .getList().forEach( al -> System.out.println(al.getValue())); } @Test public void queryName() throws ParseException { @@ -106,4 +124,13 @@ public class PerformanceInformationServiceTest { .getList().forEach( al -> System.out.println(al)); } + @Test + public void between() throws ParseException { + performanceInformationService.queryDateBetween("2202",DateUtils.stringToDate("2017-10-15 01:00:00"),DateUtils.stringToDate("2017-10-15 02:00:00")).forEach( p -> System.out.println(p)); + } + + @Test + public void sum() throws ParseException { + System.out.println(performanceInformationService.queryDataBetweenSum("2202","cpu",DateUtils.stringToDate("2017-10-18 09:00:00"),DateUtils.stringToDate("2017-10-18 10:00:00"))); + } } diff --git a/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java b/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java index 810a0dcd..c4b363df 100755 --- a/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/util/DateUtilsTest.java @@ -77,13 +77,17 @@ public class DateUtilsTest { @Test public void addDate(){ try { - System.out.println(DateUtils.addDate(new Date(),"hour",5)); - System.out.println(DateUtils.addDate(new Date(),"day",5)); - System.out.println(DateUtils.addDate(new Date(),"month",5)); - System.out.println(DateUtils.addDate(new Date(),"year",5)); + LocalDateTime localDateTime = LocalDateTime.now(); + System.out.println(localDateTime.withDayOfMonth(0)); + System.out.println(DateUtils.addDate(new Date(),"day",1)); + /*System.out.println(DateUtils.addDate(new Date(),"month",1)); + System.out.println(DateUtils.addDate(new Date(),"year",-1));*/ } catch (ParseException e) { e.printStackTrace(); } } + + + } |