summaryrefslogtreecommitdiff
path: root/src/com/p4square
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/p4square')
-rw-r--r--src/com/p4square/grow/frontend/ChapterCompletePage.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/com/p4square/grow/frontend/ChapterCompletePage.java b/src/com/p4square/grow/frontend/ChapterCompletePage.java
index b3896e9..a2c4ebe 100644
--- a/src/com/p4square/grow/frontend/ChapterCompletePage.java
+++ b/src/com/p4square/grow/frontend/ChapterCompletePage.java
@@ -4,6 +4,7 @@
package com.p4square.grow.frontend;
+import java.util.Date;
import java.util.Map;
import freemarker.template.Template;
@@ -22,10 +23,14 @@ import com.p4square.fmfacade.json.JsonRequestClient;
import com.p4square.fmfacade.json.JsonResponse;
import com.p4square.fmfacade.json.ClientException;
+import com.p4square.f1oauth.Attribute;
+import com.p4square.f1oauth.F1API;
+import com.p4square.f1oauth.F1User;
+
import com.p4square.grow.config.Config;
import com.p4square.grow.model.TrainingRecord;
-import com.p4square.grow.provider.TrainingRecordProvider;
import com.p4square.grow.provider.Provider;
+import com.p4square.grow.provider.TrainingRecordProvider;
/**
* This resource displays the transitional page between chapters.
@@ -93,6 +98,9 @@ public class ChapterCompletePage extends FreeMarkerPageResource {
return new StringRepresentation("Redirecting to " + nextPage);
}
+ // Publish the training chapter complete attribute.
+ assignAttribute();
+
// Find the next chapter
String nextChapter = null;
{
@@ -149,6 +157,32 @@ public class ChapterCompletePage extends FreeMarkerPageResource {
}
}
+ private void assignAttribute() {
+ if (!(getRequest().getClientInfo().getUser() instanceof F1User)) {
+ // Only useful if the user is from F1.
+ return;
+ }
+
+ F1User user = (F1User) getRequest().getClientInfo().getUser();
+
+ // Update the attribute.
+ String attributeName = "Training Complete - " + mChapter;
+
+ try {
+ Attribute attribute = new Attribute();
+ attribute.setStartDate(new Date());
+
+ F1API f1 = mGrowFrontend.getF1Access().getAuthenticatedApi(user);
+ if (!f1.addAttribute(user.getIdentifier(), attributeName, attribute)) {
+ LOG.error("addAttribute failed for " + user.getIdentifier()
+ + " with attribute " + attributeName);
+ }
+ } catch (Exception e) {
+ LOG.error("addAttribute failed for " + user.getIdentifier()
+ + " with attribute " + attributeName, e);
+ }
+ }
+
/**
* @return The backend endpoint URI
*/