diff --git a/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java b/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java index 24d4842..79df861 100644 --- a/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java +++ b/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java @@ -23,5 +23,5 @@ public interface HistoryDAO extends JpaRepository { Page findAllByProbe(Probe probe, Pageable pageable); @Query("SELECT h FROM History h WHERE h.probe.id = :#{#probe.id} and h.type.id = :#{#type.id}") - List findAllByProbeAndType(@Param("probe") Probe probe, @Param("type") MetaHistoryType type); + Page findAllByProbeAndType(@Param("probe") Probe probe, @Param("type") MetaHistoryType type, Pageable pageable); } diff --git a/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java b/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java index 8200d55..75da08d 100644 --- a/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java +++ b/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java @@ -11,8 +11,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; -import java.util.List; - @Service("HistoryService") public class HistoryService { @@ -27,8 +25,10 @@ public class HistoryService { // return this.historyDAO.findAllByProbeOrderByIdDesc(probe); // } - public List readAllByProbeAndType(Probe probe, MetaHistoryType type) { - return this.historyDAO.findAllByProbeAndType(probe, type); + public Page readAllByProbeAndType(Probe probe, MetaHistoryType type, int pageNo, int countPerPage) { + Pageable pageRequest = + new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id")); + return this.historyDAO.findAllByProbeAndType(probe, type, pageRequest); } public Page readAllByProbe(Probe probe, int pageNo, int countPerPage) { diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java index 08a06d2..faa2d1f 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java +++ b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java @@ -15,10 +15,12 @@ import java.util.List; */ @Repository public interface SensorDAO extends JpaRepository { + + List findAllByTarget(Target target); @Query("SELECT s from Sensor s WHERE s.target in (:targetList)") - List findAllByTarget(@Param("targetList") List targetList); + List findAllByTargetList(@Param("targetList") List targetList); // List findAllByTargetList(List targets); } 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 9d85c15..126c584 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 @@ -9,11 +9,9 @@ import com.loafle.overflow.module.probe.service.ProbeService; import com.loafle.overflow.module.sensor.dao.SensorDAO; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.target.model.Target; -import com.loafle.overflow.module.target.service.TargetService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; /** @@ -45,8 +43,18 @@ public class SensorService { List targetList = this.infraService.readAllTargetByProbeList(probeList); - return this.sensorDAO.findAllByTarget(targetList); + return this.sensorDAO.findAllByTargetList(targetList); } + + public List readAllByInfra(Infra infra) { + Infra dbInfra = this.infraService.read(infra.getId()); + + if(dbInfra == null || dbInfra.getTarget() == null) return null; + + return this.sensorDAO.findAllByTarget(dbInfra.getTarget()); + + } + public Sensor read(String id) { return this.sensorDAO.findOne(Long.valueOf(id)); } diff --git a/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java b/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java index b62da4d..cc443ba 100644 --- a/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java @@ -5,7 +5,6 @@ import com.loafle.overflow.module.member.model.Member; import com.loafle.overflow.module.meta.model.MetaHistoryType; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.spring.AppConfigTest; -import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.util.List; import java.util.Random; /** @@ -42,12 +40,12 @@ public class HistoryServiceTest { } - @Test - @Ignore - public void readAllByProbeAndType() { - List result = this.historyService.readAllByProbeAndType(new Probe(1), new MetaHistoryType(1)); - Assert.assertNotNull(result); - } +// @Test +// @Ignore +// public void readAllByProbeAndType() { +// List result = this.historyService.readAllByProbeAndType(new Probe(1), new MetaHistoryType(1)); +// Assert.assertNotNull(result); +// } // @Test // public void readAllByProbeWithPaging() { 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 be90c1a..dc02c22 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 @@ -1,11 +1,10 @@ package com.loafle.overflow.module.sensor.service; import com.loafle.overflow.module.domain.model.Domain; -import com.loafle.overflow.module.infra.service.InfraService; +import com.loafle.overflow.module.infra.model.Infra; +import com.loafle.overflow.module.infra.model.InfraMachine; import com.loafle.overflow.module.meta.model.MetaCrawler; import com.loafle.overflow.module.meta.model.MetaSensorStatus; -import com.loafle.overflow.module.probe.model.Probe; -import com.loafle.overflow.module.probe.service.ProbeService; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.spring.AppConfigTest; @@ -87,4 +86,16 @@ public class SensorServiceTest { Assert.assertNotEquals(sl.size(), 0); } + + @Test + public void readAllByInfra() { + + Infra infra = new InfraMachine(); + infra.setId(1); + + List sl = this.sensorService.readAllByInfra(infra); + + Assert.assertNotEquals(sl.size(), 0); + + } }