summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-04-06 21:25:41 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-04-06 21:26:19 -0700
commit624e5d995c2fa593fb517a99e4b8b5f775afbeaf (patch)
treec6080ebbf909fb45fb055930abe64bbfb62a41f0 /src/main
parent7367968483e4ddfedfa47598c508b343b44fc852 (diff)
Adding getLookupTable API.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/p4square/ccbapi/CCBAPI.java10
-rw-r--r--src/main/java/com/p4square/ccbapi/CCBAPIClient.java14
-rw-r--r--src/main/java/com/p4square/ccbapi/model/CustomField.java9
-rw-r--r--src/main/java/com/p4square/ccbapi/model/GetLookupTableRequest.java27
-rw-r--r--src/main/java/com/p4square/ccbapi/model/GetLookupTableResponse.java37
-rw-r--r--src/main/java/com/p4square/ccbapi/model/LookupTableItem.java59
-rw-r--r--src/main/java/com/p4square/ccbapi/model/LookupTableType.java47
7 files changed, 201 insertions, 2 deletions
diff --git a/src/main/java/com/p4square/ccbapi/CCBAPI.java b/src/main/java/com/p4square/ccbapi/CCBAPI.java
index f81a02f..bae2272 100644
--- a/src/main/java/com/p4square/ccbapi/CCBAPI.java
+++ b/src/main/java/com/p4square/ccbapi/CCBAPI.java
@@ -18,6 +18,16 @@ public interface CCBAPI extends Closeable {
GetCustomFieldLabelsResponse getCustomFieldLabels() throws IOException;
/**
+ * Retrieve the list of items in a particular lookup table.
+ *
+ * Lookup tables provide the list of options for various pulldown fields.
+ *
+ * @return A GetLookupTableResponse containing the item ids and labels.
+ * @throws IOException on failure.
+ */
+ GetLookupTableResponse getLookupTable(GetLookupTableRequest request) throws IOException;
+
+ /**
* Retrieve one or more IndividualProfiles.
*
* If any of the following properties are set on the request,
diff --git a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java
index 404253a..e3750cf 100644
--- a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java
+++ b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java
@@ -2,9 +2,7 @@ package com.p4square.ccbapi;
import com.p4square.ccbapi.exception.CCBErrorResponseException;
import com.p4square.ccbapi.model.*;
-import com.p4square.ccbapi.serializer.AddressFormSerializer;
import com.p4square.ccbapi.serializer.IndividualProfileSerializer;
-import com.p4square.ccbapi.serializer.PhoneFormSerializer;
import java.io.IOException;
import java.io.InputStream;
@@ -134,6 +132,18 @@ public class CCBAPIClient implements CCBAPI {
}
@Override
+ public GetLookupTableResponse getLookupTable(final GetLookupTableRequest request) throws IOException {
+
+ if (request.getType() == null) {
+ throw new IllegalArgumentException("LookupTableType must not be null.");
+ }
+
+ final String service = request.getType().getIdentifier() + "_list";
+
+ return makeRequest(service, EMPTY_MAP, null, GetLookupTableResponse.class);
+ }
+
+ @Override
public UpdateIndividualProfileResponse updateIndividualProfile(UpdateIndividualProfileRequest request)
throws IOException {
diff --git a/src/main/java/com/p4square/ccbapi/model/CustomField.java b/src/main/java/com/p4square/ccbapi/model/CustomField.java
index c9917e4..5b52bb3 100644
--- a/src/main/java/com/p4square/ccbapi/model/CustomField.java
+++ b/src/main/java/com/p4square/ccbapi/model/CustomField.java
@@ -71,4 +71,13 @@ public class CustomField {
public void setAdminOnly(boolean adminOnly) {
this.adminOnly = adminOnly;
}
+
+ @Override
+ public String toString() {
+ return "CustomField::{" +
+ "name='" + name + '\'' +
+ ", label='" + label + '\'' +
+ ", adminOnly=" + adminOnly +
+ '}';
+ }
}
diff --git a/src/main/java/com/p4square/ccbapi/model/GetLookupTableRequest.java b/src/main/java/com/p4square/ccbapi/model/GetLookupTableRequest.java
new file mode 100644
index 0000000..4da877e
--- /dev/null
+++ b/src/main/java/com/p4square/ccbapi/model/GetLookupTableRequest.java
@@ -0,0 +1,27 @@
+package com.p4square.ccbapi.model;
+
+/**
+ * GetLookupTableRequest contains the information necessary to get a list of lookup table values.
+ */
+public class GetLookupTableRequest {
+
+ private LookupTableType type;
+
+ public LookupTableType getType() {
+ return type;
+ }
+
+ /**
+ * Specify the type of lookup table to query.
+ *
+ * @param type A non-null lookup table type.
+ * @return this
+ */
+ public GetLookupTableRequest withType(final LookupTableType type) {
+ if (type == null) {
+ throw new IllegalArgumentException("type may not be null.");
+ }
+ this.type = type;
+ return this;
+ }
+}
diff --git a/src/main/java/com/p4square/ccbapi/model/GetLookupTableResponse.java b/src/main/java/com/p4square/ccbapi/model/GetLookupTableResponse.java
new file mode 100644
index 0000000..e1feb1e
--- /dev/null
+++ b/src/main/java/com/p4square/ccbapi/model/GetLookupTableResponse.java
@@ -0,0 +1,37 @@
+package com.p4square.ccbapi.model;
+
+import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A GetLookupTableResponse contains a list of lookup table values.
+ */
+@XmlRootElement(name="response")
+@XmlAccessorType(XmlAccessType.NONE)
+public class GetLookupTableResponse extends CCBAPIResponse {
+
+ @XmlElementWrapper(name = "items")
+ @XmlElement(name="item")
+ private List<LookupTableItem> items;
+
+ public GetLookupTableResponse() {
+ items = new ArrayList<>();
+ }
+
+ /**
+ * @return The list of items in the lookup table.
+ */
+ public List<LookupTableItem> getItems() {
+ return items;
+ }
+
+ /**
+ * Set the list of lookup table items.
+ *
+ * @param items The list of items in the lookup table.
+ */
+ public void setItems(final List<LookupTableItem> items) {
+ this.items = items;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/p4square/ccbapi/model/LookupTableItem.java b/src/main/java/com/p4square/ccbapi/model/LookupTableItem.java
new file mode 100644
index 0000000..07b39eb
--- /dev/null
+++ b/src/main/java/com/p4square/ccbapi/model/LookupTableItem.java
@@ -0,0 +1,59 @@
+package com.p4square.ccbapi.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * LookupTableItem is the definition of an item in a pulldown list.
+ */
+@XmlRootElement(name="item")
+@XmlAccessorType(XmlAccessType.NONE)
+public class LookupTableItem {
+
+ @XmlElement
+ private int id;
+
+ @XmlElement
+ private int order;
+
+ @XmlElement
+ private String name;
+
+ public int getId() {
+ return id;
+ }
+
+ public LookupTableItem setId(final int id) {
+ this.id = id;
+ return this;
+ }
+
+ public int getOrder() {
+ return order;
+ }
+
+ public LookupTableItem setOrder(final int order) {
+ this.order = order;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public LookupTableItem setName(final String name) {
+ this.name = name;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "LookupTableItem::{" +
+ "id=" + id +
+ ", order=" + order +
+ ", name='" + name + '\'' +
+ '}';
+ }
+}
diff --git a/src/main/java/com/p4square/ccbapi/model/LookupTableType.java b/src/main/java/com/p4square/ccbapi/model/LookupTableType.java
new file mode 100644
index 0000000..e80abde
--- /dev/null
+++ b/src/main/java/com/p4square/ccbapi/model/LookupTableType.java
@@ -0,0 +1,47 @@
+package com.p4square.ccbapi.model;
+
+/**
+ * A collection of lookup table types supported by CCB.
+ */
+public enum LookupTableType {
+ ABILITY,
+ ACTIVITY,
+ AGE_BRACKET,
+ AREA,
+ CHURCH_SERVICE,
+ DEPARTMENT,
+ EVENT_GROUPING,
+ GIFT,
+ GROUP_GROUPING,
+ GROUP_TYPE,
+ HOW_JOINED_CHURCH,
+ HOW_THEY_HEARD,
+ MEET_DAY,
+ MEET_TIME,
+ MEMBERSHIP_TYPE,
+ PASSION,
+ REASON_LEFT_CHURCH,
+ SCHOOL,
+ SCHOOL_GRADE,
+ SIGNIFICANT_EVENT,
+ SPIRITUAL_MATURITY,
+ STYLE,
+ TRANSACTION_GROUPING,
+ UDF_GRP_PULLDOWN_1,
+ UDF_GRP_PULLDOWN_2,
+ UDF_GRP_PULLDOWN_3,
+ UDF_IND_PULLDOWN_1,
+ UDF_IND_PULLDOWN_2,
+ UDF_IND_PULLDOWN_3,
+ UDF_IND_PULLDOWN_4,
+ UDF_IND_PULLDOWN_5,
+ UDF_IND_PULLDOWN_6,
+ UDF_RESOURCE_PULLDOWN_1;
+
+ /**
+ * @return the identifier used by the CCB API.
+ */
+ public String getIdentifier() {
+ return toString().toLowerCase();
+ }
+}