diff options
Diffstat (limited to 'src')
12 files changed, 952 insertions, 1 deletions
diff --git a/src/main/java/com/p4square/ccbapi/CCBAPI.java b/src/main/java/com/p4square/ccbapi/CCBAPI.java index eb13cbf..6b9ba2e 100644 --- a/src/main/java/com/p4square/ccbapi/CCBAPI.java +++ b/src/main/java/com/p4square/ccbapi/CCBAPI.java @@ -59,4 +59,19 @@ public interface CCBAPI extends Closeable { * @throws IOException on failure. */ UpdateIndividualProfileResponse updateIndividualProfile(UpdateIndividualProfileRequest request) throws IOException; + + /** + * Retrieve one or more {@link GroupProfile}s. + * + * If {@link GetGroupProfilesRequest#withGroupId(int)} is set on the + * request, only the specified group will be returned. + * Otherwise, all groups are returned. + * + * The appropriate CCB API will be selected based on the options used. + * + * @param request A {@link GetGroupProfilesRequest}. + * @return A {@link GetGroupProfilesResponse} object on success, including when no groups are found. + * @throws IOException on failure. + */ + GetGroupProfilesResponse getGroupProfiles(GetGroupProfilesRequest request) throws IOException; } diff --git a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java index 96abf78..a0335ba 100644 --- a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java +++ b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java @@ -165,6 +165,43 @@ public class CCBAPIClient implements CCBAPI { return makeRequest("update_individual", params, form, UpdateIndividualProfileResponse.class); } + @Override + public GetGroupProfilesResponse getGroupProfiles(GetGroupProfilesRequest request) throws IOException { + // Prepare the request. + String serviceName; + final Map<String, String> params = new HashMap<>(); + + if (request.getId() != 0) { + // Use group_profile_from_id (id) + serviceName = "group_profile_from_id"; + params.put("id", String.valueOf(request.getId())); + + } else { + // Use group_profiles + serviceName = "group_profiles"; + if (request.getModifiedSince() != null) { + params.put("modified_since", request.getModifiedSince().toString()); + } + if (request.getPage() != 0) { + params.put("page", String.valueOf(request.getPage())); + } + if (request.getPerPage() != 0) { + params.put("per_page", String.valueOf(request.getPerPage())); + } + if (request.getIncludeParticipants() != null) { + params.put("include_participants", request.getIncludeParticipants() ? "true" : "false"); + } + } + + // This option applies to all request types. + if (request.getIncludeImageUrl() != null) { + params.put("include_image_link", request.getIncludeImageUrl() ? "true" : "false"); + } + + // Send the request and parse the response. + return makeRequest(serviceName, params, null, GetGroupProfilesResponse.class); + } + /** * Build the URI for a particular service call. * diff --git a/src/main/java/com/p4square/ccbapi/model/Address.java b/src/main/java/com/p4square/ccbapi/model/Address.java index 9bbd6e3..01934d8 100644 --- a/src/main/java/com/p4square/ccbapi/model/Address.java +++ b/src/main/java/com/p4square/ccbapi/model/Address.java @@ -13,7 +13,8 @@ public class Address { @XmlEnumValue("mailing") MAILING, @XmlEnumValue("home") HOME, @XmlEnumValue("work") WORK, - @XmlEnumValue("other") OTHER; + @XmlEnumValue("other") OTHER, + @XmlEnumValue("meeting") MEETING; } @XmlAttribute(name="type") diff --git a/src/main/java/com/p4square/ccbapi/model/GetGroupProfilesRequest.java b/src/main/java/com/p4square/ccbapi/model/GetGroupProfilesRequest.java new file mode 100644 index 0000000..85bf752 --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/GetGroupProfilesRequest.java @@ -0,0 +1,145 @@ +package com.p4square.ccbapi.model; + +import java.time.LocalDate; + +/** + * GetGroupProfilesRequest is the set of options for retrieving group profiles. + * + * If {@link #withGroupId(int)} is used, this request will return only the + * requested group. + * + * Otherwise, this request allows you to pass in a given date and have all + * groups created or modified since that date returned to you. If a date is + * not provided, all groups in the system will be returned. + * + * The image link in the image element will expire, and should be cached. + * Including it will significantly increase the runtime of the service and may + * cause a timeout. Please consider using {@link #withPerPage(int)} and + * {@link #withPage(int)} if you want to get the images from your groups. + */ +public class GetGroupProfilesRequest { + + // Used with group_profile_from_id + private int id; + + // Used with group_profiles + private LocalDate modifiedSince; + private int page; + private int perPage; + private Boolean includeParticipants; + + // Used with any. + private Boolean includeImageLink; + + public int getId() { + return id; + } + + /** + * Request the {@link GroupProfile} for the given group id. + * + * @param id The id. + * @return this. + */ + public GetGroupProfilesRequest withGroupId(final int id) { + this.id = id; + return this; + } + + public Boolean getIncludeImageUrl() { + return includeImageLink; + } + + /** + * Include the image URL in the result. + * + * Note: The image link in the image element will expire, and should be cached. + * + * @param value True if the image link should be included. + * @return this. + */ + public GetGroupProfilesRequest withIncludeImageUrl(final boolean value) { + this.includeImageLink = value; + return this; + } + + public LocalDate getModifiedSince() { + return modifiedSince; + } + + /** + * Retrieve all groups modified since the given time. + * + * Note: This cannot be used with {@link #withGroupId(int)}. + * + * @param modifiedSince The given time. + * @return this. + */ + public GetGroupProfilesRequest withModifiedSince(final LocalDate modifiedSince) { + this.modifiedSince = modifiedSince; + return this; + } + + public int getPage() { + return page; + } + + + /** + * Select the page of results when paginating results. + * + * Note: This cannot be used with {@link #withGroupId(int)}. + * + * Defaults to 1 if {@link #withPerPage(int)} is specified on the request. + * + * @param page The starting page number. + * @return this. + */ + public GetGroupProfilesRequest withPage(final int page) { + this.page = page; + return this; + } + + public int getPerPage() { + return perPage; + } + + /** + * Limit the number of groups returned. + * + * Note: This cannot be used with {@link #withGroupId(int)}. + * + * Defaults to 25 if {@link #withPage(int)} is specified on the request. + * + * @param perPage The maximum number to return. + * @return this. + */ + public GetGroupProfilesRequest withPerPage(final int perPage) { + this.perPage = perPage; + return this; + } + + public Boolean getIncludeParticipants() { + return includeParticipants; + } + + /** + * Include all participants from the group in the response. + * + * {@link GroupProfile#getMainLeader()} and {@link GroupProfile#getLeaders()} + * are always populated, regardless of the value. + * + * Note: This cannot be used with {@link #withGroupId(int)}. + * + * Defaults to True. + * + * @see {@link GroupProfile#getParticipants()} + * + * @param includeParticipants + * @return this. + */ + public GetGroupProfilesRequest withIncludeParticipants(final boolean includeParticipants) { + this.includeParticipants = includeParticipants; + return this; + } +} diff --git a/src/main/java/com/p4square/ccbapi/model/GetGroupProfilesResponse.java b/src/main/java/com/p4square/ccbapi/model/GetGroupProfilesResponse.java new file mode 100644 index 0000000..270b338 --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/GetGroupProfilesResponse.java @@ -0,0 +1,27 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.util.List; + +/** + * GetGroupProfilesResponse models the response of a variety of APIs which return one or more {@link GroupProfile}s. + */ +@XmlRootElement(name="response") +@XmlAccessorType(XmlAccessType.NONE) +public class GetGroupProfilesResponse extends CCBAPIResponse { + + @XmlElementWrapper(name = "groups") + @XmlElement(name="group") + private List<GroupProfile> groups; + + /** + * @return The list of groups retrieved from CCB. + */ + public List<GroupProfile> getGroups() { + return groups; + } + + public void setGroups(List<GroupProfile> groups) { + this.groups = groups; + } +} diff --git a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java new file mode 100644 index 0000000..4da03fb --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java @@ -0,0 +1,378 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + * Representation of a Group Profile. + */ +@XmlRootElement(name="individual") +@XmlAccessorType(XmlAccessType.NONE) +public class GroupProfile { + + @XmlAttribute(name="id") + private int id; + + @XmlElement(name="name") + private String name; + + @XmlElement(name="description") + private String description; + + @XmlElement(name="image") + private String imageUrl; + + @XmlElement(name="calendar_feed") + private String calendarFeedUrl; + + @XmlElement(name="main_leader") + private IndividualProfile mainLeader; + + @XmlElement(name="coach") + private IndividualProfile coach; + + @XmlElement(name="director") + private IndividualProfile director; + + @XmlElementWrapper(name="leaders") + @XmlElement(name="leader") + private List<IndividualProfile> leaders; + + @XmlElementWrapper(name="participants") + @XmlElement(name="participant") + private List<IndividualProfile> participants; + + @XmlElement(name="current_members") + private int currentMembers; + + @XmlElement(name="group_capacity") + private String groupCapacity; + + @XmlElementWrapper(name="addresses") + @XmlElement(name="address") + private List<Address> addresses; + + @XmlElement(name="childcare_provided") + private boolean childcareProvided; + + @XmlElement(name="listed") + private boolean listed; + + @XmlElement(name="public_search_listed") + private boolean publicSearchListed; + + @XmlElement(name="inactive") + private boolean inactive; + + @XmlElement(name="notification") + private boolean notification; + + @XmlElement(name="interaction_type", defaultValue = "Announcement Only") + private InteractionType interactionType; + + @XmlElement(name="membership_type", defaultValue = "Invitation") + private MembershipType membershipType; + + @XmlElementWrapper(name="user_defined_fields") + @XmlElement(name="user_defined_field") + private CustomFieldCollection<CustomPulldownFieldValue> customPulldownFields; + + @XmlElement(name="campus") + private Reference campus; + + @XmlElement(name="group_type") + private Reference groupType; + + @XmlElement(name="department") + private Reference department; + + @XmlElement(name="area") + private Reference area; + + @XmlElement(name="meeting_day") + private Reference meetingDay; + + @XmlElement(name="meeting_time") + private Reference meetingTime; + + @XmlElement(name="creator") + private IndividualReference createdBy; + + @XmlElement(name="created") + private LocalDateTime createdTime; + + @XmlElement(name="modifier") + private IndividualReference modifiedBy; + + @XmlElement(name="modified") + private LocalDateTime modifiedTime; + + public GroupProfile() { + leaders = new ArrayList<>(); + participants = new ArrayList<>(); + addresses = new ArrayList<>(); + customPulldownFields = new CustomFieldCollection<>(); + } + + 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 String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public String getCalendarFeedUrl() { + return calendarFeedUrl; + } + + public void setCalendarFeedUrl(String calendarFeedUrl) { + this.calendarFeedUrl = calendarFeedUrl; + } + + public IndividualProfile getMainLeader() { + return mainLeader; + } + + public void setMainLeader(IndividualProfile mainLeader) { + this.mainLeader = mainLeader; + } + + public IndividualProfile getCoach() { + return coach; + } + + public void setCoach(IndividualProfile coach) { + this.coach = coach; + } + + public IndividualProfile getDirector() { + return director; + } + + public void setDirector(IndividualProfile director) { + this.director = director; + } + + public List<IndividualProfile> getLeaders() { + return leaders; + } + + public void setLeaders(List<IndividualProfile> leaders) { + this.leaders = leaders; + } + + public List<IndividualProfile> getParticipants() { + return participants; + } + + public void setParticipants(List<IndividualProfile> participants) { + this.participants = participants; + } + + public int getCurrentMembers() { + return currentMembers; + } + + public void setCurrentMembers(int currentMembers) { + this.currentMembers = currentMembers; + } + + public Integer getGroupCapacity() { + if (isGroupCapacityUnlimited()) { + return null; + } else { + return Integer.valueOf(this.groupCapacity); + } + } + + public boolean isGroupCapacityUnlimited() { + return this.groupCapacity == null || "Unlimited".equals(this.groupCapacity); + } + + public void setGroupCapacity(Integer groupCapacity) { + if (groupCapacity == null) { + this.groupCapacity = "Unlimited"; + } else { + this.groupCapacity = groupCapacity.toString(); + } + } + + public List<Address> getAddresses() { + return addresses; + } + + public void setAddresses(List<Address> addresses) { + this.addresses = addresses; + } + + public boolean isChildcareProvided() { + return childcareProvided; + } + + public void setChildcareProvided(boolean childcareProvided) { + this.childcareProvided = childcareProvided; + } + + public boolean isListed() { + return listed; + } + + public void setListed(boolean listed) { + this.listed = listed; + } + + public boolean isPublicSearchListed() { + return publicSearchListed; + } + + public void setPublicSearchListed(boolean publicSearchListed) { + this.publicSearchListed = publicSearchListed; + } + + public boolean isActive() { + return !inactive; + } + + public void setActive(boolean active) { + this.inactive = !inactive; + } + + public boolean isNotification() { + return notification; + } + + public void setNotification(boolean notification) { + this.notification = notification; + } + + public InteractionType getInteractionType() { + return interactionType; + } + + public void setInteractionType(InteractionType interactionType) { + this.interactionType = interactionType; + } + + public MembershipType getMembershipType() { + return membershipType; + } + + public void setMembershipType(MembershipType membershipType) { + this.membershipType = membershipType; + } + + public CustomFieldCollection<CustomPulldownFieldValue> getCustomPulldownFields() { + return customPulldownFields; + } + + public void setCustomPulldownFields(CustomFieldCollection<CustomPulldownFieldValue> customPulldownFields) { + this.customPulldownFields = customPulldownFields; + } + + public Reference getCampus() { + return campus; + } + + public void setCampus(Reference campus) { + this.campus = campus; + } + + public Reference getGroupType() { + return groupType; + } + + public void setGroupType(Reference groupType) { + this.groupType = groupType; + } + + public Reference getDepartment() { + return department; + } + + public void setDepartment(Reference department) { + this.department = department; + } + + public Reference getArea() { + return area; + } + + public void setArea(Reference area) { + this.area = area; + } + + public Reference getMeetingDay() { + return meetingDay; + } + + public void setMeetingDay(Reference meetingDay) { + this.meetingDay = meetingDay; + } + + public Reference getMeetingTime() { + return meetingTime; + } + + public void setMeetingTime(Reference meetingTime) { + this.meetingTime = meetingTime; + } + + 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; + } + + public LocalDateTime getModifiedTime() { + return modifiedTime; + } + + public void setModifiedTime(LocalDateTime modifiedTime) { + this.modifiedTime = modifiedTime; + } +} diff --git a/src/main/java/com/p4square/ccbapi/model/InteractionType.java b/src/main/java/com/p4square/ccbapi/model/InteractionType.java new file mode 100644 index 0000000..85475a3 --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/InteractionType.java @@ -0,0 +1,12 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.XmlEnumValue; + +/** + * Enumeration of the supported values for the interaction_type field of a GroupProfile. + */ +public enum InteractionType { + @XmlEnumValue("Announcement Only") ANNOUNCEMENT_ONLY, + @XmlEnumValue("Members Interact") MEMBERS_INTERACT, + @XmlEnumValue("Administrative") ADMINISTRATIVE; +} diff --git a/src/main/java/com/p4square/ccbapi/model/MembershipType.java b/src/main/java/com/p4square/ccbapi/model/MembershipType.java new file mode 100644 index 0000000..7906aaa --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/MembershipType.java @@ -0,0 +1,18 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.XmlEnumValue; + +/** + * Enumeration of the supported values for the membership_type field of a GroupProfile. + */ +public enum MembershipType { + /** + * Membership is open to anyone. + */ + @XmlEnumValue("Open to All") OPEN, + + /** + * Membership is moderated (Invitation or Request Required). + */ + @XmlEnumValue("Invitation or Request Required") MODERATED; +} diff --git a/src/main/java/com/p4square/ccbapi/model/Reference.java b/src/main/java/com/p4square/ccbapi/model/Reference.java new file mode 100644 index 0000000..5ac9800 --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/Reference.java @@ -0,0 +1,34 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +/** + * Generic reference to a id and name. + */ +@XmlAccessorType(XmlAccessType.NONE) +public class Reference { + @XmlAttribute(name="id") + private int id; + + @XmlValue + private String name; + + 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; + } +} diff --git a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java index 71427b5..9c7bbd6 100644 --- a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java +++ b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java @@ -283,6 +283,71 @@ public class CCBAPIClientTest { // Expect exception. } + @Test + public void testGetGroupProfilesById() throws Exception { + // Set expectation. + URI expectedURI = new URI("https://localhost:8080/api.php?srv=group_profile_from_id&id=750"); + InputStream is = getClass().getResourceAsStream("model/ccb_group_profile_from_id_response.xml"); + EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null)) + .andReturn(is); + EasyMock.replay(mockHttpClient); + + // Test group_profile_from_id. + GetGroupProfilesRequest request = new GetGroupProfilesRequest().withGroupId(750); + GetGroupProfilesResponse response = client.getGroupProfiles(request); + + // Verify results. + EasyMock.verify(mockHttpClient); + assertNull(response.getErrors()); + assertEquals(1, response.getGroups().size()); + assertEquals(750, response.getGroups().get(0).getId()); + } + + @Test + public void testGetAllGroupProfiles() throws Exception { + // Set expectation. + URI expectedURI = new URI("https://localhost:8080/api.php?srv=group_profiles"); + InputStream is = getClass().getResourceAsStream("model/ccb_group_profile_from_id_response.xml"); + EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null)) + .andReturn(is); + EasyMock.replay(mockHttpClient); + + // Test group_profile_from_id. + GetGroupProfilesRequest request = new GetGroupProfilesRequest(); + GetGroupProfilesResponse response = client.getGroupProfiles(request); + + // Verify results. + EasyMock.verify(mockHttpClient); + assertNull(response.getErrors()); + assertEquals(1, response.getGroups().size()); + assertEquals(750, response.getGroups().get(0).getId()); + } + + @Test + public void testGetAllGroupProfilesWithOptions() throws Exception { + // Set expectation. + URI expectedURI = new URI("https://localhost:8080/api.php?srv=group_profiles&per_page=2&modified_since=2018-07-08&page=1&include_participants=false&include_image_link=true"); + InputStream is = getClass().getResourceAsStream("model/ccb_group_profile_from_id_response.xml"); + EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null)) + .andReturn(is); + EasyMock.replay(mockHttpClient); + + // Test group_profile_from_id. + GetGroupProfilesRequest request = new GetGroupProfilesRequest() + .withIncludeParticipants(false) + .withIncludeImageUrl(true) + .withModifiedSince(LocalDate.parse("2018-07-08")) + .withPage(1) + .withPerPage(2); + GetGroupProfilesResponse response = client.getGroupProfiles(request); + + // Verify results. + EasyMock.verify(mockHttpClient); + assertNull(response.getErrors()); + assertEquals(1, response.getGroups().size()); + assertEquals(750, response.getGroups().get(0).getId()); + } + /** * Simple extension of CCBAPIClient to swap out the HTTPInterface with a mock. */ diff --git a/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java new file mode 100644 index 0000000..c62844c --- /dev/null +++ b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java @@ -0,0 +1,106 @@ +package com.p4square.ccbapi.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests for parsing GetGroupProfilesResponse. + */ +public class GetGroupProfilesResponseTest extends XmlBinderTestBase { + + /** + * Assert that all of the fields bind appropriately for a single profile response. + */ + @Test + public void testGetGroupProfilesResponse() throws Exception { + final GetGroupProfilesResponse response = parseFile("ccb_group_profile_from_id_response.xml", + GetGroupProfilesResponse.class); + + assertNull("Response should not have errors", response.getErrors()); + assertNotNull(response.getGroups()); + assertEquals(1, response.getGroups().size()); + + final GroupProfile group = response.getGroups().get(0); + + // IDs + assertEquals(750, group.getId()); + + assertEquals("Adamant by Lisa Bevere Book Study", group.getName()); + assertTrue(group.getDescription().startsWith("What is the truth?")); + assertTrue(group.getImageUrl().isEmpty()); + assertEquals("webcal://example.ccbchurch.com/group_calendar.ics?id=750&tk=764EFA883DDA1E11DB47671C4A3BBD9E", + group.getCalendarFeedUrl()); + + // Main Leader + assertEquals(26102, group.getMainLeader().getId()); + assertEquals("Jane", group.getMainLeader().getFirstName()); + assertEquals("Doe", group.getMainLeader().getLastName()); + assertEquals("Jane Doe", group.getMainLeader().getFullName()); + assertEquals("jane.doe@example.com", group.getMainLeader().getEmail()); + assertEquals(Phone.Type.CONTACT, group.getMainLeader().getPhones().get(0).getType()); + assertEquals("+12068675309", group.getMainLeader().getPhones().get(0).getNumber()); + + // Coach + assertEquals(29, group.getCoach().getId()); + assertEquals("John", group.getCoach().getFirstName()); + assertEquals("Doe", group.getCoach().getLastName()); + assertEquals("John Doe", group.getCoach().getFullName()); + assertEquals("john.doe@example.com", group.getCoach().getEmail()); + assertEquals("", group.getCoach().getPhones().get(0).getNumber()); + + // Director + assertEquals(33082, group.getDirector().getId()); + assertEquals("Jeff", group.getDirector().getFirstName()); + assertEquals("Doe", group.getDirector().getLastName()); + assertEquals("Jeff Doe", group.getDirector().getFullName()); + assertEquals("jeff.doe@example.com", group.getDirector().getEmail()); + assertEquals("", group.getDirector().getPhones().get(0).getNumber()); + + // Membership Capacity + assertEquals(0, group.getLeaders().size()); + assertEquals(0, group.getParticipants().size()); + assertEquals(1, group.getCurrentMembers()); + assertNull(group.getGroupCapacity()); + assertTrue(group.isGroupCapacityUnlimited()); + + // Address + assertEquals(Address.Type.MEETING, group.getAddresses().get(0).getType()); + assertEquals("1234 Example St", group.getAddresses().get(0).getStreetAddress()); + assertEquals("Puyallup", group.getAddresses().get(0).getCity()); + assertEquals("WA", group.getAddresses().get(0).getState()); + assertEquals("", group.getAddresses().get(0).getZip()); + assertEquals("-122.000000", group.getAddresses().get(0).getLongitude()); + assertEquals("47.000000", group.getAddresses().get(0).getLatitude()); + assertEquals("1234 Example St", group.getAddresses().get(0).getLine_1()); + assertEquals("Puyallup, WA", group.getAddresses().get(0).getLine_2()); + + // Attributes + assertEquals(false, group.isChildcareProvided()); + assertEquals(true, group.isListed()); + assertEquals(true, group.isPublicSearchListed()); + assertEquals(true, group.isActive()); + assertEquals(true, group.isNotification()); + assertEquals(InteractionType.MEMBERS_INTERACT, group.getInteractionType()); + assertEquals(MembershipType.MODERATED, group.getMembershipType()); + + // User Defined Fields + assertEquals("udf_1", group.getCustomPulldownFields().getByLabel("Gender").getName()); + assertEquals("Gender", group.getCustomPulldownFields().getByLabel("Gender").getLabel()); + assertEquals(2, group.getCustomPulldownFields().getByLabel("Gender").getSelection().getId()); + assertEquals("Female only", group.getCustomPulldownFields().getByLabel("Gender").getSelection().getLabel()); + assertEquals(false, group.getCustomPulldownFields().getByLabel("Gender").isAdminOnly()); + + // Reference Attributes + assertReferenceEquals(4, "Tuesday", group.getMeetingDay()); + assertReferenceEquals(33, "7:00 pm", group.getMeetingTime()); + assertReferenceEquals(4, "Community", group.getGroupType()); + assertReferenceEquals(13, "Adults", group.getDepartment()); + assertReferenceEquals(18, "Puyallup", group.getArea()); + } + + private void assertReferenceEquals(int id, String name, Reference ref) { + assertEquals(id, ref.getId()); + assertEquals(name, ref.getName()); + } +}
\ No newline at end of file diff --git a/src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml b/src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml new file mode 100644 index 0000000..566f656 --- /dev/null +++ b/src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ccb_api> + <request> + <parameters> + <argument value="group_profile_from_id" name="srv"/> + <argument value="750" name="id"/> + </parameters> + </request> + <response> + <service>group_profile_from_id</service> + <service_action>execute</service_action> + <availability>public</availability> + <groups count="1"> + <group id="750"> + <name>Adamant by Lisa Bevere Book Study</name> + <description>What is the truth? + + This has become the defining question of our time. But while everyone has an opinion, truth, it seems, is getting harder and harder to find. Perhaps that's because we are searching for something when we should be looking for someone. + + Truth has a name. + + More ancient than time and more present than this moment, the truth is not a river that changes with the cultural currents, but a rock--immovable, invincible, unshakeable--and the cornerstone of all we are and ever dream to be. + + Theologically deep yet intimately accessible. Adamant will be an anchor for your soul in a raging sea of opinions, giving you a clear sense of direction in a wandering world. + Every Other Tuesday Beginning in September 2018</description> + <image></image> + <campus id="1">Example Church</campus> + <main_leader id="26102"> + <first_name>Jane</first_name> + <last_name>Doe</last_name> + <full_name>Jane Doe</full_name> + <email>jane.doe@example.com</email> + <phones> + <phone type="contact">+12068675309</phone> + </phones> + </main_leader> + <leaders/> + <coach id="29"> + <first_name>John</first_name> + <last_name>Doe</last_name> + <full_name>John Doe</full_name> + <email>john.doe@example.com</email> + <phones type="contact"> + <phone></phone> + </phones> + </coach> + <director id="33082"> + <first_name>Jeff</first_name> + <last_name>Doe</last_name> + <full_name>Jeff Doe</full_name> + <email>jeff.doe@example.com</email> + <phones type="contact"> + <phone></phone> + </phones> + </director> + <participants/> + <group_type id="4">Community</group_type> + <department id="13">Adults</department> + <area id="18">Puyallup</area> + <calendar_feed>webcal://example.ccbchurch.com/group_calendar.ics?id=750&tk=764EFA883DDA1E11DB47671C4A3BBD9E</calendar_feed> + <registration_forms/> + <current_members>1</current_members> + <group_capacity>Unlimited</group_capacity> + <addresses> + <address type="meeting"> + <name></name> + <street_address>1234 Example St</street_address> + <city>Puyallup</city> + <state>WA</state> + <zip></zip> + <longitude>-122.000000</longitude> + <latitude>47.000000</latitude> + <line_1>1234 Example St</line_1> + <line_2>Puyallup, WA</line_2> + </address> + </addresses> + <meeting_day id="4">Tuesday</meeting_day> + <meeting_time id="33">7:00 pm</meeting_time> + <childcare_provided>false</childcare_provided> + <interaction_type>Members Interact</interaction_type> + <membership_type>Invitation or Request Required</membership_type> + <notification>true</notification> + <user_defined_fields> + <user_defined_field> + <name>udf_1</name> + <label>Gender</label> + <selection id="2">Female only</selection> + <admin_only>false</admin_only> + </user_defined_field> + <user_defined_field> + <name>udf_2</name> + <label>Marital status</label> + <selection id="3">Marrieds & Single</selection> + <admin_only>false</admin_only> + </user_defined_field> + <user_defined_field> + <name>udf_3</name> + <label>Group Category</label> + <selection id="1">Learning</selection> + <admin_only>false</admin_only> + </user_defined_field> + </user_defined_fields> + <listed>true</listed> + <public_search_listed>true</public_search_listed> + <inactive>false</inactive> + <creator id="12">Larry Cucumber</creator> + <modifier id="12">Larry Cucumber</modifier> + <created>2018-06-28 22:43:40</created> + <modified>2018-06-28 22:44:25</modified> + </group> + </groups> + </response> +</ccb_api>
\ No newline at end of file |