diff --git a/src/main/java/com/loafle/overflow/meta/dao/MetaSensorStatusDAO.java b/src/main/java/com/loafle/overflow/meta/dao/MetaSensorStatusDAO.java new file mode 100644 index 0000000..d947ca1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/meta/dao/MetaSensorStatusDAO.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.meta.dao; + +import com.loafle.overflow.meta.model.MetaSensorStatus; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * Created by snoop on 17. 6. 26. + */ +@Repository +public interface MetaSensorStatusDAO extends JpaRepository { +} diff --git a/src/main/java/com/loafle/overflow/meta/model/MetaSensorStatus.java b/src/main/java/com/loafle/overflow/meta/model/MetaSensorStatus.java new file mode 100644 index 0000000..a1c32df --- /dev/null +++ b/src/main/java/com/loafle/overflow/meta/model/MetaSensorStatus.java @@ -0,0 +1,43 @@ +package com.loafle.overflow.meta.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * Created by snoop on 17. 6. 26. + */ +@Entity +@Table(name = "META_SENSOR_STATUS", schema = "public", catalog = "postgres") +public class MetaSensorStatus { + private short id; + private String name; + + public MetaSensorStatus() { + + } + + public MetaSensorStatus(short id) { + this.id = id; + } + + @Id + public short getId() { + return id; + } + + public void setId(short id) { + this.id = id; + } + + + @Column(name = "Name", nullable = false, length = 10) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorDao.java deleted file mode 100644 index b205658..0000000 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorDao.java +++ /dev/null @@ -1,27 +0,0 @@ -//package com.loafle.overflow.module.sensor.dao; -// -// -//import com.loafle.overflow.commons.dao.JPABaseDAO; -// -//import javax.persistence.Query; -//import java.util.List; -// -///** -// * Created by root on 17. 6. 9. -// */ -//public class JPASensorDao extends JPABaseDAO implements SensorDao { -// -// public List findAllByTargetId(Target target) { -// Query query = getEntityManager().createNativeQuery("SELECT s.* FROM Sensor s WHERE s.TARGET_ID = :targetId", Sensor.class); -// query.setParameter("targetId", target.getId()); -// -// List sensors = null; -// try { -// sensors = (List)query.getResultList(); -// }catch(Exception e) { -// e.printStackTrace(); -// }finally { -// return sensors; -// } -// } -//} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemCategoryDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemCategoryDao.java deleted file mode 100644 index f241eb4..0000000 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemCategoryDao.java +++ /dev/null @@ -1,9 +0,0 @@ -//package com.loafle.overflow.module.sensor.dao; -// -//import com.loafle.overflow.commons.dao.JPABaseDAO; -// -///** -// * Created by root on 17. 6. 9. -// */ -//public class JPASensorItemCategoryDao extends JPABaseDAO implements SensorItemCategoryDao { -//} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemDao.java deleted file mode 100644 index 3a42bc9..0000000 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemDao.java +++ /dev/null @@ -1,30 +0,0 @@ -//package com.loafle.overflow.module.sensor.dao; -// -//import com.loafle.overflow.commons.dao.JPABaseDAO; -//import com.loafle.overflow.module.crawler.model.Crawler; -// -// -//import javax.persistence.Query; -//import java.util.List; -// -///** -// * Created by root on 17. 6. 9. -// */ -//public class JPASensorItemDao extends JPABaseDAO implements SensorItemDao { -// -// public List findAllByCrawlerId(Crawler crawler) { -// -// Query query = getEntityManager().createNativeQuery("SELECT si.* FROM SensorItem si WHERE si.CRAWLER_ID = :crawlerId", SensorItem.class); -// query.setParameter("crawlerId", crawler.getId()); -// -// List sensorItems = null; -// try { -// sensorItems = (List)query.getResultList(); -// }catch(Exception e) { -// e.printStackTrace(); -// }finally { -// return sensorItems; -// } -// -// } -//} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemMappingDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemMappingDao.java deleted file mode 100644 index 4c74b5d..0000000 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/JPASensorItemMappingDao.java +++ /dev/null @@ -1,28 +0,0 @@ -//package com.loafle.overflow.module.sensor.dao; -// -//import com.loafle.overflow.commons.dao.JPABaseDAO; -// -//import javax.persistence.Query; -//import java.util.List; -// -///** -// * Created by root on 17. 6. 9. -// */ -//public class JPASensorItemMappingDao extends JPABaseDAO implements SensorItemMappingDao { -// -// public List findAllBySensorId(Sensor sensor) { -// -// Query query = getEntityManager().createNativeQuery("SELECT sim.* FROM SensorItemMapping sim WHERE sim.SENSOR_ID = :sensorId", SensorItemMapping.class); -// query.setParameter("sensorId", sensor.getId()); -// -// List sensorItemMappings = null; -// try { -// sensorItemMappings = (List)query.getResultList(); -// }catch(Exception e) { -// e.printStackTrace(); -// }finally { -// return sensorItemMappings; -// } -// -// } -//} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java similarity index 65% rename from src/main/java/com/loafle/overflow/module/sensor/dao/SensorDao.java rename to src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java index 9018878..4afb306 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDao.java +++ b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorDAO.java @@ -5,13 +5,10 @@ import com.loafle.overflow.module.sensor.model.Sensor; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * Created by root on 17. 6. 9. */ @Repository -public interface SensorDao extends JpaRepository { +public interface SensorDAO extends JpaRepository { -// List findAllByTargetId(Target target); } diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemCategoryDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemCategoryDao.java deleted file mode 100644 index 2cf03d0..0000000 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemCategoryDao.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.loafle.overflow.module.sensor.dao; - - -import org.springframework.stereotype.Repository; - -/** - * Created by root on 17. 6. 9. - */ -//@Repository -//public interface SensorItemCategoryDao extends JpaRepository { -//} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java similarity index 79% rename from src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDao.java rename to src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java index d7df07b..6e72d89 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDao.java +++ b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDAO.java @@ -4,13 +4,11 @@ import com.loafle.overflow.module.sensor.model.SensorItem; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * Created by root on 17. 6. 9. */ @Repository -public interface SensorItemDao extends JpaRepository { +public interface SensorItemDAO extends JpaRepository { // List findAllByCrawlerId(Crawler crawler); } diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemMappingDao.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemMappingDao.java deleted file mode 100644 index edf2bb0..0000000 --- a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemMappingDao.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.loafle.overflow.module.sensor.dao; - - -/** - * Created by root on 17. 6. 9. - */ -//@Repository -//public interface SensorItemMappingDao extends JpaRepository { -// -//// List findAllBySensorId(Sensor sensor); -// -//} diff --git a/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java b/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java index 83b5d58..8c543d6 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java +++ b/src/main/java/com/loafle/overflow/module/sensor/model/Sensor.java @@ -1,6 +1,7 @@ package com.loafle.overflow.module.sensor.model; import com.loafle.overflow.meta.model.MetaCrawler; +import com.loafle.overflow.meta.model.MetaSensorStatus; import com.loafle.overflow.module.target.model.Target; import javax.persistence.*; @@ -15,7 +16,7 @@ public class Sensor { private long id; private Date createDate; private String description; - private String status; + private MetaSensorStatus status; private Target target; private MetaCrawler crawler; private String crawlerInputItems; @@ -49,12 +50,13 @@ public class Sensor { this.description = description; } - @Column(name = "STATUS", nullable = true, length = 50) - public String getStatus() { + @ManyToOne + @JoinColumn(name = "STATUS") + public MetaSensorStatus getStatus() { return status; } - public void setStatus(String status) { + public void setStatus(MetaSensorStatus status) { this.status = status; } @@ -78,13 +80,12 @@ public class Sensor { this.crawler = crawler; } - - @Column(name = "CRAWELR_INPUT_ITEMS", nullable = true, length = 50) - public String getcrawlerInputItems() { + @Column(name = "CRAWLER_INPUT_ITEMS", nullable = true, length = 50) + public String getCrawlerInputItems() { return crawlerInputItems; } - public void setcrawlerInputItems(String crawlerInputItems) { + public void setCrawlerInputItems(String crawlerInputItems) { this.crawlerInputItems = crawlerInputItems; } diff --git a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java index 149e5c7..04e1f3b 100644 --- a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java +++ b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java @@ -10,8 +10,8 @@ import com.loafle.overflow.module.member.dao.MemberDAO; import com.loafle.overflow.module.noauthprobe.dao.NoAuthProbeDAO; import com.loafle.overflow.module.probe.dao.ProbeDAO; import com.loafle.overflow.module.probe.dao.ProbeTaskDAO; -import com.loafle.overflow.module.sensor.dao.SensorDao; -import com.loafle.overflow.module.sensor.dao.SensorItemDao; +import com.loafle.overflow.module.sensor.dao.SensorDAO; +import com.loafle.overflow.module.sensor.dao.SensorItemDAO; import com.loafle.overflow.module.target.dao.TargetDAO; import io.grpc.ServerBuilder; import org.codehaus.jackson.map.ObjectMapper; @@ -48,8 +48,8 @@ public class DBProxy { daoMap.put("probeTask", ctx.getBean(ProbeTaskDAO.class)); daoMap.put("noauthProbe", ctx.getBean(NoAuthProbeDAO.class)); daoMap.put("emailAuth", ctx.getBean(EmailAuthDAO.class)); - daoMap.put("sensor", ctx.getBean(SensorDao.class)); - daoMap.put("sensorItem", ctx.getBean(SensorItemDao.class)); + daoMap.put("sensor", ctx.getBean(SensorDAO.class)); + daoMap.put("sensorItem", ctx.getBean(SensorItemDAO.class)); daoMap.put("domain", ctx.getBean(DomainDAO.class)); daoMap.put("target", ctx.getBean(TargetDAO.class)); daoMap.put("infra", ctx.getBean(InfraDAO.class)); diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 6ac780b..7c0aeb0 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -211,7 +211,7 @@ INSERT INTO public.domain_member (id,create_date,domain_id,member_id) VALUES ( 1,'2017-06-26 11:27:43.023',1,1); - INSERT INTO public.meta_probe_status (id,"name") VALUES ( +INSERT INTO public.meta_probe_status (id,"name") VALUES ( 1,'INITIAL'); INSERT INTO public.meta_probe_status (id,"name") VALUES ( 2,'NORMAL'); @@ -245,3 +245,8 @@ INSERT INTO public.target (id,create_date,infra_id,probe_id) VALUES ( INSERT INTO public.meta_probe_task_type (id,create_date,description,"name") VALUES ( 1,'2017-06-26 15:58:02.397','DISCOVERY START','DISCOVERY'); + +INSERT INTO public.meta_sensor_status (id,"name") VALUES ( +1,'RUNNING'); +INSERT INTO public.meta_sensor_status (id,"name") VALUES ( +2,'STOPPED'); \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/meta/dao/MetaSensorStatusDAOTest.java b/src/test/java/com/loafle/overflow/meta/dao/MetaSensorStatusDAOTest.java new file mode 100644 index 0000000..ff402d2 --- /dev/null +++ b/src/test/java/com/loafle/overflow/meta/dao/MetaSensorStatusDAOTest.java @@ -0,0 +1,38 @@ +package com.loafle.overflow.meta.dao; + +import com.loafle.overflow.AppConfig; +import com.loafle.overflow.JdbcConfiguration; +import com.loafle.overflow.meta.model.MetaSensorStatus; +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; + +/** + * Created by snoop on 17. 6. 26. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) +public class MetaSensorStatusDAOTest { + + @Autowired + private MetaSensorStatusDAO dao; + + @Test + public void Create() { + + MetaSensorStatus run = new MetaSensorStatus(); + run.setId((short)1); + run.setName("RUNNING"); + + MetaSensorStatus stop = new MetaSensorStatus(); + stop.setId((short)2); + stop.setName("STOPPED"); + + this.dao.save(run); + this.dao.save(stop); + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java b/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java new file mode 100644 index 0000000..4ab33bb --- /dev/null +++ b/src/test/java/com/loafle/overflow/module/sensor/dao/SensorDAOTest.java @@ -0,0 +1,62 @@ +package com.loafle.overflow.module.sensor.dao; + +import com.loafle.overflow.AppConfig; +import com.loafle.overflow.JdbcConfiguration; +import com.loafle.overflow.meta.model.MetaCrawler; +import com.loafle.overflow.meta.model.MetaCrawlerInputItem; +import com.loafle.overflow.meta.model.MetaSensorStatus; +import com.loafle.overflow.module.sensor.model.Sensor; +import com.loafle.overflow.module.target.model.Target; +import org.junit.After; +import org.junit.Before; +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.Date; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) +public class SensorDAOTest { + + @Autowired + private SensorDAO sensorDAO; + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void create() { + Sensor sensor = new Sensor(); + sensor.setDescription("My sensor"); + sensor.setCreateDate(new Date()); + + MetaSensorStatus status = new MetaSensorStatus(); + status.setId((short)1); + sensor.setStatus(status); + + Target target = new Target(); + target.setId(1); + sensor.setTarget(target); + + MetaCrawler crawler = new MetaCrawler(); + crawler.setId((short)1); + + MetaCrawlerInputItem inputItem = new MetaCrawlerInputItem(); + inputItem.setId(1); + + sensor.setCrawler(crawler); + sensorDAO.save(sensor); + } + + +} \ No newline at end of file