This commit is contained in:
insanity 2017-06-26 17:59:23 +09:00
parent 46dc9758b2
commit 1f69042bac
15 changed files with 176 additions and 137 deletions

View File

@ -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<MetaSensorStatus, Short> {
}

View File

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

View File

@ -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<Sensor> implements SensorDao {
//
// public List<Sensor> 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<Sensor> sensors = null;
// try {
// sensors = (List<Sensor>)query.getResultList();
// }catch(Exception e) {
// e.printStackTrace();
// }finally {
// return sensors;
// }
// }
//}

View File

@ -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<SensorItemCategory> implements SensorItemCategoryDao {
//}

View File

@ -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<SensorItem> implements SensorItemDao {
//
// public List<SensorItem> 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<SensorItem> sensorItems = null;
// try {
// sensorItems = (List<SensorItem>)query.getResultList();
// }catch(Exception e) {
// e.printStackTrace();
// }finally {
// return sensorItems;
// }
//
// }
//}

View File

@ -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<SensorItemMapping> implements SensorItemMappingDao {
//
// public List<SensorItemMapping> 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<SensorItemMapping> sensorItemMappings = null;
// try {
// sensorItemMappings = (List<SensorItemMapping>)query.getResultList();
// }catch(Exception e) {
// e.printStackTrace();
// }finally {
// return sensorItemMappings;
// }
//
// }
//}

View File

@ -5,13 +5,10 @@ import com.loafle.overflow.module.sensor.model.Sensor;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
@Repository @Repository
public interface SensorDao extends JpaRepository<Sensor, Long> { public interface SensorDAO extends JpaRepository<Sensor, Long> {
// List<Sensor> findAllByTargetId(Target target);
} }

View File

@ -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<SensorItemCategory, Long> {
//}

View File

@ -4,13 +4,11 @@ import com.loafle.overflow.module.sensor.model.SensorItem;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
@Repository @Repository
public interface SensorItemDao extends JpaRepository<SensorItem, Long> { public interface SensorItemDAO extends JpaRepository<SensorItem, Long> {
// List<SensorItem> findAllByCrawlerId(Crawler crawler); // List<SensorItem> findAllByCrawlerId(Crawler crawler);
} }

View File

@ -1,12 +0,0 @@
package com.loafle.overflow.module.sensor.dao;
/**
* Created by root on 17. 6. 9.
*/
//@Repository
//public interface SensorItemMappingDao extends JpaRepository<SensorItemMapping> {
//
//// List<SensorItemMapping> findAllBySensorId(Sensor sensor);
//
//}

View File

@ -1,6 +1,7 @@
package com.loafle.overflow.module.sensor.model; package com.loafle.overflow.module.sensor.model;
import com.loafle.overflow.meta.model.MetaCrawler; import com.loafle.overflow.meta.model.MetaCrawler;
import com.loafle.overflow.meta.model.MetaSensorStatus;
import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.module.target.model.Target;
import javax.persistence.*; import javax.persistence.*;
@ -15,7 +16,7 @@ public class Sensor {
private long id; private long id;
private Date createDate; private Date createDate;
private String description; private String description;
private String status; private MetaSensorStatus status;
private Target target; private Target target;
private MetaCrawler crawler; private MetaCrawler crawler;
private String crawlerInputItems; private String crawlerInputItems;
@ -49,12 +50,13 @@ public class Sensor {
this.description = description; this.description = description;
} }
@Column(name = "STATUS", nullable = true, length = 50) @ManyToOne
public String getStatus() { @JoinColumn(name = "STATUS")
public MetaSensorStatus getStatus() {
return status; return status;
} }
public void setStatus(String status) { public void setStatus(MetaSensorStatus status) {
this.status = status; this.status = status;
} }
@ -78,13 +80,12 @@ public class Sensor {
this.crawler = crawler; this.crawler = crawler;
} }
@Column(name = "CRAWLER_INPUT_ITEMS", nullable = true, length = 50)
@Column(name = "CRAWELR_INPUT_ITEMS", nullable = true, length = 50) public String getCrawlerInputItems() {
public String getcrawlerInputItems() {
return crawlerInputItems; return crawlerInputItems;
} }
public void setcrawlerInputItems(String crawlerInputItems) { public void setCrawlerInputItems(String crawlerInputItems) {
this.crawlerInputItems = crawlerInputItems; this.crawlerInputItems = crawlerInputItems;
} }

View File

@ -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.noauthprobe.dao.NoAuthProbeDAO;
import com.loafle.overflow.module.probe.dao.ProbeDAO; import com.loafle.overflow.module.probe.dao.ProbeDAO;
import com.loafle.overflow.module.probe.dao.ProbeTaskDAO; import com.loafle.overflow.module.probe.dao.ProbeTaskDAO;
import com.loafle.overflow.module.sensor.dao.SensorDao; import com.loafle.overflow.module.sensor.dao.SensorDAO;
import com.loafle.overflow.module.sensor.dao.SensorItemDao; import com.loafle.overflow.module.sensor.dao.SensorItemDAO;
import com.loafle.overflow.module.target.dao.TargetDAO; import com.loafle.overflow.module.target.dao.TargetDAO;
import io.grpc.ServerBuilder; import io.grpc.ServerBuilder;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
@ -48,8 +48,8 @@ public class DBProxy {
daoMap.put("probeTask", ctx.getBean(ProbeTaskDAO.class)); daoMap.put("probeTask", ctx.getBean(ProbeTaskDAO.class));
daoMap.put("noauthProbe", ctx.getBean(NoAuthProbeDAO.class)); daoMap.put("noauthProbe", ctx.getBean(NoAuthProbeDAO.class));
daoMap.put("emailAuth", ctx.getBean(EmailAuthDAO.class)); daoMap.put("emailAuth", ctx.getBean(EmailAuthDAO.class));
daoMap.put("sensor", ctx.getBean(SensorDao.class)); daoMap.put("sensor", ctx.getBean(SensorDAO.class));
daoMap.put("sensorItem", ctx.getBean(SensorItemDao.class)); daoMap.put("sensorItem", ctx.getBean(SensorItemDAO.class));
daoMap.put("domain", ctx.getBean(DomainDAO.class)); daoMap.put("domain", ctx.getBean(DomainDAO.class));
daoMap.put("target", ctx.getBean(TargetDAO.class)); daoMap.put("target", ctx.getBean(TargetDAO.class));
daoMap.put("infra", ctx.getBean(InfraDAO.class)); daoMap.put("infra", ctx.getBean(InfraDAO.class));

View File

@ -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); 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'); 1,'INITIAL');
INSERT INTO public.meta_probe_status (id,"name") VALUES ( INSERT INTO public.meta_probe_status (id,"name") VALUES (
2,'NORMAL'); 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 ( INSERT INTO public.meta_probe_task_type (id,create_date,description,"name") VALUES (
1,'2017-06-26 15:58:02.397','DISCOVERY START','DISCOVERY'); 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');

View File

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

View File

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