diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2013-10-20 23:14:51 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2013-10-20 23:14:51 -0700 |
commit | e77c9b418fdfb935ff8e99f10f607a4bbd7e1c8c (patch) | |
tree | 9005f8c0e3b18f853fb8093b01f6aad64949bc13 /src/com/p4square/grow/frontend/SurveyPageResource.java | |
parent | 5037f4797461649994068d97a8433b6cd793c523 (diff) |
First stage of a major refactoring.
Question and Answer can now be serialized and deserialized to/from JSON.
As such, I no longer have to pass awkward maps around. As part of this
change I have introduced a Provider interface to abstract out loading
and persisting these beans.
The scoring logic has been completed factored out of
SurveyResultsResource and into the various ScoringEngines. Tests have
been added for Question, Answer, and the ScoringEngines. A bug has been
fixed in computing the value for slider questions.
The label identifiers in the circle questions have changed from all
lower case to camel case. That is, topleft is now topLeft. Several
issues have been corrected in the circle answers where the point values
did not match the labels.
Testing and code coverage support and reports have been added.
Diffstat (limited to 'src/com/p4square/grow/frontend/SurveyPageResource.java')
-rw-r--r-- | src/com/p4square/grow/frontend/SurveyPageResource.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/com/p4square/grow/frontend/SurveyPageResource.java b/src/com/p4square/grow/frontend/SurveyPageResource.java index 415b46c..f864014 100644 --- a/src/com/p4square/grow/frontend/SurveyPageResource.java +++ b/src/com/p4square/grow/frontend/SurveyPageResource.java @@ -4,6 +4,8 @@ package com.p4square.grow.frontend; +import java.io.IOException; + import java.util.Map; import java.util.HashMap; @@ -27,6 +29,8 @@ import com.p4square.fmfacade.FreeMarkerPageResource; import com.p4square.grow.config.Config; import com.p4square.grow.model.Question; +import com.p4square.grow.provider.QuestionProvider; +import com.p4square.grow.provider.Provider; /** * SurveyPageResource handles rendering the survey and processing user's answers. @@ -44,6 +48,7 @@ public class SurveyPageResource extends FreeMarkerPageResource { private Config mConfig; private Template mSurveyTemplate; private JsonRequestClient mJsonClient; + private Provider<String, Question> mQuestionProvider; // Fields pertaining to this request. private String mQuestionId; @@ -62,6 +67,12 @@ public class SurveyPageResource extends FreeMarkerPageResource { } mJsonClient = new JsonRequestClient(getContext().getClientDispatcher()); + mQuestionProvider = new QuestionProvider<String>(new JsonRequestProvider<Question>(getContext().getClientDispatcher(), Question.class)) { + @Override + public String makeKey(String questionId) { + return getBackendEndpoint() + "/assessment/question/" + questionId; + } + }; mQuestionId = getAttribute("questionId"); mUserId = getRequest().getClientInfo().getUser().getIdentifier(); @@ -102,7 +113,7 @@ public class SurveyPageResource extends FreeMarkerPageResource { String selectedAnswer = getAnswer(mQuestionId); Map root = getRootObject(); - root.put("question", question.getMap()); + root.put("question", question); root.put("selectedAnswerId", selectedAnswer); // Get the question count and compute progress @@ -214,17 +225,9 @@ public class SurveyPageResource extends FreeMarkerPageResource { private Question getQuestion(String id) { try { - Map<?, ?> questionData = null; - - JsonResponse response = backendGet("/assessment/question/" + id); - if (!response.getStatus().isSuccess()) { - return null; - } - questionData = response.getMap(); + return mQuestionProvider.get(id); - return new Question((Map<String, Object>) questionData); - - } catch (ClientException e) { + } catch (IOException e) { LOG.warn("Error fetching question.", e); return null; } |