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..0eaa4bd --- /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.type.DirectionType; +import com.loafle.bridge.discoveryport.type.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/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java index a0033f4..02e9a53 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java @@ -1,7 +1,8 @@ package com.loafle.bridge.discoveryport; +import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; import com.loafle.bridge.discoveryport.type.PortType; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import com.loafle.bridge.discoveryservice.DiscoveryService; import javax.persistence.*; import java.util.Date; @@ -14,16 +15,16 @@ public class DiscoveryPort { @GeneratedValue(strategy = GenerationType.AUTO) private long id; -// @ManyToOne -// @JoinColumn(name = "HOST_ID", nullable = false) -// private DiscoveryHost host; -//public DiscoveryHost getHost() { -// return host; -//} -// -// public void setHost(DiscoveryHost host) { -// this.host = host; -// } + @ManyToOne + @JoinColumn(name = "HOST_ID", nullable = false) + private DiscoveryHost host; + public DiscoveryHost getHost() { + return host; + } + + public void setHost(DiscoveryHost host) { + this.host = host; + } @Column(nullable = false) @Enumerated(EnumType.STRING) private PortType portType; @@ -51,7 +52,6 @@ public class DiscoveryPort { @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) private Date updateDate; - public DiscoveryPort() {} public DiscoveryPort(PortType type, short portNumber) { diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java index 7cbff39..9de889d 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java @@ -1,7 +1,7 @@ package com.loafle.bridge.discoveryport; import com.loafle.bridge.discoveryport.type.PortType; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import com.loafle.bridge.discoveryservice.DiscoveryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java b/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java index 57b61a0..fc6554d 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java +++ b/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java @@ -16,7 +16,8 @@ public class ServiceScanHistory { @GeneratedValue(strategy = GenerationType.AUTO) private long id; - @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + @Column(nullable = false, insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) private Date createDate; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryService.java similarity index 97% rename from src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java rename to src/main/java/com/loafle/bridge/discoveryservice/DiscoveryService.java index b7c65ea..a110544 100644 --- a/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java +++ b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryService.java @@ -1,4 +1,4 @@ -package com.loafle.bridge.discoveryservice.entity; +package com.loafle.bridge.discoveryservice; import com.loafle.bridge.discoveryport.DiscoveryPort; import com.loafle.bridge.discoveryport.type.PortType; diff --git a/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceController.java similarity index 76% rename from src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java rename to src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceController.java index ccee053..90b6bac 100644 --- a/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java +++ b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceController.java @@ -1,7 +1,5 @@ -package com.loafle.bridge.discoveryservice.controller; +package com.loafle.bridge.discoveryservice; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; -import com.loafle.bridge.discoveryservice.repository.DiscoveryServiceRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceRepository.java similarity index 75% rename from src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java rename to src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceRepository.java index fb1427b..6b1eb2e 100644 --- a/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java +++ b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceRepository.java @@ -1,6 +1,5 @@ -package com.loafle.bridge.discoveryservice.repository; +package com.loafle.bridge.discoveryservice; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; 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..624c498 --- /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.type.DirectionType; +import com.loafle.bridge.discoveryport.type.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 diff --git a/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java index e306abb..2c0b404 100644 --- a/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java +++ b/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java @@ -4,7 +4,7 @@ import com.loafle.bridge.Application; import com.loafle.bridge.discoveryport.DiscoveryPort; import com.loafle.bridge.discoveryport.DiscoveryPortRepository; import com.loafle.bridge.discoveryport.type.PortType; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import com.loafle.bridge.discoveryservice.DiscoveryService; import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before;