diff --git a/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveriyHistoryController.java b/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveriyHistoryController.java index d458254..cfbf27c 100644 --- a/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveriyHistoryController.java +++ b/src/main/java/com/loafle/bridge/discoveryhistory/DiscoveriyHistoryController.java @@ -1,10 +1,8 @@ package com.loafle.bridge.discoveryhistory; +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; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -17,6 +15,16 @@ public class DiscoveriyHistoryController { @Autowired DiscoveryHistoryRepository discoveryHistoryRepository; + @RequestMapping(value = "/discoveryHistory", method = RequestMethod.POST) + public void post(@RequestBody DiscoveryHistory history) throws Exception { + + DiscoveryZone zone = history.getZone(); + if (zone != null) { + zone.mappingChildren(); + } + discoveryHistoryRepository.save(history); + } + @RequestMapping(value = "discoveryHistory/{id}", method = RequestMethod.GET) public DiscoveryHistory getDiscoveryHistory(@PathVariable(name = "id")long id) throws Exception { diff --git a/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java b/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java index 4d8859a..4fce7c5 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/DiscoveryHost.java @@ -109,4 +109,22 @@ public class DiscoveryHost { public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } + + public void mappingChildren(DiscoveryZone discoveryZone) { + this.setZone(discoveryZone); + + List portScanHistories = this.getHistories(); + if (portScanHistories != null) { + for (int j =0 ; j < portScanHistories.size() ; ++j) { + portScanHistories.get(j).setHost(this); + } + } + + List ports = this.getPorts(); + if (ports != null) { + for (int j =0 ; j < ports.size() ; ++j) { + ports.get(j).mappingChildren(this); + } + } + } } diff --git a/src/main/java/com/loafle/bridge/discoveryhost/PortScanHistory.java b/src/main/java/com/loafle/bridge/discoveryhost/PortScanHistory.java index d33c744..7435108 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/PortScanHistory.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/PortScanHistory.java @@ -29,7 +29,7 @@ public class PortScanHistory { } @Column(nullable = false) - private short portNumber; + private int portNumber; @Column(nullable = false) @Enumerated(EnumType.STRING) @@ -80,11 +80,11 @@ public class PortScanHistory { this.createDate = createDate; } - public short getPortNumber() { + public int getPortNumber() { return portNumber; } - public void setPortNumber(short portNumber) { + public void setPortNumber(int portNumber) { this.portNumber = portNumber; } diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java index 6b5b0f0..b8ddd55 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java @@ -113,4 +113,21 @@ public class DiscoveryPort { public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } + + public void mappingChildren(DiscoveryHost discoveryHost) { + this.setHost(discoveryHost); + List serviceScanHistories = this.getHistories(); + if (serviceScanHistories != null) { + for (int z = 0 ; z < serviceScanHistories.size() ; ++z) { + serviceScanHistories.get(z).setPort(this); + } + } + + List discoveryServices = this.getServices(); + if (discoveryServices != null) { + for (int z = 0 ; z < discoveryServices.size() ; ++z) { + discoveryServices.get(z).setPort(this); + } + } + } } diff --git a/src/main/java/com/loafle/bridge/discoveryzone/DiscoveryZone.java b/src/main/java/com/loafle/bridge/discoveryzone/DiscoveryZone.java index eaa81c4..02c21ae 100644 --- a/src/main/java/com/loafle/bridge/discoveryzone/DiscoveryZone.java +++ b/src/main/java/com/loafle/bridge/discoveryzone/DiscoveryZone.java @@ -80,4 +80,22 @@ public class DiscoveryZone { public void setDiscovery(DiscoveryHistory discovery) { this.discovery = discovery; } + + + public void mappingChildren() { + + List hostScanHistories = this.getHistories(); + if (hostScanHistories != null) { + for (int i =0 ; i < hostScanHistories.size() ; ++i) { + hostScanHistories.get(i).setZone(this); + } + } + + List hosts = this.getDiscoveryHosts(); + if (hosts != null) { + for (int i =0 ; i < hosts.size() ; ++i) { + hosts.get(i).mappingChildren(this); + } + } + } } diff --git a/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java index a108af0..acb5893 100644 --- a/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java +++ b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java @@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Created by root on 11/16/16. @@ -53,8 +53,8 @@ public class DiscoveryHostRepositoryTest { assertEquals(host.getId(), c.getId()); l.debug(c.getId()); - l.debug(c.getIpAddress()); - l.debug(c.getMacAddress()); + l.debug(c.getIp()); + l.debug(c.getMac()); l.debug(c.getCreateDate()); l.debug(c.getUpdateDate());