summaryrefslogtreecommitdiff
path: root/src/com/p4square
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-03-21 22:16:52 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-03-21 22:16:52 -0700
commitab52d26e4c0e3d939e681020c7c2cc3d14d4b595 (patch)
treeafe30fbc36e615e3a99d11510889274feda30085 /src/com/p4square
parentfa349e54a0f854534b1e02d31d91832cc2013c79 (diff)
Introducing the ProgressReporter interface.
A ProgressReporter will be used to record progress in the ChMS. The F1 version in complete, but needs to be plugged into AssessmentResultPage and ChapterCompletePage.
Diffstat (limited to 'src/com/p4square')
-rw-r--r--src/com/p4square/f1oauth/F1ProgressReporter.java57
-rw-r--r--src/com/p4square/grow/frontend/ProgressReporter.java29
2 files changed, 86 insertions, 0 deletions
diff --git a/src/com/p4square/f1oauth/F1ProgressReporter.java b/src/com/p4square/f1oauth/F1ProgressReporter.java
new file mode 100644
index 0000000..8382020
--- /dev/null
+++ b/src/com/p4square/f1oauth/F1ProgressReporter.java
@@ -0,0 +1,57 @@
+package com.p4square.f1oauth;
+
+import com.p4square.grow.frontend.ProgressReporter;
+import org.apache.log4j.Logger;
+import org.restlet.security.User;
+
+import java.util.Date;
+
+/**
+ * A ProgressReporter implementation to record progress in F1.
+ */
+public class F1ProgressReporter implements ProgressReporter {
+
+ private static final Logger LOG = Logger.getLogger(F1ProgressReporter.class);
+
+ private F1Access mF1Access;
+
+ public F1ProgressReporter(final F1Access f1access) {
+ mF1Access = f1access;
+ }
+
+ @Override
+ public void reportAssessmentComplete(final User user, final String level, final Date date, final String results) {
+ String attributeName = "Assessment Complete - " + level;
+ Attribute attribute = new Attribute(attributeName);
+ attribute.setStartDate(date);
+ attribute.setComment(results);
+ addAttribute(user, attribute);
+ }
+
+ @Override
+ public void reportChapterComplete(final User user, final String chapter, final Date date) {
+ final String attributeName = "Training Complete - " + chapter;
+ final Attribute attribute = new Attribute(attributeName);
+ attribute.setStartDate(date);
+ addAttribute(user, attribute);
+ }
+
+ private void addAttribute(final User user, final Attribute attribute) {
+ if (!(user instanceof F1User)) {
+ throw new IllegalArgumentException("User must be an F1User, but got " + user.getClass().getName());
+ }
+
+ try {
+ final F1User f1User = (F1User) user;
+ final F1API f1 = mF1Access.getAuthenticatedApi(f1User);
+
+ if (!f1.addAttribute(user.getIdentifier(), attribute)) {
+ LOG.error("addAttribute failed for " + user.getIdentifier() + " with attribute "
+ + attribute.getAttributeName());
+ }
+ } catch (Exception e) {
+ LOG.error("addAttribute failed for " + user.getIdentifier() + " with attribute "
+ + attribute.getAttributeName(), e);
+ }
+ }
+}
diff --git a/src/com/p4square/grow/frontend/ProgressReporter.java b/src/com/p4square/grow/frontend/ProgressReporter.java
new file mode 100644
index 0000000..9b57ff4
--- /dev/null
+++ b/src/com/p4square/grow/frontend/ProgressReporter.java
@@ -0,0 +1,29 @@
+package com.p4square.grow.frontend;
+
+import org.restlet.security.User;
+
+import java.util.Date;
+
+/**
+ * A ProgressReporter is used to record a User's progress in a Church Management System.
+ */
+public interface ProgressReporter {
+
+ /**
+ * Report that the User completed the assessment.
+ *
+ * @param user The user who completed the assessment.
+ * @param level The assessment level.
+ * @param date The completion date.
+ * @param results Result information (e.g. json of the results).
+ */
+ void reportAssessmentComplete(User user, String level, Date date, String results);
+
+ /**
+ *
+ * @param user The user who completed the chapter.
+ * @param chapter The chatper completed.
+ * @param date Teh completion date.
+ */
+ void reportChapterComplete(User user, String chapter, Date date);
+}