Apply suggestions from code review
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
		| @@ -2,4 +2,4 @@ DROP SCHEMA public CASCADE; | |||||||
| CREATE SCHEMA public; | CREATE SCHEMA public; | ||||||
| GRANT ALL ON SCHEMA public TO postgres; | GRANT ALL ON SCHEMA public TO postgres; | ||||||
| GRANT ALL ON SCHEMA public TO envoy; | GRANT ALL ON SCHEMA public TO envoy; | ||||||
| GRANT ALL ON SCHEMA public TO public; | GRANT ALL ON SCHEMA public TO public; | ||||||
|   | |||||||
| @@ -38,7 +38,7 @@ public class Startup { | |||||||
| 		final var items = new HashMap<String, ConfigItem<?>>(); | 		final var items = new HashMap<String, ConfigItem<?>>(); | ||||||
| 		items.put("homeDirectory", | 		items.put("homeDirectory", | ||||||
| 				new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true)); | 				new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true)); | ||||||
| 		items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true)); | 		items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.WARNING, true)); | ||||||
| 		items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINEST, true)); | 		items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINEST, true)); | ||||||
|  |  | ||||||
| 		final var config = new Config(); | 		final var config = new Config(); | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ public abstract class Contact { | |||||||
| 	@Temporal(TemporalType.TIMESTAMP) | 	@Temporal(TemporalType.TIMESTAMP) | ||||||
| 	private Date creationDate; | 	private Date creationDate; | ||||||
|  |  | ||||||
| 	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) | 	@ManyToMany(fetch = FetchType.EAGER) | ||||||
| 	protected Set<Contact> contacts; | 	protected Set<Contact> contacts; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
| @@ -117,7 +117,7 @@ public class PersistenceManager { | |||||||
| 	 * Searches for a {@link User} with a specific ID. | 	 * Searches for a {@link User} with a specific ID. | ||||||
| 	 * | 	 * | ||||||
| 	 * @param id the id to search for | 	 * @param id the id to search for | ||||||
| 	 * @return the user with the specified id | 	 * @return the user with the specified ID or {@code null} if none was found | ||||||
| 	 * @since Envoy Server Standalone v0.1-alpha | 	 * @since Envoy Server Standalone v0.1-alpha | ||||||
| 	 */ | 	 */ | ||||||
| 	public User getUserByID(long id) { return entityManager.find(User.class, id); } | 	public User getUserByID(long id) { return entityManager.find(User.class, id); } | ||||||
| @@ -126,7 +126,7 @@ public class PersistenceManager { | |||||||
| 	 * Searches for a {@link Group} with a specific ID. | 	 * Searches for a {@link Group} with a specific ID. | ||||||
| 	 * | 	 * | ||||||
| 	 * @param id the id to search for | 	 * @param id the id to search for | ||||||
| 	 * @return the group with the specific id | 	 * @return the group with the specified ID or {@code null} if none was found | ||||||
| 	 * @since Envoy Server Standalone v0.1-beta | 	 * @since Envoy Server Standalone v0.1-beta | ||||||
| 	 */ | 	 */ | ||||||
| 	public Group getGroupByID(long id) { return entityManager.find(Group.class, id); } | 	public Group getGroupByID(long id) { return entityManager.find(Group.class, id); } | ||||||
| @@ -135,7 +135,7 @@ public class PersistenceManager { | |||||||
| 	 * Searches for a {@link Contact} with a specific ID. | 	 * Searches for a {@link Contact} with a specific ID. | ||||||
| 	 * | 	 * | ||||||
| 	 * @param id the id to search for | 	 * @param id the id to search for | ||||||
| 	 * @return the contact with the specific id | 	 * @return the contact with the specified ID or {@code null} if none was found | ||||||
| 	 * @since Envoy Server Standalone v0.1-beta | 	 * @since Envoy Server Standalone v0.1-beta | ||||||
| 	 */ | 	 */ | ||||||
| 	public Contact getContactByID(long id) { return entityManager.find(Contact.class, id); } | 	public Contact getContactByID(long id) { return entityManager.find(Contact.class, id); } | ||||||
| @@ -166,7 +166,7 @@ public class PersistenceManager { | |||||||
| 	 * Searches for a {@link Message} with a specific id. | 	 * Searches for a {@link Message} with a specific id. | ||||||
| 	 * | 	 * | ||||||
| 	 * @param id the id to search for | 	 * @param id the id to search for | ||||||
| 	 * @return the message with the specified id | 	 * @return the message with the specified ID or {@code null} if none is found | ||||||
| 	 * @since Envoy Server Standalone v0.1-alpha | 	 * @since Envoy Server Standalone v0.1-alpha | ||||||
| 	 */ | 	 */ | ||||||
| 	public Message getMessageByID(long id) { return entityManager.find(Message.class, id); } | 	public Message getMessageByID(long id) { return entityManager.find(Message.class, id); } | ||||||
|   | |||||||
| @@ -43,7 +43,6 @@ public class ObjectWriteProxy { | |||||||
| 		// Create message targeted at the client | 		// Create message targeted at the client | ||||||
| 		final Message response = writeProxy.getMessage(); | 		final Message response = writeProxy.getMessage(); | ||||||
| 		response.socketId = recipientSocketID; | 		response.socketId = recipientSocketID; | ||||||
|  |  | ||||||
| 		logger.fine("Sending " + obj); | 		logger.fine("Sending " + obj); | ||||||
|  |  | ||||||
| 		// Serialize object to byte array | 		// Serialize object to byte array | ||||||
|   | |||||||
| @@ -38,7 +38,6 @@ public class GroupMessageProcessor implements ObjectProcessor<GroupMessage> { | |||||||
|  |  | ||||||
| 		// Checks if all memberMessageStatuses are RECEIVED and if so sets the | 		// Checks if all memberMessageStatuses are RECEIVED and if so sets the | ||||||
| 		// groupMessage Status to RECEIVED. | 		// groupMessage Status to RECEIVED. | ||||||
| 		if (!groupMessage.getMemberStatuses().containsValue(MessageStatus.SENT)) groupMessage.setStatus(MessageStatus.RECEIVED); |  | ||||||
|  |  | ||||||
| 		members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); }); | 		members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,19 +31,14 @@ public class MessageProcessor implements ObjectProcessor<Message> { | |||||||
|  |  | ||||||
| 	@Override | 	@Override | ||||||
| 	public void process(Message message, long socketID, ObjectWriteProxy writeProxy) { | 	public void process(Message message, long socketID, ObjectWriteProxy writeProxy) { | ||||||
|  | 		if (message.getStatus!=MessageStatus.WAITING) { | ||||||
|  | 			logger.warning("Received message with invalid status: " + message); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
| 		message.nextStatus(); | 		message.nextStatus(); | ||||||
| 		ConnectionManager	connectionManager	= ConnectionManager.getInstance(); | 		ConnectionManager	connectionManager	= ConnectionManager.getInstance(); | ||||||
|  |  | ||||||
| 		sendToUser(connectionManager, message, writeProxy); | 		sendToUser(connectionManager, message, writeProxy); | ||||||
| 		if (message.getStatus() != MessageStatus.SENT) { |  | ||||||
| 			// Sending a messageStatusChangeEvent to the sender |  | ||||||
| 			try { |  | ||||||
| 				writeProxy.write(socketID, new MessageStatusChangeEvent(message)); |  | ||||||
| 			} catch (IOException e) { |  | ||||||
| 				logger.warning("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID()); |  | ||||||
| 				e.printStackTrace(); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		try { | 		try { | ||||||
| 			PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message)); | 			PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message)); | ||||||
| 		} catch (EntityExistsException e) { | 		} catch (EntityExistsException e) { | ||||||
|   | |||||||
| @@ -33,8 +33,8 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat | |||||||
| 		persistenceManager.updateMessage(msg); | 		persistenceManager.updateMessage(msg); | ||||||
|  |  | ||||||
| 		// Notifies the sender of the message about the status-update to READ | 		// Notifies the sender of the message about the status-update to READ | ||||||
| 		final long senderId = msg.getSender().getID(); | 		final long senderID = msg.getSender().getID(); | ||||||
| 		if (connectionManager.isOnline(senderId)) writeProxy.write(connectionManager.getSocketId(senderId), input); | 		if (connectionManager.isOnline(senderID)) writeProxy.write(connectionManager.getSocketId(senderID), input); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	@Override | 	@Override | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 GitHub
						GitHub