summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/groupsindexer/model
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2018-07-21 22:42:50 -0700
committerJesse Morgan <jesse@jesterpm.net>2018-07-21 22:42:50 -0700
commitfafa1140f3e8eedcb0f00b25c7891093df5fbf43 (patch)
tree5a0dea7fdc11176115283bbd56ff2137130afc7b /src/main/java/com/p4square/groupsindexer/model
Initial commit of groups search lambdas
Diffstat (limited to 'src/main/java/com/p4square/groupsindexer/model')
-rw-r--r--src/main/java/com/p4square/groupsindexer/model/ErrorResponse.java22
-rw-r--r--src/main/java/com/p4square/groupsindexer/model/GroupSearchDocument.java232
-rw-r--r--src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java53
-rw-r--r--src/main/java/com/p4square/groupsindexer/model/Reference.java28
-rw-r--r--src/main/java/com/p4square/groupsindexer/model/SearchField.java52
-rw-r--r--src/main/java/com/p4square/groupsindexer/model/StringPair.java32
6 files changed, 419 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/groupsindexer/model/ErrorResponse.java b/src/main/java/com/p4square/groupsindexer/model/ErrorResponse.java
new file mode 100644
index 0000000..186bd27
--- /dev/null
+++ b/src/main/java/com/p4square/groupsindexer/model/ErrorResponse.java
@@ -0,0 +1,22 @@
+package com.p4square.groupsindexer.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class ErrorResponse {
+ @JsonProperty("error")
+ private String error;
+
+ public ErrorResponse() {}
+
+ public ErrorResponse(String error) {
+ this.error = error;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+}
diff --git a/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocument.java b/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocument.java
new file mode 100644
index 0000000..e336cb8
--- /dev/null
+++ b/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocument.java
@@ -0,0 +1,232 @@
+package com.p4square.groupsindexer.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A group description in ElasticSearch.
+ */
+public class GroupSearchDocument {
+
+ @JsonProperty("id")
+ private int id;
+
+ @JsonProperty("name")
+ private String name;
+
+ @JsonProperty("description")
+ private String description;
+
+ @JsonProperty("image-url")
+ private String imageUrl;
+
+ @JsonProperty("leader-id")
+ private int leaderId;
+
+ @JsonProperty("leader-name")
+ private String leaderName;
+
+ @JsonProperty("leader-email")
+ private String leaderEmail;
+
+ @JsonProperty("member-count")
+ private int currentMembers;
+
+ @JsonProperty("group-capacity")
+ private Integer groupCapacity;
+
+ @JsonProperty("childcare")
+ private boolean childcareProvided;
+
+ @JsonProperty("listed")
+ private boolean listed;
+
+ @JsonProperty("public")
+ private boolean publicSearchListed;
+
+ @JsonProperty("active")
+ private boolean active;
+
+ @JsonProperty("udf")
+ private Map<String, Reference> customFields;
+
+ private Reference campus;
+ private Reference groupType;
+ private Reference department;
+ private Reference area;
+ private Reference meetingDay;
+ private Reference meetingTime;
+
+ public GroupSearchDocument() {
+ customFields = new HashMap<>();
+ }
+
+ 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 int getLeaderId() {
+ return leaderId;
+ }
+
+ public void setLeaderId(int leaderId) {
+ this.leaderId = leaderId;
+ }
+
+ public String getLeaderName() {
+ return leaderName;
+ }
+
+ public void setLeaderName(String leaderName) {
+ this.leaderName = leaderName;
+ }
+
+ public String getLeaderEmail() {
+ return leaderEmail;
+ }
+
+ public void setLeaderEmail(String leaderEmail) {
+ this.leaderEmail = leaderEmail;
+ }
+
+ public String getImageUrl() {
+ return imageUrl;
+ }
+
+ public void setImageUrl(String imageUrl) {
+ this.imageUrl = imageUrl;
+ }
+
+ public int getCurrentMembers() {
+ return currentMembers;
+ }
+
+ public void setCurrentMembers(int currentMembers) {
+ this.currentMembers = currentMembers;
+ }
+
+ public Integer getGroupCapacity() {
+ return this.groupCapacity;
+ }
+
+ @JsonIgnore
+ public boolean isGroupCapacityUnlimited() {
+ return this.groupCapacity == null;
+ }
+
+ public void setGroupCapacity(Integer groupCapacity) {
+ this.groupCapacity = groupCapacity;
+ }
+
+ 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 active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ 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 Map<String, Reference> getCustomFields() {
+ return customFields;
+ }
+
+ public void setCustomFields(Map<String, Reference> customFields) {
+ this.customFields = customFields;
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java b/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java
new file mode 100644
index 0000000..ebe852d
--- /dev/null
+++ b/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java
@@ -0,0 +1,53 @@
+package com.p4square.groupsindexer.model;
+
+import com.p4square.ccbapi.model.CustomPulldownFieldValue;
+import com.p4square.ccbapi.model.GroupProfile;
+
+import java.util.function.Function;
+
+/**
+ * GroupSearchDocumentAdapter is a function which converts a CCB {@link GroupProfile} to a {@link GroupSearchDocument}.
+ */
+public class GroupSearchDocumentAdapter implements Function<GroupProfile, GroupSearchDocument> {
+ @Override
+ public GroupSearchDocument apply(GroupProfile groupProfile) {
+ final GroupSearchDocument doc = new GroupSearchDocument();
+
+ doc.setId(groupProfile.getId());
+ doc.setName(groupProfile.getName());
+ doc.setDescription(groupProfile.getDescription());
+ doc.setImageUrl(groupProfile.getImageUrl());
+ doc.setLeaderId(groupProfile.getMainLeader().getId());
+ doc.setLeaderName(groupProfile.getMainLeader().getFullName());
+ doc.setLeaderEmail(groupProfile.getMainLeader().getEmail());
+ doc.setCurrentMembers(groupProfile.getCurrentMembers());
+ doc.setGroupCapacity(groupProfile.getGroupCapacity());
+ doc.setChildcareProvided(groupProfile.isChildcareProvided());
+ doc.setListed(groupProfile.isListed());
+ doc.setPublicSearchListed(groupProfile.isPublicSearchListed());
+ doc.setActive(groupProfile.isActive());
+ doc.setCampus(adaptReference(groupProfile.getCampus()));
+ doc.setGroupType(adaptReference(groupProfile.getGroupType()));
+ doc.setDepartment(adaptReference(groupProfile.getDepartment()));
+ doc.setArea(adaptReference(groupProfile.getArea()));
+ doc.setMeetingDay(adaptReference(groupProfile.getMeetingDay()));
+ doc.setMeetingTime(adaptReference(groupProfile.getMeetingTime()));
+
+ for (final CustomPulldownFieldValue field : groupProfile.getCustomPulldownFields()) {
+ final Reference ref = new Reference();
+ ref.setId(String.valueOf(field.getSelection().getId()));
+ ref.setLabel(field.getSelection().getLabel());
+ doc.getCustomFields().put(field.getName(), ref);
+ }
+
+
+ return doc;
+ }
+
+ private Reference adaptReference(com.p4square.ccbapi.model.Reference r) {
+ final Reference ref = new Reference();
+ ref.setId(String.valueOf(r.getId()));
+ ref.setLabel(r.getName());
+ return ref;
+ }
+}
diff --git a/src/main/java/com/p4square/groupsindexer/model/Reference.java b/src/main/java/com/p4square/groupsindexer/model/Reference.java
new file mode 100644
index 0000000..84dcc15
--- /dev/null
+++ b/src/main/java/com/p4square/groupsindexer/model/Reference.java
@@ -0,0 +1,28 @@
+package com.p4square.groupsindexer.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Reference {
+
+ @JsonProperty("id")
+ private String id;
+
+ @JsonProperty("label")
+ private String label;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+}
diff --git a/src/main/java/com/p4square/groupsindexer/model/SearchField.java b/src/main/java/com/p4square/groupsindexer/model/SearchField.java
new file mode 100644
index 0000000..454b082
--- /dev/null
+++ b/src/main/java/com/p4square/groupsindexer/model/SearchField.java
@@ -0,0 +1,52 @@
+package com.p4square.groupsindexer.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+
+/**
+ * SearchField describes a pulldown field and its options.
+ */
+public class SearchField {
+
+ @JsonProperty("id")
+ private String id;
+
+ @JsonProperty("label")
+ private String label;
+
+ @JsonProperty("values")
+ private List<StringPair> values;
+
+ public SearchField() { }
+
+ public SearchField(String id, String label, List<StringPair> values) {
+ this.id = id;
+ this.label = label;
+ this.values = values;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public List<StringPair> getValues() {
+ return values;
+ }
+
+ public void setValues(List<StringPair> values) {
+ this.values = values;
+ }
+}
diff --git a/src/main/java/com/p4square/groupsindexer/model/StringPair.java b/src/main/java/com/p4square/groupsindexer/model/StringPair.java
new file mode 100644
index 0000000..a16040a
--- /dev/null
+++ b/src/main/java/com/p4square/groupsindexer/model/StringPair.java
@@ -0,0 +1,32 @@
+package com.p4square.groupsindexer.model;
+
+/**
+ * A key/value pair of Strings.
+ */
+public class StringPair {
+ private String key;
+ private String value;
+
+ public static StringPair of(String key, String value) {
+ final StringPair pair = new StringPair();
+ pair.setKey(key);
+ pair.setValue(value);
+ return pair;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}