Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
1114db4941
|
@ -16,6 +16,9 @@ public class PageUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PageRequest getPageRequest(PageParams pageParams) {
|
public static PageRequest getPageRequest(PageParams pageParams) {
|
||||||
|
if(pageParams.getSortCol().isEmpty()) pageParams.setSortCol("id");
|
||||||
|
if(pageParams.getSortDirection().isEmpty()) pageParams.setSortDirection("descending");
|
||||||
|
|
||||||
return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(),
|
return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(),
|
||||||
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
|
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.loafle.overflow.module.infra.service;
|
package com.loafle.overflow.module.infra.service;
|
||||||
|
|
||||||
|
import com.loafle.overflow.commons.model.PageParams;
|
||||||
|
import com.loafle.overflow.commons.utils.PageUtil;
|
||||||
import com.loafle.overflow.module.domain.model.Domain;
|
import com.loafle.overflow.module.domain.model.Domain;
|
||||||
import com.loafle.overflow.module.infra.dao.InfraDAO;
|
import com.loafle.overflow.module.infra.dao.InfraDAO;
|
||||||
import com.loafle.overflow.module.infra.model.Infra;
|
import com.loafle.overflow.module.infra.model.Infra;
|
||||||
|
@ -8,9 +10,6 @@ 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.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;
|
||||||
|
@ -36,20 +35,13 @@ public class InfraService {
|
||||||
return this.infraDAO.findOne(id);
|
return this.infraDAO.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Infra> readAllByProbe(Probe probe, int pageNo, int countPerPage) {
|
public Page<Infra> readAllByProbe(Probe probe, PageParams pageParams) {
|
||||||
Pageable pageRequest =
|
return this.infraDAO.findAllByProbe(probe, PageUtil.getPageRequest(pageParams));
|
||||||
new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id"));
|
|
||||||
return this.infraDAO.findAllByProbe(probe, pageRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Infra> readAllByDomain(Domain domain, int pageNo, int countPerPage) {
|
public Page<Infra> readAllByDomain(Domain domain, PageParams pageParams) {
|
||||||
|
|
||||||
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
||||||
|
return this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams));
|
||||||
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) {
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.loafle.overflow.module.sensor.dao;
|
||||||
|
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
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;
|
||||||
|
@ -17,10 +19,10 @@ import java.util.List;
|
||||||
public interface SensorDAO extends JpaRepository<Sensor, Long> {
|
public interface SensorDAO extends JpaRepository<Sensor, Long> {
|
||||||
|
|
||||||
|
|
||||||
List<Sensor> findAllByTarget(Target target);
|
Page<Sensor> findAllByTarget(Target target, Pageable pageable);
|
||||||
|
|
||||||
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
|
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
|
||||||
List<Sensor> findAllByTargetList(@Param("targetList") List<Target> targetList);
|
Page<Sensor> findAllByTargetList(@Param("targetList") List<Target> targetList, Pageable pageable);
|
||||||
// List<Sensor> findAllByTargetList(List<Target> targets);
|
// List<Sensor> findAllByTargetList(List<Target> targets);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.loafle.overflow.module.sensor.dao;
|
||||||
|
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.sensor.model.SensorItem;
|
import com.loafle.overflow.module.sensor.model.SensorItem;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@ -12,5 +13,5 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public interface SensorItemDAO extends JpaRepository<SensorItem, Long> {
|
public interface SensorItemDAO extends JpaRepository<SensorItem, Long> {
|
||||||
List<SensorItem> findAllBySensor(Sensor sensor);
|
List<SensorItem> findAllBySensor(Sensor sensor, Pageable pageable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.loafle.overflow.module.sensor.service;
|
package com.loafle.overflow.module.sensor.service;
|
||||||
|
|
||||||
|
import com.loafle.overflow.commons.model.PageParams;
|
||||||
|
import com.loafle.overflow.commons.utils.PageUtil;
|
||||||
import com.loafle.overflow.module.sensor.dao.SensorItemDAO;
|
import com.loafle.overflow.module.sensor.dao.SensorItemDAO;
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.sensor.model.SensorItem;
|
import com.loafle.overflow.module.sensor.model.SensorItem;
|
||||||
|
@ -29,8 +31,8 @@ public class SensorItemService {
|
||||||
return this.sensorItemDAO.findOne(Long.valueOf(id));
|
return this.sensorItemDAO.findOne(Long.valueOf(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SensorItem> readAllBySensor(Sensor sensor) {
|
public List<SensorItem> readAllBySensor(Sensor sensor, PageParams pageParams) {
|
||||||
return this.sensorItemDAO.findAllBySensor(sensor);
|
return this.sensorItemDAO.findAllBySensor(sensor, PageUtil.getPageRequest(pageParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(SensorItem sensorItem) {
|
public void remove(SensorItem sensorItem) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.loafle.overflow.module.sensor.service;
|
package com.loafle.overflow.module.sensor.service;
|
||||||
|
|
||||||
|
import com.loafle.overflow.commons.model.PageParams;
|
||||||
|
import com.loafle.overflow.commons.utils.PageUtil;
|
||||||
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.service.InfraService;
|
import com.loafle.overflow.module.infra.service.InfraService;
|
||||||
|
@ -11,6 +13,7 @@ import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.sensor.model.SensorItem;
|
import com.loafle.overflow.module.sensor.model.SensorItem;
|
||||||
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.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
@ -38,25 +41,25 @@ public class SensorService {
|
||||||
return this.sensorDAO.save(sensor);
|
return this.sensorDAO.save(sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Sensor> readAllByTarget(Target target) {
|
// public List<Sensor> readAllByTarget(Target target, PageParams pageParams) {
|
||||||
return this.sensorDAO.findAllByTarget(target);
|
// return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams));
|
||||||
}
|
// }
|
||||||
|
|
||||||
public List<Sensor> readAllByDomain(Domain domain) {
|
public Page<Sensor> readAllByDomain(Domain domain, PageParams pageParams) {
|
||||||
|
|
||||||
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
||||||
|
|
||||||
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
|
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
|
||||||
|
|
||||||
return this.sensorDAO.findAllByTargetList(targetList);
|
return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Sensor> readAllByInfra(long infraId) {
|
public Page<Sensor> readAllByInfra(long infraId, PageParams pageParams) {
|
||||||
Infra dbInfra = this.infraService.read(infraId);
|
Infra dbInfra = this.infraService.read(infraId);
|
||||||
|
|
||||||
if(dbInfra == null || dbInfra.getTarget() == null) return null;
|
if(dbInfra == null || dbInfra.getTarget() == null) return null;
|
||||||
|
|
||||||
return this.sensorDAO.findAllByTarget(dbInfra.getTarget());
|
return this.sensorDAO.findAllByTarget(dbInfra.getTarget(), PageUtil.getPageRequest(pageParams));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.loafle.overflow.module.meta.model.MetaSensorItem;
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.sensor.model.SensorItem;
|
import com.loafle.overflow.module.sensor.model.SensorItem;
|
||||||
import com.loafle.overflow.spring.AppConfigTest;
|
import com.loafle.overflow.spring.AppConfigTest;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -13,9 +12,7 @@ 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.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by insanity on 17. 6. 28.
|
* Created by insanity on 17. 6. 28.
|
||||||
|
@ -49,14 +46,14 @@ public class SensorItemServiceTest {
|
||||||
Assert.assertNotNull(res);
|
Assert.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void readAllBySensor() throws IOException {
|
// public void readAllBySensor() throws IOException {
|
||||||
Sensor sensor = new Sensor();
|
// Sensor sensor = new Sensor();
|
||||||
sensor.setId(1);
|
// sensor.setId(1);
|
||||||
List<SensorItem> sensorItems = this.sensorItemService.readAllBySensor(sensor);
|
// List<SensorItem> sensorItems = this.sensorItemService.readAllBySensor(sensor);
|
||||||
|
//
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String json = objectMapper.writeValueAsString(sensorItems);
|
// String json = objectMapper.writeValueAsString(sensorItems);
|
||||||
System.out.println(json);
|
// System.out.println(json);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package com.loafle.overflow.module.sensor.service;
|
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.model.InfraMachine;
|
|
||||||
import com.loafle.overflow.module.meta.model.MetaCrawler;
|
import com.loafle.overflow.module.meta.model.MetaCrawler;
|
||||||
import com.loafle.overflow.module.meta.model.MetaSensorStatus;
|
import com.loafle.overflow.module.meta.model.MetaSensorStatus;
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
|
@ -18,7 +15,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by insanity on 17. 6. 28.
|
* Created by insanity on 17. 6. 28.
|
||||||
|
@ -62,40 +58,40 @@ public class SensorServiceTest {
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void readAllByTarget() throws Exception {
|
// public void readAllByTarget() throws Exception {
|
||||||
Target target = new Target();
|
// Target target = new Target();
|
||||||
target.setId(1);
|
// target.setId(1);
|
||||||
List<Sensor> sensors = this.sensorService.readAllByTarget(target);
|
// List<Sensor> sensors = this.sensorService.readAllByTarget(target);
|
||||||
|
//
|
||||||
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
//
|
||||||
|
// String json = objectMapper.writeValueAsString(sensors);
|
||||||
|
//
|
||||||
|
// System.out.println(json);
|
||||||
|
// }
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// @Test
|
||||||
|
// public void readAllByTargetList() {
|
||||||
|
//
|
||||||
|
// Domain domain = new Domain();
|
||||||
|
// domain.setId(1);
|
||||||
|
//
|
||||||
|
// List<Sensor> sl = this.sensorService.readAllByDomain(domain);
|
||||||
|
//
|
||||||
|
// Assert.assertNotEquals(sl.size(), 0);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
String json = objectMapper.writeValueAsString(sensors);
|
// @Test
|
||||||
|
// public void readAllByInfra() {
|
||||||
System.out.println(json);
|
//
|
||||||
}
|
// Infra infra = new InfraMachine();
|
||||||
|
// infra.setId(1);
|
||||||
@Test
|
//
|
||||||
public void readAllByTargetList() {
|
// List<Sensor> sl = this.sensorService.readAllByInfra(1);
|
||||||
|
//
|
||||||
Domain domain = new Domain();
|
// Assert.assertNotEquals(sl.size(), 0);
|
||||||
domain.setId(1);
|
//
|
||||||
|
// }
|
||||||
List<Sensor> sl = this.sensorService.readAllByDomain(domain);
|
|
||||||
|
|
||||||
Assert.assertNotEquals(sl.size(), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void readAllByInfra() {
|
|
||||||
|
|
||||||
Infra infra = new InfraMachine();
|
|
||||||
infra.setId(1);
|
|
||||||
|
|
||||||
List<Sensor> sl = this.sensorService.readAllByInfra(1);
|
|
||||||
|
|
||||||
Assert.assertNotEquals(sl.size(), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user