summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-09-27 11:05:43 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-09-27 11:05:43 -0700
commitbdf47fc7340ec2a3ecaa6b11bbf87f0f5eaaeea1 (patch)
treeb0faa7efb72587f99cd742caffcfb00d3f625cd9 /src/com/p4square/grow
parent8fa4f1fb4f122ee1e27c6015479bcd883b4b0671 (diff)
Adding support to fetch attributes for a user.
Diffstat (limited to 'src/com/p4square/grow')
-rw-r--r--src/com/p4square/grow/frontend/AssessmentResultsPage.java4
-rw-r--r--src/com/p4square/grow/frontend/ChapterCompletePage.java4
-rw-r--r--src/com/p4square/grow/tools/AttributeTool.java55
3 files changed, 52 insertions, 11 deletions
diff --git a/src/com/p4square/grow/frontend/AssessmentResultsPage.java b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
index ff1832c..2035ce8 100644
--- a/src/com/p4square/grow/frontend/AssessmentResultsPage.java
+++ b/src/com/p4square/grow/frontend/AssessmentResultsPage.java
@@ -113,12 +113,12 @@ public class AssessmentResultsPage extends FreeMarkerPageResource {
String attributeName = "Assessment Complete - " + results.get("result");
try {
- Attribute attribute = new Attribute();
+ Attribute attribute = new Attribute(attributeName);
attribute.setStartDate(new Date());
attribute.setComment(JsonEncodedProvider.MAPPER.writeValueAsString(results));
F1API f1 = mGrowFrontend.getF1Access().getAuthenticatedApi(user);
- if (!f1.addAttribute(user.getIdentifier(), attributeName, attribute)) {
+ if (!f1.addAttribute(user.getIdentifier(), attribute)) {
LOG.error("addAttribute failed for " + user.getIdentifier()
+ " with attribute " + attributeName);
}
diff --git a/src/com/p4square/grow/frontend/ChapterCompletePage.java b/src/com/p4square/grow/frontend/ChapterCompletePage.java
index a2c4ebe..f07a870 100644
--- a/src/com/p4square/grow/frontend/ChapterCompletePage.java
+++ b/src/com/p4square/grow/frontend/ChapterCompletePage.java
@@ -169,11 +169,11 @@ public class ChapterCompletePage extends FreeMarkerPageResource {
String attributeName = "Training Complete - " + mChapter;
try {
- Attribute attribute = new Attribute();
+ Attribute attribute = new Attribute(attributeName);
attribute.setStartDate(new Date());
F1API f1 = mGrowFrontend.getF1Access().getAuthenticatedApi(user);
- if (!f1.addAttribute(user.getIdentifier(), attributeName, attribute)) {
+ if (!f1.addAttribute(user.getIdentifier(), attribute)) {
LOG.error("addAttribute failed for " + user.getIdentifier()
+ " with attribute " + attributeName);
}
diff --git a/src/com/p4square/grow/tools/AttributeTool.java b/src/com/p4square/grow/tools/AttributeTool.java
index 0775087..8e0540a 100644
--- a/src/com/p4square/grow/tools/AttributeTool.java
+++ b/src/com/p4square/grow/tools/AttributeTool.java
@@ -6,6 +6,7 @@ package com.p4square.grow.tools;
import java.util.Arrays;
import java.util.Date;
+import java.util.List;
import java.util.Map;
import org.restlet.Client;
@@ -32,11 +33,13 @@ public class AttributeTool {
public static void usage() {
System.out.println("java com.p4square.grow.tools.AttributeTool <command>...\n");
System.out.println("Commands:");
- System.out.println("\t--domain <domain> Set config domain");
- System.out.println("\t--dev Set config domain to dev");
- System.out.println("\t--config <file> Merge in config file");
- System.out.println("\t--list List all attributes");
- System.out.println("\t--assign <user> <attribute> <comment> Assign an attribute");
+ System.out.println("\t--domain <domain> Set config domain");
+ System.out.println("\t--dev Set config domain to dev");
+ System.out.println("\t--config <file> Merge in config file");
+ System.out.println("\t--list List all attributes");
+ System.out.println("\t--assign <userId> <attribute> <comment> Assign an attribute");
+ System.out.println("\t--getall <userId> Get an attribute");
+ System.out.println("\t--get <userId> <attribute> Get an attribute");
}
public static void main(String... args) {
@@ -73,6 +76,12 @@ public class AttributeTool {
} else if ("--assign".equals(args[offset])) {
offset = assign(args, ++offset);
+ } else if ("--getall".equals(args[offset])) {
+ offset = getall(args, ++offset);
+
+ } else if ("--get".equals(args[offset])) {
+ offset = get(args, ++offset);
+
} else {
throw new IllegalArgumentException("Unknown command " + args[offset]);
}
@@ -128,11 +137,11 @@ public class AttributeTool {
final F1API f1 = getF1API();
- Attribute attribute = new Attribute();
+ Attribute attribute = new Attribute(attributeName);
attribute.setStartDate(new Date());
attribute.setComment(comment);
- if (f1.addAttribute(userId, attributeName, attribute)) {
+ if (f1.addAttribute(userId, attribute)) {
System.out.println("Added attribute " + attributeName + " for " + userId);
} else {
System.out.println("Failed to add attribute " + attributeName + " for " + userId);
@@ -140,4 +149,36 @@ public class AttributeTool {
return offset;
}
+
+ private static int getall(String[] args, int offset) throws Exception {
+ final String userId = args[offset++];
+
+ doGet(userId, null);
+
+ return offset;
+ }
+
+ private static int get(String[] args, int offset) throws Exception {
+ final String userId = args[offset++];
+ final String attributeName = args[offset++];
+
+ doGet(userId, attributeName);
+
+ return offset;
+ }
+
+ private static void doGet(final String userId, final String attributeName) throws Exception {
+ final F1API f1 = getF1API();
+
+ List<Attribute> attributes = f1.getAttribute(userId, attributeName);
+ for (Attribute attribute : attributes) {
+ System.out.printf("%s %s %s %s %s\n%s\n\n",
+ userId,
+ attribute.getAttributeName(),
+ attribute.getId(),
+ attribute.getStartDate(),
+ attribute.getEndDate(),
+ attribute.getComment());
+ }
+ }
}