summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java31
-rw-r--r--src/test/resources/com/p4square/ccbapi/model/ccb_lookup_table_list_response.xml45
9 files changed, 274 insertions, 5 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();
+ }
+}
diff --git a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java
index 69f50c2..b7d32e1 100644
--- a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java
+++ b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java
@@ -9,12 +9,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.LocalDate;
-import java.util.Collections;
-import java.util.Map;
import org.easymock.EasyMock;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.junit.Assert.*;
@@ -111,6 +108,34 @@ public class CCBAPIClientTest {
}
@Test
+ public void testGetLookupTableListSuccess() throws Exception {
+ // Set expectation.
+ URI expectedURI = new URI("https://localhost:8080/api.php?srv=significant_event_list");
+ InputStream is = getClass().getResourceAsStream("model/ccb_lookup_table_list_response.xml");
+ EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null))
+ .andReturn(is);
+ EasyMock.replay(mockHttpClient);
+
+ // Test significant_event_list.
+ GetLookupTableResponse response = client.getLookupTable(
+ new GetLookupTableRequest().withType(LookupTableType.SIGNIFICANT_EVENT));
+
+ // Verify results.
+ EasyMock.verify(mockHttpClient);
+ assertNull(response.getErrors());
+ assertEquals(5, response.getItems().size());
+ assertEquals(1, response.getItems().get(0).getId());
+ assertEquals(1, response.getItems().get(0).getOrder());
+ assertEquals("High School Graduation", response.getItems().get(0).getName());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetLookupTableListWithNullType() throws Exception {
+ // This should throw an IllegalArgumentException.
+ client.getLookupTable(new GetLookupTableRequest());
+ }
+
+ @Test
public void testGetIndividualProfilesById() throws Exception {
// Set expectation.
URI expectedURI = new URI("https://localhost:8080/api.php?srv=individual_profile_from_id&individual_id=48");
diff --git a/src/test/resources/com/p4square/ccbapi/model/ccb_lookup_table_list_response.xml b/src/test/resources/com/p4square/ccbapi/model/ccb_lookup_table_list_response.xml
new file mode 100644
index 0000000..632b02c
--- /dev/null
+++ b/src/test/resources/com/p4square/ccbapi/model/ccb_lookup_table_list_response.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ccb_api>
+ <request>
+ <parameters>
+ <argument value="significant_event_list" name="srv"/>
+ </parameters>
+ </request>
+ <response>
+ <service>significant_event_list</service>
+ <service_action>execute</service_action>
+ <availability>public</availability>
+ <items count="5">
+ <item>
+ <item_id type="significant_event">1</item_id>
+ <id>1</id>
+ <name>High School Graduation</name>
+ <order>1</order>
+ </item>
+ <item>
+ <item_id type="significant_event">2</item_id>
+ <id>2</id>
+ <name>College Graduation</name>
+ <order>2</order>
+ </item>
+ <item>
+ <item_id type="significant_event">3</item_id>
+ <id>3</id>
+ <name>Moved Into Town</name>
+ <order>3</order>
+ </item>
+ <item>
+ <item_id type="significant_event">4</item_id>
+ <id>4</id>
+ <name>Moved Out of Town</name>
+ <order>4</order>
+ </item>
+ <item>
+ <item_id type="significant_event">5</item_id>
+ <id>5</id>
+ <name>Dedicated at Baby Dedication</name>
+ <order>5</order>
+ </item>
+ </items>
+ </response>
+</ccb_api> \ No newline at end of file