From 5768363d8767ba503ef643579331efe8efe61849 Mon Sep 17 00:00:00 2001 From: guochuyicmri Date: Wed, 12 Jun 2019 11:53:34 +0800 Subject: Use isEmpty() Change-Id: I881a72ace5b3975abbb15b2ac78172dc2494e529 Issue-ID: USECASEUI-275 Signed-off-by: guochuyicmri --- .../server/service/AlarmsInformationService.java | 2 - .../service/PerformanceInformationService.java | 4 -- .../service/impl/AlarmsInformationServiceImpl.java | 49 ------------- .../impl/PerformanceInformationServiceImpl.java | 84 ---------------------- .../impl/AlarmsInformationServiceImplTest.java | 15 ---- .../PerformanceInformationServiceImplTest.java | 36 ---------- 6 files changed, 190 deletions(-) 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 9a86f92f..11f4d010 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 @@ -32,8 +32,6 @@ public interface AlarmsInformationService { int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize); - Page queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage, int pageSize); - List queryId(String[] id); int queryDateBetween(String sourceId, String startTime, String endTime,String level); 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 83991a24..f6a8d1d9 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 @@ -28,10 +28,6 @@ public interface PerformanceInformationService { String updatePerformanceInformation(PerformanceInformation performanceInformation); - int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize); - - Page queryPerformanceInformation(PerformanceInformation performanceInformation, int currentPage, int pageSize); - List queryId(String[] id); List queryDateBetween(String eventId, Date startDate, Date endDate); 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 00c9a51c..720d3ca4 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 @@ -120,55 +120,6 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService { } } - @SuppressWarnings("unchecked") - @Override - public Page queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage, - int pageSize) { - Page page = new Page(); - int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize); - int offset = page.countOffset(currentPage, pageSize); - - try(Session session = getSession()){ - 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+"%'"); - } - if(null!=alarmsInformation.getValue()) { - String ver=alarmsInformation.getValue(); - hql.append(" and a.value like '%"+ver+"%'"); - } - if(null!=alarmsInformation.getSourceId()) { - String ver=alarmsInformation.getSourceId(); - hql.append(" and a.sourceId = '"+ver+"'"); - } - if(null!=alarmsInformation.getStartEpochMicroSec() || alarmsInformation.getLastEpochMicroSec()!= null) { - hql.append(" and a.startEpochMicrosec between :startTime and :endTime"); - } - } - Query query = session.createQuery(hql.toString()); - if(null!=alarmsInformation.getStartEpochMicroSec() || alarmsInformation.getLastEpochMicroSec()!= null) { - query.setString("startTime",alarmsInformation.getStartEpochMicroSec()); - query.setString("endTime",alarmsInformation.getLastEpochMicroSec()); - } - query.setFirstResult(offset); - query.setMaxResults(pageSize); - List list= query.list(); - page.setPageNo(currentPage); - page.setPageSize(pageSize); - page.setTotalRecords(allRow); - page.setList(list); - session.flush(); - return page; - } catch (Exception e) { - logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage()); - return null; - } - } - @SuppressWarnings("unchecked") @Override public List queryId(String[] id) { 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 a1d55616..64ab23f4 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 @@ -88,90 +88,6 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation } } - public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) { - try(Session session = getSession()){ - StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1"); - if (null == performanceInformation) { - }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.getSourceId()) { - String ver=performanceInformation.getSourceId(); - hql.append(" and a.sourceId = '"+ver+"'"); - } - if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) { - hql.append(" and a.startEpochMicrosec between :startTime and :endTime"); - } - } - Query query = session.createQuery(hql.toString()); - if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) { - query.setString("startTime",performanceInformation.getStartEpochMicrosec()); - query.setString("endTime",performanceInformation.getLastEpochMicroSec()); - } - long q=(long) query.uniqueResult(); - session.flush(); - return (int)q; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage()); - return 0; - } - } - - @SuppressWarnings("unchecked") - @Override - public Page queryPerformanceInformation(PerformanceInformation performanceInformation, - int currentPage, int pageSize) { - Page page = new Page(); - int allRow =this.getAllCount(performanceInformation,currentPage,pageSize); - int offset = page.countOffset(currentPage, pageSize); - - try(Session session = getSession()){ - StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 "); - if (null == performanceInformation) { - }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.getSourceId()) { - String ver=performanceInformation.getSourceId(); - hql.append(" and a.sourceId = '"+ver+"'"); - } - if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) { - hql.append(" and a.startEpochMicrosec between :startTime and :endTime"); - } - } - Query query = session.createQuery(hql.toString()); - if(null!=performanceInformation.getStartEpochMicrosec() || performanceInformation.getLastEpochMicroSec()!= null) { - query.setString("startTime",performanceInformation.getStartEpochMicrosec()); - query.setString("endTime",performanceInformation.getLastEpochMicroSec()); - } - query.setFirstResult(offset); - query.setMaxResults(pageSize); - List list= query.list(); - - page.setPageNo(currentPage); - page.setPageSize(pageSize); - page.setTotalRecords(allRow); - page.setList(list); - session.flush(); - return page; - } catch (Exception e) { - logger.error("exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage()); - return null; - } - } - @SuppressWarnings("unchecked") @Override public List queryId(String[] id) { diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java index 49d3fa46..61aba39d 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImplTest.java @@ -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 { diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java index 08a9c8b2..79bbf18d 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImplTest.java @@ -155,42 +155,6 @@ public class PerformanceInformationServiceImplTest { } } - @Test - public void testGetAllCount() throws Exception { - new MockUp() { - @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 { -- cgit 1.2.3-korg