Use isEmpty() 27/89727/1
authorguochuyicmri <guochuyi@chinamobile.com>
Wed, 12 Jun 2019 03:53:34 +0000 (11:53 +0800)
committerguochuyicmri <guochuyi@chinamobile.com>
Wed, 12 Jun 2019 03:53:45 +0000 (11:53 +0800)
Change-Id: I881a72ace5b3975abbb15b2ac78172dc2494e529
Issue-ID: USECASEUI-275
Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
server/src/main/java/org/onap/usecaseui/server/service/AlarmsInformationService.java
server/src/main/java/org/onap/usecaseui/server/service/PerformanceInformationService.java
server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java
server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java

index 9a86f92..11f4d01 100644 (file)
@@ -32,8 +32,6 @@ public interface AlarmsInformationService {
     
     int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize);
     
-    Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage, int pageSize);
-
     List<AlarmsInformation> queryId(String[] id);
 
     int queryDateBetween(String sourceId, String startTime, String endTime,String level);
index 83991a2..f6a8d1d 100644 (file)
@@ -28,10 +28,6 @@ public interface PerformanceInformationService {
     
     String updatePerformanceInformation(PerformanceInformation performanceInformation);
     
-    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);
index 00c9a51..720d3ca 100755 (executable)
@@ -120,55 +120,6 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
                }\r
        }\r
 \r
-       @SuppressWarnings("unchecked")\r
-       @Override\r
-       public Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage,\r
-                       int pageSize) {\r
-               Page<AlarmsInformation> page = new Page<AlarmsInformation>();\r
-               int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);\r
-               int offset = page.countOffset(currentPage, pageSize);\r
-               \r
-               try(Session session = getSession()){\r
-                       StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");\r
-                       if (null == alarmsInformation) {\r
-                               //logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");\r
-                       }else {\r
-                               if(null!=alarmsInformation.getName()) {\r
-                                       String ver=alarmsInformation.getName();\r
-                                       hql.append(" and a.name like '%"+ver+"%'");\r
-                               }\r
-                               if(null!=alarmsInformation.getValue()) {\r
-                                       String ver=alarmsInformation.getValue();\r
-                                       hql.append(" and a.value like '%"+ver+"%'");\r
-                               }\r
-                               if(null!=alarmsInformation.getSourceId()) {\r
-                                       String ver=alarmsInformation.getSourceId();\r
-                                       hql.append(" and a.sourceId = '"+ver+"'");\r
-                               }\r
-                               if(null!=alarmsInformation.getStartEpochMicroSec() || alarmsInformation.getLastEpochMicroSec()!= null) {\r
-                                       hql.append(" and a.startEpochMicrosec between :startTime and :endTime");\r
-                               }\r
-                       }\r
-                       Query query = session.createQuery(hql.toString());\r
-                       if(null!=alarmsInformation.getStartEpochMicroSec() || alarmsInformation.getLastEpochMicroSec()!= null) {\r
-                               query.setString("startTime",alarmsInformation.getStartEpochMicroSec());\r
-                               query.setString("endTime",alarmsInformation.getLastEpochMicroSec());\r
-                       }\r
-                       query.setFirstResult(offset);\r
-                       query.setMaxResults(pageSize);\r
-                       List<AlarmsInformation> list= query.list();\r
-                       page.setPageNo(currentPage);\r
-                       page.setPageSize(pageSize);\r
-                       page.setTotalRecords(allRow);\r
-                       page.setList(list);\r
-                       session.flush();\r
-                       return page;\r
-               } catch (Exception e) {\r
-                       logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());\r
-                       return null;\r
-               }\r
-       }\r
-\r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<AlarmsInformation> queryId(String[] id) {\r
index a1d5561..64ab23f 100755 (executable)
@@ -88,90 +88,6 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
                }\r
        }\r
 \r
-       public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) {\r
-               try(Session session = getSession()){\r
-                       StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1");\r
-                       if (null == performanceInformation) {\r
-                       }else {\r
-                               if(null!=performanceInformation.getName()) {\r
-                                       String ver=performanceInformation.getName();\r
-                                       hql.append(" and a.name like '%"+ver+"%'");\r
-                               }\r
-                               if(null!=performanceInformation.getValue()) {\r
-                                       String ver=performanceInformation.getValue();\r
-                                       hql.append(" and a.value like '%"+ver+"%'");\r
-                               }\r
-                               if(null!=performanceInformation.getSourceId()) {\r
-                                       String ver=performanceInformation.getSourceId();\r
-                                       hql.append(" and a.sourceId = '"+ver+"'");\r
-                               }\r
-                               if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) {\r
-                                       hql.append(" and a.startEpochMicrosec between :startTime and :endTime");\r
-                               }\r
-                       }\r
-                       Query query = session.createQuery(hql.toString());\r
-                       if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) {\r
-                               query.setString("startTime",performanceInformation.getStartEpochMicrosec());\r
-                               query.setString("endTime",performanceInformation.getLastEpochMicroSec());\r
-                       }\r
-                       long q=(long) query.uniqueResult();\r
-                       session.flush();\r
-                       return (int)q;\r
-               } catch (Exception e) {\r
-                       logger.error("exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage());\r
-                       return 0;\r
-               }\r
-       }\r
-\r
-       @SuppressWarnings("unchecked")\r
-       @Override\r
-       public Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation,\r
-               int currentPage, int pageSize) {\r
-               Page<PerformanceInformation> page = new Page<PerformanceInformation>();\r
-               int allRow =this.getAllCount(performanceInformation,currentPage,pageSize);\r
-               int offset = page.countOffset(currentPage, pageSize);\r
-\r
-               try(Session session = getSession()){\r
-                       StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 ");\r
-                       if (null == performanceInformation) {\r
-                       }else {\r
-                               if(null!=performanceInformation.getName()) {\r
-                                       String ver=performanceInformation.getName();\r
-                                       hql.append(" and a.name like '%"+ver+"%'");\r
-                               }\r
-                               if(null!=performanceInformation.getValue()) {\r
-                                       String ver=performanceInformation.getValue();\r
-                                       hql.append(" and a.value like '%"+ver+"%'");\r
-                               }\r
-                               if(null!=performanceInformation.getSourceId()) {\r
-                                       String ver=performanceInformation.getSourceId();\r
-                                       hql.append(" and a.sourceId = '"+ver+"'");\r
-                               }\r
-                               if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) {\r
-                                       hql.append(" and a.startEpochMicrosec between :startTime and :endTime");\r
-                               }\r
-                       }\r
-                       Query query = session.createQuery(hql.toString());\r
-                       if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) {\r
-                               query.setString("startTime",performanceInformation.getStartEpochMicrosec());\r
-                               query.setString("endTime",performanceInformation.getLastEpochMicroSec());\r
-                       }\r
-                       query.setFirstResult(offset);\r
-                       query.setMaxResults(pageSize);\r
-                       List<PerformanceInformation> list= query.list();\r
-\r
-                       page.setPageNo(currentPage);\r
-                       page.setPageSize(pageSize);\r
-                       page.setTotalRecords(allRow);\r
-                       page.setList(list);\r
-                       session.flush();\r
-                       return page;\r
-               } catch (Exception e) {\r
-                       logger.error("exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage());\r
-                       return null;\r
-               }\r
-       }\r
-\r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public List<PerformanceInformation> queryId(String[] id) {\r
index 49d3fa4..61aba39 100644 (file)
@@ -176,21 +176,6 @@ public class AlarmsInformationServiceImplTest {
                }
        }
 
-       @Test
-       public void testQueryAlarmsInformation() throws Exception {
-               try {
-                       AlarmsInformation ai = new AlarmsInformation();
-                       ai.setName("");
-                       ai.setValue("");
-                       ai.setSourceId("");
-                       ai.setStartEpochMicroSec("");;
-                       ai.setLastEpochMicroSec("");;
-                       alarmsInformationServiceImpl.queryAlarmsInformation(ai, 1, 1);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
        @Test
        public void testQueryId() throws Exception {
                try {
index 08a9c8b..79bbf18 100644 (file)
@@ -155,42 +155,6 @@ public class PerformanceInformationServiceImplTest {
                }
        }
 
-       @Test
-       public void testGetAllCount() throws Exception {
-               new MockUp<Query>() {
-                       @Mock
-                       public Object uniqueResult() {
-                               return "1";
-                       }
-               };
-               try {
-                       PerformanceInformation pi = new PerformanceInformation();
-                       pi.setName("");
-                       pi.setValue("");
-                       pi.setSourceId("");
-                       pi.setStartEpochMicrosec("");;
-                       pi.setLastEpochMicroSec("");;
-                       performanceInformationServiceImpl.getAllCount(pi, 1, 1);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
-       @Test
-       public void testQueryPerformanceInformation() throws Exception {
-               try {
-                       PerformanceInformation pi = new PerformanceInformation();
-                       pi.setName("");
-                       pi.setValue("");
-                       pi.setSourceId("");
-                       pi.setStartEpochMicrosec("");;
-                       pi.setLastEpochMicroSec("");;
-                       performanceInformationServiceImpl.queryPerformanceInformation(pi, 1, 1);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
        @Test
        public void testQueryId() throws Exception {
                try {