Upload monitor service code for usecase-ui 93/13893/1
authorshentao <shentao@chinamobile.com>
Wed, 20 Sep 2017 13:32:03 +0000 (21:32 +0800)
committershentao <shentao@chinamobile.com>
Wed, 20 Sep 2017 13:32:14 +0000 (21:32 +0800)
Change-Id: I0e437747bbeba94d93da47b9b7dc1e4f53cc78f3
Issue-Id: USECASEUI-41
Signed-off-by: shentao <shentao@chinamobile.com>
31 files changed:
pom.xml
src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
src/main/java/org/onap/usecaseui/server/bean/ActiveAlarmInfo.java
src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java
src/main/java/org/onap/usecaseui/server/bean/AlarmsInformation.java
src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java
src/main/java/org/onap/usecaseui/server/bean/PerformanceInformation.java
src/main/java/org/onap/usecaseui/server/constant/Constant.java
src/main/java/org/onap/usecaseui/server/controller/AlarmController.java
src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java
src/main/java/org/onap/usecaseui/server/dao/UsecaseuiDataSource.java
src/main/java/org/onap/usecaseui/server/exception/ErrorCodeException.java
src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
src/main/java/org/onap/usecaseui/server/listener/UsecaseServerEventListener.java
src/main/java/org/onap/usecaseui/server/security/RestfulSecurityConfig.java
src/main/java/org/onap/usecaseui/server/service/AlarmService.java
src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java
src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java
src/main/java/org/onap/usecaseui/server/service/PerformanceHeaderService.java
src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java
src/main/java/org/onap/usecaseui/server/service/impl/AlarmServiceImpl.java
src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
src/main/java/org/onap/usecaseui/server/service/impl/InitializationServiceImpl.java
src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
src/main/java/org/onap/usecaseui/server/util/CSVUtils.java
src/main/java/org/onap/usecaseui/server/util/DataUtils.java [moved from src/main/java/org/onap/usecaseui/server/util/BeanUtils.java with 94% similarity]
src/main/java/org/onap/usecaseui/server/util/Page.java [new file with mode: 0644]
src/main/resources/application.properties
src/test/java/org/onap/usecaseui/server/UsecaseuiServerApplicationTests.java

diff --git a/pom.xml b/pom.xml
index d82d639..fedfb8e 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.3</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
index 83b09dc..c12bb24 100644 (file)
@@ -22,7 +22,7 @@ import org.springframework.context.annotation.ComponentScan;
 import org.springframework.web.client.RestTemplate;
 
 @SpringBootApplication
-@ComponentScan(basePackages = "org.openecomp.usecaseui.server")
+@ComponentScan(basePackages = "org.onap.usecaseui.server")
 public class UsecaseuiServerApplication {
 
     @Bean
index c11eb5e..d204d68 100644 (file)
  */
 package org.onap.usecaseui.server.bean;
 
-import java.io.Serializable;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
-/**
- * <活跃告警管理>
- * @author donghu
- * @version [版本号, 2017年8月17日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
+
 @Entity
 @Table(name = "EP_ACTIVE_ALARM")
-public class ActiveAlarmInfo implements Serializable
+public class ActiveAlarmInfo 
 {
-       /**
-        * 主键
-        */
+
        @Id
        @Column(name = "id", nullable = true)
        private String id;
 
-    /**
-        * 设备名称
-        */
+
        @Column(name = "devName")
        private String devName;
        
-       /**
-     * 设备IP
-     */
+
     @Column(name = "devIp")
     private String devIp;
     
-    /**
-     * 设备序列号
-     */
+
     @Column(name = "serialNumber")
     private String serialNumber;
     
-       /**
-     * 告警产生时间
-     */
+
        @Column(name = "alarmRaisedTime")
        private String alarmRaisedTime;
        
-    /**
-     * 告警更新时间
-     */
+
     @Column(name = "alarmChangedTime")
     private String alarmChangedTime;
 
-       /**
-     * 告警序列号
-     */
+
        @Column(name = "alarmIdentifier")
        private String alarmIdentifier;
        
-       /**
-     * 通知类型
-     */
+
     @Column(name = "notificationType")
     private String notificationType;
 
-       /**
-     * 告警对象实例
-     */
+
        @Column(name = "managedObjectInstance")
        private String managedObjectInstance;
 
-       /**
-     * 告警类型
-     */
+
        @Column(name = "eventType")
        private Integer eventType;
 
-        /**
-     * 告警可能原因
-     */
+
        @Column(name = "probableCause")
        private String probableCause;
 
-       /**
-     * 告警描述
-     */
+
     @Column(name = "specificProblem")
     private String specificProblem;
 
-       /**
-     * 告警级别
-     */
+
        @Column(name = "perceivedSeverity")
        private String perceivedSeverity;
 
-       /**
-     * 告警附加文本
-     */
+
        @Column(name = "additionalText")
        private String additionalText;
 
-       /**
-     * 告警附加信息
-     */
+
        @Column(name = "additionalInformation")
        private String additionalInformation;
        
-       /**
-     * 告警清除类型
-     */
+
     @Column(name = "clearedManner")
     private String clearedManner;
        
-    /**
-     * 告警状态
-     */
+
        @Column(name = "alarmState")
        private Integer alarmState;
        
-    /**
-        * 确认时间
-        */
+
        @Column(name = "ackTime")
        private String ackTime;
        
-       /**
-        * 确认人
-        */
+
        @Column(name = "ackUser")
     private String ackUser;
        
index 7634403..1bfc13c 100644 (file)
@@ -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{
@@ -103,7 +99,7 @@ public class AlarmsHeader implements Serializable{
        private String alarmInterfaceA;
        
        @Column(name = "status")
-       private int status;
+       private String status;
        
        @Column(name = "createTime")
        private Date createTime;
@@ -295,11 +291,11 @@ public class AlarmsHeader implements Serializable{
                this.alarmInterfaceA = alarmInterfaceA;
        }
 
-       public int getStatus() {
+       public String getStatus() {
                return status;
        }
 
-       public void setStatus(int status) {
+       public void setStatus(String status) {
                this.status = status;
        }
 
index 9648921..7a44a04 100644 (file)
@@ -23,11 +23,7 @@ import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
-/**
- * 
- * @author xuekui
- *
- */
+
 @Entity
 @Table(name="alarms_additionalinformation")
 public class AlarmsInformation implements Serializable{
index a72864b..acaff0e 100644 (file)
@@ -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 PerformanceHeader implements Serializable{
index fec3237..0e9124b 100644 (file)
@@ -23,11 +23,7 @@ import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
-/**
- * 
- * @author xuekui
- *
- */
+
 @Entity
 @Table(name="alarms_additionalinformation")
 public class PerformanceInformation implements Serializable{
index 74f618c..8377dd5 100644 (file)
  */
 package org.onap.usecaseui.server.controller;
 
-import java.io.IOException;
-
+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.onap.usecaseui.server.bean.AlarmsHeader;
+import org.onap.usecaseui.server.bean.AlarmsInformation;
+import org.onap.usecaseui.server.service.AlarmsHeaderService;
+import org.onap.usecaseui.server.service.AlarmsInformationService;
 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.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-/**
- * <告警rest控制器实现>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 @Controller
 @org.springframework.context.annotation.Configuration
@@ -47,28 +61,79 @@ public class AlarmController
 
     private static final Logger logger = LoggerFactory.getLogger(AlarmController.class);
 
+    @Resource(name = "AlarmsHeaderService")
+    private AlarmsHeaderService alarmsHeaderService;
+
+    @Resource(name = "AlarmsInformationService")
+    private AlarmsInformationService alarmsInformationService;
+
 
     @ResponseBody
     @RequestMapping(value = {"/alarm/getData"}, method = RequestMethod.GET , produces = "application/json")
-    public String getAlarmData(HttpServletRequest request){
-        String eventId = request.getParameter("eventId");
-        String vfStatus = request.getParameter("vfStatus");
-        String status = request.getParameter("status");
-
-        return "";
+    public String getAlarmData(HttpServletRequest request) throws JsonProcessingException {
+        String eventId = request.getParameter("ALARM_eventId");
+        String vfStatus = request.getParameter("ALARM_vfStatus");
+        String status = request.getParameter("ALARM_status");
+        String eventName = request.getParameter("ALARM_eventName");
+        String name = request.getParameter("ALARM_name");
+        String value = request.getParameter("ALARM_value");
+        int currentPage = Integer.parseInt(request.getParameter("ALARM_currentPage"));
+        int pageSize = Integer.parseInt(request.getParameter("ALARM_pageSize"));
+        AlarmsHeader alarmsHeader = new AlarmsHeader();
+        AlarmsInformation alarmsInformation = new AlarmsInformation();
+        if (null != eventId){
+            alarmsHeader.setEventId(eventId);
+            alarmsInformation.setEventId(eventId);
+        }
+        if (null != vfStatus)
+            alarmsHeader.setVfStatus(vfStatus);
+        if (null != status)
+            alarmsHeader.setStatus(status);
+        if (null != eventName)
+            alarmsHeader.setEventName(eventName);
+        if (null != name)
+            alarmsInformation.setName(name);
+        if (null != value)
+            alarmsInformation.setValue(value);
+        List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(alarmsHeader,currentPage,pageSize).getList();
+        List<AlarmsInformation> alarmsInformations = alarmsInformationService.queryAlarmsInformation(alarmsInformation,currentPage,pageSize).getList();
+        Map<String,Object> maps = new HashMap<>();
+        if (null != alarmsHeaders && alarmsHeaders.size() > 0)
+            maps.put("alarms_header",alarmsHeaders);
+        if (null != alarmsInformations && alarmsInformations.size() > 0)
+            maps.put("alarms_information",alarmsInformations);
+        return new ObjectMapper().writeValueAsString(maps);
     }
 
     @RequestMapping(value = { "/alarm/genCsv" } , method = RequestMethod.GET , produces = "application/json")
     public String generateCsvFile(HttpServletRequest request){
-        String result = "{result:failure}";
-        String ids = request.getParameter("ids");
+        String[] headers = new String[]{"version",
+                "eventName","domain","eventId","eventType","nfcNamingCode",
+                "nfNamingCode","sourceId","sourceName","reportingEntityId",
+                "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
+                "sequence","measurementsForVfScalingVersion","measurementInterval","value","name",
+                "createTime","updateTime"};
+        String event_ids = request.getParameter("ids");
+        String[] eventId = event_ids.split(",");
 
-        return result;
+        return "";
     }
 
+
     @RequestMapping(value = { "/alarm/updateStatus" } , method = RequestMethod.GET , produces = "application/json")
     public String updateStatus(HttpServletRequest request){
-        return "";
+        String id = request.getParameter("ALARM_eventId");
+        String vfStatus = request.getParameter("ALARM_vfstatus");
+        String status = request.getParameter("ALARM_status");
+        AlarmsHeader alarmsHeader = new AlarmsHeader();
+        if (null != id)
+            alarmsHeader.setEventId(id);
+        if (null != vfStatus)
+            alarmsHeader.setVfStatus(vfStatus);
+        if (null != status)
+            alarmsHeader.setStatus(status);
+        String result = alarmsHeaderService.updateAlarmsHeader(alarmsHeader);
+        return result;
     }
 
 
index 6732bc9..bd39843 100644 (file)
  */
 package org.onap.usecaseui.server.controller;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.usecaseui.server.bean.PerformanceHeader;
+import org.onap.usecaseui.server.bean.PerformanceInformation;
+import org.onap.usecaseui.server.service.PerformanceHeaderService;
+import org.onap.usecaseui.server.service.PerformanceInformationService;
 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;
@@ -24,33 +32,133 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import javax.xml.crypto.Data;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 @Controller
 @Configuration
 @EnableAspectJAutoProxy
 public class PerformanceController {
 
+    @Resource(name = "PerformanceHeaderService")
+    private PerformanceHeaderService performanceHeaderService;
+
+    @Resource(name = "PerformanceInformationService")
+    private PerformanceInformationService performanceInformationService;
+
+    private final String csvPath = "";
+
     private Logger looger = LoggerFactory.getLogger(PerformanceController.class);
 
     @ResponseBody
     @RequestMapping(value = {"/pro/getData"},method = RequestMethod.GET, produces = "application/json")
-    public String getPerformanceData(HttpServletRequest request){
-
-        return "";
+    public String getPerformanceData(HttpServletRequest request) throws JsonProcessingException {
+        String eventId = request.getParameter("PERFORMANCE_eventId");
+        String eventName = request.getParameter("PERFORMANCE_eventName");
+        String name = request.getParameter("PERFORMANCE_name");
+        String value = request.getParameter("PERFORMANCE_value");
+        int currentPage = Integer.parseInt(request.getParameter("PERFORMANCE_currentPage"));
+        int pageSize = Integer.parseInt(request.getParameter("PERFORMANCE_pageSize"));
+        PerformanceHeader performanceHeader = new PerformanceHeader();
+        PerformanceInformation performanceInformation = new PerformanceInformation();
+        if (null != eventId){
+            performanceHeader.setEventId(eventId);
+            performanceInformation.setEventId(eventId);
+        }
+        if (null != eventName)
+            performanceHeader.setEventName(eventName);
+        if (null != name)
+            performanceInformation.setName(name);
+        if (null != value)
+            performanceInformation.setValue(value);
+        List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(performanceHeader,currentPage,pageSize).getList();
+        List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(performanceInformation,currentPage,pageSize).getList();
+        Map<String,Object> maps = new HashMap<>();
+        if (null != performanceHeaders && performanceHeaders.size() > 0)
+            maps.put("performance_header",performanceHeaders);
+        if (null != performanceInformations && performanceInformations.size() > 0)
+            maps.put("performance_information",performanceInformations);
+        return new ObjectMapper().writeValueAsString(maps);
     }
 
     @RequestMapping(value = {"/pro/genCsv"}, method = RequestMethod.GET, produces = "application/json")
     public String generateCsvFile(HttpServletRequest request){
-        String[] headers = new String[]{};
+        String[] headers = new String[]{"version",
+                "eventName","domain","eventId","eventType","nfcNamingCode",
+                "nfNamingCode","sourceId","sourceName","reportingEntityId",
+                "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
+                "sequence","measurementsForVfScalingVersion","measurementInterval","value","name",
+                "createTime","updateTime"};
+        List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(null,1,100).getList();
+        List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(null,1,100).getList();
+        List<String[]> csvData = new ArrayList<>();
+
         return "";
     }
 
-    @RequestMapping(value = {"/pro/genDia"}, method = RequestMethod.GET, produces = "application/json")
-    public String generateDiagram(HttpServletRequest request){
+    @RequestMapping(value = {"/pro/genDiaCsv"}, method = RequestMethod.GET, produces = "application/json")
+    public String generateDiaCsvFile(HttpServletRequest request){
+        String[] headers = new String[]{"","","",""};
+        List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(null,1,100).getList();
+        List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(null,1,100).getList();
+        List<String[]> csvData = new ArrayList<>();
 
         return "";
     }
 
+    @ResponseBody
+    @RequestMapping(value = {"/pro/genDia"}, method = RequestMethod.GET, produces = "application/json")
+    public String generateDiagram(HttpServletRequest request) throws ParseException, JsonProcessingException {
+        String id = request.getParameter("PERFORMANCE_id");
+        String data = request.getParameter("PERFORMANCE_data");
+        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
+        Date beginDate = new Date();
+        Calendar date = Calendar.getInstance();
+        date.setTime(beginDate);
+        PerformanceInformation p = new PerformanceInformation();
+        p.setEventId(id);
+        if ("hour".equals(data)){
+            date.set(Calendar.DATE, date.get(Calendar.HOUR) - 1);
+            Date endDate = dft.parse(dft.format(date.getTime()));
+            p.setCreateTime(endDate);
+        }
+        if ("day".equals(data)){
+            date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
+            Date endDate = dft.parse(dft.format(date.getTime()));
+            p.setCreateTime(endDate);
+        }
+        if ("month".equals(data)){
+            date.set(Calendar.DATE, date.get(Calendar.MONTH) - 1);
+            Date endDate = dft.parse(dft.format(date.getTime()));
+            p.setCreateTime(endDate);
+        }
+        if ("year".equals(data)){
+            date.set(Calendar.DATE, date.get(Calendar.YEAR) - 1);
+            Date endDate = dft.parse(dft.format(date.getTime()));
+            p.setCreateTime(endDate);
+        }
+        List<PerformanceInformation> informationList = performanceInformationService.queryPerformanceInformation(p,1,4).getList();
+        return new ObjectMapper().writeValueAsString(informationList);
+    }
+
 
 }
index 4ac6251..475adc0 100644 (file)
@@ -22,14 +22,7 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.jdbc.datasource.DriverManagerDataSource;
 import org.springframework.stereotype.Component;
 
-/**
- * <一句话功能简述>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
+
 @Component
 public class UsecaseuiDataSource
 {
index 65bc776..b4850fc 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.onap.usecaseui.server.exception;
 
+
 public class ErrorCodeException extends Exception
 {
     private static final long serialVersionUID = 3220072444842529499L;
index 292b000..70a3bce 100644 (file)
@@ -25,14 +25,7 @@ import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
 import org.springframework.orm.jpa.JpaTransactionManager;
 import org.springframework.transaction.PlatformTransactionManager;
 
-/**
- * <Hibernate配置>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
+
 @org.springframework.context.annotation.Configuration
 public class HibernateConfiguration
 {
@@ -45,7 +38,7 @@ public class HibernateConfiguration
         LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
         sessionFactory.setDataSource(dataSource);
         sessionFactory.setHibernateProperties(hibernateProperties());
-        sessionFactory.setPackagesToScan(new String[] {"org.openecomp.usecaseui.server.bean"});
+        sessionFactory.setPackagesToScan(new String[] {"org.onap.usecaseui.server.bean"});
         return sessionFactory;
     }
 
index 2590d2c..5038c46 100644 (file)
@@ -22,14 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.ApplicationListener;
 
-/**
- * <一句话功能简述>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
+
 public class UsecaseServerEventListener implements ApplicationListener<ApplicationReadyEvent>
 {
     private static final Logger logger = LoggerFactory.getLogger(UsecaseServerEventListener.class);
index 25c2364..0363b81 100644 (file)
@@ -24,14 +24,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
-/**
- * <一句话功能简述>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月21日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
+
 //@Configuration
 //@EnableWebSecurity
 public class RestfulSecurityConfig extends WebSecurityConfigurerAdapter
index 5f00227..0834cec 100644 (file)
@@ -17,14 +17,6 @@ package org.onap.usecaseui.server.service;
 
 import org.onap.usecaseui.server.bean.ActiveAlarmInfo;
 
-/**
- * <一句话功能简述>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
 public interface AlarmService
 {
     String hello();
index 0c017af..7ea8aec 100644 (file)
@@ -15,9 +15,9 @@
  */
 package org.onap.usecaseui.server.service;
 
-import java.util.List;
 
 import org.onap.usecaseui.server.bean.AlarmsHeader;
+import org.onap.usecaseui.server.util.Page;
 
 public interface AlarmsHeaderService {
     
@@ -25,6 +25,8 @@ public interface AlarmsHeaderService {
     
     String updateAlarmsHeader(AlarmsHeader alarmsHeader);
     
-    List<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader);
+    int getAllCount();
+    
+    Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader,int currentPage,int pageSize);
     
 }
index 126eb18..a9e01a5 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.usecaseui.server.service;
 
 import org.onap.usecaseui.server.bean.AlarmsInformation;
+import org.onap.usecaseui.server.util.Page;
 
 
 public interface AlarmsInformationService {
@@ -24,4 +25,7 @@ public interface AlarmsInformationService {
     
     String updateAlarmsInformation(AlarmsInformation alarmsInformation);
     
+    int getAllCount();
+    
+    Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation,int currentPage,int pageSize);
 }
index 04de043..ed4226c 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.usecaseui.server.service;
 
 import org.onap.usecaseui.server.bean.PerformanceHeader;
+import org.onap.usecaseui.server.util.Page;
 
 
 public interface PerformanceHeaderService {
@@ -24,4 +25,7 @@ public interface PerformanceHeaderService {
     
     String updatePerformanceHeader(PerformanceHeader performanceHeder);
     
+    int getAllCount();
+    
+    Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder,int currentPage,int pageSize);
 }
index 545c0f0..51c0e1a 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.usecaseui.server.service;
 
 import org.onap.usecaseui.server.bean.PerformanceInformation;
+import org.onap.usecaseui.server.util.Page;
 
 
 public interface PerformanceInformationService {
@@ -24,4 +25,7 @@ public interface PerformanceInformationService {
     
     String updatePerformanceInformation(PerformanceInformation performanceInformation);
     
+    int getAllCount();
+    
+    Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation,int currentPage,int pageSize);
 }
index 6cc8de1..4e0f8f9 100644 (file)
@@ -30,14 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
 
-/**
- * <告警接口实现类>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
+
 @Service("AlarmService")
 @Transactional
 @org.springframework.context.annotation.Configuration
@@ -54,13 +47,7 @@ public class AlarmServiceImpl implements AlarmService
         return "Hello";
     }
 
-    /**
-     * <保存活跃告警信息>
-     * <功能详细描述>
-     * @param acAlarmInfo 活跃告警对象
-     * @return 对象id
-     * @see [类、类#方法、类#成员]
-     */
+
     @Transactional
     public String saveActiveAlarmInfo(ActiveAlarmInfo acAlarmInfo)
     {
index 8e41968..d0e571a 100644 (file)
 package org.onap.usecaseui.server.service.impl;
 
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
 import javax.transaction.Transactional;
 
+import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,8 +46,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
 
     @Autowired
     private SessionFactory sessionFactory;
-
-       @Override
+    
+    
        public String saveAlarmsHeader(AlarmsHeader alarmsHeader) {
                 try{
                    if (null == alarmsHeader) {
@@ -58,11 +62,12 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
                    session.close();
                    return "1";
                } catch (Exception e) {
-                   logger.error("Exception occurred while performing AlarmsHeaderServiceImpl saveActiveAlarmInfo. Details:" + e.getMessage());
+                   logger.error("Exception occurred while performing AlarmsHeaderServiceImpl saveAlarmsHeader. Details:" + e.getMessage());
                    return "0";
                }
                
        }
+       
 
        @Override
        public String updateAlarmsHeader(AlarmsHeader alarmsHeader) {
@@ -79,15 +84,135 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
             session.close();
             return "1";
         } catch (Exception e) {
-            logger.error("Exception occurred while performing AlarmsHeaderServiceImpl saveActiveAlarmInfo. Details:" + e.getMessage());
+            logger.error("Exception occurred while performing AlarmsHeaderServiceImpl updateAlarmsHeader. Details:" + e.getMessage());
             return "0";
         }
        }
 
+       public int getAllCount() {
+               try{
+            Session session = sessionFactory.openSession();
+            long q=(long)session.createQuery("select count(*) from AlarmsHeader").uniqueResult();
+            session.flush();
+            session.close();
+            return (int)q;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing AlarmsHeaderServiceImpl getAllCount. Details:" + e.getMessage());
+            return -1;
+        }
+       }
+
+       @SuppressWarnings("unchecked")
        @Override
-       public List<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader) {
-               // TODO Auto-generated method stub
-               return null;
+       public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
+               Page<AlarmsHeader> page = new Page<AlarmsHeader>();
+               int allRow =this.getAllCount();
+               int offset = page.countOffset(currentPage, pageSize);
+               
+               try{
+                       Date date = new Date();
+//                     SimpleDateFormat date = new SimpleDateFormat("yy-MM-dd hh:mm:ss");
+                       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 like '%"+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 like '%"+ver+"%'");
+            }else if(null!=alarmsHeader.getUpdateTime()) {
+               Date ver =alarmsHeader.getUpdateTime();
+               hql.append(" and a.updateTime like '%"+ver+"%'");
+            }
+            logger.info("AlarmsHeaderServiceImpl saveAlarmsHeader: alarmsHeader={}", alarmsHeader);
+            Session session = sessionFactory.openSession();
+            Transaction tx = session.beginTransaction(); 
+            Query query = session.createQuery(hql.toString());
+            query.setFirstResult(offset);
+            query.setMaxResults(pageSize);
+            List<AlarmsHeader> list= query.list();
+            page.setPageNo(currentPage);
+            page.setPageSize(pageSize);
+            page.setTotalRecords(allRow);
+            page.setList(list);
+            tx.commit();
+            session.flush();
+            session.close();
+            return page;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing AlarmsHeaderServiceImpl queryAlarmsHeader. Details:" + e.getMessage());
+            return null;
+        }
        }
 
        
index a354526..8c9af44 100644 (file)
 package org.onap.usecaseui.server.service.impl;
 
 
+import java.util.Date;
+import java.util.List;
+
 import javax.transaction.Transactional;
 
+import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
 import org.onap.usecaseui.server.bean.AlarmsInformation;
 import org.onap.usecaseui.server.service.AlarmsInformationService;
+import org.onap.usecaseui.server.util.Page;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +51,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
                    if (null == alarmsInformation) {
                        logger.error("alarmsInformation AlarmsInformation alarmsInformation is null!");
                    }
-                   logger.info("AlarmsHeaderServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
+                   logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
                    Session session = sessionFactory.openSession();
                    Transaction tx = session.beginTransaction();     
                    session.save(alarmsInformation);
@@ -67,7 +72,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
             if (null == alarmsInformation) {
                 logger.error("alarmsInformation AlarmsInformation alarmsInformation is null!");
             }
-            logger.info("AlarmsHeaderServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
+            logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);
             Session session = sessionFactory.openSession();
             Transaction tx = session.beginTransaction();     
             session.update(alarmsInformation);
@@ -76,10 +81,75 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
             session.close();
             return "1";
         } catch (Exception e) {
-            logger.error("Exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());
+            logger.error("Exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
             return "0";
         }
        }
+       
+
+       public int getAllCount() {
+               try{
+            Session session = sessionFactory.openSession();
+            Transaction tx = session.beginTransaction();     
+            long q=(long)session.createQuery("select count(*) from AlarmsInformation").uniqueResult();
+            tx.commit();
+            session.flush();
+            session.close();
+            return (int)q;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
+            return 0;
+        }
+       }
+
+       @SuppressWarnings("unchecked")
+       @Override
+       public Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage,
+                       int pageSize) {
+               Page<AlarmsInformation> page = new Page<AlarmsInformation>();
+               int allRow =this.getAllCount();
+               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 like '%"+ver+"%'");
+            }else if(null!=alarmsInformation.getCreateTime()) {
+               Date ver =alarmsInformation.getCreateTime();
+               hql.append(" and a.createTime like '%"+ver+"%'");
+            }else 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();
+            Transaction tx = session.beginTransaction(); 
+            Query query = session.createQuery(hql.toString());
+            query.setFirstResult(offset);
+            query.setMaxResults(pageSize);
+            List<AlarmsInformation> list= query.list();
+            page.setPageNo(currentPage);
+            page.setPageSize(pageSize);
+            page.setTotalRecords(allRow);
+            page.setList(list);
+            tx.commit();
+            session.flush();
+            session.close();
+            return page;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());
+            return null;
+        }
+       }
 
     
     
index 9322cc4..adc1ffe 100644 (file)
@@ -23,14 +23,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
 
-/**
- * <系统初始化>
- * <功能详细描述>
- * @author  donghu
- * @version  [版本号, 2017年8月17日]
- * @see  [相关类/方法]
- * @since  [产品/模块版本]
- */
+
 @Service("InitializationService")
 @Transactional
 @org.springframework.context.annotation.Configuration
index e5ba0a7..244a96b 100644 (file)
 package org.onap.usecaseui.server.service.impl;
 
 
+import java.util.Date;
+import java.util.List;
+
 import javax.transaction.Transactional;
 
+import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
 import org.onap.usecaseui.server.bean.PerformanceHeader;
 import org.onap.usecaseui.server.service.PerformanceHeaderService;
+import org.onap.usecaseui.server.util.Page;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +46,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
     @Autowired
     private SessionFactory sessionFactory;
 
+
        @Override
        public String savePerformanceHeader(PerformanceHeader performanceHeder) {
                 try{
@@ -62,11 +68,12 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
                
        }
 
+
        @Override
        public String updatePerformanceHeader(PerformanceHeader performanceHeder) {
                try{
             if (null == performanceHeder){
-                logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");
+                logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");
             }
             logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder);
             Session session = sessionFactory.openSession();
@@ -77,12 +84,119 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
             session.close();
             return "1";
         } catch (Exception e) {
-            logger.error("Exception occurred while performing PerformanceHeaderServiceImpl savePerformanceHeader. Details:" + e.getMessage());
+            logger.error("Exception occurred while performing PerformanceHeaderServiceImpl updatePerformanceHeader. Details:" + e.getMessage());
             return "0";
         }
        }
 
 
+       public int getAllCount() {
+               try{
+            Session session = sessionFactory.openSession();
+            Transaction tx = session.beginTransaction();     
+            long q=(long)session.createQuery("select count(*) from PerformanceHeader").uniqueResult();
+            tx.commit();
+            session.flush();
+            session.close();
+            return (int)q;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage());
+            return 0;
+        }
+       }
+
+       @SuppressWarnings("unchecked")
+       @Override
+       public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage,
+                       int pageSize) {
+               Page<PerformanceHeader> page = new Page<PerformanceHeader>();
+               int allRow =this.getAllCount();
+               int offset = page.countOffset(currentPage, pageSize);
+               
+               try{
+                       StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");
+            if (null == performanceHeder) {
+                logger.error("PerformanceHeaderServiceImpl queryAlarmsHeader 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 like '%"+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.eventSourceType like '%"+ver+"%'");
+            }else if(null!=performanceHeder.getCreateTime()) {
+               Date ver =performanceHeder.getCreateTime();
+               hql.append(" and a.createTime like '%"+ver+"%'");
+            }else 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();
+            Transaction tx = session.beginTransaction(); 
+            Query query = session.createQuery(hql.toString());
+            query.setFirstResult(offset);
+            query.setMaxResults(pageSize);
+            List<PerformanceHeader> list= query.list();
+            page.setPageNo(currentPage);
+            page.setPageSize(pageSize);
+            page.setTotalRecords(allRow);
+            page.setList(list);
+            tx.commit();
+            session.flush();
+            session.close();
+            return page;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing PerformanceHeaderServiceImpl queryPerformanceHeader. Details:" + e.getMessage());
+            return null;
+        }
+       }
+
+
     
     
 }
index 1b29987..04ef2fa 100644 (file)
 package org.onap.usecaseui.server.service.impl;
 
 
+import java.util.Date;
+import java.util.List;
+
 import javax.transaction.Transactional;
 
+import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
 import org.onap.usecaseui.server.bean.PerformanceInformation;
 import org.onap.usecaseui.server.service.PerformanceInformationService;
+import org.onap.usecaseui.server.util.Page;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -40,6 +45,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
     @Autowired
     private SessionFactory sessionFactory;
 
+
        @Override
        public String savePerformanceInformation(PerformanceInformation performanceInformation) {
                 try {
@@ -55,12 +61,13 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
                    session.close();
                    return "1";
                } catch (Exception e) {
-                   logger.error("Exception occurred while performing PerformanceInformationServiceImpl performanceInformation. Details:" + e.getMessage());
+                   logger.error("Exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage());
                    return "0";
                }
                
        }
 
+
        @Override
        public String updatePerformanceInformation(PerformanceInformation performanceInformation) {
                try {
@@ -76,12 +83,77 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
             session.close();
             return "1";
         } catch (Exception e) {
-            logger.error("Exception occurred while performing PerformanceInformationServiceImpl performanceInformation. Details:" + e.getMessage());
+            logger.error("Exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage());
             return "0";
         }
        }
 
 
+       public int getAllCount() {
+               try{
+            Session session = sessionFactory.openSession();
+            Transaction tx = session.beginTransaction();     
+            long q=(long)session.createQuery("select count(*) from PerformanceInformation").uniqueResult();
+            tx.commit();
+            session.flush();
+            session.close();
+            return (int)q;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage());
+            return 0;
+        }
+       }
+
+       @SuppressWarnings("unchecked")  
+       @Override
+       public Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation,
+                       int currentPage, int pageSize) {
+               Page<PerformanceInformation> page = new Page<PerformanceInformation>();
+               int allRow =this.getAllCount();
+               int offset = page.countOffset(currentPage, pageSize);
+               
+               try{
+                       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 like '%"+ver+"%'");
+            }else if(null!=performanceInformation.getCreateTime()) {
+               Date ver =performanceInformation.getCreateTime();
+               hql.append(" and a.createTime like '%"+ver+"%'");
+            }else 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();
+            Transaction tx = session.beginTransaction(); 
+            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);
+            page.setList(list);
+            tx.commit();
+            session.flush();
+            session.close();
+            return page;
+        } catch (Exception e) {
+            logger.error("Exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage());
+            return null;
+        }
+       }
+
+
     
     
     
index e11adde..8c7a489 100644 (file)
@@ -19,15 +19,14 @@ import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVPrinter;
 import org.apache.commons.csv.CSVRecord;
+import org.aspectj.util.FileUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
+import java.io.*;
 import java.util.List;
 
+
 public class CSVUtils {
     //CSV文件分隔符
     private final static String NEW_LINE_SEPARATOR="\n";
@@ -40,6 +39,23 @@ public class CSVUtils {
      * @param filePath 创建的csv文件路径
      * **/
     public static void writeCsv(String[] headers,List<String[]> data,String filePath) {
+        try{
+            CSVFormat formator = CSVFormat.DEFAULT.withHeader(headers);
+            String dir = filePath.substring(0,filePath.lastIndexOf('/'));
+            File file = new File(dir);
+            if (!file.exists())
+                 file.mkdirs();
+            try(Writer writer = new FileWriter(filePath);
+                CSVPrinter printer = new CSVPrinter(writer,formator)){
+                for(String[] str : data){
+                    printer.printRecord(str);
+                }
+            }
+
+            logger.info("CSV File Generate Success,FilePath:"+filePath);
+        }catch (IOException e){
+            logger.error("CSV File Generate Failure:"+e.getMessage());
+        }
     }
 
     /**读取csv文件
diff --git a/src/main/java/org/onap/usecaseui/server/util/Page.java b/src/main/java/org/onap/usecaseui/server/util/Page.java
new file mode 100644 (file)
index 0000000..fd7665f
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.usecaseui.server.util;
+
+import java.util.List;
+
+public class Page<E> {
+
+       private List<E> list;
+
+       private int totalRecords;
+
+       private int pageSize;
+
+       private int pageNo;
+       
+       
+       
+       
+       public List<E> getList() {
+               return list;
+       }
+
+       public void setList(List<E> list) {
+               this.list = list;
+       }
+
+       public int getTotalRecords() {
+               return totalRecords;
+       }
+
+       public void setTotalRecords(int totalRecords) {
+               this.totalRecords = totalRecords;
+       }
+
+       public int getPageSize() {
+               return pageSize;
+       }
+
+       public void setPageSize(int pageSize) {
+               this.pageSize = pageSize;
+       }
+
+       public int getPageNo() {
+               return pageNo;
+       }
+
+       public void setPageNo(int pageNo) {
+               this.pageNo = pageNo;
+       }
+
+
+       public int getTotalPages() {
+               return (totalRecords+pageSize-1)/pageSize;
+       }       
+       
+
+       public int countOffset(int currentPage,int pageSize) {
+               int offset =pageSize*(currentPage-1);
+               return offset;
+       }
+
+       public int getTopageNo() {
+               return 1;
+       }
+
+       public int getPreviousPageNo() {
+               if(pageNo<=1) {
+                       return 1;
+               }
+               return pageNo-1;
+       }
+
+       public int getNextPageNo() {
+               if(pageNo>=getBottomPageNo()) {
+                       return getBottomPageNo();
+               }
+               return pageNo+1;
+       }
+
+       public int getBottomPageNo() {
+               return getTotalPages();
+       }
+       
+}
index 5851136..4630f2b 100644 (file)
@@ -20,9 +20,9 @@ spring.http.multipart.max-file-size=128MB
 spring.http.multipart.max-request-size=128MB
 
 ## App DB Properties
-spring.datasource.url=jdbc:mysql://127.0.0.1:3306/usecase
+spring.datasource.url=jdbc:mysql://localhost:3306/uui
 spring.datasource.username=root
-spring.datasource.password=root
+spring.datasource.password=
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
 spring.database.driver.classname=com.mysql.jdbc.Driver
 spring.jpa.show-sql=false
index 34aad8e..4fc3e74 100644 (file)
  */
 package org.onap.usecaseui.server;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.onap.usecaseui.server.bean.AlarmsHeader;
+import org.onap.usecaseui.server.bean.AlarmsInformation;
+import org.onap.usecaseui.server.service.AlarmsHeaderService;
+import org.onap.usecaseui.server.service.AlarmsInformationService;
+import org.onap.usecaseui.server.service.impl.AlarmsHeaderServiceImpl;
+import org.onap.usecaseui.server.service.impl.AlarmsInformationServiceImpl;
+import org.onap.usecaseui.server.util.Page;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
 public class UsecaseuiServerApplicationTests {
-
+       
+//     @Autowired
+//     AlarmsInformationService info;
+       
+       @Autowired
+       AlarmsHeaderService alarm;
+       
        @Test
-       public void contextLoads() {
+       public void contextLoads() throws ParseException {
+//             AlarmsInformation in= new AlarmsInformation();
+//             Date date =new Date();
+//             in.setName("name");
+//             in.setEventId("eventId");
+//             in.setValue("value");
+//             in.setCreateTime(date);
+//             in.setUpdateTime(date);
+//             String d=info.saveAlarmsInformation(in);
+//             String d=info.updateAlarmsInformation(in);
+               
+//             int c=alarm.getAllCount();
+               
+               AlarmsHeader a = new AlarmsHeader();
+//             a.setVersion("1");
+               a.setDomain("3");
+//             SimpleDateFormat e =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//             a.setCreateTime(e.parse("2017-09-03 15:25:11"));
+               Page<AlarmsHeader> b = alarm.queryAlarmsHeader(a, 1, 5);
+               String c =b.getList().get(0).getEventName();
+               System.out.println("============"+c);
+               Assert.assertEquals("2", c);
+               
        }
 }