summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/frontend/SurveyPageResource.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-10-20 23:14:51 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-10-20 23:14:51 -0700
commite472550fe154f0afa5b36d2a7e2334d4680d7884 (patch)
tree8131e3fa7db162f9a072ef4d89e7fb25d338cdd4 /src/com/p4square/grow/frontend/SurveyPageResource.java
parent31303114ef03b13ab320ee553f11a73346be7f4a (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.java25
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 8d89bb8..803dfc4 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 net.jesterpm.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;
}