diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java index 374aacd..471e6bd 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java @@ -58,4 +58,8 @@ public class CentralSensorItemService implements SensorItemService { this.sensorItemDAO.deleteById(sensorItemID); } + public void removeAllBySensorID(Long sensorID) throws OverflowException { + this.sensorItemDAO.deleteAll(this.readAllBySensorID(sensorID)); + } + } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java index d213b59..1624ae9 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java @@ -57,8 +57,15 @@ public class CentralSensorService implements SensorService { @Transactional @Override public Sensor modify(Long sensorID, List metaDisplayItemMappings) throws OverflowException { - // FIXME : not impl - return null; + Sensor sensor = this.read(sensorID); + if (null == sensor) { + throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorID)); + } + this.sensorItemService.readAllBySensorID(sensorID); + for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) { + this.sensorItemService.regist(sensor, metaDisplayItemMapping); + } + return sensor; } @Override diff --git a/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java b/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java index b9c161b..ef16cdb 100644 --- a/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java @@ -1,8 +1,13 @@ package com.loafle.overflow.central.module.sensor.service; +import com.loafle.overflow.central.module.meta.dao.MetaCrawlerMappingDAO; import com.loafle.overflow.central.module.meta.dao.MetaDisplayItemMappingDAO; import com.loafle.overflow.central.spring.AppConfigTest; -import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.ArrayList; +import java.util.List; + +import com.loafle.overflow.model.meta.MetaCrawlerMapping; import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.target.Target; import com.loafle.overflow.service.central.sensor.SensorService; @@ -30,9 +35,8 @@ public class SensorServiceTest { @Autowired MetaDisplayItemMappingDAO metaDisplayItemMappingService; - @Autowired - ObjectMapper objectMapper; + MetaCrawlerMappingDAO metaCrawlerMappingDAO; @Test @Ignore @@ -42,7 +46,40 @@ public class SensorServiceTest { Sensor sensor = new Sensor(); sensor.setTarget(target); + List metaCrawlerMappings = this.metaCrawlerMappingDAO.findAll(); + sensor.setMetaCrawlerMapping(metaCrawlerMappings.get(0)); + Sensor result = this.sensorService.regist(sensor, this.metaDisplayItemMappingService.findAll()); Assert.assertNotNull(result); } + + @Test + @Ignore + public void readAllByTargetID() throws Exception { + this.regist(); + Assert.assertNotNull(this.sensorService.readAllByTargetID(Long.valueOf(1))); + } + + @Test + @Ignore + public void readAllByTargetIn() throws Exception { + this.regist(); + List targets = new ArrayList(); + Target t1 = new Target(); + t1.setId(Long.valueOf(1)); + Target t2 = new Target(); + t2.setId(Long.valueOf(2)); + targets.add(t1); + targets.add(t2); + List sensors = this.sensorService.readAllByTargetIn(targets); + Assert.assertNotNull(sensors); + } + + @Test + @Ignore + public void readAllByTargetInfraProbeID() throws Exception { + this.regist(); + List sensors = this.sensorService.readAllByTargetInfraProbeID(Long.valueOf(1)); + Assert.assertNotNull(sensors); + } }