diff --git a/pom.xml b/pom.xml
index ccdc953..588ba00 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
com.loafle.overflow
commons-java
- 1.0.103-SNAPSHOT
+ 1.0.106-SNAPSHOT
diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java
index cd718f5..f2d52a4 100644
--- a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java
+++ b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java
@@ -1,7 +1,5 @@
package com.loafle.overflow.central.module.sensor.dao;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -15,11 +13,9 @@ import com.loafle.overflow.model.target.Target;
*/
@Repository
public interface SensorDAO extends JpaRepository {
- Page findAllByTargetId(Long targetID, Pageable pageable);
-
List findAllByTargetId(Long targetID);
- Page findAllByTargetIn(List targets, Pageable pageable);
+ List findAllByTargetIn(List targets);
- Page findAllByTargetInfraId(Long infraID, Pageable pageable);
+ List findAllByTargetInfraProbeId(Long probeId);
}
diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java
index 0342ca7..55a830f 100644
--- a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java
+++ b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java
@@ -1,9 +1,9 @@
package com.loafle.overflow.central.module.sensor.dao;
+import java.util.List;
+
import com.loafle.overflow.model.sensor.SensorItem;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -12,5 +12,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface SensorItemDAO extends JpaRepository {
- Page findAllBySensorId(Long sensorId, Pageable pageable);
+ List findAllBySensorId(Long sensorId);
}
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 172e671..374aacd 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
@@ -1,16 +1,14 @@
package com.loafle.overflow.central.module.sensor.service;
-import com.loafle.overflow.central.commons.utils.PageUtil;
-import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
import com.loafle.overflow.central.module.sensor.dao.SensorItemDAO;
import com.loafle.overflow.core.exception.OverflowException;
-import com.loafle.overflow.core.model.PageParams;
+import com.loafle.overflow.model.meta.MetaDisplayItemMapping;
import com.loafle.overflow.model.sensor.Sensor;
import com.loafle.overflow.model.sensor.SensorItem;
import com.loafle.overflow.service.central.sensor.SensorItemService;
+
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
@@ -25,38 +23,39 @@ public class CentralSensorItemService implements SensorItemService {
@Autowired
private SensorItemDAO sensorItemDAO;
@Autowired
- private SensorDAO sensorDAO;
+ private CentralSensorService sensorService;
- @Transactional
- public SensorItem regist(SensorItem sensorItem) throws OverflowException {
- Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get();
- s.setItemCount(s.getItemCount() + 1);
- this.sensorDAO.save(s);
+ public SensorItem regist(Sensor sensor, MetaDisplayItemMapping metaDisplayItemMapping) throws OverflowException {
+ SensorItem sensorItem = new SensorItem();
+ sensorItem.setMetaDisplayItemMapping(metaDisplayItemMapping);
+ sensorItem.setSensor(sensor);
return this.sensorItemDAO.save(sensorItem);
}
- @Transactional
- public boolean registAll(List sensorItemList) throws OverflowException {
- Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get();
- s.setItemCount(sensorItemList.size());
- this.sensorDAO.save(s);
- this.sensorItemDAO.saveAll(sensorItemList);
- return true;
- }
-
- public SensorItem read(String id) throws OverflowException {
+ @Override
+ public SensorItem read(Long id) throws OverflowException {
return this.sensorItemDAO.findById(Long.valueOf(id)).get();
}
- public Page readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException {
- return this.sensorItemDAO.findAllBySensorId(sensorID, PageUtil.getPageRequest(pageParams));
+ @Override
+ public List readAllBySensorID(Long sensorID) throws OverflowException {
+ return this.sensorItemDAO.findAllBySensorId(sensorID);
}
@Transactional
- public void remove(SensorItem sensorItem) throws OverflowException {
- Sensor s = sensorItem.getSensor();
- s.setItemCount(s.getItemCount() - 1);
- this.sensorDAO.save(s);
- this.sensorItemDAO.delete(sensorItem);
+ @Override
+ public void remove(Long sensorItemID) throws OverflowException {
+ SensorItem sensorItem = this.read(sensorItemID);
+ if (null == sensorItem) {
+ throw new OverflowException(String.format("ID[%d] of SensorItem is not valid", sensorItemID));
+ }
+ Sensor sensor = sensorItem.getSensor();
+ if (null == sensor) {
+ throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorItem.getSensor().getId()));
+ }
+ sensor.setItemCount(sensor.getItemCount() - 1);
+ this.sensorService.regist(sensor);
+ this.sensorItemDAO.deleteById(sensorItemID);
}
+
}
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 174726e..d213b59 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
@@ -1,20 +1,18 @@
package com.loafle.overflow.central.module.sensor.service;
-import com.loafle.overflow.central.commons.utils.PageUtil;
import com.loafle.overflow.central.module.sensor.dao.SensorDAO;
import com.loafle.overflow.core.exception.OverflowException;
-import com.loafle.overflow.core.model.PageParams;
+import com.loafle.overflow.model.meta.MetaDisplayItemMapping;
+import com.loafle.overflow.model.meta.MetaSensorStatus;
import com.loafle.overflow.model.sensor.Sensor;
-import com.loafle.overflow.model.sensor.SensorItem;
-import com.loafle.overflow.service.central.sensor.SensorItemService;
+import com.loafle.overflow.model.target.Target;
import com.loafle.overflow.service.central.sensor.SensorService;
import com.loafle.overflow.service.central.target.TargetService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
-import javax.transaction.Transactional;
import java.util.List;
/**
@@ -24,56 +22,96 @@ import java.util.List;
public class CentralSensorService implements SensorService {
@Autowired
- SensorDAO sensorDAO;
+ private SensorDAO sensorDAO;
@Autowired
- private SensorItemService sensorItemService;
+ private CentralSensorItemService sensorItemService;
@Autowired
private TargetService targetService;
@Transactional
- public Sensor regist(Sensor sensor, Long targetID) throws OverflowException {
+ @Override
+ public Sensor regist(Sensor sensor, List metaDisplayItemMappings) throws OverflowException {
+ Long targetID = sensor.getTarget().getId();
+ Target t = this.targetService.read(targetID);
+ if (null == t) {
+ throw new OverflowException(String.format("ID[%d] of Target is not valid", targetID));
+ }
+ if (null == sensor.getName()) {
+ String crawlerName = sensor.getMetaCrawlerMapping().getMetaCrawler().getName();
+ String targetTypeName = sensor.getTarget().getMetaTargetType().getName();
+ sensor.setName(targetTypeName + " Sensor via " + crawlerName);
+ }
+ sensor.setMetaSensorStatus(MetaSensorStatus.Enum.RUNNING.to());
+ Sensor s = this.sensorDAO.save(sensor);
+ s.setItemCount(0);
this.targetService.increaseSensorCount(targetID);
- return this.sensorDAO.save(sensor);
+
+ for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
+ this.sensorItemService.regist(s, metaDisplayItemMapping);
+ }
+ return s;
}
+ @Transactional
+ @Override
+ public Sensor modify(Long sensorID, List metaDisplayItemMappings) throws OverflowException {
+ // FIXME : not impl
+ return null;
+ }
+
+ @Override
public Sensor read(Long id) throws OverflowException {
return this.sensorDAO.findById(id).get();
}
@Transactional
- public void remove(Long id, Long targertID) throws OverflowException {
- this.targetService.decreaseSensorCount(targertID);
+ @Override
+ public void remove(Long id) throws OverflowException {
+ Sensor sensor = this.read(id);
+ if (null == sensor) {
+ throw new OverflowException(String.format("ID[%d] of Sensor is not valid", id));
+ }
+ this.targetService.decreaseSensorCount(sensor.getTarget().getId());
this.sensorDAO.deleteById(id);
}
- public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
- // FIXME: NOT IMPLEMENTS
- return null;
- }
-
- public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
- // FIXME: NOT IMPLEMENTS
- return null;
- }
-
- public Page readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
- return this.sensorDAO.findAllByTargetInfraId(infraID, PageUtil.getPageRequest(pageParams));
- }
-
- public Page readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
- return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
+ @Override
+ public List readAll() throws OverflowException {
+ return this.sensorDAO.findAll();
}
@Override
+ public List readAllByTargetID(Long targetID) throws OverflowException {
+ return this.sensorDAO.findAllByTargetId(targetID);
+ }
+
+ @Override
+ public List readAllByTargetIn(List targets) throws OverflowException {
+ return this.sensorDAO.findAllByTargetIn(targets);
+ }
+
+ @Override
+ public List readAllByTargetInfraProbeID(Long probeID) throws OverflowException {
+ return this.sensorDAO.findAllByTargetInfraProbeId(probeID);
+ }
+
+ public Sensor regist(Sensor sensor) throws OverflowException {
+ Long targetID = sensor.getTarget().getId();
+ Target t = this.targetService.read(targetID);
+ if (null == t) {
+ throw new OverflowException(String.format("ID[%d] of Target is not valid", targetID));
+ }
+ return this.sensorDAO.save(sensor);
+ }
+
public Sensor increaseSensorItemCount(Long id) throws OverflowException {
Sensor s = this.sensorDAO.findById(id).get();
s.setItemCount(s.getItemCount() + 1);
return this.sensorDAO.save(s);
}
- @Override
public Sensor decreaseSensorItemCount(Long id) throws OverflowException {
Sensor s = this.sensorDAO.findById(id).get();
int count = s.getItemCount();
@@ -83,25 +121,4 @@ public class CentralSensorService implements SensorService {
return this.sensorDAO.save(s);
}
- @Transactional
- public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson)
- throws OverflowException {
-
- this.targetService.increaseSensorCount(sensor.getTarget().getId());
- this.sensorDAO.save(sensor);
-
- for (SensorItem sensorItem : sensorItemList) {
- sensorItem.setSensor(sensor);
- }
-
- this.sensorItemService.registAll(sensorItemList);
-
- return sensor;
- }
-
- @Override
- public String generateSensorConfig(Sensor sensor) throws OverflowException {
- return null;
- }
-
}
\ No newline at end of file
diff --git a/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAOTest.java b/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAOTest.java
index e075b37..341cfd6 100644
--- a/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAOTest.java
+++ b/src/test/java/com/loafle/overflow/central/module/infra/dao/InfraHostPortDAOTest.java
@@ -5,9 +5,7 @@ import static org.junit.Assert.assertNotNull;
import java.util.List;
import com.loafle.overflow.central.spring.AppConfigTest;
-import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.infra.InfraHostPort;
-import com.loafle.overflow.model.member.Member;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceTest.java
index 5e8770c..f0df2a4 100644
--- a/src/test/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceTest.java
+++ b/src/test/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceTest.java
@@ -6,7 +6,6 @@ import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.discovery.Port;
import com.loafle.overflow.model.discovery.Service;
import com.loafle.overflow.model.discovery.Zone;
-import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.meta.MetaCryptoType;
import com.loafle.overflow.model.meta.MetaIPType;
import com.loafle.overflow.model.meta.MetaPortType;
@@ -23,8 +22,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import static org.junit.Assert.*;
-
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("test")
@ContextConfiguration(classes = { AppConfigTest.class })
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 dd1bee4..bda62dc 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,141 +1,49 @@
-// package com.loafle.overflow.central.module.sensor.service;
+ package com.loafle.overflow.central.module.sensor.service;
-// import com.loafle.overflow.central.module.meta.model.MetaCrawler;
-// import com.loafle.overflow.central.module.meta.model.MetaSensorStatus;
-// import com.loafle.overflow.central.module.sensor.model.Sensor;
-// import com.loafle.overflow.central.module.target.model.Target;
-// import com.loafle.overflow.central.spring.AppConfigTest;
-// import com.fasterxml.jackson.databind.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 com.loafle.overflow.central.spring.AppConfigTest;
+ import com.fasterxml.jackson.databind.ObjectMapper;
+ import com.loafle.overflow.service.central.sensor.SensorService;
+ 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.Date;
-// import java.util.HashMap;
-// import java.util.Map;
+ import java.io.IOException;
+ import java.util.Date;
+ import java.util.HashMap;
+ import java.util.Map;
-// /**
-// * Created by insanity on 17. 6. 28.
-// */
-// //@Ignore
-// @RunWith(SpringJUnit4ClassRunner.class)
-// @ContextConfiguration(classes = {AppConfigTest.class})
-// public class SensorServiceTest {
-// @Autowired
-// SensorService sensorService;
+ /**
+ * Created by insanity on 17. 6. 28.
+ */
+ //@Ignore
+ @RunWith(SpringJUnit4ClassRunner.class)
+ @ContextConfiguration(classes = {AppConfigTest.class})
+ public class SensorServiceTest {
+ @Autowired
+ SensorService sensorService;
-// @Autowired
-// ObjectMapper objectMapper;
+ @Autowired
+ ObjectMapper objectMapper;
-// @Ignore
-// @Test
-// public void regist() throws Exception {
-// Sensor sensor = new Sensor();
-// MetaSensorStatus status = new MetaSensorStatus((short)1);
-// sensor.setStatus(status);
-// MetaCrawler crawler = new MetaCrawler();
-// crawler.setId((short)1);
-// sensor.setCrawler(crawler);
-// Target target = new Target();
-// target.setId(1);
-// sensor.setTarget(target);
-// sensor.setCreateDate(new Date());
-// Sensor res = this.sensorService.regist(sensor);
-// Assert.assertNotNull(res);
-// }
+ @Test
+ public void regist() throws Exception {
+ Sensor sensor = new Sensor();
+ MetaSensorStatus status = new MetaSensorStatus((short)1);
+ sensor.setStatus(status);
+ MetaCrawler crawler = new MetaCrawler();
+ crawler.setId((short)1);
+ sensor.setCrawler(crawler);
+ Target target = new Target();
+ target.setId(1);
+ sensor.setTarget(target);
+ sensor.setCreateDate(new Date());
-// @Test
-// public void read() throws Exception {
-// Sensor res = this.sensorService.read("1");
-// Assert.assertNotNull(res);
-
-// ObjectMapper objectMapper = new ObjectMapper();
-
-// // String json = objectMapper.writeValueAsString(res);
-
-// String json = this.objectMapper.writeValueAsString(res);
-
-// System.out.println(json);
-// }
-
-// @Test
-// public void generateSensorConfig() throws IOException {
-
-// Sensor sensor = new Sensor();
-// sensor.setId(5);
-// String result = this.sensorService.generateSensorConfig(sensor);
-
-// System.out.println(result);
-
-// }
-
-// @Test
-// public void testJsonToMap() throws IOException {
-
-// String json = "{\"interval\":5}";
-
-// ObjectMapper objectMapper = new ObjectMapper();
-
-// Map mm = new HashMap<>();
-
-// mm = objectMapper.readValue(json, HashMap.class);
-
-// System.out.println(mm.get("interval"));
-
-// }
-
-// @Test
-// public void stringbbb() {
-// StringBuffer stringBuffer = new StringBuffer();
-
-// stringBuffer.append("222222222222222222222222222");
-// System.out.println(stringBuffer.toString());
-// stringBuffer.setLength(0);
-// System.out.println(stringBuffer.toString());
-// stringBuffer.append("3333333333");
-// System.out.println(stringBuffer.toString());
-// }
-
-// // @Test
-// // public void readAllByTarget() throws Exception {
-// // Target target = new Target();
-// // target.setId(1);
-// // List sensors = this.sensorService.readAllByTarget(target);
-// //
-// // ObjectMapper objectMapper = new ObjectMapper();
-// //
-// // String json = objectMapper.writeValueAsString(sensors);
-// //
-// // System.out.println(json);
-// // }
-
-// // @Test
-// // public void readAllByTargetList() {
-// //
-// // Domain domain = new Domain();
-// // domain.setId(1);
-// //
-// // List sl = this.sensorService.readAllByDomain(domain);
-// //
-// // Assert.assertNotEquals(sl.size(), 0);
-// //
-// // }
-
-// // @Test
-// // public void readAllByInfra() {
-// //
-// // Infra infra = new InfraMachine();
-// // infra.setId(1);
-// //
-// // List sl = this.sensorService.readAllByInfra(1);
-// //
-// // Assert.assertNotEquals(sl.size(), 0);
-// //
-// // }
-// }
+ Sensor res = this.sensorService.regist(sensor);
+ Assert.assertNotNull(res);
+ }
+ }