From cab24784bf83b0030927070ad311312d8e393c6f Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de> Date: Thu, 6 Sep 2012 00:33:12 +0200 Subject: [PATCH] Prepare session controller for get and post of feedback --- .../de/thm/arsnova/SessionController.java | 22 +++++++++ .../thm/arsnova/services/ISessionService.java | 4 ++ .../thm/arsnova/services/SessionService.java | 45 ++++++++++++++++--- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/thm/arsnova/SessionController.java b/src/main/java/de/thm/arsnova/SessionController.java index 5cc061b9..57c07d40 100644 --- a/src/main/java/de/thm/arsnova/SessionController.java +++ b/src/main/java/de/thm/arsnova/SessionController.java @@ -18,13 +18,17 @@ */ package de.thm.arsnova; +import java.util.List; + import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import de.thm.arsnova.entities.Session; import de.thm.arsnova.services.ISessionService; @@ -43,4 +47,22 @@ public class SessionController { response.setStatus(HttpStatus.NOT_FOUND.value()); return null; } + + @RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.GET) + public List<Integer> getFeedback(@PathVariable String sessionkey, HttpServletResponse response) { + List<Integer> feedback = sessionService.getFeedback(sessionkey); + if (feedback != null) return feedback; + + response.setStatus(HttpStatus.NOT_FOUND.value()); + return null; + } + + @RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.POST) + public List<Integer> postFeedback(@PathVariable String sessionkey, @RequestBody int value, HttpServletResponse response) { + List<Integer> feedback = sessionService.getFeedback(sessionkey); + if (feedback != null) return feedback; + + response.setStatus(HttpStatus.NOT_FOUND.value()); + return null; + } } diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java index 97f6ed60..949ebee3 100644 --- a/src/main/java/de/thm/arsnova/services/ISessionService.java +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -18,11 +18,15 @@ */ package de.thm.arsnova.services; +import java.util.List; + import de.thm.arsnova.entities.Session; public interface ISessionService { public Session getSession(String keyword); + public List<Integer> getFeedback(String keyword); + public void postFeedback(String keyword, int value); } \ No newline at end of file diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index f10b9522..962a923e 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -19,6 +19,8 @@ package de.thm.arsnova.services; import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; import net.sf.json.JSONObject; @@ -36,15 +38,15 @@ import de.thm.arsnova.entities.Session; public class SessionService implements ISessionService { private final com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session("localhost", 5984); - public static final Logger logger = LoggerFactory - .getLogger(SessionService.class); - + private final Database database = session.getDatabase("arsnova"); + + public static final Logger logger = LoggerFactory.getLogger(SessionService.class); + @Override public Session getSession(String keyword) { - Database db = session.getDatabase("arsnova"); View view = new View("session/by_keyword"); view.setKey(URLEncoder.encode("\""+keyword+"\"")); - ViewResults results = db.view(view); + ViewResults results = database.view(view); if (results.getJSONArray("rows").optJSONObject(0) == null) return null; @@ -55,4 +57,37 @@ public class SessionService implements ISessionService { return null; } + @Override + public List<Integer> getFeedback(String keyword) { + String sessionId = this.getSessionId(keyword); + if (sessionId == null) return null; + + View view = new View("understanding/by_session"); + view.setGroup(true); + view.setStartKey(URLEncoder.encode("[\""+sessionId+"\"]")); + view.setEndKey(URLEncoder.encode("[\""+sessionId+"\"],{}")); + ViewResults results = database.view(view); + + //if (results.getJSONArray("rows").optJSONObject(0) == null) return null; + + logger.info("Feedback: {}", results.getJSONObject("rows")); + + return null; + } + + @Override + public void postFeedback(String keyword, int value) { + + } + + private String getSessionId(String keyword) { + View view = new View("session/by_keyword"); + view.setKey(URLEncoder.encode("\""+keyword+"\"")); + ViewResults results = database.view(view); + + if (results.getJSONArray("rows").optJSONObject(0) == null) return null; + + return results.getJSONArray("rows").optJSONObject(0).optJSONObject("value").getString("_id"); + } + } -- GitLab