diff options
Diffstat (limited to 'src/com/p4square/grow/frontend')
| -rw-r--r-- | src/com/p4square/grow/frontend/ErrorPage.java | 3 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/TrainingPageResource.java | 69 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/VideosResource.java | 15 | 
3 files changed, 19 insertions, 68 deletions
| diff --git a/src/com/p4square/grow/frontend/ErrorPage.java b/src/com/p4square/grow/frontend/ErrorPage.java index b57cc49..721b477 100644 --- a/src/com/p4square/grow/frontend/ErrorPage.java +++ b/src/com/p4square/grow/frontend/ErrorPage.java @@ -31,6 +31,9 @@ public class ErrorPage extends WriterRepresentation {      public static final ErrorPage RENDER_ERROR =          new ErrorPage("Error rendering page."); +    public static final ErrorPage BACKEND_ERROR = +        new ErrorPage("Error communicating with backend."); +      private static Template cTemplate = null;      private final String mMessage; diff --git a/src/com/p4square/grow/frontend/TrainingPageResource.java b/src/com/p4square/grow/frontend/TrainingPageResource.java index 6c89ac9..6615295 100644 --- a/src/com/p4square/grow/frontend/TrainingPageResource.java +++ b/src/com/p4square/grow/frontend/TrainingPageResource.java @@ -65,7 +65,7 @@ public class TrainingPageResource extends FreeMarkerPageResource {      }      /** -     * Return a page with a survey question. +     * Return a page of videos.       */      @Override      protected Representation get() { @@ -121,76 +121,11 @@ public class TrainingPageResource extends FreeMarkerPageResource {          } catch (Exception e) {              cLog.fatal("Could not render page: " + e.getMessage(), e);              setStatus(Status.SERVER_ERROR_INTERNAL); -            return null; +            return ErrorPage.RENDER_ERROR;          }      }      /** -     * Record a survey answer and redirect to the next question. -     */ -    @Override -    protected Representation post(Representation entity) { -        return null; -        /*final Form form = new Form(entity); -        final String answerId = form.getFirstValue("answer"); - -        if (mQuestionId == null || answerId == null || answerId.length() == 0) { -            // Something is wrong. -            setStatus(Status.CLIENT_ERROR_BAD_REQUEST); -            return null; -        } - -        try { -            // Find the question -            Map questionData = null; -            { -                JsonResponse response = backendGet("/assessment/question/" + mQuestionId); -                if (!response.getStatus().isSuccess()) { -                    // User is answering a question which doesn't exist -                    setStatus(Status.CLIENT_ERROR_NOT_FOUND); -                    return null; -                } - -                questionData = response.getMap(); -            } - -            // Store answer -            { -                Map<String, String> answer = new HashMap<String, String>(); -                answer.put("answerId", answerId); -                JsonResponse response = backendPut("/accounts/" + mUserId + -                        "/assessment/answers/" + mQuestionId, answer); - -                if (!response.getStatus().isSuccess()) { -                    // Something went wrong talking to the backend, error out. -                    cLog.fatal("Error recording survey answer " + response.getStatus()); -                    setStatus(Status.SERVER_ERROR_INTERNAL); -                    return null; -                } -            } - -            // Find the next question or finish the assessment. -            String nextPage = mConfig.getString("dynamicRoot", ""); -            { -                String nextQuestionId = (String) questionData.get("nextQuestion"); -                if (nextQuestionId == null) { -                    nextPage += "/account/assessment/results"; -                } else { -                    nextPage += "/account/assessment/question/" + nextQuestionId; -                } -            } - -            getResponse().redirectSeeOther(nextPage); -            return null; - -        } catch (Exception e) { -            cLog.fatal("Could not render page: " + e.getMessage(), e); -            setStatus(Status.SERVER_ERROR_INTERNAL); -            return null; -        }*/ -    } - -    /**       * @return The backend endpoint URI       */      private String getBackendEndpoint() { diff --git a/src/com/p4square/grow/frontend/VideosResource.java b/src/com/p4square/grow/frontend/VideosResource.java index fed315b..e85ecd4 100644 --- a/src/com/p4square/grow/frontend/VideosResource.java +++ b/src/com/p4square/grow/frontend/VideosResource.java @@ -4,6 +4,7 @@  package com.p4square.grow.frontend; +import java.util.HashMap;  import java.util.Map;  import freemarker.template.Template; @@ -62,7 +63,7 @@ public class VideosResource extends ServerResource {              JsonResponse response = backendGet("/training/" + mChapter + "/videos/" + mVideoId);              if (response.getStatus().isSuccess()) { -                return new JacksonRepresentation<Map>(response.getMap());  +                return new JacksonRepresentation<Map>(response.getMap());              } else {                  setStatus(response.getStatus()); @@ -81,6 +82,18 @@ public class VideosResource extends ServerResource {       */      @Override      protected Representation post(Representation entity) { +        Map<String, Object> data = new HashMap<String, Object>(); +        data.put("completed", "t"); +        JsonResponse response = backendPut("/accounts/" + mUserId + "/training/videos/" + mVideoId, data); + +        if (!response.getStatus().isSuccess()) { +            // Something went wrong talking to the backend, error out. +            cLog.fatal("Error recording completed video " + response.getStatus()); +            setStatus(Status.SERVER_ERROR_INTERNAL); +            return ErrorPage.BACKEND_ERROR; +        } + +        setStatus(Status.SUCCESS_NO_CONTENT);          return null;      } | 
