From 151f74ffa870561bbb3c857c0f07aeb4b27968f5 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 8 Jul 2018 09:34:59 -0700 Subject: Add Groups Service APIs --- .../com/p4square/ccbapi/model/GroupProfile.java | 367 +++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 src/main/java/com/p4square/ccbapi/model/GroupProfile.java (limited to 'src/main/java/com/p4square/ccbapi/model/GroupProfile.java') 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..6140200 --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java @@ -0,0 +1,367 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.net.URL; +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 URL imageUrl; + + @XmlElement(name="calendar_feed") + private URL 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 leaders; + + @XmlElementWrapper(name="participants") + @XmlElement(name="participant") + private List participants; + + @XmlElement(name="current_members") + private int currentMembers; + + @XmlElement(name="group_capacity") + private String groupCapacity; + + @XmlElementWrapper(name="addresses") + @XmlElement(name="address") + private List
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 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 meeting_day; + + @XmlElement(name="meeting_time") + private Reference meeting_time; + + @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 URL getImageUrl() { + return imageUrl; + } + + public void setImageUrl(URL imageUrl) { + this.imageUrl = imageUrl; + } + + public URL getCalendarFeedUrl() { + return calendarFeedUrl; + } + + public void setCalendarFeedUrl(URL 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 getLeaders() { + return leaders; + } + + public void setLeaders(List leaders) { + this.leaders = leaders; + } + + public List getParticipants() { + return participants; + } + + public void setParticipants(List participants) { + this.participants = participants; + } + + public int getCurrentMembers() { + return currentMembers; + } + + public void setCurrentMembers(int currentMembers) { + this.currentMembers = currentMembers; + } + + public String getGroupCapacity() { + return groupCapacity; + } + + public void setGroupCapacity(String groupCapacity) { + this.groupCapacity = groupCapacity; + } + + public List
getAddresses() { + return addresses; + } + + public void setAddresses(List
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 isInactive() { + return inactive; + } + + public void setInactive(boolean inactive) { + 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 getCustomPulldownFields() { + return customPulldownFields; + } + + public void setCustomPulldownFields(CustomFieldCollection 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 getMeeting_day() { + return meeting_day; + } + + public void setMeeting_day(Reference meeting_day) { + this.meeting_day = meeting_day; + } + + public Reference getMeeting_time() { + return meeting_time; + } + + public void setMeeting_time(Reference meeting_time) { + this.meeting_time = meeting_time; + } + + 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; + } +} -- cgit v1.2.3 From 3dac0195d484bebd1c604e175bcddd2edb994f82 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 8 Jul 2018 22:03:53 -0700 Subject: Add unit tests for groups models --- .../com/p4square/ccbapi/model/GroupProfile.java | 53 +++++++---- .../ccbapi/model/GetGroupProfilesResponseTest.java | 106 +++++++++++++++++++++ 2 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java (limited to 'src/main/java/com/p4square/ccbapi/model/GroupProfile.java') diff --git a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java index 6140200..cf826e6 100644 --- a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java +++ b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java @@ -1,7 +1,6 @@ package com.p4square.ccbapi.model; import javax.xml.bind.annotation.*; -import java.net.URL; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -23,10 +22,10 @@ public class GroupProfile { private String description; @XmlElement(name="image") - private URL imageUrl; + private String imageUrl; @XmlElement(name="calendar_feed") - private URL calendarFeedUrl; + private String calendarFeedUrl; @XmlElement(name="main_leader") private IndividualProfile mainLeader; @@ -93,10 +92,10 @@ public class GroupProfile { private Reference area; @XmlElement(name="meeting_day") - private Reference meeting_day; + private Reference meetingDay; @XmlElement(name="meeting_time") - private Reference meeting_time; + private Reference meetingTime; @XmlElement(name="creator") private IndividualReference createdBy; @@ -141,19 +140,19 @@ public class GroupProfile { this.description = description; } - public URL getImageUrl() { + public String getImageUrl() { return imageUrl; } - public void setImageUrl(URL imageUrl) { + public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } - public URL getCalendarFeedUrl() { + public String getCalendarFeedUrl() { return calendarFeedUrl; } - public void setCalendarFeedUrl(URL calendarFeedUrl) { + public void setCalendarFeedUrl(String calendarFeedUrl) { this.calendarFeedUrl = calendarFeedUrl; } @@ -205,12 +204,24 @@ public class GroupProfile { this.currentMembers = currentMembers; } - public String getGroupCapacity() { - return groupCapacity; + public Integer getGroupCapacity() { + if (isGroupCapacityUnlimited()) { + return null; + } else { + return Integer.valueOf(this.groupCapacity); + } } - public void setGroupCapacity(String groupCapacity) { - this.groupCapacity = 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
getAddresses() { @@ -317,20 +328,20 @@ public class GroupProfile { this.area = area; } - public Reference getMeeting_day() { - return meeting_day; + public Reference getMeetingDay() { + return meetingDay; } - public void setMeeting_day(Reference meeting_day) { - this.meeting_day = meeting_day; + public void setMeetingDay(Reference meetingDay) { + this.meetingDay = meetingDay; } - public Reference getMeeting_time() { - return meeting_time; + public Reference getMeetingTime() { + return meetingTime; } - public void setMeeting_time(Reference meeting_time) { - this.meeting_time = meeting_time; + public void setMeetingTime(Reference meetingTime) { + this.meetingTime = meetingTime; } public IndividualReference getCreatedBy() { 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..b20aa09 --- /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(false, group.isInactive()); + 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 -- cgit v1.2.3 From 633d0cebff548b6a54ac33e464447d93e800bf12 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 14 Jul 2018 12:11:53 -0700 Subject: Invert GroupProfile active/inactive flag. The flag in CCB is called inactive, but I'm renaming it to active to avoid the negative. --- src/main/java/com/p4square/ccbapi/model/GroupProfile.java | 8 ++++---- .../com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/p4square/ccbapi/model/GroupProfile.java') diff --git a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java index cf826e6..4da03fb 100644 --- a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java +++ b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java @@ -256,12 +256,12 @@ public class GroupProfile { this.publicSearchListed = publicSearchListed; } - public boolean isInactive() { - return inactive; + public boolean isActive() { + return !inactive; } - public void setInactive(boolean inactive) { - this.inactive = inactive; + public void setActive(boolean active) { + this.inactive = !inactive; } public boolean isNotification() { diff --git a/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java index b20aa09..c62844c 100644 --- a/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java +++ b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java @@ -79,7 +79,7 @@ public class GetGroupProfilesResponseTest extends XmlBinderTestBase { assertEquals(false, group.isChildcareProvided()); assertEquals(true, group.isListed()); assertEquals(true, group.isPublicSearchListed()); - assertEquals(false, group.isInactive()); + assertEquals(true, group.isActive()); assertEquals(true, group.isNotification()); assertEquals(InteractionType.MEMBERS_INTERACT, group.getInteractionType()); assertEquals(MembershipType.MODERATED, group.getMembershipType()); -- cgit v1.2.3