restored functionality with envoy-common (#32)

This commit is contained in:
delvh 2020-03-26 16:54:12 +01:00 committed by GitHub
parent eba02422e3
commit 6d8294a96a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 20 deletions

View File

@ -68,14 +68,14 @@ public class Message {
*/
public Message(envoy.data.Message message) {
PersistenceManager persMan = PersistenceManager.getInstance();
id = message.getId();
id = message.getID();
status = message.getStatus();
text = message.getText();
creationDate = message.getCreationDate();
receivedDate = message.getReceivedDate();
readDate = message.getReadDate();
sender = persMan.getUserById(message.getSenderId());
recipient = persMan.getUserById(message.getRecipientId());
sender = persMan.getUserById(message.getSenderID());
recipient = persMan.getUserById(message.getRecipientID());
forwarded = message.isForwarded();
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import javax.persistence.*;
/**
* This class serves as a way to let Hibernate communicate with the server
* 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
*/
public User(envoy.data.User user) {
id = user.getId();
id = user.getID();
name = user.getName();
status = user.getStatus();
}

View File

@ -26,7 +26,7 @@ public class ContactOperationProcessor implements ObjectProcessor<ContactOperati
switch (evt.getOperationType()) {
case ADD:
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);
PersistenceManager.getInstance().addContact(userId, contactId);

View File

@ -2,8 +2,8 @@ package envoy.server.processors;
import java.io.IOException;
import envoy.data.IdGenerator;
import envoy.event.IdGeneratorRequest;
import envoy.data.IDGenerator;
import envoy.event.IDGeneratorRequest;
import envoy.server.data.ConfigItem;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ObjectWriteProxy;
@ -16,19 +16,19 @@ import envoy.server.net.ObjectWriteProxy;
* @author Kai S. K. Engelbart
* @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;
@Override
public Class<IdGeneratorRequest> getInputClass() { return IdGeneratorRequest.class; }
public Class<IDGeneratorRequest> getInputClass() { return IDGeneratorRequest.class; }
@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.");
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));
PersistenceManager.getInstance().updateConfigItem(currentId);

View File

@ -26,21 +26,21 @@ public class MessageProcessor implements ObjectProcessor<Message> {
ConnectionManager connectionManager = ConnectionManager.getInstance();
message.nextStatus();
if (connectionManager.isOnline(message.getRecipientId())) try {
if (connectionManager.isOnline(message.getRecipientID())) try {
// 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
message.setReceivedDate(new Date());
message.nextStatus();
writeProxy.write(socketId, new MessageStatusChangeEvent(message));
} 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();
}
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
}
@Override
public Class<Message> getInputClass() { return Message.class; }
}

View File

@ -27,7 +27,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
// 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"));
envoy.server.data.Message msg = persistenceManager.getMessageById(input.getId());
envoy.server.data.Message msg = persistenceManager.getMessageById(input.getID());
msg.setStatus(input.get());
msg.setReadDate(input.getDate());
persistenceManager.updateMessage(msg);

View File

@ -30,7 +30,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
@Override
public void process(UserStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
// 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");
return;
}
@ -58,7 +58,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
* @param evt the {@link UserStatusChangeEvent}
* @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
@ -75,7 +75,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
if (connectionManager.isOnline(contact.getId())) writeProxy.write(connectionManager.getSocketId(contact.getId()), evt);
} catch (IOException e) {
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");
}
}