From 52539d7aaba96b7997a3c5a07e4a1ad234af7d04 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 4 Aug 2013 16:09:29 -0700 Subject: Committing everything since its long overdue. --- .../grow/backend/resources/SurveyResource.java | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/com/p4square/grow/backend/resources/SurveyResource.java (limited to 'src/com/p4square/grow/backend/resources/SurveyResource.java') 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 + */ +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); + } +} -- cgit v1.2.3