diff --git a/.gitignore b/.gitignore index 45f0edd..ca26b00 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,5 @@ fabric.properties .gitignore 제거할 예정 .idea/ 제거할 예정 +.idea/ +bridge.iml diff --git a/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java b/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java index 0d46681..460c4f3 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java @@ -1,7 +1,114 @@ package com.loafle.bridge.discoveryhost.entity; +import com.loafle.bridge.discoveryport.entity.DiscoveryPort; +import com.loafle.bridge.discoveryzone.DiscoveryZone; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + /** * Created by root on 16. 11. 15. */ +@Entity public class DiscoveryHost { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column(name = "IP_ADDRESS",nullable = false) + private long ipAddress; + + @Column(name = "MAC_ADDRESS",nullable = false) + private long macAddress; + +// @ManyToOne +// @JoinColumn(name = "ZONE_ID", nullable = false) +// private DiscoveryZone zone; + +// public DiscoveryZone getZone() { +// return zone; +// } +// +// public void setZone(DiscoveryZone zone) { +// this.zone = zone; +// } + + @OneToMany(mappedBy = "host") + private List histories; + + public List getHistories() { + return histories; + } + + public void setHistories(List histories) { + this.histories = histories; + } + +// @OneToMany(mappedBy = "host") +// 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 DiscoveryHost(){} + public DiscoveryHost(long ip, long mac){ + this.ipAddress = ip; + this.macAddress = mac; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getIpAddress() { + return ipAddress; + } + + public void setIpAddress(long ipAddress) { + this.ipAddress = ipAddress; + } + + public long getMacAddress() { + return macAddress; + } + + public void setMacAddress(long macAddress) { + this.macAddress = macAddress; + } + + + + 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/bridge/discoveryhost/entity/PortScanHistory.java b/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java new file mode 100644 index 0000000..4dee0a6 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java @@ -0,0 +1,130 @@ +package com.loafle.bridge.discoveryhost.entity; + +import com.loafle.bridge.discoveryport.constant.DirectionType; +import com.loafle.bridge.discoveryport.constant.PortType; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 11/16/16. + */ +@Entity +public class PortScanHistory { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private DiscoveryHost host; + + public DiscoveryHost getHost() { + return host; + } + + public void setHost(DiscoveryHost host) { + this.host = host; + } + + @Column(nullable = false) + private short portNumber; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PortType portType; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private DirectionType directionType; + + @Column(nullable = true) + private String description; + + @Column(nullable = true) + private Date sendTime; + + @Column(nullable = true) + private Date resultTime; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + + public PortScanHistory(){} + + public PortScanHistory(DiscoveryHost host, short portNumber, + PortType portType, DirectionType directionType, + String description) { + this.host = host; + this.portNumber = portNumber; + this.portType = portType; + this.directionType = directionType; + this.description = description; + } + + 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 short getPortNumber() { + return portNumber; + } + + public void setPortNumber(short portNumber) { + this.portNumber = portNumber; + } + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + this.portType = portType; + } + + public DirectionType getDirectionType() { + return directionType; + } + + public void setDirectionType(DirectionType directionType) { + this.directionType = directionType; + } + + public Date getSendTime() { + return sendTime; + } + + public void setSendTime(Date sendTime) { + this.sendTime = sendTime; + } + + public Date getResultTime() { + return resultTime; + } + + public void setResultTime(Date resultTime) { + this.resultTime = resultTime; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java b/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java index 927db2c..9b7cf08 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java @@ -1,7 +1,12 @@ package com.loafle.bridge.discoveryhost.repository; +import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + /** * Created by root on 16. 11. 15. */ -public class DiscoveryHostRepository { +@RepositoryRestResource(collectionResourceRel = "discoveryHost", path = "discoveryHost") +public interface DiscoveryHostRepository extends JpaRepository { } diff --git a/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java new file mode 100644 index 0000000..9cdee24 --- /dev/null +++ b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java @@ -0,0 +1,80 @@ +package com.loafle.bridge.discoveryhost.repository; + +import com.loafle.bridge.Application; +import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; +import com.loafle.bridge.discoveryhost.entity.PortScanHistory; +import com.loafle.bridge.discoveryport.constant.DirectionType; +import com.loafle.bridge.discoveryport.constant.PortType; +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 11/16/16. + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Application.class) +public class DiscoveryHostRepositoryTest { + + @Autowired + private DiscoveryHostRepository repository; + + Logger l = Logger.getLogger(this.getClass()); + + @Before + public void Before() { + repository.save(new DiscoveryHost(3232235986l,52242420297l)); + } + + @After + public void After() { + repository.deleteAll(); + } + + @Test + public void TestHost() { + DiscoveryHost host = new DiscoveryHost(3232235986l,52242420297l); + repository.save(host); + + DiscoveryHost c = repository.findOne(host.getId()); + + assertEquals(host.getId(), c.getId()); + + l.debug(c.getId()); + l.debug(c.getIpAddress()); + l.debug(c.getMacAddress()); + l.debug(c.getCreateDate()); + l.debug(c.getUpdateDate()); + + } + + @Test + public void TestPortHistory() { + List list = repository.findAll(); + + DiscoveryHost h = list.get(0); + + List p = new ArrayList(); + p.add(new PortScanHistory(h, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + + h.setHistories(p); + + repository.flush(); + + DiscoveryHost ff = repository.findOne(h.getId()); + + System.out.println("ddddd"+ff.getId()); + + } +} \ No newline at end of file