From fafa1140f3e8eedcb0f00b25c7891093df5fbf43 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 21 Jul 2018 22:42:50 -0700 Subject: Initial commit of groups search lambdas --- .../model/GroupSearchDocumentAdapter.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java (limited to 'src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java') 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 { + @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; + } +} -- cgit v1.2.3