summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/frontend
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-09-21 15:01:40 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-09-21 15:01:40 -0700
commitd01b3c8e49251c85cfa9c426064b841233c6c8e4 (patch)
tree755dbbf4ecc373b84f55f81d9de83e7d03454c49 /src/com/p4square/grow/frontend
parentc2feb363e513c0dea83d507eb9ba1918748d4e8e (diff)
Adding Support for Assigning Attributes in F1.
Adding a new interface, F1API for F1 APIs which require a valid access token. This is now used by AssessmentResultsPage to assign an attribute each time someone completes the assessment. Also adding an AttributeTool to list all attributes and assign attributes to users.
Diffstat (limited to 'src/com/p4square/grow/frontend')
-rw-r--r--src/com/p4square/grow/frontend/AssessmentResultsPage.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/com/p4square/grow/frontend/AssessmentResultsPage.java b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
index c205503..ff1832c 100644
--- a/src/com/p4square/grow/frontend/AssessmentResultsPage.java
+++ b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
@@ -4,6 +4,7 @@
package com.p4square.grow.frontend;
+import java.util.Date;
import java.util.Map;
import freemarker.template.Template;
@@ -22,9 +23,12 @@ 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.provider.JsonEncodedProvider;
/**
* This page fetches the user's final score and displays the transitional page between
@@ -105,7 +109,23 @@ public class AssessmentResultsPage extends FreeMarkerPageResource {
F1User user = (F1User) getRequest().getClientInfo().getUser();
- // TODO: Update the attribute.
+ // Update the attribute.
+ String attributeName = "Assessment Complete - " + results.get("result");
+
+ try {
+ Attribute attribute = new Attribute();
+ attribute.setStartDate(new Date());
+ attribute.setComment(JsonEncodedProvider.MAPPER.writeValueAsString(results));
+
+ 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);
+ }
}
/**
@@ -124,7 +144,8 @@ public class AssessmentResultsPage extends FreeMarkerPageResource {
final JsonResponse response = mJsonClient.get(getBackendEndpoint() + uri);
final Status status = response.getStatus();
if (!status.isSuccess() && !Status.CLIENT_ERROR_NOT_FOUND.equals(status)) {
- LOG.warn("Error making backend request for '" + uri + "'. status = " + response.getStatus().toString());
+ LOG.warn("Error making backend request for '" + uri + "'. status = "
+ + response.getStatus().toString());
}
return response;