From c5387027e73a282c44e577cabbe9884e406e3927 Mon Sep 17 00:00:00 2001
From: Daniel Vogel <daniel.vogel@mni.thm.de>
Date: Mon, 12 Jan 2015 23:39:33 +0100
Subject: [PATCH] Adjusted method for getting all public pool sessions to new
 CouchDB view

---
 .../arsnova/controller/SessionController.java |  4 ++--
 .../java/de/thm/arsnova/dao/CouchDBDao.java   | 24 +++++++++----------
 .../java/de/thm/arsnova/dao/IDatabaseDao.java |  2 +-
 .../thm/arsnova/services/ISessionService.java |  2 +-
 .../thm/arsnova/services/SessionService.java  |  2 +-
 .../de/thm/arsnova/dao/StubDatabaseDao.java   |  2 +-
 6 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/controller/SessionController.java b/src/main/java/de/thm/arsnova/controller/SessionController.java
index 0e68a0ef..92d64fb2 100644
--- a/src/main/java/de/thm/arsnova/controller/SessionController.java
+++ b/src/main/java/de/thm/arsnova/controller/SessionController.java
@@ -193,10 +193,10 @@ public class SessionController extends AbstractController {
 	
 
 	@RequestMapping(value = "/publicpool", method = RequestMethod.GET)
-	public final Map<String, ArrayList<Session>> getPublicPoolSessions(
+	public final List<Session> getPublicPoolSessions(
 			final HttpServletResponse response
 			) {
-		Map<String, ArrayList<Session>> sessions;
+		List<Session> sessions;
 		sessions = sessionService.getPublicPoolSessions();
 
 		if (sessions == null || sessions.isEmpty()) {
diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
index 158a75d6..7a5e8b46 100644
--- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
@@ -130,22 +130,22 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 	
 	@Override
-	public final Map<String, ArrayList<Session>> getPublicPoolSessions() {
-		Map<String, ArrayList<Session>> sessionMap = new HashMap<String, ArrayList<Session>>();
+	public final List<Session> getPublicPoolSessions() {
 		final NovaView view = new NovaView("session/public_pool_by_id");
-		view.setGroup(true);
+
 		final ViewResults sessions = getDatabase().view(view);
 
-		//final List<Session> result = new ArrayList<Session>();
-		Collection<Session> result = null;
-		for (Document d : sessions.getResults()) {
-			final JSONArray jsonSessions = d.getJSONObject().getJSONArray("value");
-			
-			sessionMap.put(
-					d.getJSONObject().getString("key"),
-					new ArrayList(JSONArray.toCollection(jsonSessions, Session.class)));
+		final List<Session> result = new ArrayList<Session>();
+		
+		for (final Document d : sessions.getResults()) {
+			final Session session = (Session) JSONObject.toBean(
+					d.getJSONObject().getJSONObject("value"),
+					Session.class
+					);
+			//session.set_id(d.getId());
+			result.add(session);
 		}
-		return sessionMap;
+		return result;
 	}
 	
 	@Override
diff --git a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
index bfb1502a..b0cada55 100644
--- a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
+++ b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
@@ -42,7 +42,7 @@ public interface IDatabaseDao {
 
 	List<Session> getMySessions(User user);
 	
-	Map<String, ArrayList<Session>> getPublicPoolSessions();
+	List<Session> getPublicPoolSessions();
 
 	Session saveSession(User user, Session session);
 
diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java
index 1cf5b978..37672066 100644
--- a/src/main/java/de/thm/arsnova/services/ISessionService.java
+++ b/src/main/java/de/thm/arsnova/services/ISessionService.java
@@ -40,7 +40,7 @@ public interface ISessionService {
 
 	List<Session> getMySessions();
 	
-	Map<String, ArrayList<Session>> getPublicPoolSessions();
+	List<Session> getPublicPoolSessions();
 
 	List<Session> getMyVisitedSessions();
 
diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java
index 1f87b7db..445abe20 100644
--- a/src/main/java/de/thm/arsnova/services/SessionService.java
+++ b/src/main/java/de/thm/arsnova/services/SessionService.java
@@ -158,7 +158,7 @@ public class SessionService implements ISessionService {
 	
 	@Override
 	@PreAuthorize("isAuthenticated()")
-	public final Map<String, ArrayList<Session>> getPublicPoolSessions() {
+	public final List<Session> getPublicPoolSessions() {
 		return databaseDao.getPublicPoolSessions();
 	}
 
diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
index 08349c91..eec8823c 100644
--- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
+++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
@@ -195,7 +195,7 @@ public class StubDatabaseDao implements IDatabaseDao {
 	}
 	
 	@Override
-	public Map<String, ArrayList<Session>> getPublicPoolSessions() {
+	public List<Session> getPublicPoolSessions() {
 		// TODO Auto-generated method stub
 		return null;
 	}
-- 
GitLab