From 967e152ee991b0f52923bdf8ae9078d0ebbee44c Mon Sep 17 00:00:00 2001
From: Christoph Thelen <christoph.thelen@mni.thm.de>
Date: Wed, 24 Oct 2012 10:31:59 +0200
Subject: [PATCH] Fixed creation of JSON object

---
 .../java/de/thm/arsnova/dao/CouchDBDao.java   |  7 ++-
 .../de/thm/arsnova/entities/LoggedIn.java     | 46 +-------------
 .../thm/arsnova/entities/VisitedSession.java  | 63 +++++++++++++++++++
 3 files changed, 69 insertions(+), 47 deletions(-)
 create mode 100644 src/main/java/de/thm/arsnova/entities/VisitedSession.java

diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
index f18961fd..023b385f 100644
--- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
@@ -56,9 +56,9 @@ import com.fourspaces.couchdb.ViewResults;
 
 import de.thm.arsnova.entities.Feedback;
 import de.thm.arsnova.entities.LoggedIn;
-import de.thm.arsnova.entities.LoggedIn.VisitedSession;
 import de.thm.arsnova.entities.Session;
 import de.thm.arsnova.entities.User;
+import de.thm.arsnova.entities.VisitedSession;
 import de.thm.arsnova.exceptions.ForbiddenException;
 import de.thm.arsnova.exceptions.NotFoundException;
 import de.thm.arsnova.services.ISessionService;
@@ -545,7 +545,10 @@ public class CouchDBDao implements IDatabaseDao {
 			}
 			this.getDatabase().saveDocument(doc);
 			
-			return (LoggedIn) JSONObject.toBean(doc.getJSONObject(), LoggedIn.class);
+			LoggedIn l = (LoggedIn) JSONObject.toBean(doc.getJSONObject(), LoggedIn.class);
+			Collection<VisitedSession> visitedSessions = JSONArray.toCollection(doc.getJSONObject().getJSONArray("visitedSessions"), VisitedSession.class);
+			l.setVisitedSessions(new ArrayList<VisitedSession>(visitedSessions));
+			return l;
 		} catch (UnsupportedEncodingException e) {
 			return null;
 		} catch (IOException e) {
diff --git a/src/main/java/de/thm/arsnova/entities/LoggedIn.java b/src/main/java/de/thm/arsnova/entities/LoggedIn.java
index 42fd6728..fd081f36 100644
--- a/src/main/java/de/thm/arsnova/entities/LoggedIn.java
+++ b/src/main/java/de/thm/arsnova/entities/LoggedIn.java
@@ -45,7 +45,7 @@ public class LoggedIn {
 	
 	private boolean isAlreadyVisited(Session s) {
 		for (VisitedSession vs : this.visitedSessions) {
-			if (vs._id.equals(s.get_id())) {
+			if (vs.get_id().equals(s.get_id())) {
 				return true;
 			}
 		}
@@ -115,48 +115,4 @@ public class LoggedIn {
 				+ ", timestamp=" + timestamp + ", visitedSessions="
 				+ visitedSessions + "]";
 	}
-
-	public static class VisitedSession {
-		private String _id;
-		private String name;
-		private String keyword;
-		
-		public VisitedSession() {}
-		
-		public VisitedSession(Session s) {
-			this._id = s.get_id();
-			this.name = s.getName();
-			this.keyword = s.getKeyword();
-		}
-
-		public String get_id() {
-			return _id;
-		}
-
-		public void set_id(String _id) {
-			this._id = _id;
-		}
-
-		public String getName() {
-			return name;
-		}
-
-		public void setName(String name) {
-			this.name = name;
-		}
-
-		public String getKeyword() {
-			return keyword;
-		}
-
-		public void setKeyword(String keyword) {
-			this.keyword = keyword;
-		}
-
-		@Override
-		public String toString() {
-			return "VisitedSession [_id=" + _id + ", name=" + name
-					+ ", keyword=" + keyword + "]";
-		}
-	}
 }
\ No newline at end of file
diff --git a/src/main/java/de/thm/arsnova/entities/VisitedSession.java b/src/main/java/de/thm/arsnova/entities/VisitedSession.java
new file mode 100644
index 00000000..50cb8819
--- /dev/null
+++ b/src/main/java/de/thm/arsnova/entities/VisitedSession.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 THM webMedia
+ * 
+ * This file is part of ARSnova.
+ *
+ * ARSnova is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * ARSnova is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.thm.arsnova.entities;
+
+public class VisitedSession {
+		private String _id;
+		private String name;
+		private String keyword;
+		
+		public VisitedSession() {}
+		
+		public VisitedSession(Session s) {
+			this._id = s.get_id();
+			this.name = s.getName();
+			this.keyword = s.getKeyword();
+		}
+
+		public String get_id() {
+			return _id;
+		}
+
+		public void set_id(String _id) {
+			this._id = _id;
+		}
+
+		public String getName() {
+			return name;
+		}
+
+		public void setName(String name) {
+			this.name = name;
+		}
+
+		public String getKeyword() {
+			return keyword;
+		}
+
+		public void setKeyword(String keyword) {
+			this.keyword = keyword;
+		}
+
+		@Override
+		public String toString() {
+			return "VisitedSession [_id=" + _id + ", name=" + name
+					+ ", keyword=" + keyword + "]";
+		}
+	}
\ No newline at end of file
-- 
GitLab