From 994d5e2f69f4a554492af5ef0a6319ef15b8f386 Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 20 Sep 2017 18:16:21 +0900 Subject: [PATCH] sensor display item --- .../meta/dao/MetaSensorDisplayItemDAO.java | 19 +++++ .../meta/dao/MetaSensorItemUnitDAO.java | 12 +++ .../meta/model/MetaSensorDisplayItem.java | 80 +++++++++++++++++++ .../module/meta/model/MetaSensorItemKey.java | 11 +++ .../module/meta/model/MetaSensorItemUnit.java | 53 ++++++++++++ .../service/MetaSensorDisplayItemService.java | 31 +++++++ .../service/MetaSensorItemUnitService.java | 19 +++++ .../sensor/dao/SensorItemDependencyDAO.java | 18 +++++ .../sensor/model/SensorItemDependency.java | 48 +++++++++++ .../service/SensorItemDependencyService.java | 29 +++++++ src/main/resources/local/init.sql | 21 +++++ .../MetaSensorItemUnitServiceTest.java | 78 ++++++++++++++++++ 12 files changed, 419 insertions(+) create mode 100644 src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemDAO.java create mode 100644 src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorItemUnitDAO.java create mode 100644 src/main/java/com/loafle/overflow/module/meta/model/MetaSensorDisplayItem.java create mode 100644 src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemUnit.java create mode 100644 src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemService.java create mode 100644 src/main/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitService.java create mode 100644 src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDependencyDAO.java create mode 100644 src/main/java/com/loafle/overflow/module/sensor/model/SensorItemDependency.java create mode 100644 src/main/java/com/loafle/overflow/module/sensor/service/SensorItemDependencyService.java create mode 100644 src/test/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitServiceTest.java diff --git a/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemDAO.java b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemDAO.java new file mode 100644 index 0000000..c671bb9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemDAO.java @@ -0,0 +1,19 @@ +package com.loafle.overflow.module.meta.dao; + +import com.loafle.overflow.module.meta.model.MetaCrawler; +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * Created by insanity on 17. 9. 20. + */ +@Repository +public interface MetaSensorDisplayItemDAO extends JpaRepository { + + public List findAllByCrawler(MetaCrawler crawler); + + +} diff --git a/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorItemUnitDAO.java b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorItemUnitDAO.java new file mode 100644 index 0000000..258f63c --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorItemUnitDAO.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.module.meta.dao; + +import com.loafle.overflow.module.meta.model.MetaSensorItemUnit; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * Created by insanity on 17. 9. 20. + */ +@Repository +public interface MetaSensorItemUnitDAO extends JpaRepository { +} diff --git a/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorDisplayItem.java b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorDisplayItem.java new file mode 100644 index 0000000..abac127 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorDisplayItem.java @@ -0,0 +1,80 @@ +package com.loafle.overflow.module.meta.model; + + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by insanity on 17. 9. 20. + */ +@Entity +@Table(name = "META_SENSOR_DISPLAY_ITEM", schema = "public") +public class MetaSensorDisplayItem { + + private long id; + private String name; + private MetaCrawler crawler; + private MetaSensorItemUnit unit; + private Date createDate; + private MetaSensorItemType itemType; + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Column(name = "NAME", nullable = false, length = 50) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @ManyToOne + @JoinColumn(name = "CRAWLER_ID", nullable = false) + public MetaCrawler getCrawler() { + return crawler; + } + + public void setCrawler(MetaCrawler crawler) { + this.crawler = crawler; + } + + @ManyToOne + @JoinColumn(name = "UNIT_ID", nullable = true) + public MetaSensorItemUnit getUnit() { + return unit; + } + + public void setUnit(MetaSensorItemUnit unit) { + this.unit = unit; + } + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + + @ManyToOne + @JoinColumn(name = "TYPE_ID", nullable = false) + public MetaSensorItemType getItemType() { + return itemType; + } + + public void setItemType(MetaSensorItemType itemType) { + this.itemType = itemType; + } +} diff --git a/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemKey.java b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemKey.java index ccd80cd..d3455fb 100644 --- a/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemKey.java +++ b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemKey.java @@ -16,6 +16,7 @@ public class MetaSensorItemKey { private String option; private MetaCrawler crawler; private Date createDate; + private MetaSensorItemUnit unit; @Id @GeneratedValue(strategy= GenerationType.IDENTITY) @@ -83,4 +84,14 @@ public class MetaSensorItemKey { public void setCreateDate(Date createDate) { this.createDate = createDate; } + + @ManyToOne + @JoinColumn(name = "UNIT_ID", nullable = true) + public MetaSensorItemUnit getUnit() { + return unit; + } + + public void setUnit(MetaSensorItemUnit unit) { + this.unit = unit; + } } diff --git a/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemUnit.java b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemUnit.java new file mode 100644 index 0000000..e92ddd4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorItemUnit.java @@ -0,0 +1,53 @@ +package com.loafle.overflow.module.meta.model; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by insanity on 17. 9. 19. + */ +@Entity +@Table(name = "META_SENSOR_ITEM_UNIT", schema = "public") +public class MetaSensorItemUnit { + private short id; + private String unit; + private Date createDate; + private String mark; + + @Id + public short getId() { + return id; + } + + public void setId(short id) { + this.id = id; + } + + @Column(name = "UNIT", nullable = false) + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + @Column(name = "MARK", nullable = false) + public String getMark() { + return mark; + } + + public void setMark(String mark) { + this.mark = mark; + } +} diff --git a/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemService.java b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemService.java new file mode 100644 index 0000000..04ae00b --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemService.java @@ -0,0 +1,31 @@ +package com.loafle.overflow.module.meta.service; + +import com.loafle.overflow.module.meta.dao.MetaSensorDisplayItemDAO; +import com.loafle.overflow.module.meta.model.MetaCrawler; +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Created by insanity on 17. 9. 20. + */ + +@Service("MetaSensorDisplayItemService") +public class MetaSensorDisplayItemService { + @Autowired + private MetaSensorDisplayItemDAO displayItemDAO; + + public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) { + return this.displayItemDAO.save(item); + } + + public MetaSensorDisplayItem read(long id) { + return this.displayItemDAO.findOne(id); + } + + public List readAllByCrawler(MetaCrawler crawler) { + return this.displayItemDAO.findAllByCrawler(crawler); + } +} diff --git a/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitService.java b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitService.java new file mode 100644 index 0000000..593cdf6 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitService.java @@ -0,0 +1,19 @@ +package com.loafle.overflow.module.meta.service; + +import com.loafle.overflow.module.meta.dao.MetaSensorItemUnitDAO; +import com.loafle.overflow.module.meta.model.MetaSensorItemUnit; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Created by insanity on 17. 9. 20. + */ +@Service("MetaSensorItemUnitService") +public class MetaSensorItemUnitService { + @Autowired + private MetaSensorItemUnitDAO sensorItemUnitDAO; + + public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) { + return this.sensorItemUnitDAO.save(sensorItemUnit); + } +} diff --git a/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDependencyDAO.java b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDependencyDAO.java new file mode 100644 index 0000000..2ad6be8 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensor/dao/SensorItemDependencyDAO.java @@ -0,0 +1,18 @@ +package com.loafle.overflow.module.sensor.dao; + +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import com.loafle.overflow.module.sensor.model.SensorItemDependency; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * Created by insanity on 17. 9. 20. + */ +@Repository +public interface SensorItemDependencyDAO extends JpaRepository { + + List findAllByDisplayItem(MetaSensorDisplayItem displayItem); +} diff --git a/src/main/java/com/loafle/overflow/module/sensor/model/SensorItemDependency.java b/src/main/java/com/loafle/overflow/module/sensor/model/SensorItemDependency.java new file mode 100644 index 0000000..6226f6b --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensor/model/SensorItemDependency.java @@ -0,0 +1,48 @@ +package com.loafle.overflow.module.sensor.model; + +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import com.loafle.overflow.module.meta.model.MetaSensorItemKey; + +import javax.persistence.*; + +/** + * Created by insanity on 17. 9. 20. + */ +@Entity +@Table(name = "SENSOR_ITEM_DEPENDENCY", schema = "public") +public class SensorItemDependency { + private long id; + private MetaSensorDisplayItem displayItem; + private MetaSensorItemKey sensorItem; + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + @ManyToOne + @JoinColumn(name = "DISPLAY_ITEM_ID", nullable = false) + public MetaSensorDisplayItem getDisplayItem() { + return displayItem; + } + + public void setDisplayItem(MetaSensorDisplayItem displayItem) { + this.displayItem = displayItem; + } + + @ManyToOne + @JoinColumn(name = "SENSOR_ITEM_ID", nullable = false) + public MetaSensorItemKey getSensorItem() { + return sensorItem; + } + + public void setSensorItem(MetaSensorItemKey sensorItem) { + this.sensorItem = sensorItem; + } +} diff --git a/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemDependencyService.java b/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemDependencyService.java new file mode 100644 index 0000000..b6fcd83 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemDependencyService.java @@ -0,0 +1,29 @@ +package com.loafle.overflow.module.sensor.service; + +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import com.loafle.overflow.module.sensor.dao.SensorItemDependencyDAO; +import com.loafle.overflow.module.sensor.model.SensorItemDependency; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Created by insanity on 17. 9. 20. + */ + +@Service("SensorItemDependencyService") +public class SensorItemDependencyService { + + @Autowired + private SensorItemDependencyDAO sensorItemDependencyDAO; + + public SensorItemDependency regist(SensorItemDependency dependency) { + return this.sensorItemDependencyDAO.save(dependency); + } + + public List readAllByDisplayItem(MetaSensorDisplayItem displayItem) { + return this.sensorItemDependencyDAO.findAllByDisplayItem(displayItem); + } +} diff --git a/src/main/resources/local/init.sql b/src/main/resources/local/init.sql index f709da9..6181197 100644 --- a/src/main/resources/local/init.sql +++ b/src/main/resources/local/init.sql @@ -913,6 +913,27 @@ INSERT INTO public.meta_history_type (id,create_date,"name") VALUES ( 6,'2017-08-23 13:28:26.966','Sensor'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +1,'2017-09-20 14:16:26.213','%','Percentage'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +2,'2017-09-20 14:16:26.256','Bytes','Byte'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +3,'2017-09-20 14:16:26.272','KB','KByte'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +4,'2017-09-20 14:16:26.289','MB','MByte'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +5,'2017-09-20 14:16:26.305','GB','GByte'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +6,'2017-09-20 14:16:26.321','','Count'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +7,'2017-09-20 14:16:26.339','Jiffies','Jiffy'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +8,'2017-09-20 14:16:26.355','BPS','Byte Per Second'); +INSERT INTO public.meta_sensor_item_unit (id,create_date,mark,unit) VALUES ( +9,'2017-09-20 14:16:26.372','PPS','Packet Per Second'); + + + diff --git a/src/test/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitServiceTest.java b/src/test/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitServiceTest.java new file mode 100644 index 0000000..aa99541 --- /dev/null +++ b/src/test/java/com/loafle/overflow/module/meta/service/MetaSensorItemUnitServiceTest.java @@ -0,0 +1,78 @@ +package com.loafle.overflow.module.meta.service; + +import com.loafle.overflow.module.meta.model.MetaSensorItemUnit; +import com.loafle.overflow.spring.AppConfigTest; +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. 7. 27. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfigTest.class}) +public class MetaSensorItemUnitServiceTest { + + @Autowired + private MetaSensorItemUnitService service; + + @Test + public void regist() throws Exception { + MetaSensorItemUnit unit1 = new MetaSensorItemUnit(); + unit1.setId((short)1); + unit1.setUnit("Percentage"); + unit1.setMark("%"); + this.service.regist(unit1); + + MetaSensorItemUnit unit2 = new MetaSensorItemUnit(); + unit2.setId((short)2); + unit2.setUnit("Byte"); + unit2.setMark("Bytes"); + this.service.regist(unit2); + + MetaSensorItemUnit unit3 = new MetaSensorItemUnit(); + unit3.setId((short)3); + unit3.setUnit("KByte"); + unit3.setMark("KB"); + this.service.regist(unit3); + + MetaSensorItemUnit unit4 = new MetaSensorItemUnit(); + unit4.setId((short)4); + unit4.setUnit("MByte"); + unit4.setMark("MB"); + this.service.regist(unit4); + + MetaSensorItemUnit unit5 = new MetaSensorItemUnit(); + unit5.setId((short)5); + unit5.setUnit("GByte"); + unit5.setMark("GB"); + this.service.regist(unit5); + + MetaSensorItemUnit unit6 = new MetaSensorItemUnit(); + unit6.setId((short)6); + unit6.setUnit("Count"); + unit6.setMark(""); + this.service.regist(unit6); + + MetaSensorItemUnit unit7 = new MetaSensorItemUnit(); + unit7.setId((short)7); + unit7.setUnit("Jiffy"); + unit7.setMark("Jiffies"); + this.service.regist(unit7); + + MetaSensorItemUnit unit8 = new MetaSensorItemUnit(); + unit8.setId((short)8); + unit8.setUnit("Byte Per Second"); + unit8.setMark("BPS"); + this.service.regist(unit8); + + MetaSensorItemUnit unit9 = new MetaSensorItemUnit(); + unit9.setId((short)9); + unit9.setUnit("Packet Per Second"); + unit9.setMark("PPS"); + this.service.regist(unit9); + } + +} \ No newline at end of file