Skip to content
Snippets Groups Projects
Commit 72067dc1 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Removed obsolete application event handling

The removed implementation used events wich were never published in any
part of the application.
parent 66ae49ba
Branches
Tags
No related merge requests found
package de.thm.arsnova.events;
import org.springframework.context.ApplicationEvent;
import de.thm.arsnova.entities.User;
public class ARSnovaEvent extends ApplicationEvent {
private static final long serialVersionUID = 1L;
private String sessionKey;
private User user;
private final String eventName;
private final Object data;
private final Destination destination;
public enum Destination {
USER,
SESSION
};
public ARSnovaEvent(Object source, String sKey, String eName, Object d) {
super(source);
this.data = d;
this.eventName = eName;
this.sessionKey = sKey;
this.destination = Destination.SESSION;
}
public ARSnovaEvent(Object source, User recipient, String eName, Object d) {
super(source);
this.data = d;
this.eventName = eName;
this.user = recipient;
this.destination = Destination.USER;
}
public String getSessionKey() {
return sessionKey;
}
public String getEventName() {
return eventName;
}
public Object getData() {
return data;
}
public User getRecipient() {
return user;
}
public Destination getDestinationType() {
return destination;
}
}
package de.thm.arsnova.events;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import de.thm.arsnova.services.UserSessionService;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
@Component
public class ARSnovaEventListener implements ApplicationListener<ARSnovaEvent> {
public static final Logger LOGGER = LoggerFactory.getLogger(ARSnovaEventListener.class);
@Autowired
private ARSnovaSocketIOServer socketIoServer;
@Autowired
private UserSessionService userSessionService;
@Override
public void onApplicationEvent(ARSnovaEvent event) {
userSessionService.sendEventViaWebSocket(socketIoServer, event);
}
}
package de.thm.arsnova.events;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
@Service
public class Publisher implements ApplicationContextAware {
@Autowired
private ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext c) {
this.context = c;
}
public void publish(ARSnovaEvent event) {
this.context.publishEvent(event);
}
}
package de.thm.arsnova.events;
......@@ -4,11 +4,9 @@ import java.util.UUID;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.events.ARSnovaEvent;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
public interface UserSessionService {
enum Role {
STUDENT,
SPEAKER
......@@ -16,18 +14,16 @@ public interface UserSessionService {
void setUser(User user);
User getUser();
void setSession(Session session);
Session getSession();
void setSocketId(UUID socketId);
UUID getSocketId();
void setRole(Role role);
Role getRole();
boolean inSession();
boolean isAuthenticated();
void sendEventViaWebSocket(ARSnovaSocketIOServer server, ARSnovaEvent event);
}
......@@ -11,9 +11,6 @@ import org.springframework.stereotype.Component;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.events.ARSnovaEvent;
import de.thm.arsnova.events.ARSnovaEvent.Destination;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
......@@ -21,16 +18,16 @@ public class UserSessionServiceImpl implements UserSessionService, Serializable
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(UserSessionServiceImpl.class);
private User user;
private Session session;
private UUID socketId;
private Role role;
@Override
public void setUser(User u) {
this.user = u;
this.user.setRole(this.role);
public void setUser(final User u) {
user = u;
user.setRole(role);
}
@Override
......@@ -39,79 +36,49 @@ public class UserSessionServiceImpl implements UserSessionService, Serializable
}
@Override
public void setSession(Session s) {
this.session = s;
public void setSession(final Session s) {
session = s;
}
@Override
public Session getSession() {
return this.session;
return session;
}
@Override
public void setSocketId(UUID sId) {
this.socketId = sId;
public void setSocketId(final UUID sId) {
socketId = sId;
}
@Override
public UUID getSocketId() {
return this.socketId;
return socketId;
}
private boolean hasConnectedWebSocket() {
return getSocketId() != null;
}
@Override
public boolean inSession() {
return (
this.isAuthenticated()
&& this.getSession() != null
);
}
@Override
public boolean isAuthenticated() {
return (
this.getUser() != null
&& this.getRole() != null
);
return isAuthenticated()
&& getSession() != null;
}
@Override
public void sendEventViaWebSocket(ARSnovaSocketIOServer server, ARSnovaEvent event) {
if (event == null) {
LOGGER.info("Trying to send NULL event");
return;
}
if (
event.getDestinationType() == Destination.SESSION
&& hasConnectedWebSocket()
&& session != null
&& event.getSessionKey().equals(session.getKeyword())
) {
server.sendToClient(getSocketId(), event);
}
if (
event.getDestinationType() == Destination.USER
&& hasConnectedWebSocket()
&& user != null
&& event.getRecipient().getUsername().equals(user.getUsername())
) {
server.sendToClient(getSocketId(), event);
}
public boolean isAuthenticated() {
return getUser() != null
&& getRole() != null;
}
@Override
public void setRole(Role r) {
public void setRole(final Role r) {
role = r;
if (user != null) {
user.setRole(role);
}
}
@Override
public Role getRole() {
return role;
......
......@@ -27,7 +27,6 @@ import com.corundumstudio.socketio.parser.Packet;
import com.corundumstudio.socketio.parser.PacketType;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.events.ARSnovaEvent;
import de.thm.arsnova.exceptions.NoContentException;
import de.thm.arsnova.services.IFeedbackService;
import de.thm.arsnova.services.ISessionService;
......@@ -305,20 +304,6 @@ public class ARSnovaSocketIOServer {
broadcastInSession(sessionKey, "lecQuestionAvail", lecturerQuestionId);
}
/** Sends event to a websocket connection identified by UUID
*
* @param sessionId The UUID of the websocket ID
* @param event The event to be send to client
* TODO This method is unimplemented!
*/
public void sendToClient(final UUID sessionId, final ARSnovaEvent event) {
for (final SocketIOClient c : server.getAllClients()) {
if (c.getSessionId().equals(sessionId)) {
break;
}
}
}
public void broadcastInSession(final String sessionKey, final String eventName, final Object data) {
/**
* collect a list of users which are in the current session iterate over
......
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