summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-08-28 07:34:22 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-08-28 07:34:22 -0700
commit66469ff2f76ac916e289e066377570b38554fdcc (patch)
tree98c576775605bb46b012cc28646ca023f38da319 /src
parent6eba410e5eb53ee887e430f4f98ba03ffaa2a474 (diff)
Rough outline of the F1 attribute logic.
Parts of addAttribute have been implemented in F1User, but I may move it out into a general F1 API class.
Diffstat (limited to 'src')
-rw-r--r--src/com/p4square/f1oauth/F1OAuthHelper.java7
-rw-r--r--src/com/p4square/f1oauth/F1User.java72
-rw-r--r--src/com/p4square/f1oauth/SecondPartyVerifier.java2
-rw-r--r--src/com/p4square/grow/frontend/AssessmentResultsPage.java14
4 files changed, 93 insertions, 2 deletions
diff --git a/src/com/p4square/f1oauth/F1OAuthHelper.java b/src/com/p4square/f1oauth/F1OAuthHelper.java
index b5241c4..187fb6b 100644
--- a/src/com/p4square/f1oauth/F1OAuthHelper.java
+++ b/src/com/p4square/f1oauth/F1OAuthHelper.java
@@ -66,6 +66,13 @@ public class F1OAuthHelper extends OAuthHelper {
}
/**
+ * @return The base url for the F1 API, ending with a slash.
+ */
+ public String getBaseUrl() {
+ return mBaseUrl;
+ }
+
+ /**
* @return the URL for the initial RequestToken request.
*/
protected String getRequestTokenUrl() {
diff --git a/src/com/p4square/f1oauth/F1User.java b/src/com/p4square/f1oauth/F1User.java
index e5ab487..942f534 100644
--- a/src/com/p4square/f1oauth/F1User.java
+++ b/src/com/p4square/f1oauth/F1User.java
@@ -19,6 +19,7 @@ public class F1User extends OAuthUser {
public static final String LAST_NAME = "lastName";
public static final String ICODE = "@iCode";
+ private final String mBaseUrl;
private final Map mData;
/**
@@ -28,9 +29,10 @@ public class F1User extends OAuthUser {
* @param data F1 Person Record.
* @throws IllegalStateException if data.get("person") is null.
*/
- public F1User(OAuthUser user, Map data) {
+ public F1User(String baseUrl, OAuthUser user, Map data) {
super(user.getLocation(), user.getToken());
+ mBaseUrl = baseUrl;
mData = (Map) data.get("person");
if (mData == null) {
throw new IllegalStateException("Bad data");
@@ -67,4 +69,72 @@ public class F1User extends OAuthUser {
public Object get(String key) {
return mData.get(key);
}
+
+ /**
+ * @return the F1 API base url.
+ */
+ public String getBaseUrl() {
+ return mBaseUrl;
+ }
+
+ /*
+ public addAttribute(Attribute attribute, String comment) {
+ String baseUrl = getBaseUrl();
+ Map newAttributeTemplate = null;
+
+ // Get Attribute Template
+ Request request = new Request(Method.GET,
+ baseUrl + "People/" + getIdentifier() + "/Attributes/new.json");
+ request.setChallengeResponse(getChallengeResponse());
+ Response response = getContext().getClientDispatcher().handle(request);
+
+ Representation representation = response.getEntity();
+ try {
+ Status status = response.getStatus();
+ if (status.isSuccess()) {
+ JacksonRepresentation<Map> entity = new JacksonRepresentation<Map>(response.getEntity(), Map.class);
+ newAttributeTemplate = entity.getObject();
+ }
+
+ } finally {
+ if (representation != null) {
+ representation.release();
+ }
+ }
+
+ if (newAttributeTemplate == null) {
+ LOG.error("Could not retrieve attribute template!");
+ return;
+ }
+
+ // Populate Attribute Template
+
+
+ // POST new attribute
+ Request request = new Request(Method.POST,
+ baseUrl + "People/" + getIdentifier() + "/Attributes.json");
+ request.setChallengeResponse(getChallengeResponse());
+ Response response = getContext().getClientDispatcher().handle(request);
+
+ Representation representation = response.getEntity();
+ try {
+ Status status = response.getStatus();
+ if (status.isSuccess()) {
+ JacksonRepresentation<Map> entity = new JacksonRepresentation<Map>(response.getEntity(), Map.class);
+ newAttributeTemplate = entity.getObject();
+ }
+
+ } finally {
+ if (representation != null) {
+ representation.release();
+ }
+ }
+
+ if (newAttributeTemplate == null) {
+ LOG.error("Could retrieve attribute template!");
+ return;
+ }
+
+ }
+ */
}
diff --git a/src/com/p4square/f1oauth/SecondPartyVerifier.java b/src/com/p4square/f1oauth/SecondPartyVerifier.java
index b1afcfa..9fb771f 100644
--- a/src/com/p4square/f1oauth/SecondPartyVerifier.java
+++ b/src/com/p4square/f1oauth/SecondPartyVerifier.java
@@ -79,7 +79,7 @@ public class SecondPartyVerifier implements Verifier {
if (status.isSuccess()) {
JacksonRepresentation<Map> entity = new JacksonRepresentation<Map>(response.getEntity(), Map.class);
Map data = entity.getObject();
- return new F1User(user, data);
+ return new F1User(mHelper.getBaseUrl(), user, data);
} else {
throw new OAuthException(status);
diff --git a/src/com/p4square/grow/frontend/AssessmentResultsPage.java b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
index 9c69c69..95c3f6a 100644
--- a/src/com/p4square/grow/frontend/AssessmentResultsPage.java
+++ b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
@@ -82,6 +82,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 +95,17 @@ 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();
+
+ // TODO: Update the attribute.
+ }
+
/**
* @return The backend endpoint URI
*/