improved JSON format
This commit is contained in:
parent
592d1145eb
commit
cde2a37afe
@ -2,7 +2,6 @@ package ch.dissem.bitmessage.server;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.BitmessageContext;
|
import ch.dissem.bitmessage.BitmessageContext;
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
|
||||||
import ch.dissem.bitmessage.networking.DefaultNetworkHandler;
|
import ch.dissem.bitmessage.networking.DefaultNetworkHandler;
|
||||||
import ch.dissem.bitmessage.ports.MemoryNodeRegistry;
|
import ch.dissem.bitmessage.ports.MemoryNodeRegistry;
|
||||||
import ch.dissem.bitmessage.repository.JdbcAddressRepository;
|
import ch.dissem.bitmessage.repository.JdbcAddressRepository;
|
||||||
@ -10,14 +9,13 @@ import ch.dissem.bitmessage.repository.JdbcConfig;
|
|||||||
import ch.dissem.bitmessage.repository.JdbcInventory;
|
import ch.dissem.bitmessage.repository.JdbcInventory;
|
||||||
import ch.dissem.bitmessage.repository.JdbcMessageRepository;
|
import ch.dissem.bitmessage.repository.JdbcMessageRepository;
|
||||||
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
||||||
|
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
public class JabitServerApplication {
|
public class JabitServerApplication {
|
||||||
@ -29,7 +27,7 @@ public class JabitServerApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("read/{broadcastAddress}")
|
@RequestMapping("read/{broadcastAddress}")
|
||||||
public List<Plaintext> read(@PathVariable String broadcastAddress) {
|
public Broadcasts read(@PathVariable String broadcastAddress) {
|
||||||
BitmessageAddress broadcaster = ctx.addresses().getAddress(broadcastAddress);
|
BitmessageAddress broadcaster = ctx.addresses().getAddress(broadcastAddress);
|
||||||
if (broadcaster == null) {
|
if (broadcaster == null) {
|
||||||
broadcaster = new BitmessageAddress(broadcastAddress);
|
broadcaster = new BitmessageAddress(broadcastAddress);
|
||||||
@ -37,7 +35,7 @@ public class JabitServerApplication {
|
|||||||
if (!broadcaster.isSubscribed()) {
|
if (!broadcaster.isSubscribed()) {
|
||||||
ctx.addSubscribtion(broadcaster);
|
ctx.addSubscribtion(broadcaster);
|
||||||
}
|
}
|
||||||
return ctx.messages().findMessages(broadcaster);
|
return new Broadcasts(broadcaster, ctx.messages().findMessages(broadcaster));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JabitServerApplication() {
|
public JabitServerApplication() {
|
||||||
|
@ -1,7 +1,31 @@
|
|||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities;
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by chrigu on 30.09.15.
|
* Created by chrigu on 30.09.15.
|
||||||
*/
|
*/
|
||||||
public class Broadcasts {
|
public class Broadcasts {
|
||||||
|
private final Sender sender;
|
||||||
|
private final Message[] messages;
|
||||||
|
|
||||||
|
public Broadcasts(BitmessageAddress sender, Collection<Plaintext> messages) {
|
||||||
|
this.sender = new Sender(sender);
|
||||||
|
this.messages = new Message[messages.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (Plaintext msg : messages) {
|
||||||
|
this.messages[i] = new Message(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sender getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message[] getMessages() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,43 @@
|
|||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities;
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by chrigu on 30.09.15.
|
* Created by chrigu on 30.09.15.
|
||||||
*/
|
*/
|
||||||
public class Message {
|
public class Message {
|
||||||
|
private Object id;
|
||||||
|
private String subject;
|
||||||
|
private String body;
|
||||||
|
|
||||||
|
public Message(){}
|
||||||
|
public Message(Plaintext plaintext) {
|
||||||
|
this.id = plaintext.getId();
|
||||||
|
this.subject = plaintext.getSubject();
|
||||||
|
this.body = plaintext.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Object id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubject(String subject) {
|
||||||
|
this.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubject() {
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBody(String body) {
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,24 @@
|
|||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities;
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by chrigu on 30.09.15.
|
* Created by chrigu on 30.09.15.
|
||||||
*/
|
*/
|
||||||
public class Sender {
|
public class Sender {
|
||||||
|
private final String address;
|
||||||
|
private final String alias;
|
||||||
|
|
||||||
|
public Sender(BitmessageAddress address) {
|
||||||
|
this.address = address.getAddress();
|
||||||
|
this.alias = address.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAlias() {
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user