From 578036fbc94c509ad619596e64bd683b056b76a0 Mon Sep 17 00:00:00 2001
From: Christoph Thelen <christoph.thelen@mni.thm.de>
Date: Mon, 9 Feb 2015 13:35:53 +0100
Subject: [PATCH] Fix for #14608: Update lock in session object

This change also removes the "lockSession" method from CouchDB.
Instead, the more general update method is used which also
has the required caching annotations.
---
 src/main/java/de/thm/arsnova/dao/CouchDBDao.java   | 14 --------------
 src/main/java/de/thm/arsnova/dao/IDatabaseDao.java |  2 --
 .../de/thm/arsnova/services/SessionService.java    |  3 ++-
 .../java/de/thm/arsnova/dao/StubDatabaseDao.java   |  6 ------
 4 files changed, 2 insertions(+), 23 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
index 781801e5e..5cd4730db 100644
--- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
@@ -1272,20 +1272,6 @@ public class CouchDBDao implements IDatabaseDao {
 		}
 	}
 
-	@Override
-	public Session lockSession(final Session session, final Boolean lock) {
-		try {
-			final Document s = database.getDocument(session.get_id());
-			s.put("active", lock);
-			database.saveDocument(s);
-			session.set_rev(s.getRev());
-			return session;
-		} catch (final IOException e) {
-			LOGGER.error("Could not lock session {}", session);
-		}
-		return null;
-	}
-
 	@Override
 	@CachePut(value = "sessions")
 	public Session updateSession(final Session session) {
diff --git a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
index 09146dc25..17fba6ffe 100644
--- a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
+++ b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
@@ -126,8 +126,6 @@ public interface IDatabaseDao {
 
 	List<Session> getCourseSessions(List<Course> courses);
 
-	Session lockSession(Session session, Boolean lock);
-
 	Session updateSession(Session session);
 
 	void deleteSession(Session session);
diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java
index bf43823c7..330f0bde1 100644
--- a/src/main/java/de/thm/arsnova/services/SessionService.java
+++ b/src/main/java/de/thm/arsnova/services/SessionService.java
@@ -265,8 +265,9 @@ public class SessionService implements ISessionService {
 		if (!session.isCreator(user)) {
 			throw new ForbiddenException();
 		}
+		session.setActive(lock);
 		socketIoServer.reportSessionStatus(sessionkey, lock);
-		return databaseDao.lockSession(session, lock);
+		return databaseDao.updateSession(session);
 	}
 
 	@Override
diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
index 6ab182634..b3c85df2f 100644
--- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
+++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
@@ -378,12 +378,6 @@ public class StubDatabaseDao implements IDatabaseDao {
 		return null;
 	}
 
-	@Override
-	public Session lockSession(Session session, Boolean lock) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
 	@Override
 	public Session updateSession(Session session) {
 		// TODO Auto-generated method stub
-- 
GitLab