summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/f1oauth/F1ProgressReporter.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-04-09 15:53:24 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-04-09 15:53:24 -0700
commit371ccae3d1f31ec38f4af77fb7fcd175d49b3cd5 (patch)
tree38c4f1e8828f9af9c4b77a173bee0d312b321698 /src/main/java/com/p4square/f1oauth/F1ProgressReporter.java
parentbbf907e51dfcf157bdee24dead1d531122aa25db (diff)
parent3102d8bce3426d9cf41aeaf201c360d342677770 (diff)
Merge pull request #10 from PuyallupFoursquare/maven
Switching from Ivy+Ant to Maven.
Diffstat (limited to 'src/main/java/com/p4square/f1oauth/F1ProgressReporter.java')
-rw-r--r--src/main/java/com/p4square/f1oauth/F1ProgressReporter.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/f1oauth/F1ProgressReporter.java b/src/main/java/com/p4square/f1oauth/F1ProgressReporter.java
new file mode 100644
index 0000000..8382020
--- /dev/null
+++ b/src/main/java/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);
+ }
+ }
+}