infra target paging

This commit is contained in:
insanity 2017-08-24 16:30:21 +09:00
parent 00b1cb7a4f
commit f4bc20e55b
3 changed files with 53 additions and 49 deletions

View File

@ -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<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")
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)")

View File

@ -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<Infra> readAllByProbe(Probe probe) {
return this.infraDAO.findAllByProbe(probe);
public Page<Infra> 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<Infra> readAllByDomain(Domain domain) {
public Page<Infra> readAllByDomain(Domain domain, int pageNo, int countPerPage) {
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) {
return this.infraDAO.findAllByProbeList(probeList);
}
// public List<Infra> readAllByProbeList(List<Probe> probeList) {
// return this.infraDAO.findAllByProbeList(probeList);
// }
public List<Target> readAllTargetByDomain(Domain domain) {
@ -59,4 +68,5 @@ public class InfraService {
// return null;
}
}

View File

@ -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<Infra> 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<Infra> 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<Infra> 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<Infra> fl = this.infraService.readAllByDomain(domain);
//
// System.out.println(fl.size());
// ObjectMapper objectMapper = new ObjectMapper();
// String json = objectMapper.writeValueAsString(fl);
//
// System.out.println(json);
//
// }
}