restored functionality with envoy-common (#32)
This commit is contained in:
parent
1302967fc4
commit
cb8750bdbb
@ -68,14 +68,14 @@ public class Message {
|
|||||||
*/
|
*/
|
||||||
public Message(envoy.data.Message message) {
|
public Message(envoy.data.Message message) {
|
||||||
PersistenceManager persMan = PersistenceManager.getInstance();
|
PersistenceManager persMan = PersistenceManager.getInstance();
|
||||||
id = message.getId();
|
id = message.getID();
|
||||||
status = message.getStatus();
|
status = message.getStatus();
|
||||||
text = message.getText();
|
text = message.getText();
|
||||||
creationDate = message.getCreationDate();
|
creationDate = message.getCreationDate();
|
||||||
receivedDate = message.getReceivedDate();
|
receivedDate = message.getReceivedDate();
|
||||||
readDate = message.getReadDate();
|
readDate = message.getReadDate();
|
||||||
sender = persMan.getUserById(message.getSenderId());
|
sender = persMan.getUserById(message.getSenderID());
|
||||||
recipient = persMan.getUserById(message.getRecipientId());
|
recipient = persMan.getUserById(message.getRecipientID());
|
||||||
forwarded = message.isForwarded();
|
forwarded = message.isForwarded();
|
||||||
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
|
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class serves as a way to let Hibernate communicate with the server
|
* This class serves as a way to let Hibernate communicate with the server
|
||||||
* without bringing the dependency of JPA/Hibernate into the client.<br>
|
* without bringing the dependency of JPA/Hibernate into the client.<br>
|
||||||
@ -60,7 +59,7 @@ public class User {
|
|||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public User(envoy.data.User user) {
|
public User(envoy.data.User user) {
|
||||||
id = user.getId();
|
id = user.getID();
|
||||||
name = user.getName();
|
name = user.getName();
|
||||||
status = user.getStatus();
|
status = user.getStatus();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class ContactOperationProcessor implements ObjectProcessor<ContactOperati
|
|||||||
switch (evt.getOperationType()) {
|
switch (evt.getOperationType()) {
|
||||||
case ADD:
|
case ADD:
|
||||||
final long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId);
|
final long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId);
|
||||||
final long contactId = evt.get().getId();
|
final long contactId = evt.get().getID();
|
||||||
|
|
||||||
System.out.printf("Adding user %s to the contact list of user %d.%n", evt.get(), userId);
|
System.out.printf("Adding user %s to the contact list of user %d.%n", evt.get(), userId);
|
||||||
PersistenceManager.getInstance().addContact(userId, contactId);
|
PersistenceManager.getInstance().addContact(userId, contactId);
|
||||||
|
@ -2,8 +2,8 @@ package envoy.server.processors;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import envoy.data.IdGenerator;
|
import envoy.data.IDGenerator;
|
||||||
import envoy.event.IdGeneratorRequest;
|
import envoy.event.IDGeneratorRequest;
|
||||||
import envoy.server.data.ConfigItem;
|
import envoy.server.data.ConfigItem;
|
||||||
import envoy.server.data.PersistenceManager;
|
import envoy.server.data.PersistenceManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
@ -16,19 +16,19 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
* @author Kai S. K. Engelbart
|
* @author Kai S. K. Engelbart
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public class IDGeneratorRequestProcessor implements ObjectProcessor<IdGeneratorRequest> {
|
public class IDGeneratorRequestProcessor implements ObjectProcessor<IDGeneratorRequest> {
|
||||||
|
|
||||||
private static final long ID_RANGE = 200;
|
private static final long ID_RANGE = 200;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<IdGeneratorRequest> getInputClass() { return IdGeneratorRequest.class; }
|
public Class<IDGeneratorRequest> getInputClass() { return IDGeneratorRequest.class; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(IdGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(IDGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
System.out.println("Received id generation request.");
|
System.out.println("Received id generation request.");
|
||||||
|
|
||||||
ConfigItem currentId = PersistenceManager.getInstance().getConfigItemById("currentMessageId");
|
ConfigItem currentId = PersistenceManager.getInstance().getConfigItemById("currentMessageId");
|
||||||
IdGenerator generator = new IdGenerator(Integer.parseInt(currentId.getValue()), ID_RANGE);
|
IDGenerator generator = new IDGenerator(Integer.parseInt(currentId.getValue()), ID_RANGE);
|
||||||
currentId.setValue(String.valueOf(Integer.parseInt(currentId.getValue()) + ID_RANGE));
|
currentId.setValue(String.valueOf(Integer.parseInt(currentId.getValue()) + ID_RANGE));
|
||||||
PersistenceManager.getInstance().updateConfigItem(currentId);
|
PersistenceManager.getInstance().updateConfigItem(currentId);
|
||||||
|
|
||||||
|
@ -26,21 +26,21 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
|||||||
|
|
||||||
ConnectionManager connectionManager = ConnectionManager.getInstance();
|
ConnectionManager connectionManager = ConnectionManager.getInstance();
|
||||||
message.nextStatus();
|
message.nextStatus();
|
||||||
if (connectionManager.isOnline(message.getRecipientId())) try {
|
if (connectionManager.isOnline(message.getRecipientID())) try {
|
||||||
// If recipient is online, send the message directly
|
// If recipient is online, send the message directly
|
||||||
writeProxy.write(connectionManager.getSocketId(message.getRecipientId()), message);
|
writeProxy.write(connectionManager.getSocketId(message.getRecipientID()), message);
|
||||||
|
|
||||||
// Update the message status to RECEIVED
|
// Update the message status to RECEIVED
|
||||||
message.setReceivedDate(new Date());
|
message.setReceivedDate(new Date());
|
||||||
message.nextStatus();
|
message.nextStatus();
|
||||||
writeProxy.write(socketId, new MessageStatusChangeEvent(message));
|
writeProxy.write(socketId, new MessageStatusChangeEvent(message));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Recipient online. Failed to send message" + message.getId());
|
System.err.println("Recipient online. Failed to send message" + message.getID());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
|
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<Message> getInputClass() { return Message.class; }
|
public Class<Message> getInputClass() { return Message.class; }
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
|
|||||||
// Any other status than READ is not supposed to be sent to the server
|
// Any other status than READ is not supposed to be sent to the server
|
||||||
if (input.get() != MessageStatus.READ) throw new IOException(new EnvoyException("Message " + input + " has an invalid status"));
|
if (input.get() != MessageStatus.READ) throw new IOException(new EnvoyException("Message " + input + " has an invalid status"));
|
||||||
|
|
||||||
envoy.server.data.Message msg = persistenceManager.getMessageById(input.getId());
|
envoy.server.data.Message msg = persistenceManager.getMessageById(input.getID());
|
||||||
msg.setStatus(input.get());
|
msg.setStatus(input.get());
|
||||||
msg.setReadDate(input.getDate());
|
msg.setReadDate(input.getDate());
|
||||||
persistenceManager.updateMessage(msg);
|
persistenceManager.updateMessage(msg);
|
||||||
|
@ -30,7 +30,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
|
|||||||
@Override
|
@Override
|
||||||
public void process(UserStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(UserStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
// new status should not equal old status
|
// new status should not equal old status
|
||||||
if (input.get().equals(persistenceManager.getUserById(input.getId()).getStatus())) {
|
if (input.get().equals(persistenceManager.getUserById(input.getID()).getStatus())) {
|
||||||
System.out.println("Received an unnecessary UserStatusChangeEvent");
|
System.out.println("Received an unnecessary UserStatusChangeEvent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
|
|||||||
* @param evt the {@link UserStatusChangeEvent}
|
* @param evt the {@link UserStatusChangeEvent}
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public static void updateUserStatus(UserStatusChangeEvent evt) { updateUserStatus(persistenceManager.getUserById(evt.getId())); }
|
public static void updateUserStatus(UserStatusChangeEvent evt) { updateUserStatus(persistenceManager.getUserById(evt.getID())); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* notifies active contacts of this {@link User} that his {@link UserStatus} has
|
* notifies active contacts of this {@link User} that his {@link UserStatus} has
|
||||||
@ -75,7 +75,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
|
|||||||
if (connectionManager.isOnline(contact.getId())) writeProxy.write(connectionManager.getSocketId(contact.getId()), evt);
|
if (connectionManager.isOnline(contact.getId())) writeProxy.write(connectionManager.getSocketId(contact.getId()), evt);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.err.println("Could not notify online contacts of user " + evt.getId() + " that his status has been changed");
|
System.err.println("Could not notify online contacts of user " + evt.getID() + " that his status has been changed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user