Updated database implementation

*Added a contact abstract class that serves as a superclass for user and
group
* Added a group class
* Updated persistenceManager to fit the new contact system.
* Updated all classes that used methods, that were updated.
This commit is contained in:
DieGurke
2020-03-25 16:34:55 +01:00
parent 1302967fc4
commit 1bedd5fb7f
13 changed files with 215 additions and 90 deletions

View File

@ -1,7 +1,11 @@
package envoy.server.processors;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.NoResultException;
@ -45,7 +49,7 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
System.out.println("Rejecting handshake on socket " + socketId);
return;
}
connectionManager.registerUser(user.getId(), socketId);
connectionManager.registerUser(user.getID(), socketId);
// Notifies contacts of this users online-going and updates his status in the
// database
@ -53,12 +57,12 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
UserStatusChangeProcessor.updateUserStatus(user);
// Create contacts
Contacts contacts = new Contacts(user.getContacts().stream().map(envoy.server.data.User::toCommonUser).collect(Collectors.toList()));
contacts.getContacts().add(user.toCommonUser());
Contacts contacts = new Contacts(user.getContacts().stream().map(envoy.server.data.User::toCommon).collect(Collectors.toList()));
contacts.getContacts().add(user.toCommon());
// Complete handshake
System.out.println("Sending user...");
writeProxy.write(socketId, user.toCommonUser());
writeProxy.write(socketId, user.toCommon());
System.out.println("Sending contacts...");
writeProxy.write(socketId, contacts);
System.out.println("Acquiring pending messages for the client...");
@ -94,7 +98,7 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
envoy.server.data.User user = persistenceManager.getUserByName(credentials.getIdentifier());
// Checking if user is already online
if (connectionManager.isOnline(user.getId())) {
if (connectionManager.isOnline(user.getID())) {
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.ALREADY_ONLINE));
return null;
}
@ -140,7 +144,7 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
user.setStatus(User.UserStatus.ONLINE);
user.setPasswordHash(credentials.getPasswordHash());
user.setContacts(new ArrayList<>());
persistenceManager.addUser(user);
persistenceManager.addContact(user);
return user;
}
}