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