Skip to content
Snippets Groups Projects
Commit 307b5506 authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Implemented missing Web Socket notification of deleted feedback

parent d8ea00f3
Branches
Tags
No related merge requests found
package de.thm.arsnova; package de.thm.arsnova;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -108,24 +111,29 @@ public class FeedbackStorage { ...@@ -108,24 +111,29 @@ public class FeedbackStorage {
} }
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
public void cleanFeedbackVotes(final int cleanupFeedbackDelay) { public Map<String, List<User>> cleanFeedbackVotes(final int cleanupFeedbackDelay) {
final Map<String, List<User>> removedFeedbackOfUsersInSession = new HashMap<String, List<User>>();;
for (final String keyword : data.keySet()) { for (final String keyword : data.keySet()) {
cleanSessionFeedbackVotes(keyword, cleanupFeedbackDelay); List<User> feedbackOfUsers = cleanFeedbackVotesInSession(keyword, cleanupFeedbackDelay);
removedFeedbackOfUsersInSession.put(keyword, feedbackOfUsers);
} }
return removedFeedbackOfUsersInSession;
} }
private void cleanSessionFeedbackVotes(final String keyword, final int cleanupFeedbackDelay) { private List<User> cleanFeedbackVotesInSession(final String keyword, final int cleanupFeedbackDelay) {
final long timelimitInMillis = 60000 * (long) cleanupFeedbackDelay; final long timelimitInMillis = 60000 * (long) cleanupFeedbackDelay;
final long maxAllowedTimeInMillis = System.currentTimeMillis() - timelimitInMillis; final long maxAllowedTimeInMillis = System.currentTimeMillis() - timelimitInMillis;
final Map<String, FeedbackStorageObject> sessionFeedbacks = data.get(keyword); final Map<String, FeedbackStorageObject> sessionFeedbacks = data.get(keyword);
final List<User> feedbackOfUsers = new ArrayList<User>();
for (final Map.Entry<String, FeedbackStorageObject> entry : sessionFeedbacks.entrySet()) { for (final Map.Entry<String, FeedbackStorageObject> entry : sessionFeedbacks.entrySet()) {
if ( final boolean timeIsUp = entry.getValue().getTimestamp().getTime() < maxAllowedTimeInMillis;
entry.getValue().getTimestamp().getTime() < maxAllowedTimeInMillis if (timeIsUp) {
) {
sessionFeedbacks.remove(entry.getKey()); sessionFeedbacks.remove(entry.getKey());
feedbackOfUsers.add(entry.getValue().user);
} }
} }
return feedbackOfUsers;
} }
} }
...@@ -19,7 +19,11 @@ ...@@ -19,7 +19,11 @@
package de.thm.arsnova.services; package de.thm.arsnova.services;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -66,7 +70,33 @@ public class FeedbackService implements IFeedbackService { ...@@ -66,7 +70,33 @@ public class FeedbackService implements IFeedbackService {
@Override @Override
@Scheduled(fixedDelay = DEFAULT_SCHEDULER_DELAY) @Scheduled(fixedDelay = DEFAULT_SCHEDULER_DELAY)
public final void cleanFeedbackVotes() { public final void cleanFeedbackVotes() {
feedbackStorage.cleanFeedbackVotes(cleanupFeedbackDelay); Map<String, List<User>> deletedFeedbackOfUsersInSession = feedbackStorage.cleanFeedbackVotes(cleanupFeedbackDelay);
/*
* mapping (Session -> Users) is not suitable for web sockets, because we want to sent all affected
* sessions to a single user in one go instead of sending multiple messages for each session. Hence,
* we need the mapping (User -> Sessions)
*/
final Map<User, Set<String>> affectedSessionsOfUsers = new HashMap<User, Set<String>>();
for (Map.Entry<String, List<User>> entry : deletedFeedbackOfUsersInSession.entrySet()) {
final String sessionKeyword = entry.getKey();
final List<User> users = entry.getValue();
for (User user : users) {
Set<String> affectedSessions;
if (affectedSessionsOfUsers.containsKey(user)) {
affectedSessions = affectedSessionsOfUsers.get(user);
} else {
affectedSessions = new HashSet<String>();
}
affectedSessions.add(sessionKeyword);
affectedSessionsOfUsers.put(user, affectedSessions);
}
}
for (Map.Entry<User, Set<String>> entry : affectedSessionsOfUsers.entrySet()) {
final User user = entry.getKey();
final Set<String> arsSessions = entry.getValue();
server.reportDeletedFeedback(user.getUsername(), arsSessions);
}
} }
@Override @Override
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment