blob: 5d6eeef777302d3384a0b5d0c4ff48a786127226 (
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
56
57
58
59
60
61
62
63
|
package com.p4square.groupsindexer.model;
import com.p4square.ccbapi.model.CustomPulldownFieldValue;
import com.p4square.ccbapi.model.GroupProfile;
import java.util.Arrays;
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().getFirstName() + " " +
abbreviateName(groupProfile.getMainLeader().getLastName()));
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;
}
private String abbreviateName(final String name) {
return Arrays.stream(name.split(" "))
.map(s -> s.substring(0, 1) + ".")
.reduce("", String::concat);
}
}
|