From 64c13e3235e32344a0c7c5febbefe802e9102ace Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 10 Sep 2013 00:06:54 -0700 Subject: Adding redirect page /account. /account redirects to either the assessment or the training page, as appropriate. This change adds the /accounts/UID backend resource, which simply stores an arbitrary json document for now. --- .../p4square/grow/frontend/SurveyPageResource.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (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 b6c53f5..4d87027 100644 --- a/src/com/p4square/grow/frontend/SurveyPageResource.java +++ b/src/com/p4square/grow/frontend/SurveyPageResource.java @@ -195,6 +195,24 @@ public class SurveyPageResource extends FreeMarkerPageResource { } } + private Map getAccount(String id) { + try { + Map account = null; + + JsonResponse response = backendGet("/accounts/" + id); + if (!response.getStatus().isSuccess()) { + return null; + } + account = response.getMap(); + + return account; + + } catch (ClientException e) { + LOG.warn("Error fetching account.", e); + return null; + } + } + private Map getQuestion(String id) { try { Map questionData = null; @@ -217,6 +235,14 @@ public class SurveyPageResource extends FreeMarkerPageResource { String nextQuestionId = (String) questionData.get("nextQuestion"); if (nextQuestionId == null) { + // Just finished the last question. Update the user's account + Map account = getAccount(mUserId); + if (account == null) { + account = new HashMap(); + } + account.put("landing", "training"); + backendPut("/accounts/" + mUserId, account); + String nextPage = mConfig.getString("dynamicRoot", ""); nextPage += "/account/assessment/results"; getResponse().redirectSeeOther(nextPage); -- cgit v1.2.3