From 500d9769086823a11b2ac43c455370029760ebbd Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 14 Aug 2017 16:48:32 +0900 Subject: [PATCH] fixed sensor readallbydomain --- .../overflow/module/infra/dao/InfraDAO.java | 8 +++++ .../module/infra/service/InfraService.java | 8 +++++ .../overflow/module/sensor/dao/SensorDAO.java | 4 +++ .../module/sensor/service/SensorService.java | 21 ++++++++++++++ .../overflow/module/target/dao/TargetDAO.java | 7 ++++- .../infra/service/InfraServiceTest.java | 21 ++++++++++++++ .../sensor/service/SensorServiceTest.java | 20 ++++++++++++- .../module/target/dao/TargetDAOTest.java | 29 +++++++++++++++++++ 8 files changed, 116 insertions(+), 2 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 e124b32..5c3178a 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 @@ -3,7 +3,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.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -15,4 +18,9 @@ import java.util.List; public interface InfraDAO extends JpaRepository { public List findAllByProbe(Probe probe); + List findAllByProbe(List probeList); + + + @Query("SELECT DISTINCT i.target FROM Infra i WHERE i.probe IN (:probeList)") + List findAllTargetByProbeList(@Param("probeList") List probeList); } \ No newline at end of file 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 e37a092..a936e49 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 @@ -4,6 +4,7 @@ import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.infra.dao.InfraDAO; 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.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,4 +32,11 @@ public class InfraService { return this.infraDAO.findAllByProbe(probe); } + public List readAllByProbeList(List probeList) { + return this.infraDAO.findAllByProbe(probeList); + } + + public List readAllTargetByProbeList(List probeList) { + return this.infraDAO.findAllTargetByProbeList(probeList); + } } 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 ef7b776..ad20dba 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 @@ -1,6 +1,7 @@ package com.loafle.overflow.module.sensor.dao; +import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.target.model.Target; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,4 +15,7 @@ import java.util.List; @Repository public interface SensorDAO extends JpaRepository { List findAllByTarget(Target target); + + List findAllByTarget(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 92ce9ff..9d85c15 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 @@ -1,12 +1,19 @@ package com.loafle.overflow.module.sensor.service; +import com.loafle.overflow.module.domain.model.Domain; +import com.loafle.overflow.module.infra.model.Infra; +import com.loafle.overflow.module.infra.service.InfraService; 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.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; /** @@ -18,6 +25,12 @@ public class SensorService { @Autowired SensorDAO sensorDAO; + @Autowired + private ProbeService probeService; + + @Autowired + private InfraService infraService; + public Sensor regist(Sensor sensor) { return this.sensorDAO.save(sensor); } @@ -26,6 +39,14 @@ public class SensorService { return this.sensorDAO.findAllByTarget(target); } + public List readAllByDomain(Domain domain) { + + List probeList = this.probeService.readAllByDomain(domain); + + List targetList = this.infraService.readAllTargetByProbeList(probeList); + + return this.sensorDAO.findAllByTarget(targetList); + } public Sensor read(String id) { return this.sensorDAO.findOne(Long.valueOf(id)); } diff --git a/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java b/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java index 960cf95..3769833 100644 --- a/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java +++ b/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java @@ -1,8 +1,11 @@ package com.loafle.overflow.module.target.dao; +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.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -13,5 +16,7 @@ import java.util.List; */ @Repository public interface TargetDAO extends JpaRepository { -// List findAllByProbe(Probe probe); +// List findAllByProbe(Probe probe);] + + } 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 62062a7..12915f3 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 @@ -1,8 +1,10 @@ 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.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; @@ -14,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.List; + /** * Created by snoop on 17. 7. 27. */ @@ -24,6 +28,9 @@ public class InfraServiceTest { @Autowired private InfraService infraService; + @Autowired + private ProbeService probeService; + @Ignore @Test public void regist() throws Exception { @@ -77,4 +84,18 @@ public class InfraServiceTest { System.out.println(json); } + @Test + public void readAllByProbeList() { + + Domain domain = new Domain(); + domain.setId(1); + + List pl = this.probeService.readAllByDomain(domain); + + List fl = this.infraService.readAllByProbeList(pl); + + System.out.println(fl.size()); + + } + } \ No newline at end of file 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 376a142..be90c1a 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,7 +1,11 @@ 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.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; @@ -20,13 +24,15 @@ import java.util.List; /** * Created by insanity on 17. 6. 28. */ -@Ignore +//@Ignore @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppConfigTest.class}) public class SensorServiceTest { @Autowired SensorService sensorService; + + @Ignore @Test public void regist() throws Exception { @@ -69,4 +75,16 @@ public class SensorServiceTest { System.out.println(json); } + + @Test + public void readAllByTargetList() { + + Domain domain = new Domain(); + domain.setId(1); + + List sl = this.sensorService.readAllByDomain(domain); + + Assert.assertNotEquals(sl.size(), 0); + + } } diff --git a/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java b/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java index 6e9ed86..1c8706f 100644 --- a/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java +++ b/src/test/java/com/loafle/overflow/module/target/dao/TargetDAOTest.java @@ -1,7 +1,36 @@ package com.loafle.overflow.module.target.dao; +import com.loafle.overflow.module.domain.model.Domain; +import com.loafle.overflow.module.infra.model.Infra; +import com.loafle.overflow.module.infra.service.InfraService; +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.junit.Assert; +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.util.List; + /** * Created by insanity on 17. 6. 28. */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfigTest.class}) public class TargetDAOTest { + + @Autowired + private TargetDAO targetDAO; + + @Autowired + private ProbeService probeService; + + @Autowired + private InfraService infraService; + + }