commit 4008097387456bfb8eedfeab5559fa2a174c343b Author: snoop Date: Thu Jun 22 11:52:31 2017 +0900 first overflow dao commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86dcd6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,85 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### Maven template +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + +# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) +!/.mvn/wrapper/maven-wrapper.jar +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.idea/ +*.iml +target/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5319182 --- /dev/null +++ b/pom.xml @@ -0,0 +1,132 @@ + + + 4.0.0 + + + com.loafle + maven_parent_jar + 1.0.0-RELEASE + + + com.loafle + overflow_dao + jar + 1.0.0-SNAPSHOT + + + 1.2.0 + 4.3.10.Final + + + + + io.grpc + grpc-netty + ${grpc.version} + + + io.grpc + grpc-protobuf + ${grpc.version} + + + io.grpc + grpc-stub + ${grpc.version} + + + org.mockito + mockito-core + 1.9.5 + test + + + + + org.hibernate + hibernate-entitymanager + 5.2.10.Final + + + + + org.postgresql + postgresql + 9.4-1200-jdbc41 + + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.13 + + + + com.loafle + overflow_jpa_base_dao + 1.0.0-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + src/main/resources + true + + + + + src/test/resources + true + + + + + + kr.motd.maven + os-maven-plugin + 1.4.1.Final + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} + grpc-java + io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} + + + + + compile + compile-custom + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/dao/agent/dao/AgentDAO.java b/src/main/java/com/loafle/overflow/dao/agent/dao/AgentDAO.java new file mode 100644 index 0000000..f724662 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/agent/dao/AgentDAO.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.dao.agent.dao; + +import com.loafle.overflow.dao.agent.model.Agent; +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.member.model.Member; + +import java.util.List; + +/** + * Created by insanity on 17. 5. 29. + */ +public interface AgentDAO extends BaseDAO { + public List findAgentListByMemberId(Member member); +} diff --git a/src/main/java/com/loafle/overflow/dao/agent/dao/JPAAgentDAO.java b/src/main/java/com/loafle/overflow/dao/agent/dao/JPAAgentDAO.java new file mode 100644 index 0000000..19f7fd9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/agent/dao/JPAAgentDAO.java @@ -0,0 +1,32 @@ +package com.loafle.overflow.dao.agent.dao; + +import com.loafle.overflow.dao.agent.model.Agent; +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.member.model.Member; + +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by insanity on 17. 5. 29. + */ +public class JPAAgentDAO extends JPABaseDAO implements AgentDAO { + + public List findAgentListByMemberId(Member member) { + Query query = getEntityManager() + .createNativeQuery("SELECT agt.* FROM AGENT agt WHERE agt.MEMBER_ID = :member", Agent.class); + query.setParameter("member", member.getId()); + + List list = new ArrayList<>(); + try { + list = query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return list; + } + } + +} diff --git a/src/main/java/com/loafle/overflow/dao/agent/model/Agent.java b/src/main/java/com/loafle/overflow/dao/agent/model/Agent.java new file mode 100644 index 0000000..7e3842a --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/agent/model/Agent.java @@ -0,0 +1,82 @@ +package com.loafle.overflow.dao.agent.model; + +import com.loafle.overflow.dao.member.model.Member; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * Created by insanity on 17. 5. 29. + */ + +@Entity(name="AGENT") +public class Agent implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "MEMBER_ID", nullable=false) + private Member member; + + @Column(name="AUTHORIZED_DATE") + private Long authorizedDate; + + @Column(name="DESCRIPTION") + private String description; + + @Column(name="LAST_POLLING_DATE") + private Long lastPollingDate; + + @Column(name="STATUS") + private String status; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } + + public Long getAuthorizedDate() { + return authorizedDate; + } + + public void setAuthorizedDate(Long authorizedDate) { + this.authorizedDate = authorizedDate; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Long getLastPollingDate() { + return lastPollingDate; + } + + public void setLastPollingDate(Long lastPollingDate) { + this.lastPollingDate = lastPollingDate; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/apikey/dao/ApiKeyDao.java b/src/main/java/com/loafle/overflow/dao/apikey/dao/ApiKeyDao.java new file mode 100644 index 0000000..760862e --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/apikey/dao/ApiKeyDao.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.dao.apikey.dao; + +import com.loafle.overflow.dao.apikey.model.Apikey; +import com.loafle.overflow.commons.dao.BaseDAO; + + +/** + * Created by root on 17. 6. 1. + */ +public interface ApiKeyDao extends BaseDAO { + Apikey findByApiKey(Apikey apikey); +} diff --git a/src/main/java/com/loafle/overflow/dao/apikey/dao/JPAApiKeyDao.java b/src/main/java/com/loafle/overflow/dao/apikey/dao/JPAApiKeyDao.java new file mode 100644 index 0000000..54b4d71 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/apikey/dao/JPAApiKeyDao.java @@ -0,0 +1,28 @@ +package com.loafle.overflow.dao.apikey.dao; + +import com.loafle.overflow.dao.apikey.model.Apikey; +import com.loafle.overflow.commons.dao.JPABaseDAO; + + +import javax.persistence.Query; + +/** + * Created by root on 17. 6. 1. + */ +public class JPAApiKeyDao extends JPABaseDAO implements ApiKeyDao { + public Apikey findByApiKey(Apikey apikey) { + + Query query = getEntityManager().createNativeQuery("SELECT ak.* FROM API_KEY ak WHERE ak.API_KEY = :apikey", Apikey.class); + query.setParameter("apikey", apikey.getApiKey()); + + Apikey ak = null; + try { + ak = (Apikey)query.getSingleResult(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return ak; + } + + } +} diff --git a/src/main/java/com/loafle/overflow/dao/apikey/model/Apikey.java b/src/main/java/com/loafle/overflow/dao/apikey/model/Apikey.java new file mode 100644 index 0000000..4306b9b --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/apikey/model/Apikey.java @@ -0,0 +1,61 @@ +package com.loafle.overflow.dao.apikey.model; + +import com.loafle.overflow.dao.member.model.Member; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 1. + */ +@Entity +@Table(name ="API_KEY") +public class Apikey { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="API_KEY", unique=true, nullable=false) + private String apiKey; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CREATE_DATE", nullable=false) + private Date createDate; + + @ManyToOne + @JoinColumn(name = "MEMBER_ID", nullable=false) + private Member member; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerDAO.java b/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerDAO.java new file mode 100644 index 0000000..b50f4ac --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerDAO.java @@ -0,0 +1,13 @@ +package com.loafle.overflow.dao.crawler.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; + +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public interface CrawlerDAO extends BaseDAO { + public List findAll(); +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerInputItemDAO.java b/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerInputItemDAO.java new file mode 100644 index 0000000..f1aefb4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerInputItemDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.crawler.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItem; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public interface CrawlerInputItemDAO extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerInputItemMappingDAO.java b/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerInputItemMappingDAO.java new file mode 100644 index 0000000..f8e60ed --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/dao/CrawlerInputItemMappingDAO.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.dao.crawler.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItemMapping; + +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public interface CrawlerInputItemMappingDAO extends BaseDAO { + public List findByCrawlerId(Crawler crawler); +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerDAO.java b/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerDAO.java new file mode 100644 index 0000000..2e4adb7 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerDAO.java @@ -0,0 +1,27 @@ +package com.loafle.overflow.dao.crawler.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; + +import javax.persistence.Query; +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerDAO extends JPABaseDAO implements CrawlerDAO { + @Override + public List findAll() { + Query query = getEntityManager().createNativeQuery("SELECT c.* FROM CRAWLER c ", Crawler.class); + + List crs = null; + + try { + crs = (List)query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return crs; + } + } +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerInputItemDAO.java b/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerInputItemDAO.java new file mode 100644 index 0000000..6ec961d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerInputItemDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.crawler.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItem; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerInputItemDAO extends JPABaseDAO implements CrawlerInputItemDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerInputItemMappingDAO.java b/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerInputItemMappingDAO.java new file mode 100644 index 0000000..d436ce3 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/dao/JPACrawlerInputItemMappingDAO.java @@ -0,0 +1,29 @@ +package com.loafle.overflow.dao.crawler.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItemMapping; + +import javax.persistence.Query; +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerInputItemMappingDAO extends JPABaseDAO implements CrawlerInputItemMappingDAO { + @Override + public List findByCrawlerId(Crawler crawler) { + Query query = getEntityManager().createNativeQuery("SELECT m.* FROM CRAWLER_INPUT_ITEM_MAPPING m WHERE m.crawler_id = :crawler_id", CrawlerInputItemMapping.class); + query.setParameter("crawler_id", crawler.getId()); + + List crs = null; + + try { + crs = (List)query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return crs; + } + } +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/model/Crawler.java b/src/main/java/com/loafle/overflow/dao/crawler/model/Crawler.java new file mode 100644 index 0000000..17c6b2c --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/model/Crawler.java @@ -0,0 +1,76 @@ +package com.loafle.overflow.dao.crawler.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@SuppressWarnings("serial") +@Entity(name="CRAWLER") +public class Crawler implements Serializable { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="NAME", nullable=false) + private String name; + + @Column(name="DESCRIPTION") + private String description; + + @Column(name="CRAWLER_TYPE") + private String crawlerType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + public Crawler() { + } + + public Crawler(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCrawlerType() { + return crawlerType; + } + + public void setCrawlerType(String crawlerType) { + this.crawlerType = crawlerType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/model/CrawlerInputItem.java b/src/main/java/com/loafle/overflow/dao/crawler/model/CrawlerInputItem.java new file mode 100644 index 0000000..d09839d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/model/CrawlerInputItem.java @@ -0,0 +1,75 @@ +package com.loafle.overflow.dao.crawler.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@SuppressWarnings("serial") +@Entity(name="CRAWLER_INPUT_ITEM") +public class CrawlerInputItem implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name = "NAME") + private String name; + + @Column(name = "DESCRIPTION") + private String description; + + @Column(name = "DATA_TYPE") + private String dataType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + + public CrawlerInputItem(){} + + public CrawlerInputItem(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/crawler/model/CrawlerInputItemMapping.java b/src/main/java/com/loafle/overflow/dao/crawler/model/CrawlerInputItemMapping.java new file mode 100644 index 0000000..52a9c30 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/crawler/model/CrawlerInputItemMapping.java @@ -0,0 +1,86 @@ +package com.loafle.overflow.dao.crawler.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@SuppressWarnings("serial") +@Entity(name="CRAWLER_INPUT_ITEM_MAPPING") +public class CrawlerInputItemMapping implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "CRAWLER_ID", nullable=false) + private Crawler crawler; + + @ManyToOne + @JoinColumn(name = "CRAWLER_INPUT_ITEM_ID", nullable=false) + private CrawlerInputItem crawlerInputItem; + + @Column(name = "PRIORITY") + private short priority; + + @Column(name = "REQUIRED_TYPE") + private boolean requiredType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + public CrawlerInputItemMapping(){} + public CrawlerInputItemMapping(Long id){ + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Crawler getCrawler() { + return crawler; + } + + public void setCrawler(Crawler crawler) { + this.crawler = crawler; + } + + public CrawlerInputItem getCrawlerInputItem() { + return crawlerInputItem; + } + + public void setCrawlerInputItem(CrawlerInputItem crawlerInputItem) { + this.crawlerInputItem = crawlerInputItem; + } + + public short getPriority() { + return priority; + } + + public void setPriority(short priority) { + this.priority = priority; + } + + public boolean isRequiredType() { + return requiredType; + } + + public void setRequiredType(boolean requiredType) { + this.requiredType = requiredType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/HostDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/HostDao.java new file mode 100644 index 0000000..2db7de4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/HostDao.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.dao.apikey.model.Apikey; +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.discovery.model.Host; + +/** + * Created by root on 17. 6. 4. + */ +public interface HostDao extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAHostDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAHostDao.java new file mode 100644 index 0000000..173b656 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAHostDao.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.discovery.model.Host; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAHostDao extends JPABaseDAO implements HostDao { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAPortDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAPortDao.java new file mode 100644 index 0000000..f7d05cc --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAPortDao.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.discovery.model.Port; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAPortDao extends JPABaseDAO implements PortDao { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAServiceDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAServiceDao.java new file mode 100644 index 0000000..1fecca2 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAServiceDao.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.discovery.model.Service; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAServiceDao extends JPABaseDAO implements ServiceDao { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAZoneDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAZoneDao.java new file mode 100644 index 0000000..6139cb1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/JPAZoneDao.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.dao.discovery.dao; + + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.discovery.model.Zone; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAZoneDao extends JPABaseDAO implements ZoneDao { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/PortDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/PortDao.java new file mode 100644 index 0000000..2c3c3fe --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/PortDao.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.discovery.model.Port; + +/** + * Created by root on 17. 6. 4. + */ +public interface PortDao extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/ServiceDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/ServiceDao.java new file mode 100644 index 0000000..3162cfd --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/ServiceDao.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.discovery.model.Service; + +/** + * Created by root on 17. 6. 4. + */ +public interface ServiceDao extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/dao/ZoneDao.java b/src/main/java/com/loafle/overflow/dao/discovery/dao/ZoneDao.java new file mode 100644 index 0000000..7412a3e --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/dao/ZoneDao.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.discovery.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.discovery.model.Zone; + +/** + * Created by root on 17. 6. 4. + */ +public interface ZoneDao extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/model/Host.java b/src/main/java/com/loafle/overflow/dao/discovery/model/Host.java new file mode 100644 index 0000000..c7c94c9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/model/Host.java @@ -0,0 +1,115 @@ +package com.loafle.overflow.dao.discovery.model; + +import org.codehaus.jackson.annotate.JsonIgnore; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + +/** + * Created by root on 17. 6. 4. + */ +@Entity +public class Host { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column(name = "IP",nullable = false) + private long ip; + + @Column(name = "MAC",nullable = false) + private long mac; + + @ManyToOne + @JoinColumn(name = "ZONE_ID", nullable = false) + @JsonIgnore + private Zone zone; + + public Zone getZone() { + return zone; + } + + public void setZone(Zone zone) { + this.zone = zone; + } + + + + @OneToMany(mappedBy = "host",cascade = CascadeType.ALL) + private List ports; + + public List getPorts() { + return ports; + } + + public void setPorts(List ports) { + this.ports = ports; + } + + @Column(name = "CREATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + @Column(name = "UPDATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) + private Date updateDate; + + + public Host(){} + + public Host(long ip, long mac){ + this.ip = ip; + this.mac = mac; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getIp() { + return ip; + } + + public void setIp(long ip) { + this.ip = ip; + } + + public long getMac() { + return mac; + } + + public void setMac(long mac) { + this.mac = mac; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + public void mappingChildren(Zone discoveryZone) { + this.setZone(discoveryZone); + + List ports = this.getPorts(); + if (ports != null) { + for (int j =0 ; j < ports.size() ; ++j) { + ports.get(j).mappingChildren(this); + } + } + } +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/model/Port.java b/src/main/java/com/loafle/overflow/dao/discovery/model/Port.java new file mode 100644 index 0000000..792d1a1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/model/Port.java @@ -0,0 +1,123 @@ +package com.loafle.overflow.dao.discovery.model; + +import com.loafle.overflow.dao.discovery.type.PortType; +import org.codehaus.jackson.annotate.JsonIgnore; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + +/** + * Created by root on 17. 6. 4. + */ +@Entity +public class Port { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @ManyToOne + @JoinColumn(nullable = false) + @JsonIgnore + private Host host; + public Host getHost() { + return host; + } + + public void setHost(Host host) { + this.host = host; + } + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PortType portType; + + @Column(nullable = false) + private int portNumber; + + + @OneToMany(mappedBy = "port" ,cascade = CascadeType.ALL) + private List services; + + public List getServices() { + return services; + } + + public void setServices(List services) { + this.services = services; + } + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) + private Date updateDate; + + public Port() {} + + public Port(PortType type, int portNumber) { + this.portType = type; + this.portNumber = portNumber; + } + + public Port(Host host, PortType type, int portNumber) { + this.host = host; + this.portType = type; + this.portNumber = portNumber; + } + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + this.portType = portType; + } + + public int getPortNumber() { + return portNumber; + } + + public void setPortNumber(int portNumber) { + this.portNumber = portNumber; + } + + + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + public void mappingChildren(Host discoveryHost) { + this.setHost(discoveryHost); + + + List discoveryServices = this.getServices(); + if (discoveryServices != null) { + for (int z = 0 ; z < discoveryServices.size() ; ++z) { + discoveryServices.get(z).setPort(this); + } + } + } +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/model/Service.java b/src/main/java/com/loafle/overflow/dao/discovery/model/Service.java new file mode 100644 index 0000000..17401cf --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/model/Service.java @@ -0,0 +1,92 @@ +package com.loafle.overflow.dao.discovery.model; + +import com.loafle.overflow.dao.discovery.type.PortType; +import org.codehaus.jackson.annotate.JsonIgnore; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 4. + */ +@Entity +public class Service { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @ManyToOne + @JoinColumn(nullable = false) + @JsonIgnore + private Port port; + public Port getPort() { + return port; + } + + public void setPort(Port port) { + this.port = port; + } + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PortType portType; + + @Column(nullable = false) + private String serviceName; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false ,insertable = false) + private Date updateDate; + + public Service() {} + + public Service(Port port,PortType t, String serviceName) { + this.port = port; + this.portType = t; + this.serviceName = serviceName; + } + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + this.portType = portType; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/model/Zone.java b/src/main/java/com/loafle/overflow/dao/discovery/model/Zone.java new file mode 100644 index 0000000..18a56d8 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/model/Zone.java @@ -0,0 +1,111 @@ +package com.loafle.overflow.dao.discovery.model; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + +/** + * Created by root on 17. 6. 4. + */ +@Entity +public class Zone { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column(nullable=false) + private long ip; + + @Column(nullable=false) + private long cidr; + +// @JoinColumn(nullable=false) +// @OneToOne +// @JsonIgnore +// private DiscoveryHistory discovery; + +// @OneToMany(mappedBy = "zone", cascade = CascadeType.ALL) +// private List histories; + + @OneToMany(mappedBy = "zone", cascade = CascadeType.ALL) + private List hosts; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) + private Date updateDate; + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + + + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getIp() { + return ip; + } + + public void setIp(long ip) { + this.ip = ip; + } + + public long getCidr() { + return cidr; + } + + public void setCidr(long cidr) { + this.cidr = cidr; + } + + + + + public List getHosts() { + return hosts; + } + + public void setHosts(List hosts) { + this.hosts = hosts; + } + +// public void mappingChildren(DiscoveryHistory history) { +// this.setDiscovery(history); +// List hostScanHistories = this.getHistories(); +// if (hostScanHistories != null) { +// for (int i =0 ; i < hostScanHistories.size() ; ++i) { +// hostScanHistories.get(i).setZone(this); +// } +// } +// +// List hosts = this.getHosts(); +// if (hosts != null) { +// for (int i =0 ; i < hosts.size() ; ++i) { +// hosts.get(i).mappingChildren(this); +// } +// } +// } +} diff --git a/src/main/java/com/loafle/overflow/dao/discovery/type/DirectionType.java b/src/main/java/com/loafle/overflow/dao/discovery/type/DirectionType.java new file mode 100644 index 0000000..0771f36 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/type/DirectionType.java @@ -0,0 +1,19 @@ +package com.loafle.overflow.dao.discovery.type; + +/** + * Created by root on 16. 11. 15. + */ +public enum DirectionType { + Send("S"), + Recv("R"), + Timeout("T"), + Closed("C"); + + private String stringValue; + DirectionType(String string) {stringValue = string;} + @Override + public String toString() { + return stringValue; + } +} + diff --git a/src/main/java/com/loafle/overflow/dao/discovery/type/PortType.java b/src/main/java/com/loafle/overflow/dao/discovery/type/PortType.java new file mode 100644 index 0000000..d43c970 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/discovery/type/PortType.java @@ -0,0 +1,19 @@ +package com.loafle.overflow.dao.discovery.type; + +/** + * Created by root on 16. 11. 15. + */ + +public enum PortType { + TCP("TCP"), + UDP("UDP"), + TLS("TLS"); + + private String stringValue; + PortType(String string) {stringValue = string;} + + @Override + public String toString() { + return stringValue; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/email/dao/EmailAuthDAO.java b/src/main/java/com/loafle/overflow/dao/email/dao/EmailAuthDAO.java new file mode 100644 index 0000000..c9cb974 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/email/dao/EmailAuthDAO.java @@ -0,0 +1,17 @@ +package com.loafle.overflow.dao.email.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.email.model.EmailAuth; + +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 6. + */ +public interface EmailAuthDAO extends BaseDAO { + public EmailAuth findByAuthToken(EmailAuth emailAuth); + + public List findByMemberId(EmailAuth emailAuth); + +// public EmailAuth updateEmailAuth(EmailAuth emailAuth); +} diff --git a/src/main/java/com/loafle/overflow/dao/email/dao/JPAEmailAuthDAO.java b/src/main/java/com/loafle/overflow/dao/email/dao/JPAEmailAuthDAO.java new file mode 100644 index 0000000..000a53e --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/email/dao/JPAEmailAuthDAO.java @@ -0,0 +1,63 @@ +package com.loafle.overflow.dao.email.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.email.model.EmailAuth; + +import javax.persistence.Query; +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 6. + */ +public class JPAEmailAuthDAO extends JPABaseDAO implements EmailAuthDAO { + + public EmailAuth findByAuthToken(EmailAuth emailAuth) { + Query query = getEntityManager().createNativeQuery("SELECT e.* FROM EMAIL_AUTH e WHERE e.auth_token = :auth_token", EmailAuth.class); + query.setParameter("auth_token", emailAuth.getAuthToken()); + + EmailAuth auth = null; + + try { + auth = (EmailAuth)query.getSingleResult(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return auth; + } + } + + @Override + public List findByMemberId(EmailAuth emailAuth) { + Query query = getEntityManager().createNativeQuery("SELECT e.* FROM EMAIL_AUTH e WHERE e.member_id = :member_id", EmailAuth.class); + query.setParameter("member_id", emailAuth.getMember().getId()); + + List auths = null; + + try { + auths = (List)query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return auths; + } + } + +// @Override +// public EmailAuth updateEmailAuth(EmailAuth emailAuth) { +// EntityTransaction tx = this.getEntityManager().getTransaction(); +// if (!tx.isActive()) { +// tx.begin(); +// } +// +// try { +// emailAuth.setUpdateDate(new Date()); +// +// EmailAuth result = this.getEntityManager().merge(emailAuth); +// tx.commit(); +// return result; +// }catch (Exception e) { +// tx.rollback(); +// return null; +// } +// } +} diff --git a/src/main/java/com/loafle/overflow/dao/email/model/EmailAuth.java b/src/main/java/com/loafle/overflow/dao/email/model/EmailAuth.java new file mode 100644 index 0000000..077eeec --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/email/model/EmailAuth.java @@ -0,0 +1,113 @@ +package com.loafle.overflow.dao.email.model; + +import com.loafle.overflow.dao.member.model.Member; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 6. + */ +@SuppressWarnings("serial") +@Entity(name="EMAIL_AUTH") +public class EmailAuth implements Serializable { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "MEMBER_ID", nullable=false) + private Member member; + + @Column(name="AUTH_TOKEN", unique=true, nullable=false) + private String authToken; + + @Column(name = "IS_INVALID") + private Boolean isInvalid; + + @Column(name = "IS_CONFIRM") + private Boolean isConfirm; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + @Column(name = "UPDATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = true) + private Date updateDate; + + @Column(name = "CONFIRM_DATE") + private Date confirmDate; + + public EmailAuth() { + + } + + public EmailAuth(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } + + public String getAuthToken() { + return authToken; + } + + public void setAuthToken(String authToken) { + this.authToken = authToken; + } + + public Boolean getIsInvalid() { + return isInvalid; + } + + public void setIsInvalid(Boolean invalid) { + isInvalid = invalid; + } + + public Boolean getIsConfirm() { + return isConfirm; + } + + public void setIsConfirm(Boolean confirm) { + isConfirm = confirm; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + public Date getConfirmDate() { + return confirmDate; + } + + public void setConfirmDate(Date confirmDate) { + this.confirmDate = confirmDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/member/dao/JPAMemberDAO.java b/src/main/java/com/loafle/overflow/dao/member/dao/JPAMemberDAO.java new file mode 100644 index 0000000..5a9820d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/member/dao/JPAMemberDAO.java @@ -0,0 +1,26 @@ +package com.loafle.overflow.dao.member.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.member.model.Member; + +import javax.persistence.Query; + +/** + * Created by insanity on 17. 5. 25. + */ +public class JPAMemberDAO extends JPABaseDAO implements MemberDAO{ + public Member findByEmail(Member member) { + + Query query = getEntityManager().createNativeQuery("SELECT m.* FROM MEMBER m WHERE m.email = :email", Member.class); + query.setParameter("email", member.getEmail()); + + Member retMember = null; + try { + retMember = (Member)query.getSingleResult(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return retMember; + } + } +} diff --git a/src/main/java/com/loafle/overflow/dao/member/dao/MemberDAO.java b/src/main/java/com/loafle/overflow/dao/member/dao/MemberDAO.java new file mode 100644 index 0000000..226c9fa --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/member/dao/MemberDAO.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.dao.member.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.member.model.Member; + +/** + * Created by insanity on 17. 5. 25. + */ +public interface MemberDAO extends BaseDAO { + public Member findByEmail(Member member); +} diff --git a/src/main/java/com/loafle/overflow/dao/member/model/Member.java b/src/main/java/com/loafle/overflow/dao/member/model/Member.java new file mode 100644 index 0000000..e57b566 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/member/model/Member.java @@ -0,0 +1,111 @@ +package com.loafle.overflow.dao.member.model; + + +import javax.persistence.*; +import java.io.Serializable; + + +/** + * Created by insanity on 17. 5. 23. + */ + +@Entity +@Table(name="MEMBER") +public class Member implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="EMAIL", unique=true, nullable=false) + private String email; + + @Column(name="PW_SALT", nullable=false) + private String pwSalt; + + @Column(name="DIGEST", nullable=false) + private String digest; + + @Column(name="NAME", nullable=false) + private String name; + + @Column(name="COMPANY", nullable=false) + private String company; + + @Column(name="PHONE") + private String phone; + + @Column(name="AUTHORIZED_DATE") + private Long authorizedDate; + + + public Member() { + + } + + public Member(Long id) { + this.id = id; + } + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPwSalt() { + return pwSalt; + } + + public void setPwSalt(String pwSalt) { + this.pwSalt = pwSalt; + } + + public String getDigest() { + return digest; + } + + public void setDigest(String digest) { + this.digest = digest; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public Long getAuthorizedDate() { + return authorizedDate; + } + + public void setAuthorizedDate(Long authorizedDate) { + this.authorizedDate = authorizedDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/noauthagent/dao/JPANoAuthAgentDAO.java b/src/main/java/com/loafle/overflow/dao/noauthagent/dao/JPANoAuthAgentDAO.java new file mode 100644 index 0000000..51cc5ef --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/noauthagent/dao/JPANoAuthAgentDAO.java @@ -0,0 +1,42 @@ +package com.loafle.overflow.dao.noauthagent.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.noauthagent.model.NoAuthAgent; + +import javax.persistence.Query; +import java.util.List; + +/** + * Created by root on 17. 5. 30. + */ +public class JPANoAuthAgentDAO extends JPABaseDAO implements NoAuthAgentDao { + public NoAuthAgent findByTempKey(NoAuthAgent noAuthAgent) { + Query query = getEntityManager().createNativeQuery("SELECT na.* FROM NOAUTH_AGENT na WHERE na.TEMP_KEY = :tempkey", NoAuthAgent.class); + query.setParameter("tempkey", noAuthAgent.getTempKey()); + + NoAuthAgent authAgent = null; + try { + authAgent = (NoAuthAgent)query.getSingleResult(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return authAgent; + } + } + + public List findAllByNoAuth(NoAuthAgent noAuthAgent) { + + Query query = getEntityManager().createNativeQuery("SELECT na.* FROM NOAUTH_AGENT na WHERE na.AUTH_STATUS != :authStatus", NoAuthAgent.class); + query.setParameter("authStatus", noAuthAgent.getAuthStatus().toString()); + + List authAgentList = null; + try { + authAgentList = (List)query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return authAgentList; + } + + } +} diff --git a/src/main/java/com/loafle/overflow/dao/noauthagent/dao/NoAuthAgentDao.java b/src/main/java/com/loafle/overflow/dao/noauthagent/dao/NoAuthAgentDao.java new file mode 100644 index 0000000..f6e65f1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/noauthagent/dao/NoAuthAgentDao.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.dao.noauthagent.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.noauthagent.model.NoAuthAgent; + +import java.util.List; + +/** + * Created by root on 17. 5. 30. + */ +public interface NoAuthAgentDao extends BaseDAO { + NoAuthAgent findByTempKey(NoAuthAgent noAuthAgent); + List findAllByNoAuth(NoAuthAgent noAuthAgent); +} diff --git a/src/main/java/com/loafle/overflow/dao/noauthagent/model/NoAuthAgent.java b/src/main/java/com/loafle/overflow/dao/noauthagent/model/NoAuthAgent.java new file mode 100644 index 0000000..6bcbdef --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/noauthagent/model/NoAuthAgent.java @@ -0,0 +1,95 @@ +package com.loafle.overflow.dao.noauthagent.model; + +import com.loafle.overflow.dao.noauthagent.type.AuthType; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 5. 30. + */ +@Entity +@Table(name = "NOAUTH_AGENT") +public class NoAuthAgent { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="TEMP_KEY", unique=true, nullable=false) + private String tempKey; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="DATE", nullable=false) + private Date date; + + @Column(name="API_KEY", unique = true, nullable=false) + private String apiKey; + + @Column(name="AUTH_STATUS", nullable=false) + @Enumerated(EnumType.STRING) + private AuthType authStatus; + + @Column(name="LOCAL_IP", nullable=false) + private long localIP; + + @Column(name="HOST_NAME") + private String hostName; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTempKey() { + return tempKey; + } + + public void setTempKey(String tempKey) { + this.tempKey = tempKey; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + public AuthType getAuthStatus() { + return authStatus; + } + + public void setAuthStatus(AuthType authStatus) { + this.authStatus = authStatus; + } + + public long getLocalIP() { + return localIP; + } + + public void setLocalIP(long localIP) { + this.localIP = localIP; + } + + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/noauthagent/type/AuthType.java b/src/main/java/com/loafle/overflow/dao/noauthagent/type/AuthType.java new file mode 100644 index 0000000..227339b --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/noauthagent/type/AuthType.java @@ -0,0 +1,18 @@ +package com.loafle.overflow.dao.noauthagent.type; + +/** + * Created by root on 17. 5. 31. + */ +public enum AuthType { + ACCEPT("ACCEPT"), + REFUSE("REFUSE"), + WAIT("WAIT"); + + private String stringValue; + AuthType(String string) {stringValue = string;} + + @Override + public String toString() { + return stringValue; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorDao.java new file mode 100644 index 0000000..a250f2d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorDao.java @@ -0,0 +1,29 @@ +package com.loafle.overflow.dao.sensor.dao; + + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.sensor.model.Sensor; +import com.loafle.overflow.dao.target.model.Target; + +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/dao/sensor/dao/JPASensorItemCategoryDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemCategoryDao.java new file mode 100644 index 0000000..1a0fd48 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemCategoryDao.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.sensor.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.sensor.model.SensorItemCategory; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemCategoryDao extends JPABaseDAO implements SensorItemCategoryDao { +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemDao.java new file mode 100644 index 0000000..94d648d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemDao.java @@ -0,0 +1,31 @@ +package com.loafle.overflow.dao.sensor.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.sensor.model.SensorItem; + + +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/dao/sensor/dao/JPASensorItemMappingDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemMappingDao.java new file mode 100644 index 0000000..0d610a4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/JPASensorItemMappingDao.java @@ -0,0 +1,30 @@ +package com.loafle.overflow.dao.sensor.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.sensor.model.Sensor; +import com.loafle.overflow.dao.sensor.model.SensorItemMapping; + +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/dao/sensor/dao/SensorDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorDao.java new file mode 100644 index 0000000..adc41e2 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorDao.java @@ -0,0 +1,16 @@ +package com.loafle.overflow.dao.sensor.dao; + + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.sensor.model.Sensor; +import com.loafle.overflow.dao.target.model.Target; + +import java.util.List; + +/** + * Created by root on 17. 6. 9. + */ +public interface SensorDao extends BaseDAO { + + List findAllByTargetId(Target target); +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemCategoryDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemCategoryDao.java new file mode 100644 index 0000000..678a693 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemCategoryDao.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.dao.sensor.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.sensor.model.SensorItemCategory; + +/** + * Created by root on 17. 6. 9. + */ +public interface SensorItemCategoryDao extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemDao.java new file mode 100644 index 0000000..b08f88d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemDao.java @@ -0,0 +1,16 @@ +package com.loafle.overflow.dao.sensor.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; + +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.sensor.model.SensorItem; + +import java.util.List; + +/** + * Created by root on 17. 6. 9. + */ +public interface SensorItemDao extends BaseDAO{ + + List findAllByCrawlerId(Crawler crawler); +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemMappingDao.java b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemMappingDao.java new file mode 100644 index 0000000..dd82f14 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/dao/SensorItemMappingDao.java @@ -0,0 +1,16 @@ +package com.loafle.overflow.dao.sensor.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.dao.sensor.model.Sensor; +import com.loafle.overflow.dao.sensor.model.SensorItemMapping; + +import java.util.List; + +/** + * Created by root on 17. 6. 9. + */ +public interface SensorItemMappingDao extends BaseDAO { + + List findAllBySensorId(Sensor sensor); + +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/model/Sensor.java b/src/main/java/com/loafle/overflow/dao/sensor/model/Sensor.java new file mode 100644 index 0000000..0545235 --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/model/Sensor.java @@ -0,0 +1,83 @@ +package com.loafle.overflow.dao.sensor.model; + +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.target.model.Target; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 9. + */ +@Entity +public class Sensor { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name = "INTERVAL") + private long interval; + + @Column(name = "NOTIFICATION") + private String notification; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = true) + private Date createDate; + + @ManyToOne + @JoinColumn(name = "TARGET_ID", nullable = false) + private Target target; + + @ManyToOne + @JoinColumn(name = "CRAWLER_ID", nullable = false) + private Crawler crawler; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public long getInterval() { + return interval; + } + + public void setInterval(long interval) { + this.interval = interval; + } + + public String getNotification() { + return notification; + } + + public void setNotification(String notification) { + this.notification = notification; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Target getTarget() { + return target; + } + + public void setTarget(Target target) { + this.target = target; + } + + public Crawler getCrawler() { + return crawler; + } + + public void setCrawler(Crawler crawler) { + this.crawler = crawler; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItem.java b/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItem.java new file mode 100644 index 0000000..dddcb8d --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItem.java @@ -0,0 +1,94 @@ +package com.loafle.overflow.dao.sensor.model; + +import com.loafle.overflow.dao.crawler.model.Crawler; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 9. + */ +@Entity +public class SensorItem { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="NAME", nullable=false) + private String name; + + @Column(name="DESCRIPTION", nullable=false) + private String description; + + @Column(name="DATA_TYPE",nullable=false) + private String dataType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = true) + private Date createDate; + + @ManyToOne + @JoinColumn(name="CRAWLER_ID",nullable=false) + private Crawler crawler; + + @ManyToOne + @JoinColumn(name="SENSOR_ITEM_CATEGORY_ID",nullable=false) + private SensorItemCategory sensorItemCategory; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Crawler getCrawler() { + return crawler; + } + + public void setCrawler(Crawler crawler) { + this.crawler = crawler; + } + + public SensorItemCategory getSensorItemCategory() { + return sensorItemCategory; + } + + public void setSensorItemCategory(SensorItemCategory sensorItemCategory) { + this.sensorItemCategory = sensorItemCategory; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItemCategory.java b/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItemCategory.java new file mode 100644 index 0000000..0f492af --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItemCategory.java @@ -0,0 +1,56 @@ +package com.loafle.overflow.dao.sensor.model; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 9. + */ +@Entity +public class SensorItemCategory { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="NAME", nullable=false) + private String name; + + @Column(name="DESCRIPTION", nullable=false) + private String description; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = true) + private Date createDate; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItemMapping.java b/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItemMapping.java new file mode 100644 index 0000000..0deec8b --- /dev/null +++ b/src/main/java/com/loafle/overflow/dao/sensor/model/SensorItemMapping.java @@ -0,0 +1,58 @@ +package com.loafle.overflow.dao.sensor.model; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 9. + */ +@Entity +public class SensorItemMapping { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = true) + private Date createDate; + + @ManyToOne + @JoinColumn(name = "SENSOR_ID", nullable = false) + private Sensor sensor; + + @ManyToOne + @JoinColumn(name = "SENSOR_ITEM_ID", nullable = false) + private SensorItem sensorItem; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Sensor getSensor() { + return sensor; + } + + public void setSensor(Sensor sensor) { + this.sensor = sensor; + } + + public SensorItem getSensorItem() { + return sensorItem; + } + + public void setSensorItem(SensorItem sensorItem) { + this.sensorItem = sensorItem; + } +} diff --git a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java new file mode 100644 index 0000000..9a0b515 --- /dev/null +++ b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java @@ -0,0 +1,190 @@ +package com.loafle.overflow.proxy.db; + + + + +import com.loafle.overflow.dao.agent.dao.JPAAgentDAO; +import com.loafle.overflow.dao.apikey.dao.JPAApiKeyDao; +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.dao.crawler.dao.JPACrawlerDAO; +import com.loafle.overflow.dao.crawler.dao.JPACrawlerInputItemDAO; +import com.loafle.overflow.dao.crawler.dao.JPACrawlerInputItemMappingDAO; +import com.loafle.overflow.db.api.DBGrpc; + +import com.loafle.overflow.db.api.DBInput; +import com.loafle.overflow.db.api.DBOutput; +import com.loafle.overflow.dao.email.dao.JPAEmailAuthDAO; +import com.loafle.overflow.dao.member.dao.JPAMemberDAO; +import com.loafle.overflow.dao.noauthagent.dao.JPANoAuthAgentDAO; +import com.loafle.overflow.dao.sensor.dao.JPASensorDao; +import com.loafle.overflow.dao.sensor.dao.JPASensorItemCategoryDao; +import com.loafle.overflow.dao.sensor.dao.JPASensorItemDao; +import com.loafle.overflow.dao.sensor.dao.JPASensorItemMappingDao; +import com.loafle.overflow.dao.target.dao.JPATargetDao; +import io.grpc.ServerBuilder; +import org.codehaus.jackson.map.ObjectMapper; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; + +/** + * Created by insanity on 17. 5. 23. + */ + +public class DBProxy { + + private static final Logger logger = Logger.getLogger(DBProxy.class.getName()); + private io.grpc.Server server; + + private static Map daoMap = null; + + public DBProxy() { + daoMap = new ConcurrentHashMap(); + JPAMemberDAO memberDao = new JPAMemberDAO(); + JPAAgentDAO agentDao = new JPAAgentDAO(); + JPANoAuthAgentDAO jpaNoAuthAgentDAO = new JPANoAuthAgentDAO(); + JPAApiKeyDao jpaApiKeyDao = new JPAApiKeyDao(); + JPAEmailAuthDAO emailAuthDAO = new JPAEmailAuthDAO(); + + daoMap.put("member", memberDao); + daoMap.put("agent", agentDao); + daoMap.put("noauthAgent", jpaNoAuthAgentDAO); + daoMap.put("apiKey", jpaApiKeyDao); + daoMap.put("emailAuth", emailAuthDAO); + daoMap.put("target", new JPATargetDao()); + daoMap.put("crawler", new JPACrawlerDAO()); + daoMap.put("crawlerInputItem", new JPACrawlerInputItemDAO()); + daoMap.put("crawlerInputItemMapping", new JPACrawlerInputItemMappingDAO()); + + daoMap.put("sensor", new JPASensorDao()); + daoMap.put("sensorItemCategory", new JPASensorItemCategoryDao()); + daoMap.put("sensorItem", new JPASensorItemDao()); + daoMap.put("sensorItemMapping", new JPASensorItemMappingDao()); + } + + public void start(int port) throws IOException { + server = ServerBuilder.forPort(port) + .addService(new ServiceImpl()) + .build() + .start(); + logger.info("Server started, listening on " + port); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + // Use stderr here since the logger may have been reset by its JVM shutdown hook. + System.err.println("*** shutting down gRPC server since JVM is shutting down"); + DBProxy.this.stop(); + System.err.println("*** server shut down"); + } + }); + } + + public void stop() { + if (server != null) { + server.shutdown(); + } + } + + static class ServiceImpl extends DBGrpc.DBImplBase { + @Override + public void exec(DBInput request, + io.grpc.stub.StreamObserver responseObserver) { + String targetDAO = request.getTargetDao(); + + JPABaseDAO dao = daoMap.get(targetDAO); + + if(dao != null) { + try { + + String jsonResult = doQuery(request, dao); + + DBOutput reply = DBOutput.newBuilder() + .setResult(jsonResult) + .build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + }catch(Exception e) { + e.printStackTrace(); + responseObserver.onError(e); + } + + }else { + responseObserver.onError(new Exception("Not assigned DAO :" + targetDAO)); + } + } + + private String doQuery(DBInput request, JPABaseDAO dao) throws Exception { + + String methodName = request.getMethod(); + Map params = request.getParamsMap(); + + ObjectMapper mapper = new ObjectMapper(); + + Object retObj = null; + Method method = null; + + if (methodName.equals("find")) { + method = dao.getClass().getSuperclass().getMethod(methodName, String.class); + retObj = method.invoke(dao, params.get("id")); + return mapper.writeValueAsString(retObj); + } + + List paramTypes = new ArrayList(); + List valueList = new ArrayList(); + for( String className : params.keySet() ){ + //className - model name(with package) , value - model JsonString + Class cls = Class.forName(className); + Object obj = mapper.readValue((String)params.get(className), cls); + valueList.add(obj); + paramTypes.add(cls); + } + + try { + //Check if it belongs to the JPABaseDAO. + method = dao.getClass().getSuperclass().getMethod(methodName, Object.class); + retObj = method.invoke(dao, valueList.toArray(new Object[valueList.size()])); + + }catch(NoSuchMethodException e) { + if(params.size() > 0) { + method = dao.getClass().getMethod(methodName, paramTypes.toArray(new Class[paramTypes.size()])); + retObj = method.invoke(dao, valueList.toArray(new Object[valueList.size()])); + }else { + method = dao.getClass().getMethod(methodName); + retObj = method.invoke(dao); + } + }catch(InvocationTargetException e) { + e.printStackTrace(); + } + + return mapper.writeValueAsString(retObj); + } + } + + + private void blockUntilShutdown() throws InterruptedException { + if (server != null) { + server.awaitTermination(); + } + } + + public static void main(String[] args) throws IOException, InterruptedException { + + if(args.length <= 0) { + System.out.println("Port args"); + System.out.println("first parameter is Port Number"); + return; + } + + int port = Integer.valueOf(args[0]); + + final DBProxy server = new DBProxy(); + server.start(port); + server.blockUntilShutdown(); + } +} \ No newline at end of file diff --git a/src/main/proto/grpc.proto b/src/main/proto/grpc.proto new file mode 100644 index 0000000..eb5173f --- /dev/null +++ b/src/main/proto/grpc.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "com.loafle.overflow.db.api"; + +message DBInput { + string targetDao = 1; + string method = 2; + map params = 3; +} + +message DBOutput { + string result = 1; +} + +service DB { + rpc exec(DBInput) returns (DBOutput) {} +} + diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..5063762 --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,30 @@ + + + + + com.loafle.overflow.member.model.Member + com.loafle.overflow.noauthagent.model.NoAuthAgent + com.loafle.overflow.apikey.model.Apikey + com.loafle.overflow.agent.model.Agent + com.loafle.overflow.email.model.EmailAuth + com.loafle.overflow.target.model.Target + com.loafle.overflow.crawler.model.Crawler + com.loafle.overflow.crawler.model.CrawlerInputItem + com.loafle.overflow.crawler.model.CrawlerInputItemMapping + + com.loafle.overflow.sensor.model.Sensor + com.loafle.overflow.sensor.model.SensorItem + com.loafle.overflow.sensor.model.SensorItemMapping + com.loafle.overflow.sensor.model.SensorItemCategory + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/_ b/src/main/resources/_ new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/loafle/TestClient.java b/src/test/java/com/loafle/TestClient.java new file mode 100644 index 0000000..5b97925 --- /dev/null +++ b/src/test/java/com/loafle/TestClient.java @@ -0,0 +1,118 @@ +package com.loafle; + + +import com.loafle.overflow.db.api.DBGrpc; +import com.loafle.overflow.db.api.DBInput; +import com.loafle.overflow.db.api.DBOutput; +import com.loafle.overflow.dao.member.model.Member; +import com.loafle.overflow.dao.target.model.Target; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.StatusRuntimeException; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class TestClient { + + private static final Logger logger = Logger.getLogger(TestClient.class.getName()); + + private final ManagedChannel channel; + private final DBGrpc.DBBlockingStub dbStub; + + public TestClient() { + channel = ManagedChannelBuilder.forAddress("127.0.0.1", 50006).usePlaintext(true).build(); + dbStub = DBGrpc.newBlockingStub(channel); + } + + + public void shutdown() throws InterruptedException { + channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + + + public void execute() { + + try { + Member m = new Member(); + m.setId(Long.parseLong("2")); + m.setName("geek"); + m.setCompany("loafle"); + m.setDigest("bbbbbbbbb"); + m.setPwSalt("salktttt"); + m.setEmail("insanity@loafle.com"); + + ObjectMapper mapper = new ObjectMapper(); + + DBInput request = DBInput.newBuilder() + .setTargetDao("member") + .setMethod("findByEmail") + .putParams("com.loafle.overflow.member.model.Member", mapper.writeValueAsString(m)) + //.putParams("id", "1") + .build(); + DBOutput response; + try { + response = dbStub.exec(request); + } catch (StatusRuntimeException e) { + logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); + return; + } + logger.log(Level.INFO, response.getResult()); + }catch(Exception e) { + e.printStackTrace(); + } + + } + + @Test + public void testRPCServer() { + TestClient client = new TestClient(); + try { + client.execute(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + client.shutdown(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + + + @Test + public void testClassName() throws ClassNotFoundException, IOException { + + String testRes = "[{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL2222\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL3333\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL4444\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL5555\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL6666\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}}]"; + + ObjectMapper mapper = new ObjectMapper(); + Class cls = Class.forName("[L" + "com.loafle.overflow.target.model.Target" + ";"); +// Class cls = Class.forName("java.util.List"); + + Object obj = mapper.readValue(testRes, cls); + + + List aa = Arrays.asList((Object[])obj); + + System.out.println(aa.getClass()); +// List tl = (List)aa; + + +// List aaa = (List)obj.; +// +// +// for( Target t : aaa) { +// System.out.println(t); +// } + + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java new file mode 100644 index 0000000..7ee9b82 --- /dev/null +++ b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java @@ -0,0 +1,36 @@ +package com.loafle.overflow.agent.dao; + +import com.loafle.overflow.dao.agent.dao.JPAAgentDAO; +import com.loafle.overflow.dao.agent.model.Agent; +import com.loafle.overflow.dao.member.model.Member; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Created by root on 17. 6. 4. + */ +@Ignore +public class JPAAgentDAOTest { + + private JPAAgentDAO jpaAgentDAO = null; + + @Before + public void before() { + this.jpaAgentDAO = new JPAAgentDAO(); + } + + + @Test + public void createAgent() { + Member m = new Member(); + m.setId(Long.valueOf(1)); + Agent agent = new Agent(); + agent.setDescription("test agent"); + agent.setMember(m); + Agent savedAgent = jpaAgentDAO.create(agent); + + System.out.println(savedAgent.getDescription()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/apikey/dao/JPAApiKeyDaoTest.java b/src/test/java/com/loafle/overflow/apikey/dao/JPAApiKeyDaoTest.java new file mode 100644 index 0000000..e48b331 --- /dev/null +++ b/src/test/java/com/loafle/overflow/apikey/dao/JPAApiKeyDaoTest.java @@ -0,0 +1,56 @@ +package com.loafle.overflow.apikey.dao; + +import com.loafle.overflow.dao.apikey.dao.JPAApiKeyDao; +import com.loafle.overflow.dao.apikey.model.Apikey; +import com.loafle.overflow.dao.member.model.Member; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Date; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAApiKeyDaoTest { + + private JPAApiKeyDao jpaApiKeyDao; + + @Before + public void Before() { + this.jpaApiKeyDao = new JPAApiKeyDao(); + } + + + @Ignore + @Test + public void findByApiKey() throws Exception { + + Apikey apikey = new Apikey(); + + apikey.setApiKey("1111111"); + + Apikey a = this.jpaApiKeyDao.findByApiKey(apikey); + + System.out.println(a.getId()); + + } + + @Ignore + @Test + public void createApiKey() { + Apikey apikey = new Apikey(); + + apikey.setApiKey("1111111"); + apikey.setCreateDate(new Date()); + Member member = new Member(); + member.setId((long)2); + apikey.setMember(member); + + + jpaApiKeyDao.create(apikey); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java new file mode 100644 index 0000000..91a7c57 --- /dev/null +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java @@ -0,0 +1,80 @@ +package com.loafle.overflow.crawler.dao; + + +import com.loafle.overflow.dao.crawler.dao.JPACrawlerDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@Ignore +public class JPACrawlerDAOTest { + + private JPACrawlerDAO jpaCrawlerDAO = null; + + @Before + public void before() { + this.jpaCrawlerDAO = new JPACrawlerDAO(); + + } + + // TODO Crawler Meta Data Insert + @Test + public void TestInsertList() { + List crawlers = new ArrayList(); + + Crawler crawler1 = new Crawler(); + crawler1.setName("SNMP Crawler"); + crawler1.setDescription("SNMP Crawler"); + crawler1.setCrawlerType("SNMP"); + + Crawler crawler2 = new Crawler(); + crawler2.setName("WMI Crawler"); + crawler2.setDescription("WMI Crawler"); + crawler2.setCrawlerType("WMI"); + + Crawler crawler3 = new Crawler(); + crawler3.setName("HTTP Crawler"); + crawler3.setDescription("HTTP Crawler"); + crawler3.setCrawlerType("Network"); + + Crawler crawler4 = new Crawler(); + crawler4.setName("FTP Crawler"); + crawler4.setDescription("FTP Crawler"); + crawler4.setCrawlerType("Network"); + + crawlers.add(crawler1); + crawlers.add(crawler2); + crawlers.add(crawler3); + crawlers.add(crawler4); + + this.jpaCrawlerDAO.createAll(crawlers); + } + + @Test + public void TestInsert() { + Crawler crawler = new Crawler(); + crawler.setName("Mysql Crawler"); + crawler.setDescription("Mysql Crawler"); + crawler.setCrawlerType("MysqlCrawler"); + this.jpaCrawlerDAO.create(crawler); + } + // TODO Crawler Select Test + + @Test + public void TestListAll() { + List ls = this.jpaCrawlerDAO.findAll(); + System.out.println(ls.size()); + } + // TODO Crawler Update Test + + // TODO Crawler Delete Test +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java new file mode 100644 index 0000000..997868a --- /dev/null +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java @@ -0,0 +1,64 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.dao.crawler.dao.JPACrawlerInputItemDAO; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItem; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@Ignore +public class JPACrawlerInputItemDAOTest { + + private JPACrawlerInputItemDAO inputItemDAO = null; + + @Before + public void before() { + this.inputItemDAO = new JPACrawlerInputItemDAO(); + } + + @Test + public void TestInsertList() { + List cris = new ArrayList(); + + CrawlerInputItem item1 = new CrawlerInputItem(); + item1.setName("ID"); + item1.setDataType("String"); + item1.setDescription("Auth ID"); + + CrawlerInputItem item2 = new CrawlerInputItem(); + item2.setName("PW"); + item2.setDataType("String"); + item2.setDescription("Auth PW"); + + CrawlerInputItem item3 = new CrawlerInputItem(); + item3.setName("AuthType"); + item3.setDataType("Select"); + item3.setDescription("MD5||SHA"); + + CrawlerInputItem item4 = new CrawlerInputItem(); + item4.setName("community"); + item4.setDataType("String"); + item4.setDescription("community"); + + CrawlerInputItem item5 = new CrawlerInputItem(); + item5.setName("textfield"); + item5.setDataType("String"); + item5.setDescription("User ID"); + + cris.add(item1); + cris.add(item2); + cris.add(item3); + cris.add(item4); + cris.add(item5); + + this.inputItemDAO.createAll(cris); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java new file mode 100644 index 0000000..d42d23b --- /dev/null +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java @@ -0,0 +1,91 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.dao.crawler.dao.JPACrawlerInputItemMappingDAO; +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItem; +import com.loafle.overflow.dao.crawler.model.CrawlerInputItemMapping; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@Ignore +public class JPACrawlerInputItemMappingDAOTest { + + private JPACrawlerInputItemMappingDAO mappingDAO = null; + + @Before + public void before() { + this.mappingDAO = new JPACrawlerInputItemMappingDAO(); + } + + @Test + public void TestInsert() { + CrawlerInputItemMapping itemMapping = new CrawlerInputItemMapping(); + itemMapping.setCrawler(new Crawler((long)5)); + itemMapping.setCrawlerInputItem(new CrawlerInputItem((long)1)); + itemMapping.setPriority((short) 1); + itemMapping.setRequiredType(true); + + CrawlerInputItemMapping itemMapping1 = new CrawlerInputItemMapping(); + itemMapping1.setCrawler(new Crawler((long)5)); + itemMapping1.setCrawlerInputItem(new CrawlerInputItem((long)2)); + itemMapping1.setPriority((short) 2); + itemMapping1.setRequiredType(true); + + CrawlerInputItemMapping itemMapping2 = new CrawlerInputItemMapping(); + itemMapping2.setCrawler(new Crawler((long)1)); + itemMapping2.setCrawlerInputItem(new CrawlerInputItem((long)1)); + itemMapping2.setPriority((short) 1); + itemMapping2.setRequiredType(true); + + CrawlerInputItemMapping itemMapping3 = new CrawlerInputItemMapping(); + itemMapping3.setCrawler(new Crawler((long)1)); + itemMapping3.setCrawlerInputItem(new CrawlerInputItem((long)2)); + itemMapping3.setPriority((short) 2); + itemMapping3.setRequiredType(true); + + CrawlerInputItemMapping itemMapping4 = new CrawlerInputItemMapping(); + itemMapping4.setCrawler(new Crawler((long)1)); + itemMapping4.setCrawlerInputItem(new CrawlerInputItem((long)3)); + itemMapping4.setPriority((short) 3); + itemMapping4.setRequiredType(true); + + CrawlerInputItemMapping itemMapping5 = new CrawlerInputItemMapping(); + itemMapping5.setCrawler(new Crawler((long)2)); + itemMapping5.setCrawlerInputItem(new CrawlerInputItem((long)1)); + itemMapping5.setPriority((short) 1); + itemMapping5.setRequiredType(true); + + CrawlerInputItemMapping itemMapping6 = new CrawlerInputItemMapping(); + itemMapping6.setCrawler(new Crawler((long)2)); + itemMapping6.setCrawlerInputItem(new CrawlerInputItem((long)2)); + itemMapping6.setPriority((short) 2); + itemMapping6.setRequiredType(true); + + List crs = new ArrayList(); + crs.add(itemMapping); + crs.add(itemMapping1); + crs.add(itemMapping2); + crs.add(itemMapping3); + crs.add(itemMapping4); + crs.add(itemMapping5); + crs.add(itemMapping6); + + this.mappingDAO.createAll(crs); + } + + @Test + public void TestFindByCrawlerId() { + List ls = this.mappingDAO.findByCrawlerId(new Crawler((long)5)); + System.out.println(ls.size()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java b/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java new file mode 100644 index 0000000..45134f9 --- /dev/null +++ b/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java @@ -0,0 +1,77 @@ +package com.loafle.overflow.email.dao; + +import com.loafle.overflow.dao.email.dao.JPAEmailAuthDAO; +import com.loafle.overflow.dao.email.model.EmailAuth; +import com.loafle.overflow.dao.member.model.Member; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Date; +import java.util.List; + +/** + * Created by geek@loafle.com on 17. 6. 6. + */ +@Ignore +public class JPAEmailAuthDAOTest { + + private JPAEmailAuthDAO emailAuthDAO = null; + + @Before + public void before() { + + this.emailAuthDAO = new JPAEmailAuthDAO(); + } + + @Test + @Ignore + public void createEmailAuth() { + EmailAuth auth = new EmailAuth(); + + auth.setAuthToken("0F2003A6-83B0-40F5-B56A-0485F458CA911"); + auth.setMember(new Member(Long.valueOf(1))); + auth.setIsInvalid(false); +// auth.setUpdateDate(new Date()); + auth.setIsConfirm(false); + EmailAuth ret = emailAuthDAO.create(auth); + System.out.println(ret.getId()); + } + + @Test + @Ignore + public void updateEmailAuth() { + EmailAuth auth = this.emailAuthDAO.find("1"); + + auth.setIsInvalid(true); + auth.setUpdateDate(new Date()); + auth.setConfirmDate(new Date()); + + this.emailAuthDAO.update(auth); + System.out.println(auth.getConfirmDate()); + } + + @Test + @Ignore + public void TestFindByAuthToken() { + EmailAuth auth = new EmailAuth(); + auth.setAuthToken("3C03F8AB-1D4D-4C8A-8C36-EE2D644988B5"); + + EmailAuth temp = this.emailAuthDAO.findByAuthToken(auth); + + System.out.println(temp.getId()); + Assert.assertNotNull(temp); + } + + @Test + @Ignore + public void TestFindByMemberId() { + EmailAuth auth = new EmailAuth(); + auth.setMember(new Member((long)4)); + List ems = this.emailAuthDAO.findByMemberId(auth); + + System.out.println(ems.get(0).getMember().getEmail()); + Assert.assertEquals((long)1, (long)ems.size()); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/member/dao/JPAMemberDAOTest.java b/src/test/java/com/loafle/overflow/member/dao/JPAMemberDAOTest.java new file mode 100644 index 0000000..e63376e --- /dev/null +++ b/src/test/java/com/loafle/overflow/member/dao/JPAMemberDAOTest.java @@ -0,0 +1,44 @@ +package com.loafle.overflow.member.dao; + +import com.loafle.overflow.dao.member.dao.JPAMemberDAO; +import com.loafle.overflow.dao.member.model.Member; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +@Ignore +public class JPAMemberDAOTest { + + private JPAMemberDAO jpaMemberDAO = null; + + @Before + public void before() { + + this.jpaMemberDAO = new JPAMemberDAO(); + } + + @Test + public void findByEmail() throws Exception { + } + +// @Ignore + @Test + public void createMember() { + Member m = new Member(); + + m.setName("geek"); + m.setCompany("loafle"); + m.setDigest("bbbbbbbbb"); + m.setPwSalt("salktttt"); + m.setPhone("000-000-0000"); + m.setEmail("geek@loafle.com"); + + this.jpaMemberDAO.create(m); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAOTest.java b/src/test/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAOTest.java new file mode 100644 index 0000000..e001e7d --- /dev/null +++ b/src/test/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAOTest.java @@ -0,0 +1,61 @@ +package com.loafle.overflow.noauthagent.dao; + +import com.loafle.overflow.dao.noauthagent.dao.JPANoAuthAgentDAO; +import com.loafle.overflow.dao.noauthagent.model.NoAuthAgent; +import com.loafle.overflow.dao.noauthagent.type.AuthType; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Date; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +public class JPANoAuthAgentDAOTest { + + private JPANoAuthAgentDAO jpaNoAuthAgentDAO = null; + + @Before + public void Before() { + this.jpaNoAuthAgentDAO = new JPANoAuthAgentDAO(); + } + + @Test + public void findByTempKey() throws Exception { + + NoAuthAgent noAuthAgent = new NoAuthAgent(); + noAuthAgent.setTempKey("3398473-90847903874"); + + NoAuthAgent aa = this.jpaNoAuthAgentDAO.findByTempKey(noAuthAgent); + + System.out.println(aa.getAuthStatus()); + + } + + @Test + public void findAllByNoAuth() throws Exception { + } + + + @Test + public void createNoAuthAgent() { + NoAuthAgent noAuthAgent = new NoAuthAgent(); + + + noAuthAgent.setApiKey("aaaaaaa"); + noAuthAgent.setDate(new Date()); + noAuthAgent.setHostName("Snoop pc"); + noAuthAgent.setLocalIP(4123); + noAuthAgent.setTempKey("3398473-90847903874"); + noAuthAgent.setAuthStatus(AuthType.WAIT); + + this.jpaNoAuthAgentDAO.create(noAuthAgent); + } + + + + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorDaoTest.java new file mode 100644 index 0000000..94c5f00 --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorDaoTest.java @@ -0,0 +1,59 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.sensor.dao.JPASensorDao; +import com.loafle.overflow.dao.sensor.dao.SensorDao; +import com.loafle.overflow.dao.sensor.model.Sensor; +import com.loafle.overflow.dao.target.model.Target; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorDaoTest { + + private SensorDao sensorDao = null; + + @Before + public void before() { + this.sensorDao = new JPASensorDao(); + } + + @Test + public void findAllByAgentID() throws Exception { + } + + + @Ignore + @Test + public void create() { + + + Sensor sensor = new Sensor(); + + Crawler crawler = new Crawler(); + crawler.setId(1L); + + Target target = new Target(); + target.setId(1L); + + sensor.setCrawler(crawler); + sensor.setInterval(1); + sensor.setNotification("nothing"); + sensor.setTarget(target); + + this.sensorDao.create(sensor); + + } + + @Test + public void list() { + +// this.sensorDao.findAllByAgentID() + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemCategoryDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemCategoryDaoTest.java new file mode 100644 index 0000000..095897a --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemCategoryDaoTest.java @@ -0,0 +1,39 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.dao.sensor.dao.JPASensorItemCategoryDao; +import com.loafle.overflow.dao.sensor.dao.SensorItemCategoryDao; +import com.loafle.overflow.dao.sensor.model.SensorItemCategory; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemCategoryDaoTest { + + private SensorItemCategoryDao sensorItemCategoryDao = null; + + @Before + public void before() { + + this.sensorItemCategoryDao = new JPASensorItemCategoryDao(); + } + + + @Ignore + @Test + public void create() { + + SensorItemCategory sensorItemCategory = new SensorItemCategory(); + + sensorItemCategory.setName("count"); + sensorItemCategory.setDescription("count !!!!"); + + this.sensorItemCategoryDao.create(sensorItemCategory); + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemDaoTest.java new file mode 100644 index 0000000..ce8a42b --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemDaoTest.java @@ -0,0 +1,65 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.dao.crawler.model.Crawler; +import com.loafle.overflow.dao.sensor.dao.JPASensorItemDao; +import com.loafle.overflow.dao.sensor.dao.SensorItemDao; +import com.loafle.overflow.dao.sensor.model.SensorItem; +import com.loafle.overflow.dao.sensor.model.SensorItemCategory; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemDaoTest { + + private SensorItemDao sensorItemDao = null; + + @Before + public void before() { + this.sensorItemDao = new JPASensorItemDao(); + } + + @Ignore + @Test + public void create() { + + + SensorItem sensorItem = new SensorItem(); + + Crawler crawler = new Crawler(); + crawler.setId(1L); + + SensorItemCategory category = new SensorItemCategory(); + category.setId(1L); + + sensorItem.setCrawler(crawler); + sensorItem.setDataType("int"); + sensorItem.setDescription("count getget"); + sensorItem.setName("net.mysql.connection_count"); + sensorItem.setSensorItemCategory(category); + + this.sensorItemDao.create(sensorItem); + + } + + @Ignore + @Test + public void list() { + + Crawler crawler = new Crawler(); + crawler.setId(1L); + + List is = this.sensorItemDao.findAllByCrawlerId(crawler); + + + System.out.println(is.size()); + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDaoTest.java new file mode 100644 index 0000000..8b56cd0 --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDaoTest.java @@ -0,0 +1,64 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.dao.sensor.dao.JPASensorItemMappingDao; +import com.loafle.overflow.dao.sensor.dao.SensorItemMappingDao; +import com.loafle.overflow.dao.sensor.model.Sensor; +import com.loafle.overflow.dao.sensor.model.SensorItem; +import com.loafle.overflow.dao.sensor.model.SensorItemMapping; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemMappingDaoTest { + + private SensorItemMappingDao sensorItemMappingDao = null; + + @Before + public void before() { + this.sensorItemMappingDao = new JPASensorItemMappingDao(); + } + + + @Ignore + @Test + public void create() { + + SensorItemMapping mapping = new SensorItemMapping(); + + Sensor sensor = new Sensor(); + + sensor.setId(1L); + + SensorItem sensorItem = new SensorItem(); + + sensorItem.setId(1L); + + mapping.setSensor(sensor); + + mapping.setSensorItem(sensorItem); + + this.sensorItemMappingDao.create(mapping); + + } + + @Test + public void list() { + + Sensor sensor = new Sensor(); + + sensor.setId(1L); + + List ml = this.sensorItemMappingDao.findAllBySensorId(sensor); + + System.out.println(ml.size()); + + } + +} \ No newline at end of file diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml new file mode 100644 index 0000000..4fb2352 --- /dev/null +++ b/src/test/resources/logback.xml @@ -0,0 +1,17 @@ + + + overflow_proxy_db + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n + + + + + + + + + \ No newline at end of file