discovery zone
This commit is contained in:
snoop 2016-11-16 18:24:18 +09:00
parent 70abe8569c
commit 8ca70fd7a1
10 changed files with 325 additions and 9 deletions

View File

@ -1,4 +1,4 @@
package com.loafle.bridge.discoveryHistory; package com.loafle.bridge.discoveryhistory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;

View File

@ -1,4 +1,4 @@
package com.loafle.bridge.discoveryHistory; package com.loafle.bridge.discoveryhistory;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;
@ -19,7 +19,7 @@ public class DiscoveryHistory
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false)
private Date endDate; private Date endDate;
@Column(name="RESULT", nullable=false) @Column(nullable=false)
private Boolean result; private Boolean result;
// private null DiscoveryZone; // private null DiscoveryZone;

View File

@ -1,6 +1,4 @@
package com.loafle.bridge.discoveryHistory; package com.loafle.bridge.discoveryhistory;
import com.loafle.bridge.discoveryHistory.DiscoveryHistory;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;

View File

@ -1,9 +1,57 @@
package com.loafle.bridge.discoveryzone; package com.loafle.bridge.discoveryzone;
import javax.persistence.*;
import java.util.List;
/** /**
* Created by root on 16. 11. 15. * Created by root on 16. 11. 15.
*/ */
@Entity
public class DiscoveryZone { public class DiscoveryZone {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(nullable=false)
private long ip;
@Column(nullable=false)
private long cidr;
@OneToMany(mappedBy = "zone")
private List<HostScanHistory> hostScanHistories;
public List<HostScanHistory> getHostScanHistories() {
return hostScanHistories;
}
public void setHostScanHistories(List<HostScanHistory> hostScanHistories) {
this.hostScanHistories = hostScanHistories;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getIp() {
return ip;
}
public void setIp(long ip) {
this.ip = ip;
}
public long getCidr() {
return cidr;
}
public void setCidr(long cidr) {
this.cidr = cidr;
}
} }

View File

@ -1,7 +1,31 @@
package com.loafle.bridge.discoveryzone; package com.loafle.bridge.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 java.util.List;
/** /**
* Created by root on 16. 11. 15. * Created by root on 16. 11. 15.
*/ */
@RestController
public class DiscoveryZoneController { public class DiscoveryZoneController {
@Autowired
DiscoveryZoneRepository discoveryZoneRepository;
@RequestMapping(value = "discoveryZone/{id}", method = RequestMethod.GET)
public DiscoveryZone getDiscoveryZone(@PathVariable(name = "id")long id) throws Exception {
return this.discoveryZoneRepository.findOne(id);
}
@RequestMapping(value = "discoveryZone/", method = RequestMethod.GET)
public List<DiscoveryZone> getDiscoveryZoneList() throws Exception {
return this.discoveryZoneRepository.findAll();
}
} }

View File

@ -1,7 +1,12 @@
package com.loafle.bridge.discoveryzone; package com.loafle.bridge.discoveryzone;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
/** /**
* Created by root on 16. 11. 15. * Created by root on 16. 11. 15.
*/ */
public class DiscoveryZoneRepository { @RepositoryRestResource(collectionResourceRel = "discoveryZone", path = "discoveryZone")
public interface DiscoveryZoneRepository extends JpaRepository<DiscoveryZone,Long> {
} }

View File

@ -0,0 +1,103 @@
package com.loafle.bridge.discoveryzone;
import javax.persistence.*;
import java.util.Date;
/**
* Created by snoop on 16. 11. 16.
*/
@Entity
public class HostScanHistory {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(nullable=false)
private long ip;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, updatable = false)
private Date createDate;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, updatable = false)
private Date sendDate;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, updatable = false)
private Date resultDate;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private ResultType resultType;
@Column
private String description;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private DiscoveryZone zone;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getIp() {
return ip;
}
public void setIp(long ip) {
this.ip = ip;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getSendDate() {
return sendDate;
}
public void setSendDate(Date sendDate) {
this.sendDate = sendDate;
}
public Date getResultDate() {
return resultDate;
}
public void setResultDate(Date resultDate) {
this.resultDate = resultDate;
}
public ResultType getResultType() {
return resultType;
}
public void setResultType(ResultType resultType) {
this.resultType = resultType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public DiscoveryZone getZone() {
return zone;
}
public void setZone(DiscoveryZone zone) {
this.zone = zone;
}
}

View File

@ -0,0 +1,16 @@
package com.loafle.bridge.discoveryzone;
/**
* Created by snoop on 16. 11. 16.
*/
public enum ResultType {
Success("S"),
Timeout("T");
private String stringValue;
ResultType(String string) {stringValue = string;}
@Override
public String toString() {
return stringValue;
}
}

View File

@ -1,8 +1,8 @@
package com.loafle.bridge.discoveryHistory.repository; package com.loafle.bridge.discoveryHistory.repository;
import com.loafle.bridge.Application; import com.loafle.bridge.Application;
import com.loafle.bridge.discoveryHistory.DiscoveryHistory; import com.loafle.bridge.discoveryhistory.DiscoveryHistory;
import com.loafle.bridge.discoveryHistory.DiscoveryHistoryRepository; import com.loafle.bridge.discoveryhistory.DiscoveryHistoryRepository;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -0,0 +1,122 @@
package com.loafle.bridge.discoveryzone;
import com.loafle.bridge.Application;
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.data.jpa.convert.threeten.Jsr310JpaConverters;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.*;
/**
* Created by snoop on 16. 11. 16.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
public class DiscoveryZoneRepositoryTest {
@Autowired
DiscoveryZoneRepository discoveryZoneRepository;
@Before
public void setUp() throws Exception {
DiscoveryZone discoveryZone = new DiscoveryZone();
String cidr = "827452358680";
String ip = "3232235983";
discoveryZone.setCidr(Long.parseLong(cidr));
discoveryZone.setIp(Long.parseLong(ip));
discoveryZoneRepository.save(discoveryZone);
}
@After
public void tearDown() throws Exception {
}
@Test
public void InsertZone() throws Exception {
DiscoveryZone discoveryZone = new DiscoveryZone();
String cidr = "827452358680";
String ip = "3232235983";
discoveryZone.setCidr(Long.parseLong(cidr));
discoveryZone.setIp(Long.parseLong(ip));
discoveryZoneRepository.save(discoveryZone);
}
@Test
@Transactional
public void InsertHostHistory() throws Exception {
DiscoveryZone zone = discoveryZoneRepository.findOne((long)1);
HostScanHistory hostScanHistory = null;
System.out.println("!!!!!!!!!!!!!!!!!!!!!= " + zone.getCidr());
List<HostScanHistory> hostScanHistories = new ArrayList<HostScanHistory>();
String ip = "3232235983";
for( int indexI = 0 ; indexI < 5; ++indexI) {
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(zone);
hostScanHistories.add(hostScanHistory);
}
zone.setHostScanHistories(hostScanHistories);
discoveryZoneRepository.save(zone);
// discoveryZoneRepository.flush();
DiscoveryZone zzzz = discoveryZoneRepository.findOne(zone.getId());
if(zzzz.getHostScanHistories() != null && zzzz.getHostScanHistories().size() > 0) {
System.out.println("zzzz. = " + zzzz.getHostScanHistories().size());
}
else {
System.out.println("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
}
}
}