summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/backend/resources/SurveyResource.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-09-03 07:11:35 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-09-03 07:11:35 -0700
commit598c241ddb15d89a59629b0e3b49803a405e6249 (patch)
tree2092f5f6a41454bf618b2351f1ead6f4b88f27c7 /src/com/p4square/grow/backend/resources/SurveyResource.java
parent235e27865559a72a903be28fd33cfeb8759730b4 (diff)
Fixing the assessment to take the user to the question after the last answered question
Diffstat (limited to 'src/com/p4square/grow/backend/resources/SurveyResource.java')
-rw-r--r--src/com/p4square/grow/backend/resources/SurveyResource.java39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/com/p4square/grow/backend/resources/SurveyResource.java b/src/com/p4square/grow/backend/resources/SurveyResource.java
index d22d763..76cbe30 100644
--- a/src/com/p4square/grow/backend/resources/SurveyResource.java
+++ b/src/com/p4square/grow/backend/resources/SurveyResource.java
@@ -4,9 +4,13 @@
package com.p4square.grow.backend.resources;
+import java.io.IOException;
+
import java.util.Map;
import java.util.HashMap;
+import org.codehaus.jackson.map.ObjectMapper;
+
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.resource.ServerResource;
@@ -24,7 +28,9 @@ import com.p4square.grow.backend.db.CassandraDatabase;
* @author Jesse Morgan <jesse@jesterpm.net>
*/
public class SurveyResource extends ServerResource {
- private final static Logger cLog = Logger.getLogger(SurveyResource.class);
+ private static final Logger LOG = Logger.getLogger(SurveyResource.class);
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
private CassandraDatabase mDb;
@@ -45,16 +51,24 @@ public class SurveyResource extends ServerResource {
*/
@Override
protected Representation get() {
- String result = "";
+ String result = "{}";
if (mQuestionId == null) {
// TODO: List all question ids
} else if (mQuestionId.equals("first")) {
- // TODO: Get the first question id from db?
- result = "1";
+ // Get the first question id from db?
+ Map<?, ?> questionSummary = getQuestionsSummary();
+ mQuestionId = (String) questionSummary.get("first");
+
+ } else if (mQuestionId.equals("count")) {
+ // Get the first question id from db?
+ Map<?, ?> questionSummary = getQuestionsSummary();
- } else {
+ return new StringRepresentation(String.valueOf((Integer) questionSummary.get("count")));
+ }
+
+ if (mQuestionId != null) {
// Get a question by id
result = mDb.getKey("strings", "/questions/" + mQuestionId);
@@ -67,4 +81,19 @@ public class SurveyResource extends ServerResource {
return new StringRepresentation(result);
}
+
+ private Map<?, ?> getQuestionsSummary() {
+ try {
+ String json = mDb.getKey("strings", "/questions");
+
+ if (json != null) {
+ return MAPPER.readValue(json, Map.class);
+ }
+
+ } catch (IOException e) {
+ LOG.info("Exception reading questions summary.", e);
+ }
+
+ return null;
+ }
}