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
commit6008c965642f4d420f64d0df449bc627b78963c7 (patch)
tree136207c4b02b1e946f065ed1430ca967e678122e /src/com/p4square/grow/backend/resources/SurveyResource.java
parenteb881fdc9b62d1b9d1f5c61f1f4077065db7e933 (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;
+ }
}