This commit is contained in:
jackdaw 2016-11-15 18:56:24 +09:00
parent 1db6a3ae7b
commit d6e3450e2b
7 changed files with 108 additions and 89 deletions

View File

@ -4,6 +4,14 @@ package com.loafle.bridge.discoveryport.constant;
* Created by root on 16. 11. 15.
*/
public enum DirectionType {
S, // Send
R // Recv
Send("S"),
Recv("R");
private String stringValue;
DirectionType(String string) {stringValue = string;}
@Override
public String toString() {
return stringValue;
}
}

View File

@ -5,5 +5,14 @@ package com.loafle.bridge.discoveryport.constant;
*/
public enum PortType {
TCP,UDP
TCP("TCP"),
UDP("UDP");
private String stringValue;
PortType(String string) {stringValue = string;}
@Override
public String toString() {
return stringValue;
}
}

View File

@ -1,7 +1,25 @@
package com.loafle.bridge.discoveryport.controller;
import com.loafle.bridge.discoveryport.entity.DiscoveryPort;
import com.loafle.bridge.discoveryport.repository.DiscoveryPortRepository;
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 DiscoveryPortController {
@Autowired
DiscoveryPortRepository repository;
@RequestMapping(value = "/discoveryPort/{id}", method = RequestMethod.GET)
public DiscoveryPort get(@PathVariable(value = "id") long id) {
return repository.findOne(id);
}
}

View File

@ -1,6 +1,5 @@
package com.loafle.bridge.discoveryport.entity;
import com.loafle.bridge.discoveryhost.entity.DiscoveryHost;
import com.loafle.bridge.discoveryport.constant.PortType;
import javax.persistence.*;
@ -15,13 +14,13 @@ public class DiscoveryPort {
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ManyToOne
@JoinColumn(name = "HOST_ID", nullable = false)
private DiscoveryHost host;
// @ManyToOne
// @JoinColumn(name = "HOST_ID", nullable = false)
// private DiscoveryHost host;
@Column(name = "PORT_TYPE",nullable = false)
@Enumerated(EnumType.STRING)
private PortType type;
private PortType portType;
@Column(name = "PORT_NUMBER",nullable = false)
private short portNumber;
@ -29,32 +28,18 @@ public class DiscoveryPort {
@OneToMany(mappedBy = "port" , fetch = FetchType.LAZY)
private List<ServiceScanHistory> histories;
@Column(name = "CREATE_AT",nullable = false,updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date createAt;
@Column(name = "CREATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
private Date createDate;
@Column(name = "UPDATE_AT",nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date updateAt;
@Column(name = "UPDATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false)
private Date updateDate;
public DiscoveryPort() {}
public DiscoveryHost getHost() {
return host;
}
public void setHost(DiscoveryHost host) {
this.host = host;
}
public DiscoveryPort(PortType type, DiscoveryHost host, short port, Date createAt, Date updateAt) {
this.host = host;
this.type = type;
this.portNumber = port;
this.createAt = createAt;
this.updateAt = updateAt;
public DiscoveryPort(PortType type, short portNumber) {
this.portType = type;
this.portNumber = portNumber;
}
public long getId() {
@ -65,12 +50,12 @@ public class DiscoveryPort {
this.id = id;
}
public PortType getType() {
return type;
public PortType getPortType() {
return portType;
}
public void setType(PortType type) {
this.type = type;
public void setPortType(PortType portType) {
this.portType = portType;
}
public short getPortNumber() {
@ -81,22 +66,6 @@ public class DiscoveryPort {
this.portNumber = portNumber;
}
public Date getCreateAt() {
return createAt;
}
public void setCreateAt(Date createAt) {
this.createAt = createAt;
}
public Date getUpdateAt() {
return updateAt;
}
public void setUpdateAt(Date updateAt) {
this.updateAt = updateAt;
}
public List<ServiceScanHistory> getHistories() {
return histories;
}
@ -104,4 +73,20 @@ public class DiscoveryPort {
public void setHistories(List<ServiceScanHistory> histories) {
this.histories = histories;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
}

View File

@ -28,9 +28,8 @@ public class ServiceScanHistory {
@Enumerated(EnumType.STRING)
private DirectionType direction;
@Column(name = "CREATE_AT",nullable = false,updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date createAt;
@Column(name = "CREATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false)
private Date createDate;
@Lob
@Column(name = "PACKET", nullable = false)
@ -43,7 +42,6 @@ public class ServiceScanHistory {
this.serviceName = serviceName;
this.direction = direction;
this.packet = packet;
this.createAt = createAt;
}
public long getId() {
@ -78,12 +76,12 @@ public class ServiceScanHistory {
this.direction = direction;
}
public Date getCreateAt() {
return createAt;
public Date getCreateDate() {
return createDate;
}
public void setCreateAt(Date createAt) {
this.createAt = createAt;
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public byte[] getPacket() {

View File

@ -1,23 +1,17 @@
package hello;
import hello.entity.Member;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
/**
* Created by jackdaw on 16. 11. 11.
*/
@Configuration
public class JPAConfiguration extends RepositoryRestMvcConfiguration {
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(Member.class);
//config.setDefaultMediaType(MediaType.APPLICATION_JSON);
//config.useHalAsDefaultJsonMediaType(false);
}
}
//@Configuration
//public class JPAConfiguration extends RepositoryRestMvcConfiguration {
//
// @Override
// protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
// config.exposeIdsFor(Member.class);
// //config.setDefaultMediaType(MediaType.APPLICATION_JSON);
// //config.useHalAsDefaultJsonMediaType(false);
// }
//}

View File

@ -39,11 +39,11 @@ public class DiscoveryPortRepositoryTest {
@Before
public void Before() {
repo.save(new DiscoveryPort(PortType.TCP,null ,(short)1, new Date(), new Date()));
repo.save(new DiscoveryPort(PortType.UDP,null , (short)2, new Date(), new Date()));
repo.save(new DiscoveryPort(PortType.TCP,null , (short)3, new Date(), new Date()));
repo.save(new DiscoveryPort(PortType.UDP,null , (short)4, new Date(), new Date()));
repo.save(new DiscoveryPort(PortType.TCP,null , (short)5, new Date(), new Date()));
repo.save(new DiscoveryPort(PortType.TCP,(short)1));
repo.save(new DiscoveryPort(PortType.UDP, (short)2));
repo.save(new DiscoveryPort(PortType.TCP, (short)3));
repo.save(new DiscoveryPort(PortType.UDP, (short)4));
repo.save(new DiscoveryPort(PortType.TCP, (short)5));
}
@After
@ -52,19 +52,20 @@ public class DiscoveryPortRepositoryTest {
}
@Test
@Transactional
public void TestInsertPort() {
DiscoveryPort p = new DiscoveryPort(PortType.TCP, null ,(short)1, new Date(), new Date());
DiscoveryPort p = new DiscoveryPort(PortType.TCP, (short)1);
repo.save(p);
DiscoveryPort compare = repo.findOne(p.getId());
assertEquals(p.getId(),compare.getId());
l.debug(p.getId());
l.debug(p.getType());
l.debug(p.getPortNumber());
l.debug(p.getCreateAt());
l.debug(p.getUpdateAt());
l.debug("!!!!!!!" + compare.getId());
l.debug("!!!!!!!" + compare.getPortType());
l.debug("!!!!!!!" + compare.getPortNumber());
l.debug("!!!!!!!" + compare.getCreateDate());
l.debug("!!!!!!!" + compare.getUpdateDate());
}
@ -77,11 +78,11 @@ public class DiscoveryPortRepositoryTest {
List<ServiceScanHistory> h = new ArrayList<ServiceScanHistory>();
byte [] a = {10,20,30,40,50};
h.add(new ServiceScanHistory(p,"testservice1", DirectionType.S,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice2", DirectionType.R,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice3", DirectionType.S,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice4", DirectionType.R,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice5", DirectionType.S,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice1", DirectionType.Send,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice2", DirectionType.Recv,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice3", DirectionType.Send,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice4", DirectionType.Recv,a, new Date()));
h.add(new ServiceScanHistory(p,"testservice5", DirectionType.Send,a, new Date()));
p.setHistories(h);
repo.save(p);
@ -93,5 +94,11 @@ public class DiscoveryPortRepositoryTest {
List<ServiceScanHistory> l2 = find.getHistories();
assertEquals(l1.size(), l2.size());
for (int i =0 ; i < l2.size() ; ++i) {
ServiceScanHistory s = l2.get(i);
l.debug(s.getDirection());
}
}
}