From d48ab6da51f4922b3fe786cdcbc5c4ec145e7ef5 Mon Sep 17 00:00:00 2001 From: snoop Date: Thu, 24 Aug 2017 15:29:24 +0900 Subject: [PATCH 1/3] fixed parameter type abstract -> long --- .../loafle/overflow/module/sensor/service/SensorService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java b/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java index 126c584..92b8a53 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java +++ b/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java @@ -46,8 +46,8 @@ public class SensorService { return this.sensorDAO.findAllByTargetList(targetList); } - public List readAllByInfra(Infra infra) { - Infra dbInfra = this.infraService.read(infra.getId()); + public List readAllByInfra(long infraId) { + Infra dbInfra = this.infraService.read(infraId); if(dbInfra == null || dbInfra.getTarget() == null) return null; From f4bc20e55b44334d6be30540c3a2210659e76055 Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 24 Aug 2017 16:30:21 +0900 Subject: [PATCH 2/3] infra target paging --- .../overflow/module/infra/dao/InfraDAO.java | 9 ++- .../module/infra/service/InfraService.java | 24 +++++-- .../infra/service/InfraServiceTest.java | 69 ++++++++----------- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java b/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java index f8e1d53..96601ad 100644 --- a/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java +++ b/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java @@ -1,9 +1,10 @@ package com.loafle.overflow.module.infra.dao; -import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.target.model.Target; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -16,10 +17,12 @@ import java.util.List; */ @Repository public interface InfraDAO extends JpaRepository { - public List findAllByProbe(Probe probe); + List findAllByProbe(Probe probe); + + Page findAllByProbe(Probe probe, Pageable pageable); @Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList) AND i.target != NULL") - List findAllByProbeList(@Param("probeList") List probeList); + Page findAllByProbeList(@Param("probeList") List probeList, Pageable pageable); @Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)") diff --git a/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java b/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java index 2941963..e43e4dd 100644 --- a/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java +++ b/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java @@ -7,6 +7,10 @@ import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.service.ProbeService; import com.loafle.overflow.module.target.model.Target; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.List; @@ -32,20 +36,25 @@ public class InfraService { return this.infraDAO.findOne(id); } - public List readAllByProbe(Probe probe) { - return this.infraDAO.findAllByProbe(probe); + public Page readAllByProbe(Probe probe, int pageNo, int countPerPage) { + Pageable pageRequest = + new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id")); + return this.infraDAO.findAllByProbe(probe, pageRequest); } - public List readAllByDomain(Domain domain) { + public Page readAllByDomain(Domain domain, int pageNo, int countPerPage) { List probeList = this.probeService.readAllByDomain(domain); - return this.infraDAO.findAllByProbeList(probeList); + Pageable pageRequest = + new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id")); + + return this.infraDAO.findAllByProbeList(probeList, pageRequest); } - public List readAllByProbeList(List probeList) { - return this.infraDAO.findAllByProbeList(probeList); - } +// public List readAllByProbeList(List probeList) { +// return this.infraDAO.findAllByProbeList(probeList); +// } public List readAllTargetByDomain(Domain domain) { @@ -59,4 +68,5 @@ public class InfraService { // return null; } + } diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java index 5c59e80..33e174a 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java @@ -2,24 +2,15 @@ package com.loafle.overflow.module.infra.service; import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.infra.model.Infra; -import com.loafle.overflow.module.infra.model.InfraMachine; -import com.loafle.overflow.module.meta.model.MetaInfraType; -import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.service.ProbeService; -import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.spring.AppConfigTest; import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.IOException; -import java.util.List; - /** * Created by snoop on 17. 7. 27. */ @@ -57,20 +48,20 @@ public class InfraServiceTest { System.out.println(json); } - @Test - public void readAllProbe() throws IOException { - - Probe probe = new Probe(); - probe.setId(1); - - List infraList = this.infraService.readAllByProbe(probe); - - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(infraList); - - System.out.println(json); - - } +// @Test +// public void readAllProbe() throws IOException { +// +// Probe probe = new Probe(); +// probe.setId(1); +// +// List infraList = this.infraService.readAllByProbe(probe); +// +// ObjectMapper objectMapper = new ObjectMapper(); +// String json = objectMapper.writeValueAsString(infraList); +// +// System.out.println(json); +// +// } @Test public void readAllTarget() { @@ -80,21 +71,21 @@ public class InfraServiceTest { // this.infraService.readAllTargetByProbeList() } - @Test - public void readAllByProbeList() throws IOException { - - Domain domain = new Domain(); - domain.setId(1); - - - List fl = this.infraService.readAllByDomain(domain); - - System.out.println(fl.size()); - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(fl); - - System.out.println(json); - - } +// @Test +// public void readAllByProbeList() throws IOException { +// +// Domain domain = new Domain(); +// domain.setId(1); +// +// +// List fl = this.infraService.readAllByDomain(domain); +// +// System.out.println(fl.size()); +// ObjectMapper objectMapper = new ObjectMapper(); +// String json = objectMapper.writeValueAsString(fl); +// +// System.out.println(json); +// +// } } \ No newline at end of file From f4d92d8b4c84e74cfc72236a25f8a6bbd9bc59f7 Mon Sep 17 00:00:00 2001 From: snoop Date: Thu, 24 Aug 2017 16:59:16 +0900 Subject: [PATCH 3/3] added probeHost service --- .../overflow/module/sensor/service/SensorServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/loafle/overflow/module/sensor/service/SensorServiceTest.java b/src/test/java/com/loafle/overflow/module/sensor/service/SensorServiceTest.java index dc02c22..5e8fc4a 100644 --- a/src/test/java/com/loafle/overflow/module/sensor/service/SensorServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/sensor/service/SensorServiceTest.java @@ -93,7 +93,7 @@ public class SensorServiceTest { Infra infra = new InfraMachine(); infra.setId(1); - List sl = this.sensorService.readAllByInfra(infra); + List sl = this.sensorService.readAllByInfra(1); Assert.assertNotEquals(sl.size(), 0);