diff --git a/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemMappingDAO.java b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemMappingDAO.java deleted file mode 100644 index e5ba583..0000000 --- a/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayItemMappingDAO.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.loafle.overflow.module.meta.dao; - -import com.loafle.overflow.module.meta.model.MetaSensorDisplayMapping; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * Created by insanity on 17. 11. 7. - */ -@Repository -public interface MetaSensorDisplayItemMappingDAO extends JpaRepository { - public List findAllByDisplayItem(MetaSensorDisplayMapping mapping); -} diff --git a/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayMappingDAO.java b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayMappingDAO.java new file mode 100644 index 0000000..ef602b3 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/dao/MetaSensorDisplayMappingDAO.java @@ -0,0 +1,21 @@ +package com.loafle.overflow.module.meta.dao; + +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import com.loafle.overflow.module.meta.model.MetaSensorDisplayMapping; +import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * Created by insanity on 17. 11. 7. + */ +@Repository +public interface MetaSensorDisplayMappingDAO extends JpaRepository { + + @Query("SELECT m.itemKey from MetaSensorDisplayMapping m where m.displayItem = (:displayItem)") + public List findAllByDisplayItem(@Param("displayItem") MetaSensorDisplayItem displayItem); +} 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 index 29e9dcc..dc2baed 100644 --- a/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorDisplayItem.java +++ b/src/main/java/com/loafle/overflow/module/meta/model/MetaSensorDisplayItem.java @@ -19,6 +19,13 @@ public class MetaSensorDisplayItem { private MetaSensorItemUnit unit; private Date createDate; + public MetaSensorDisplayItem() { + + } + public MetaSensorDisplayItem(long id) { + this.id = id; + } + @Id public long getId() { return id; 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 d3455fb..517bcd5 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 @@ -18,6 +18,14 @@ public class MetaSensorItemKey { private Date createDate; private MetaSensorItemUnit unit; + public MetaSensorItemKey() { + + } + + public MetaSensorItemKey(long id) { + this.id = id; + } + @Id @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { diff --git a/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemMappingService.java b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemMappingService.java deleted file mode 100644 index 4ffef3b..0000000 --- a/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayItemMappingService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.loafle.overflow.module.meta.service; - -import com.loafle.overflow.module.meta.dao.MetaSensorDisplayItemMappingDAO; -import com.loafle.overflow.module.meta.model.MetaSensorDisplayMapping; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * Created by insanity on 17. 11. 7. - */ -@Service("MetaSensorDisplayItemMappingService") -public class MetaSensorDisplayItemMappingService { - @Autowired - private MetaSensorDisplayItemMappingDAO mappingDAO; - - public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) { - return this.mappingDAO.save(m); - } - - public List findAllByDisplayItem(MetaSensorDisplayMapping mapping) { - return this.mappingDAO.findAllByDisplayItem(mapping); - } -} diff --git a/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayMappingService.java b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayMappingService.java new file mode 100644 index 0000000..033899e --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayMappingService.java @@ -0,0 +1,28 @@ +package com.loafle.overflow.module.meta.service; + +import com.loafle.overflow.module.meta.dao.MetaSensorDisplayMappingDAO; +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import com.loafle.overflow.module.meta.model.MetaSensorDisplayMapping; +import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Created by insanity on 17. 11. 7. + */ +@Service("MetaSensorDisplayMappingService") +public class MetaSensorDisplayMappingService { + @Autowired + private MetaSensorDisplayMappingDAO mappingDAO; + + public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) { + return this.mappingDAO.save(m); + } + + public List findAllByDisplayItem(MetaSensorDisplayItem displayItem) { + return this.mappingDAO.findAllByDisplayItem(displayItem); + } + +} diff --git a/src/main/resources/local/init.sql b/src/main/resources/local/init.sql index c059a23..b99d7d6 100644 --- a/src/main/resources/local/init.sql +++ b/src/main/resources/local/init.sql @@ -958,6 +958,63 @@ INSERT INTO meta_sensor_display_item (id,create_date,description,display_name,"k INSERT INTO meta_sensor_display_item (id,create_date,description,display_name,"key",crawler_id,unit_id) VALUES ( '16','2017-11-07 16:08:59','','CPU Privilege (%)','wmi.cpu.usage.privilege','23','1'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'1','1','119'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'2','1','120'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'3','1','121'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'4','1','122'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'5','1','123'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'6','1','124'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'7','1','125'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'8','1','126'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'9','1','127'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'10','1','128'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'11','2','119'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'12','3','120'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'13','4','121'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'14','5','122'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'15','6','123'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'16','7','124'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'17','8','125'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'18','9','126'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'19','10','127'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'20','11','128'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'21','12','129'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'22','12','130'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'23','12','131'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'24','12','132'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'25','13','129'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'26','14','130'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'27','15','131'); +INSERT INTO meta_sensor_display_mapping (id,display_item_id,item_key_id) VALUES ( +'28','16','132'); + INSERT INTO public.meta_vendor_crawler (id,create_date,crawler_id,vendor_id) VALUES ( 1,'2017-07-27 15:29:48.634',23,26); INSERT INTO public.meta_vendor_crawler (id,create_date,crawler_id,vendor_id) VALUES ( diff --git a/src/test/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayMappingServiceTest.java b/src/test/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayMappingServiceTest.java new file mode 100644 index 0000000..b5d9cff --- /dev/null +++ b/src/test/java/com/loafle/overflow/module/meta/service/MetaSensorDisplayMappingServiceTest.java @@ -0,0 +1,32 @@ +package com.loafle.overflow.module.meta.service; + +import com.loafle.overflow.module.meta.model.MetaSensorDisplayItem; +import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import com.loafle.overflow.spring.AppConfigTest; +import org.junit.Assert; +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.List; + +/** + * Created by insanity on 17. 11. 7. + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfigTest.class}) +public class MetaSensorDisplayMappingServiceTest { + + @Autowired + MetaSensorDisplayMappingService service; + + + @Test + public void read() { + List list = this.service.findAllByDisplayItem(new MetaSensorDisplayItem(1)); + Assert.assertNotNull(list); + } +}