This commit is contained in:
jackdaw 2016-11-16 12:23:21 +09:00
parent ea914f8ce7
commit 04da526b05
7 changed files with 183 additions and 16 deletions

View File

@ -6,7 +6,8 @@ package com.loafle.bridge.discoveryport.constant;
public enum PortType {
TCP("TCP"),
UDP("UDP");
UDP("UDP"),
TLS("TLS");
private String stringValue;
PortType(String string) {stringValue = string;}

View File

@ -10,28 +10,44 @@ import java.util.List;
public class DiscoveryPort {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
// @ManyToOne
// @JoinColumn(name = "HOST_ID", nullable = false)
// private DiscoveryHost host;
@Column(name = "PORT_TYPE",nullable = false)
//public DiscoveryHost getHost() {
// return host;
//}
//
// public void setHost(DiscoveryHost host) {
// this.host = host;
// }
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private PortType portType;
@Column(name = "PORT_NUMBER",nullable = false)
@Column(nullable = false)
private short portNumber;
@OneToMany(mappedBy = "port" , fetch = FetchType.LAZY)
@OneToMany(mappedBy = "port")
private List<ServiceScanHistory> histories;
@Column(name = "CREATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
// @OneToMany(mappedBy = "port")
// private List<DiscoveryService> services;
//
// public List<DiscoveryService> getServices() {
// return services;
// }
//
// public void setServices(List<DiscoveryService> services) {
// this.services = services;
// }
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
private Date createDate;
@Column(name = "UPDATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false)
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false)
private Date updateDate;
@ -83,6 +99,9 @@ public class DiscoveryPort {
}
public Date getUpdateDate() {
if (this.updateDate == null) {
this.updateDate = new Date();
}
return updateDate;
}

View File

@ -13,28 +13,38 @@ import java.util.Date;
public class ServiceScanHistory {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PORT_ID")
@JoinColumn
private DiscoveryPort port;
@Column(name = "SERVICE_NAME", nullable = false)
@Column(nullable = false)
private String serviceName;
@Column(name = "DIRECTION", nullable = false)
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private DirectionType direction;
@Column(name = "CREATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
private Date createDate;
@Lob
@Column(name = "PACKET", nullable = false)
@Column(nullable = false)
private byte[] packet;
@Column
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ServiceScanHistory() {}
public ServiceScanHistory(DiscoveryPort port, String serviceName, DirectionType direction, byte[] packet, Date createAt) {

View File

@ -1,7 +1,23 @@
package com.loafle.bridge.discoveryservice.controller;
import com.loafle.bridge.discoveryservice.entity.DiscoveryService;
import com.loafle.bridge.discoveryservice.repository.DiscoveryServiceRepository;
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;
/**
* Created by root on 16. 11. 15.
*/
@RestController
public class DiscoveryServiceController {
@Autowired
DiscoveryServiceRepository repository;
@RequestMapping(value = "/discoveryService/{id}", method = RequestMethod.GET)
public DiscoveryService get(@PathVariable(value = "id") long id) {
return repository.findOne(id);
}
}

View File

@ -1,7 +1,75 @@
package com.loafle.bridge.discoveryservice.entity;
import com.loafle.bridge.discoveryport.constant.PortType;
import javax.persistence.*;
import java.util.Date;
/**
* Created by root on 16. 11. 15.
*/
@Entity
public class DiscoveryService {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
// @ManyToOne
// @JoinColumn(nullable = false)
// private DiscoveryPort port;
// public DiscoveryPort getPort() {
// return port;
// }
//
// public void setPort(DiscoveryPort port) {
// this.port = port;
// }
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private PortType portType;
@Column(nullable = false)
private String serviceName;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
private Date createDate;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false)
private Date updateDate;
public DiscoveryService() {}
public DiscoveryService(PortType t, String serviceName) {
this.portType = t;
this.serviceName = serviceName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getUpdateDate() {
if (this.updateDate == null) {
this.updateDate = new Date();
}
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
}

View File

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

View File

@ -0,0 +1,48 @@
package com.loafle.bridge.discoveryservice.repository;
import com.loafle.bridge.Application;
import com.loafle.bridge.discoveryport.constant.PortType;
import com.loafle.bridge.discoveryservice.entity.DiscoveryService;
import org.apache.log4j.Logger;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Created by root on 16. 11. 16.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
public class DiscoveryServiceRepositoryTest {
@Autowired
private DiscoveryServiceRepository repo;
private Logger log = Logger.getLogger(this.getClass());
@Before
public void Before() {
repo.save(new DiscoveryService(PortType.TLS,"HTTP"));
repo.save(new DiscoveryService(PortType.TCP,"WMI"));
repo.save(new DiscoveryService(PortType.UDP,"DNS"));
}
@After
public void After() {
repo.deleteAll();
}
@Test
public void TestBefore() {
List<DiscoveryService> l = repo.findAll();
assertEquals(3, l.size());
}
}