From a33b84405f9fbfa3755931ef537019762f0069b4 Mon Sep 17 00:00:00 2001 From: jackdaw Date: Thu, 17 Nov 2016 11:55:25 +0900 Subject: [PATCH 1/3] . --- .../discoveryhistory/DiscoveryHistory.java | 2 +- .../bridge/discoveryhost/DiscoveryHost.java | 6 +- .../DiscoveryPortController.java | 71 ++++++++++++++++--- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveryHistory.java b/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveryHistory.java index a7378bc..ccc2ed6 100644 --- a/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveryHistory.java +++ b/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveryHistory.java @@ -25,7 +25,7 @@ public class DiscoveryHistory private Boolean result; @JoinColumn - @OneToOne + @OneToOne(cascade = CascadeType.ALL) private DiscoveryZone zone; public DiscoveryZone getZone() { diff --git a/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java b/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java index bca84a2..289c176 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java @@ -2,11 +2,8 @@ package com.loafle.bridge.discoveryhost; import com.loafle.bridge.discoveryport.DiscoveryPort; import com.loafle.bridge.discoveryzone.DiscoveryZone; -import org.hibernate.annotations.*; -import org.hibernate.annotations.CascadeType; import javax.persistence.*; -import javax.persistence.Entity; import java.util.Date; import java.util.List; @@ -49,8 +46,7 @@ public class DiscoveryHost { this.histories = histories; } - @OneToMany(mappedBy = "host") - @Cascade(CascadeType.ALL) + @OneToMany(mappedBy = "host",cascade = CascadeType.ALL) private List ports; public List getPorts() { diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java index 9de889d..47523f4 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java @@ -1,7 +1,11 @@ package com.loafle.bridge.discoveryport; +import com.loafle.bridge.discoveryhistory.DiscoveryHistory; +import com.loafle.bridge.discoveryhistory.DiscoveryHistoryRepository; +import com.loafle.bridge.discoveryhost.DiscoveryHost; import com.loafle.bridge.discoveryport.type.PortType; import com.loafle.bridge.discoveryservice.DiscoveryService; +import com.loafle.bridge.discoveryzone.DiscoveryZone; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -10,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.transaction.Transactional; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -22,26 +27,74 @@ public class DiscoveryPortController { @Autowired DiscoveryPortRepository repository; + @Autowired + DiscoveryHistoryRepository repo; + @RequestMapping(value = "/discoveryPort/{id}", method = RequestMethod.GET) public DiscoveryPort get(@PathVariable(value = "id") long id) { return repository.findOne(id); } - @RequestMapping(value ="/index") + @RequestMapping(value ="/jack") @Transactional public void index() { - DiscoveryPort p = new DiscoveryPort(PortType.TCP,(short)12786); +// DiscoveryPort p = new DiscoveryPort(PortType.TCP,(short)12786); +// +// List ss = new ArrayList<>(); +// +// repository.save(p); +// +// ss.add(new DiscoveryService(p,PortType.TCP,"DNS")); +// ss.add(new DiscoveryService(p,PortType.TCP,"TEST")); +// ss.add(new DiscoveryService(p,PortType.TCP,"ABB")); +// +// p.setServices(ss); +// +// repository.save(p); - List ss = new ArrayList<>(); + DiscoveryHistory d = new DiscoveryHistory(); + d.setResult(true); + d.setStartDate(new Date()); + d.setEndDate(new Date()); - repository.save(p); + DiscoveryZone z = new DiscoveryZone(); + String cidr = "827452358680"; + String ip = "3232235983"; + z.setCidr(Long.parseLong(cidr)); + z.setIp(Long.parseLong(ip)); - ss.add(new DiscoveryService(p,PortType.TCP,"DNS")); - ss.add(new DiscoveryService(p,PortType.TCP,"TEST")); - ss.add(new DiscoveryService(p,PortType.TCP,"ABB")); + d.setZone(z); - p.setServices(ss); - repository.save(p); + List hl = new ArrayList<>(); + + //add host + for (int i =0 ; i < 10 ; ++i) { + DiscoveryHost host = new DiscoveryHost(3232235986l,52242420297l); + host.setZone(z); + + List p = new ArrayList(); + host.setPorts(p); + + //add port + for (int j =0 ; j < 10 ; ++j) { + DiscoveryPort port = new DiscoveryPort(host, PortType.TCP, 9840); + p.add(port); + + List ss = new ArrayList<>(); + + ss.add(new DiscoveryService(port,PortType.TCP,"DNS")); + ss.add(new DiscoveryService(port,PortType.TCP,"TEST")); + ss.add(new DiscoveryService(port,PortType.TCP,"ABB")); + + port.setServices(ss); + } + hl.add(host); + } + z.setDiscoveryHosts(hl); + + repo.save(d); + + DiscoveryHistory find = repo.findOne(d.getId()); } } From 8c656cb4d8c2f3cd77fb3314bdbc42e525f3463d Mon Sep 17 00:00:00 2001 From: jackdaw Date: Thu, 17 Nov 2016 13:54:36 +0900 Subject: [PATCH 2/3] .test insert controller method --- .../discoveryport/DiscoveryPortController.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java index 47523f4..08ed111 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java @@ -6,6 +6,8 @@ import com.loafle.bridge.discoveryhost.DiscoveryHost; import com.loafle.bridge.discoveryport.type.PortType; import com.loafle.bridge.discoveryservice.DiscoveryService; import com.loafle.bridge.discoveryzone.DiscoveryZone; +import com.loafle.bridge.discoveryzone.HostScanHistory; +import com.loafle.bridge.discoveryzone.ResultType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -64,7 +66,21 @@ public class DiscoveryPortController { z.setIp(Long.parseLong(ip)); d.setZone(z); + // host scan histories + List hostScanHistories = new ArrayList(); + for( int indexI = 0 ; indexI < 5; ++indexI) { + HostScanHistory hostScanHistory = new HostScanHistory(); + hostScanHistory.setIp(Long.parseLong(ip)); + hostScanHistory.setCreateDate(new Date()); + hostScanHistory.setSendDate(new Date()); + hostScanHistory.setResultDate(new Date()); + hostScanHistory.setDescription("hgihihihih"); + hostScanHistory.setResultType(ResultType.Success); + hostScanHistory.setZone(z); + hostScanHistories.add(hostScanHistory); + } + z.setHostScanHistories(hostScanHistories); List hl = new ArrayList<>(); From 56fdb5832e9d9d401f301f3cb338c774fcbf588b Mon Sep 17 00:00:00 2001 From: geek Date: Thu, 17 Nov 2016 14:53:19 +0900 Subject: [PATCH 3/3] ip property name change --- .../bridge/discoveryhost/DiscoveryHost.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java b/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java index 289c176..4d8859a 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java @@ -17,11 +17,11 @@ public class DiscoveryHost { @GeneratedValue(strategy = GenerationType.AUTO) private long id; - @Column(name = "IP_ADDRESS",nullable = false) - private long ipAddress; + @Column(name = "IP",nullable = false) + private long ip; - @Column(name = "MAC_ADDRESS",nullable = false) - private long macAddress; + @Column(name = "MAC",nullable = false) + private long mac; @ManyToOne @JoinColumn(name = "ZONE_ID", nullable = false) @@ -66,8 +66,8 @@ public class DiscoveryHost { public DiscoveryHost(){} public DiscoveryHost(long ip, long mac){ - this.ipAddress = ip; - this.macAddress = mac; + this.ip = ip; + this.mac = mac; } public long getId() { @@ -78,24 +78,22 @@ public class DiscoveryHost { this.id = id; } - public long getIpAddress() { - return ipAddress; + public long getIp() { + return ip; } - public void setIpAddress(long ipAddress) { - this.ipAddress = ipAddress; + public void setIp(long ip) { + this.ip = ip; } - public long getMacAddress() { - return macAddress; + public long getMac() { + return mac; } - public void setMacAddress(long macAddress) { - this.macAddress = macAddress; + public void setMac(long mac) { + this.mac = mac; } - - public Date getCreateDate() { return createDate; }