From 54a7a3184dc565fe513aa520e1344b2303ea6834 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 19 Aug 2018 15:57:06 -0700 Subject: Add campus_list API --- LICENSE.md | 2 +- README.md | 3 +- src/main/java/com/p4square/ccbapi/CCBAPI.java | 8 +++ .../java/com/p4square/ccbapi/CCBAPIClient.java | 5 ++ .../java/com/p4square/ccbapi/model/Campus.java | 78 ++++++++++++++++++++++ .../ccbapi/model/GetCampusListResponse.java | 37 ++++++++++ .../java/com/p4square/ccbapi/CCBAPIClientTest.java | 18 +++++ .../ccbapi/model/GetCampusListResponseTest.java | 30 +++++++++ .../ccbapi/model/ccb_campus_list_response.xml | 22 ++++++ 9 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/p4square/ccbapi/model/Campus.java create mode 100644 src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java create mode 100644 src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java create mode 100644 src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml diff --git a/LICENSE.md b/LICENSE.md index cde32f0..b38bc38 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2016 Jesse Morgan +Copyright (c) 2016-2018 Jesse Morgan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index ca23386..92664be 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Only a few services are currently supported. The client currently supports: * `update_individual` * `group_profiles` * `group_profile_from_id` +* `campus_list` * List Lookup Tables Adding new services is relatively easy. Skip down to the Contributing section @@ -97,7 +98,7 @@ CCBAPIClient is thread-safe and manages its own pool of HTTP connections. ## License -Copyright (c) 2016 Jesse Morgan +Copyright (c) 2016-2018 Jesse Morgan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/main/java/com/p4square/ccbapi/CCBAPI.java b/src/main/java/com/p4square/ccbapi/CCBAPI.java index 6b9ba2e..86bc8ea 100644 --- a/src/main/java/com/p4square/ccbapi/CCBAPI.java +++ b/src/main/java/com/p4square/ccbapi/CCBAPI.java @@ -28,6 +28,14 @@ public interface CCBAPI extends Closeable { */ GetLookupTableResponse getLookupTable(GetLookupTableRequest request) throws IOException; + /** + * Retrieve the list of campuses. + * + * @return A {@link GetCampusListResponse} containing the campus ids and names. + * @throws IOException on failure. + */ + GetCampusListResponse getCampusList() throws IOException; + /** * Retrieve one or more {@link IndividualProfile}s. * diff --git a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java index a0335ba..2c75d62 100644 --- a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java +++ b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java @@ -150,6 +150,11 @@ public class CCBAPIClient implements CCBAPI { return makeRequest(service, EMPTY_MAP, null, GetLookupTableResponse.class); } + @Override + public GetCampusListResponse getCampusList() throws IOException { + return makeRequest("campus_list", EMPTY_MAP, null, GetCampusListResponse.class); + } + @Override public UpdateIndividualProfileResponse updateIndividualProfile(UpdateIndividualProfileRequest request) throws IOException { diff --git a/src/main/java/com/p4square/ccbapi/model/Campus.java b/src/main/java/com/p4square/ccbapi/model/Campus.java new file mode 100644 index 0000000..9d3288f --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/Campus.java @@ -0,0 +1,78 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.time.LocalDateTime; + +/** + * Representation of a Campus. + */ +@XmlRootElement(name="campus") +@XmlAccessorType(XmlAccessType.NONE) +public class Campus { + + @XmlAttribute(name="id") + private int id; + + @XmlElement(name="name") + private String name; + + @XmlElement(name="active") + private boolean active; + + @XmlElement(name="creator") + private IndividualReference createdBy; + + @XmlElement(name="created") + private LocalDateTime createdTime; + + @XmlElement(name="modifier") + private IndividualReference modifiedBy; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public IndividualReference getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(IndividualReference createdBy) { + this.createdBy = createdBy; + } + + public LocalDateTime getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(LocalDateTime createdTime) { + this.createdTime = createdTime; + } + + public IndividualReference getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(IndividualReference modifiedBy) { + this.modifiedBy = modifiedBy; + } +} diff --git a/src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java b/src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java new file mode 100644 index 0000000..e5cbcaa --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java @@ -0,0 +1,37 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; + +/** + * A GetCampusListResponse contains a list of campuses. + */ +@XmlRootElement(name="response") +@XmlAccessorType(XmlAccessType.NONE) +public class GetCampusListResponse extends CCBAPIResponse { + + @XmlElementWrapper(name = "campuses") + @XmlElement(name="campus") + private List campuses; + + public GetCampusListResponse() { + campuses = new ArrayList<>(); + } + + /** + * @return The list of campuses. + */ + public List getCampuses() { + return campuses; + } + + /** + * Set the list of campuses. + * + * @param campuses The list of campuses. + */ + public void setCampuses(final List campuses) { + this.campuses = campuses; + } +} \ No newline at end of file diff --git a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java index 9c7bbd6..22f9046 100644 --- a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java +++ b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java @@ -129,6 +129,24 @@ public class CCBAPIClientTest { assertEquals("High School Graduation", response.getItems().get(0).getName()); } + @Test + public void testGetCampusList() throws Exception { + // Set expectation. + URI expectedURI = new URI("https://localhost:8080/api.php?srv=campus_list"); + InputStream is = getClass().getResourceAsStream("model/ccb_campus_list_response.xml"); + EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null)) + .andReturn(is); + EasyMock.replay(mockHttpClient); + + // Test significant_event_list. + GetCampusListResponse response = client.getCampusList(); + + // Verify results. + EasyMock.verify(mockHttpClient); + assertNull(response.getErrors()); + assertEquals(1, response.getCampuses().size()); + } + @Test(expected = IllegalArgumentException.class) public void testGetLookupTableListWithNullType() throws Exception { // This should throw an IllegalArgumentException. diff --git a/src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java new file mode 100644 index 0000000..9b635db --- /dev/null +++ b/src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java @@ -0,0 +1,30 @@ +package com.p4square.ccbapi.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests for parsing GetCampusListResponseTest. + */ +public class GetCampusListResponseTest extends XmlBinderTestBase { + + /** + * Assert that all of the fields bind appropriately. + */ + @Test + public void testGetCampusListResponse() throws Exception { + final GetCampusListResponse response = parseFile("ccb_campus_list_response.xml", + GetCampusListResponse.class); + + assertNull("Response should not have errors", response.getErrors()); + assertNotNull(response.getCampuses()); + assertEquals(1, response.getCampuses().size()); + + final Campus campus = response.getCampuses().get(0); + + assertEquals(1, campus.getId()); + assertEquals("Sample Church", campus.getName()); + assertEquals(true, campus.isActive()); + } +} \ No newline at end of file diff --git a/src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml b/src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml new file mode 100644 index 0000000..d50d00e --- /dev/null +++ b/src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml @@ -0,0 +1,22 @@ + + + + + + + + + campus_list + execute + public + + + Sample Church + 1 + System User + System User + 2015-10-22 16:52:44 + + + + -- cgit v1.2.3