sensor readallbydomain
This commit is contained in:
snoop 2017-08-14 16:48:32 +09:00
parent a07d063be1
commit 500d976908
8 changed files with 116 additions and 2 deletions

View File

@ -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<Infra, Long> {
public List<Infra> findAllByProbe(Probe probe);
List<Infra> findAllByProbe(List<Probe> probeList);
@Query("SELECT DISTINCT i.target FROM Infra i WHERE i.probe IN (:probeList)")
List<Target> findAllTargetByProbeList(@Param("probeList") List<Probe> probeList);
}

View File

@ -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<Infra> readAllByProbeList(List<Probe> probeList) {
return this.infraDAO.findAllByProbe(probeList);
}
public List<Target> readAllTargetByProbeList(List<Probe> probeList) {
return this.infraDAO.findAllTargetByProbeList(probeList);
}
}

View File

@ -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<Sensor, Long> {
List<Sensor> findAllByTarget(Target target);
List<Sensor> findAllByTarget(List<Target> targetList);
// List<Sensor> findAllByTargetList(List<Target> targets);
}

View File

@ -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<Sensor> readAllByDomain(Domain domain) {
List<Probe> probeList = this.probeService.readAllByDomain(domain);
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
return this.sensorDAO.findAllByTarget(targetList);
}
public Sensor read(String id) {
return this.sensorDAO.findOne(Long.valueOf(id));
}

View File

@ -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<Target, Long> {
// List<Target> findAllByProbe(Probe probe);
// List<Target> findAllByProbe(Probe probe);]
}

View File

@ -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<Probe> pl = this.probeService.readAllByDomain(domain);
List<Infra> fl = this.infraService.readAllByProbeList(pl);
System.out.println(fl.size());
}
}

View File

@ -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<Sensor> sl = this.sensorService.readAllByDomain(domain);
Assert.assertNotEquals(sl.size(), 0);
}
}

View File

@ -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;
}