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