infra target paging
This commit is contained in:
parent
00b1cb7a4f
commit
f4bc20e55b
|
@ -1,9 +1,10 @@
|
||||||
package com.loafle.overflow.module.infra.dao;
|
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.infra.model.Infra;
|
||||||
import com.loafle.overflow.module.probe.model.Probe;
|
import com.loafle.overflow.module.probe.model.Probe;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
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.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
@ -16,10 +17,12 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public interface InfraDAO extends JpaRepository<Infra, Long> {
|
public interface InfraDAO extends JpaRepository<Infra, Long> {
|
||||||
public List<Infra> findAllByProbe(Probe probe);
|
List<Infra> findAllByProbe(Probe probe);
|
||||||
|
|
||||||
|
Page<Infra> findAllByProbe(Probe probe, Pageable pageable);
|
||||||
|
|
||||||
@Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList) AND i.target != NULL")
|
@Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList) AND i.target != NULL")
|
||||||
List<Infra> findAllByProbeList(@Param("probeList") List<Probe> probeList);
|
Page<Infra> findAllByProbeList(@Param("probeList") List<Probe> probeList, Pageable pageable);
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)")
|
@Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)")
|
||||||
|
|
|
@ -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.probe.service.ProbeService;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
import com.loafle.overflow.module.target.model.Target;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,20 +36,25 @@ public class InfraService {
|
||||||
return this.infraDAO.findOne(id);
|
return this.infraDAO.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Infra> readAllByProbe(Probe probe) {
|
public Page<Infra> readAllByProbe(Probe probe, int pageNo, int countPerPage) {
|
||||||
return this.infraDAO.findAllByProbe(probe);
|
Pageable pageRequest =
|
||||||
|
new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id"));
|
||||||
|
return this.infraDAO.findAllByProbe(probe, pageRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Infra> readAllByDomain(Domain domain) {
|
public Page<Infra> readAllByDomain(Domain domain, int pageNo, int countPerPage) {
|
||||||
|
|
||||||
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
List<Probe> 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<Infra> readAllByProbeList(List<Probe> probeList) {
|
// public List<Infra> readAllByProbeList(List<Probe> probeList) {
|
||||||
return this.infraDAO.findAllByProbeList(probeList);
|
// return this.infraDAO.findAllByProbeList(probeList);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public List<Target> readAllTargetByDomain(Domain domain) {
|
public List<Target> readAllTargetByDomain(Domain domain) {
|
||||||
|
|
||||||
|
@ -59,4 +68,5 @@ public class InfraService {
|
||||||
// return null;
|
// return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,15 @@ package com.loafle.overflow.module.infra.service;
|
||||||
|
|
||||||
import com.loafle.overflow.module.domain.model.Domain;
|
import com.loafle.overflow.module.domain.model.Domain;
|
||||||
import com.loafle.overflow.module.infra.model.Infra;
|
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.probe.service.ProbeService;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
|
||||||
import com.loafle.overflow.spring.AppConfigTest;
|
import com.loafle.overflow.spring.AppConfigTest;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by snoop on 17. 7. 27.
|
* Created by snoop on 17. 7. 27.
|
||||||
*/
|
*/
|
||||||
|
@ -57,20 +48,20 @@ public class InfraServiceTest {
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void readAllProbe() throws IOException {
|
// public void readAllProbe() throws IOException {
|
||||||
|
//
|
||||||
Probe probe = new Probe();
|
// Probe probe = new Probe();
|
||||||
probe.setId(1);
|
// probe.setId(1);
|
||||||
|
//
|
||||||
List<Infra> infraList = this.infraService.readAllByProbe(probe);
|
// List<Infra> infraList = this.infraService.readAllByProbe(probe);
|
||||||
|
//
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String json = objectMapper.writeValueAsString(infraList);
|
// String json = objectMapper.writeValueAsString(infraList);
|
||||||
|
//
|
||||||
System.out.println(json);
|
// System.out.println(json);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readAllTarget() {
|
public void readAllTarget() {
|
||||||
|
@ -80,21 +71,21 @@ public class InfraServiceTest {
|
||||||
// this.infraService.readAllTargetByProbeList()
|
// this.infraService.readAllTargetByProbeList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void readAllByProbeList() throws IOException {
|
// public void readAllByProbeList() throws IOException {
|
||||||
|
//
|
||||||
Domain domain = new Domain();
|
// Domain domain = new Domain();
|
||||||
domain.setId(1);
|
// domain.setId(1);
|
||||||
|
//
|
||||||
|
//
|
||||||
List<Infra> fl = this.infraService.readAllByDomain(domain);
|
// List<Infra> fl = this.infraService.readAllByDomain(domain);
|
||||||
|
//
|
||||||
System.out.println(fl.size());
|
// System.out.println(fl.size());
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String json = objectMapper.writeValueAsString(fl);
|
// String json = objectMapper.writeValueAsString(fl);
|
||||||
|
//
|
||||||
System.out.println(json);
|
// System.out.println(json);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user