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/provider/QuestionProvider.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/com/p4square/grow/provider/QuestionProvider.java (limited to 'src/com/p4square/grow/provider/QuestionProvider.java') diff --git a/src/com/p4square/grow/provider/QuestionProvider.java b/src/com/p4square/grow/provider/QuestionProvider.java new file mode 100644 index 0000000..b569dc8 --- /dev/null +++ b/src/com/p4square/grow/provider/QuestionProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.grow.provider; + +import java.io.IOException; + +import com.p4square.grow.model.Question; + +/** + * QuestionProvider wraps an existing Provider to get and put Questions. + * + * @author Jesse Morgan + */ +public abstract class QuestionProvider implements Provider { + + private Provider mProvider; + + public QuestionProvider(Provider provider) { + mProvider = provider; + } + + @Override + public Question get(String key) throws IOException { + return mProvider.get(makeKey(key)); + } + + @Override + public void put(String key, Question obj) throws IOException { + mProvider.put(makeKey(key), obj); + } + + /** + * Make a Key for questionId. + * + * @param questionId The question id. + * @return a key for questionId. + */ + protected abstract K makeKey(String questionId); +} -- cgit v1.2.3