diff --git a/src/main/java/com/loafle/bridge/discoveryport/constant/DirectionType.java b/src/main/java/com/loafle/bridge/discoveryport/constant/DirectionType.java index 41b071f..eaf430b 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/constant/DirectionType.java +++ b/src/main/java/com/loafle/bridge/discoveryport/constant/DirectionType.java @@ -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; + } } + diff --git a/src/main/java/com/loafle/bridge/discoveryport/constant/PortType.java b/src/main/java/com/loafle/bridge/discoveryport/constant/PortType.java index 1a4b25e..b07ac23 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/constant/PortType.java +++ b/src/main/java/com/loafle/bridge/discoveryport/constant/PortType.java @@ -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; + } } diff --git a/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java b/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java index eb96ecf..b7db3d6 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java +++ b/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java @@ -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); + } } diff --git a/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java b/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java index 536bd67..cb4d574 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java +++ b/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java @@ -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 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 getHistories() { return histories; } @@ -104,4 +73,20 @@ public class DiscoveryPort { public void setHistories(List 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; + } } diff --git a/src/main/java/com/loafle/bridge/discoveryport/entity/ServiceScanHistory.java b/src/main/java/com/loafle/bridge/discoveryport/entity/ServiceScanHistory.java index 0fe5a82..555758f 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/entity/ServiceScanHistory.java +++ b/src/main/java/com/loafle/bridge/discoveryport/entity/ServiceScanHistory.java @@ -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() { diff --git a/src/main/java/hello/JPAConfiguration.java b/src/main/java/hello/JPAConfiguration.java index 11671fe..6003460 100644 --- a/src/main/java/hello/JPAConfiguration.java +++ b/src/main/java/hello/JPAConfiguration.java @@ -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); +// } +//} diff --git a/src/test/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepositoryTest.java index e754f01..01452d5 100644 --- a/src/test/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepositoryTest.java +++ b/src/test/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepositoryTest.java @@ -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 h = new ArrayList(); 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 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()); + + } } } \ No newline at end of file