mapping method
This commit is contained in:
parent
51331fd9b6
commit
e985f0921e
|
@ -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 {
|
||||
|
|
|
@ -109,4 +109,22 @@ public class DiscoveryHost {
|
|||
public void setUpdateDate(Date updateDate) {
|
||||
this.updateDate = updateDate;
|
||||
}
|
||||
|
||||
public void mappingChildren(DiscoveryZone discoveryZone) {
|
||||
this.setZone(discoveryZone);
|
||||
|
||||
List<PortScanHistory> portScanHistories = this.getHistories();
|
||||
if (portScanHistories != null) {
|
||||
for (int j =0 ; j < portScanHistories.size() ; ++j) {
|
||||
portScanHistories.get(j).setHost(this);
|
||||
}
|
||||
}
|
||||
|
||||
List<DiscoveryPort> ports = this.getPorts();
|
||||
if (ports != null) {
|
||||
for (int j =0 ; j < ports.size() ; ++j) {
|
||||
ports.get(j).mappingChildren(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,4 +113,21 @@ public class DiscoveryPort {
|
|||
public void setUpdateDate(Date updateDate) {
|
||||
this.updateDate = updateDate;
|
||||
}
|
||||
|
||||
public void mappingChildren(DiscoveryHost discoveryHost) {
|
||||
this.setHost(discoveryHost);
|
||||
List<ServiceScanHistory> serviceScanHistories = this.getHistories();
|
||||
if (serviceScanHistories != null) {
|
||||
for (int z = 0 ; z < serviceScanHistories.size() ; ++z) {
|
||||
serviceScanHistories.get(z).setPort(this);
|
||||
}
|
||||
}
|
||||
|
||||
List<DiscoveryService> discoveryServices = this.getServices();
|
||||
if (discoveryServices != null) {
|
||||
for (int z = 0 ; z < discoveryServices.size() ; ++z) {
|
||||
discoveryServices.get(z).setPort(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,4 +80,22 @@ public class DiscoveryZone {
|
|||
public void setDiscovery(DiscoveryHistory discovery) {
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
|
||||
public void mappingChildren() {
|
||||
|
||||
List<HostScanHistory> hostScanHistories = this.getHistories();
|
||||
if (hostScanHistories != null) {
|
||||
for (int i =0 ; i < hostScanHistories.size() ; ++i) {
|
||||
hostScanHistories.get(i).setZone(this);
|
||||
}
|
||||
}
|
||||
|
||||
List<DiscoveryHost> hosts = this.getDiscoveryHosts();
|
||||
if (hosts != null) {
|
||||
for (int i =0 ; i < hosts.size() ; ++i) {
|
||||
hosts.get(i).mappingChildren(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user