first overflow dao commit

This commit is contained in:
snoop 2017-06-22 11:52:31 +09:00
commit 4008097387
71 changed files with 3418 additions and 0 deletions

85
.gitignore vendored Normal file
View File

@ -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/

132
pom.xml Normal file
View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.loafle</groupId>
<artifactId>maven_parent_jar</artifactId>
<version>1.0.0-RELEASE</version>
</parent>
<groupId>com.loafle</groupId>
<artifactId>overflow_dao</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<grpc.version>1.2.0</grpc.version>
<hibernate.version>4.3.10.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.10.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.loafle</groupId>
<artifactId>overflow_jpa_base_dao</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.loafle</groupId>-->
<!--<artifactId>overflow_jpa_agent_dao</artifactId>-->
<!--<version>1.0.0-SNAPSHOT</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.loafle</groupId>-->
<!--<artifactId>overflow_jpa_dao</artifactId>-->
<!--<version>1.0.0-SNAPSHOT</version>-->
<!--</dependency>-->
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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<Agent> {
public List<Agent> findAgentListByMemberId(Member member);
}

View File

@ -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<Agent> implements AgentDAO {
public List<Agent> 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<Agent> list = new ArrayList<>();
try {
list = query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return list;
}
}
}

View File

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

View File

@ -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> {
Apikey findByApiKey(Apikey apikey);
}

View File

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

View File

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

View File

@ -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<Crawler> {
public List<Crawler> findAll();
}

View File

@ -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<CrawlerInputItem> {
}

View File

@ -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<CrawlerInputItemMapping> {
public List<CrawlerInputItemMapping> findByCrawlerId(Crawler crawler);
}

View File

@ -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<Crawler> implements CrawlerDAO {
@Override
public List<Crawler> findAll() {
Query query = getEntityManager().createNativeQuery("SELECT c.* FROM CRAWLER c ", Crawler.class);
List<Crawler> crs = null;
try {
crs = (List<Crawler>)query.getResultList();
} catch (Exception e) {
e.printStackTrace();
} finally {
return crs;
}
}
}

View File

@ -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<CrawlerInputItem> implements CrawlerInputItemDAO {
}

View File

@ -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<CrawlerInputItemMapping> implements CrawlerInputItemMappingDAO {
@Override
public List<CrawlerInputItemMapping> 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<CrawlerInputItemMapping> crs = null;
try {
crs = (List<CrawlerInputItemMapping>)query.getResultList();
} catch (Exception e) {
e.printStackTrace();
} finally {
return crs;
}
}
}

View File

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

View File

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

View File

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

View File

@ -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<Host> {
}

View File

@ -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<Host> implements HostDao {
}

View File

@ -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<Port> implements PortDao {
}

View File

@ -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<Service> implements ServiceDao {
}

View File

@ -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<Zone> implements ZoneDao {
}

View File

@ -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<Port> {
}

View File

@ -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<Service> {
}

View File

@ -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<Zone> {
}

View File

@ -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<Port> ports;
public List<Port> getPorts() {
return ports;
}
public void setPorts(List<Port> 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<Port> ports = this.getPorts();
if (ports != null) {
for (int j =0 ; j < ports.size() ; ++j) {
ports.get(j).mappingChildren(this);
}
}
}
}

View File

@ -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<Service> services;
public List<Service> getServices() {
return services;
}
public void setServices(List<Service> 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<Service> discoveryServices = this.getServices();
if (discoveryServices != null) {
for (int z = 0 ; z < discoveryServices.size() ; ++z) {
discoveryServices.get(z).setPort(this);
}
}
}
}

View File

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

View File

@ -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<HostScanHistory> histories;
@OneToMany(mappedBy = "zone", cascade = CascadeType.ALL)
private List<Host> 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<Host> getHosts() {
return hosts;
}
public void setHosts(List<Host> hosts) {
this.hosts = hosts;
}
// public void mappingChildren(DiscoveryHistory history) {
// this.setDiscovery(history);
// List<HostScanHistory> hostScanHistories = this.getHistories();
// if (hostScanHistories != null) {
// for (int i =0 ; i < hostScanHistories.size() ; ++i) {
// hostScanHistories.get(i).setZone(this);
// }
// }
//
// List<Host> hosts = this.getHosts();
// if (hosts != null) {
// for (int i =0 ; i < hosts.size() ; ++i) {
// hosts.get(i).mappingChildren(this);
// }
// }
// }
}

View File

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

View File

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

View File

@ -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<EmailAuth> {
public EmailAuth findByAuthToken(EmailAuth emailAuth);
public List<EmailAuth> findByMemberId(EmailAuth emailAuth);
// public EmailAuth updateEmailAuth(EmailAuth emailAuth);
}

View File

@ -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<EmailAuth> 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<EmailAuth> 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<EmailAuth> auths = null;
try {
auths = (List<EmailAuth>)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;
// }
// }
}

View File

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

View File

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

View File

@ -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<Member> {
public Member findByEmail(Member member);
}

View File

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

View File

@ -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<NoAuthAgent> 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<NoAuthAgent> 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<NoAuthAgent> authAgentList = null;
try {
authAgentList = (List<NoAuthAgent>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return authAgentList;
}
}
}

View File

@ -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> {
NoAuthAgent findByTempKey(NoAuthAgent noAuthAgent);
List<NoAuthAgent> findAllByNoAuth(NoAuthAgent noAuthAgent);
}

View File

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

View File

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

View File

@ -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<Sensor> implements SensorDao {
public List<Sensor> findAllByTargetId(Target target) {
Query query = getEntityManager().createNativeQuery("SELECT s.* FROM Sensor s WHERE s.TARGET_ID = :targetId", Sensor.class);
query.setParameter("targetId", target.getId());
List<Sensor> sensors = null;
try {
sensors = (List<Sensor>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return sensors;
}
}
}

View File

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

View File

@ -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<SensorItem> implements SensorItemDao {
public List<SensorItem> findAllByCrawlerId(Crawler crawler) {
Query query = getEntityManager().createNativeQuery("SELECT si.* FROM SensorItem si WHERE si.CRAWLER_ID = :crawlerId", SensorItem.class);
query.setParameter("crawlerId", crawler.getId());
List<SensorItem> sensorItems = null;
try {
sensorItems = (List<SensorItem>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return sensorItems;
}
}
}

View File

@ -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<SensorItemMapping> implements SensorItemMappingDao {
public List<SensorItemMapping> findAllBySensorId(Sensor sensor) {
Query query = getEntityManager().createNativeQuery("SELECT sim.* FROM SensorItemMapping sim WHERE sim.SENSOR_ID = :sensorId", SensorItemMapping.class);
query.setParameter("sensorId", sensor.getId());
List<SensorItemMapping> sensorItemMappings = null;
try {
sensorItemMappings = (List<SensorItemMapping>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return sensorItemMappings;
}
}
}

View File

@ -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<Sensor> {
List<Sensor> findAllByTargetId(Target target);
}

View File

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

View File

@ -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<SensorItem>{
List<SensorItem> findAllByCrawlerId(Crawler crawler);
}

View File

@ -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<SensorItemMapping> {
List<SensorItemMapping> findAllBySensorId(Sensor sensor);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<String, JPABaseDAO> 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<com.loafle.overflow.db.api.DBOutput> 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<String, String> 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<Class> paramTypes = new ArrayList<Class>();
List<Object> valueList = new ArrayList<Object>();
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();
}
}

19
src/main/proto/grpc.proto Normal file
View File

@ -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<string, string> params = 3;
}
message DBOutput {
string result = 1;
}
service DB {
rpc exec(DBInput) returns (DBOutput) {}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="overflow">
<class>com.loafle.overflow.member.model.Member</class>
<class>com.loafle.overflow.noauthagent.model.NoAuthAgent</class>
<class>com.loafle.overflow.apikey.model.Apikey</class>
<class>com.loafle.overflow.agent.model.Agent</class>
<class>com.loafle.overflow.email.model.EmailAuth</class>
<class>com.loafle.overflow.target.model.Target</class>
<class>com.loafle.overflow.crawler.model.Crawler</class>
<class>com.loafle.overflow.crawler.model.CrawlerInputItem</class>
<class>com.loafle.overflow.crawler.model.CrawlerInputItemMapping</class>
<class>com.loafle.overflow.sensor.model.Sensor</class>
<class>com.loafle.overflow.sensor.model.SensorItem</class>
<class>com.loafle.overflow.sensor.model.SensorItemMapping</class>
<class>com.loafle.overflow.sensor.model.SensorItemCategory</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.1.106:5432/postgres" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.user" value="vertx" />
<property name="javax.persistence.jdbc.password" value="qwe123" />
<!--<property name="hibernate.hbm2ddl.auto" value="create"/>-->
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>

0
src/main/resources/_ Normal file
View File

View File

@ -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<com.loafle.overflow.target.model.Target>");
Object obj = mapper.readValue(testRes, cls);
List<Object> aa = Arrays.asList((Object[])obj);
System.out.println(aa.getClass());
// List<Target> tl = (List<Target>)aa;
// List<Target> aaa = (List<Target>)obj.;
//
//
// for( Target t : aaa) {
// System.out.println(t);
// }
}
}

View File

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

View File

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

View File

@ -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<Crawler> crawlers = new ArrayList<Crawler>();
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<Crawler> ls = this.jpaCrawlerDAO.findAll();
System.out.println(ls.size());
}
// TODO Crawler Update Test
// TODO Crawler Delete Test
}

View File

@ -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<CrawlerInputItem> cris = new ArrayList<CrawlerInputItem>();
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);
}
}

View File

@ -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<CrawlerInputItemMapping> crs = new ArrayList<CrawlerInputItemMapping>();
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<CrawlerInputItemMapping> ls = this.mappingDAO.findByCrawlerId(new Crawler((long)5));
System.out.println(ls.size());
}
}

View File

@ -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<EmailAuth> ems = this.emailAuthDAO.findByMemberId(auth);
System.out.println(ems.get(0).getMember().getEmail());
Assert.assertEquals((long)1, (long)ems.size());
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<SensorItem> is = this.sensorItemDao.findAllByCrawlerId(crawler);
System.out.println(is.size());
}
}

View File

@ -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<SensorItemMapping> ml = this.sensorItemMappingDao.findAllBySensorId(sensor);
System.out.println(ml.size());
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="3 seconds">
<contextName>overflow_proxy_db</contextName>
<!-- TRACE > DEBUG > INFO > WARN > ERROR -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
<logger name="com.loafle" level="ALL" />
</configuration>