summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/groupsindexer/model/GroupSearchDocumentAdapter.java
blob: 744138ac50f527de7f5cf0fa9caf08dc76568a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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());
        if (groupProfile.getAddresses().size() > 0) {
            doc.setLocationCity(groupProfile.getAddresses().get(0).getCity());
        }
        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;
    }
}