diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2013-08-04 16:09:29 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2013-08-04 16:09:29 -0700 |
commit | 52539d7aaba96b7997a3c5a07e4a1ad234af7d04 (patch) | |
tree | 2686f56bc37656c0824a05e28472f7334ed39028 /src/com/p4square/grow/backend/resources/SurveyResource.java | |
parent | 69e2512750dd75fce43a21226979996c3cd7da1d (diff) |
Committing everything since its long overdue.
Diffstat (limited to 'src/com/p4square/grow/backend/resources/SurveyResource.java')
-rw-r--r-- | src/com/p4square/grow/backend/resources/SurveyResource.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/p4square/grow/backend/resources/SurveyResource.java b/src/com/p4square/grow/backend/resources/SurveyResource.java new file mode 100644 index 0000000..d22d763 --- /dev/null +++ b/src/com/p4square/grow/backend/resources/SurveyResource.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.grow.backend.resources; + +import java.util.Map; +import java.util.HashMap; + +import org.restlet.data.MediaType; +import org.restlet.data.Status; +import org.restlet.resource.ServerResource; +import org.restlet.representation.Representation; +import org.restlet.representation.StringRepresentation; + +import org.apache.log4j.Logger; + +import com.p4square.grow.backend.GrowBackend; +import com.p4square.grow.backend.db.CassandraDatabase; + +/** + * This resource manages assessment questions. + * + * @author Jesse Morgan <jesse@jesterpm.net> + */ +public class SurveyResource extends ServerResource { + private final static Logger cLog = Logger.getLogger(SurveyResource.class); + + private CassandraDatabase mDb; + + private String mQuestionId; + + @Override + public void doInit() { + super.doInit(); + + final GrowBackend backend = (GrowBackend) getApplication(); + mDb = backend.getDatabase(); + + mQuestionId = getAttribute("questionId"); + } + + /** + * Handle GET Requests. + */ + @Override + protected Representation get() { + 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"; + + } else { + // Get a question by id + result = mDb.getKey("strings", "/questions/" + mQuestionId); + + if (result == null) { + // 404 + setStatus(Status.CLIENT_ERROR_NOT_FOUND); + return null; + } + } + + return new StringRepresentation(result); + } +} |