summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/frontend/AssessmentResultsPage.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-09-22 06:40:21 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-09-22 06:40:21 -0700
commitdd4f34e216132e3a066566daf30a6f1fc1e1b872 (patch)
tree8c9e2ac3b30f207e7945dfe5f885101a6dcee995 /src/com/p4square/grow/frontend/AssessmentResultsPage.java
parent6eba410e5eb53ee887e430f4f98ba03ffaa2a474 (diff)
parent3e703186928c5bd8f2c31f90b1c6e262c4080328 (diff)
Merge branch 'f1-attributes'
Diffstat (limited to 'src/com/p4square/grow/frontend/AssessmentResultsPage.java')
-rw-r--r--src/com/p4square/grow/frontend/AssessmentResultsPage.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/com/p4square/grow/frontend/AssessmentResultsPage.java b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
index 9c69c69..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,7 +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
@@ -82,6 +88,9 @@ public class AssessmentResultsPage extends FreeMarkerPageResource {
return new StringRepresentation("Redirecting to " + nextPage);
}
+ // Publish results in F1
+ publishScoreInF1(response.getMap());
+
root.put("stage", score);
return new TemplateRepresentation(t, root, MediaType.TEXT_HTML);
@@ -92,6 +101,33 @@ public class AssessmentResultsPage extends FreeMarkerPageResource {
}
}
+ private void publishScoreInF1(Map results) {
+ 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 = "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);
+ }
+ }
+
/**
* @return The backend endpoint URI
*/
@@ -108,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;