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.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; } }