diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2013-09-17 22:28:51 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2013-09-17 22:28:51 -0700 |
commit | e931adb3c50e55e5b6af89d411bf9a7be950f69a (patch) | |
tree | 57774a79de369ef6963b52cdb074f534c4b4a926 /src/com/p4square/grow/backend/resources | |
parent | 45202b50ece500430d9e560208b08a8283f76b96 (diff) |
Fixing question 4 to skip 4a in some cases.
For this fix I am moving Question and Answer from the backend into a new
model package. Question is now used in SurveyPageResource instead of the
Map. Eventually I should encode/decode the model from the json directly.
I am adding support to the Question model to find the next question
based on the answer to the current question. If the answer has a
specific nextQuestion field, that is used. Otherwise the question's
nextQuestion field is used. This is to facilitate skipping irrelevant
questions.
Diffstat (limited to 'src/com/p4square/grow/backend/resources')
3 files changed, 2 insertions, 129 deletions
diff --git a/src/com/p4square/grow/backend/resources/Answer.java b/src/com/p4square/grow/backend/resources/Answer.java deleted file mode 100644 index 5ba1bce..0000000 --- a/src/com/p4square/grow/backend/resources/Answer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2013 Jesse Morgan - */ - -package com.p4square.grow.backend.resources; - -import java.util.Map; - -/** - * This is the model of an assessment question's answer. - * - * @author Jesse Morgan <jesse@jesterpm.net> - */ -class Answer { - public static enum ScoreType { - NONE, AVERAGE, TRUMP; - } - - private final String mAnswerId; - private final String mAnswerText; - private final ScoreType mType; - private final float mScoreFactor; - - public Answer(final String id, final Map<String, Object> answer) { - mAnswerId = id; - mAnswerText = (String) answer.get("text"); - final String typeStr = (String) answer.get("type"); - if (typeStr == null) { - mType = ScoreType.AVERAGE; - } else { - mType = ScoreType.valueOf(typeStr.toUpperCase()); - } - - if (mType != ScoreType.NONE) { - mScoreFactor = Float.valueOf((String) answer.get("score")); - } else { - mScoreFactor = 0; - } - - } - - public String getId() { - return mAnswerId; - } - - public String getText() { - return mAnswerText; - } - - public ScoreType getType() { - return mType; - } - - public float getScoreFactor() { - return mScoreFactor; - } -} diff --git a/src/com/p4square/grow/backend/resources/Question.java b/src/com/p4square/grow/backend/resources/Question.java deleted file mode 100644 index e90ca77..0000000 --- a/src/com/p4square/grow/backend/resources/Question.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2013 Jesse Morgan - */ - -package com.p4square.grow.backend.resources; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * Model of an assessment question. - * - * @author Jesse Morgan <jesse@jesterpm.net> - */ -class Question { - public static enum QuestionType { - TEXT, IMAGE, SLIDER, QUAD, CIRCLE; - } - - private final String mQuestionId; - private final QuestionType mType; - private final String mQuestionText; - private Map<String, Answer> mAnswers; - - private final String mPreviousQuestionId; - private final String mNextQuestionId; - - public Question(final Map<String, Object> map) { - mQuestionId = (String) map.get("id"); - mType = QuestionType.valueOf(((String) map.get("type")).toUpperCase()); - - mQuestionText = (String) map.get("text"); - - mPreviousQuestionId = (String) map.get("previousQuestion"); - mNextQuestionId = (String) map.get("nextQuestion"); - - mAnswers = new HashMap<String, Answer>(); - for (Map.Entry<String, Object> answer : - ((Map<String, Object>) map.get("answers")).entrySet()) { - - final String id = answer.getKey(); - final Map<String, Object> answerMap = (Map<String, Object>) answer.getValue(); - final Answer answerObj = new Answer(id, answerMap); - mAnswers.put(id, answerObj); - } - } - - public String getId() { - return mQuestionId; - } - - public QuestionType getType() { - return mType; - } - - public String getText() { - return mQuestionText; - } - - public String getPrevious() { - return mPreviousQuestionId; - } - - public String getNext() { - return mNextQuestionId; - } - - public Map<String, Answer> getAnswers() { - return Collections.unmodifiableMap(mAnswers); - } -} diff --git a/src/com/p4square/grow/backend/resources/SurveyResultsResource.java b/src/com/p4square/grow/backend/resources/SurveyResultsResource.java index e93e253..208fa2e 100644 --- a/src/com/p4square/grow/backend/resources/SurveyResultsResource.java +++ b/src/com/p4square/grow/backend/resources/SurveyResultsResource.java @@ -20,6 +20,8 @@ import org.restlet.representation.StringRepresentation; import org.apache.log4j.Logger; +import com.p4square.grow.model.Answer; +import com.p4square.grow.model.Question; import com.p4square.grow.backend.GrowBackend; import com.p4square.grow.backend.db.CassandraDatabase; |