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. --- src/com/p4square/grow/backend/GrowBackend.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/com/p4square/grow/backend/GrowBackend.java') diff --git a/src/com/p4square/grow/backend/GrowBackend.java b/src/com/p4square/grow/backend/GrowBackend.java index 533cf09..45e0fa2 100644 --- a/src/com/p4square/grow/backend/GrowBackend.java +++ b/src/com/p4square/grow/backend/GrowBackend.java @@ -15,6 +15,13 @@ import org.restlet.routing.Router; import com.p4square.grow.config.Config; import com.p4square.grow.backend.db.CassandraDatabase; +import com.p4square.grow.backend.db.CassandraKey; +import com.p4square.grow.backend.db.CassandraProviderImpl; + +import com.p4square.grow.model.Question; + +import com.p4square.grow.provider.Provider; +import com.p4square.grow.provider.QuestionProvider; import com.p4square.grow.backend.resources.AccountResource; import com.p4square.grow.backend.resources.BannerResource; @@ -29,11 +36,15 @@ import com.p4square.grow.backend.resources.TrainingResource; * @author Jesse Morgan */ public class GrowBackend extends Application { + private static final String DEFAULT_COLUMN = "value"; + private final static Logger LOG = Logger.getLogger(GrowBackend.class); private final Config mConfig; private final CassandraDatabase mDatabase; + private final Provider mQuestionProvider; + public GrowBackend() { this(new Config()); } @@ -41,6 +52,13 @@ public class GrowBackend extends Application { public GrowBackend(Config config) { mConfig = config; mDatabase = new CassandraDatabase(); + + mQuestionProvider = new QuestionProvider(new CassandraProviderImpl(mDatabase, "strings", Question.class)) { + @Override + public CassandraKey makeKey(String questionId) { + return new CassandraKey("/questions/" + questionId, DEFAULT_COLUMN); + } + }; } @Override @@ -102,6 +120,10 @@ public class GrowBackend extends Application { return mDatabase; } + public Provider getQuestionProvider() { + return mQuestionProvider; + } + /** * Stand-alone main for testing. */ -- cgit v1.2.3