From e77c9b418fdfb935ff8e99f10f607a4bbd7e1c8c Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 20 Oct 2013 23:14:51 -0700 Subject: 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. --- .../p4square/grow/frontend/SurveyPageResource.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/com/p4square/grow/frontend/SurveyPageResource.java') 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 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(new JsonRequestProvider(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) questionData); - - } catch (ClientException e) { + } catch (IOException e) { LOG.warn("Error fetching question.", e); return null; } -- cgit v1.2.3