1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.graphql.event;
23
24
25 import org.opencastproject.elasticsearch.api.SearchResult;
26 import org.opencastproject.elasticsearch.api.SearchResultItem;
27 import org.opencastproject.elasticsearch.index.objects.event.Event;
28 import org.opencastproject.graphql.type.output.OffsetPageInfo;
29
30 import java.util.Arrays;
31 import java.util.List;
32 import java.util.stream.Collectors;
33
34 import graphql.annotations.annotationTypes.GraphQLDescription;
35 import graphql.annotations.annotationTypes.GraphQLField;
36 import graphql.annotations.annotationTypes.GraphQLName;
37 import graphql.annotations.annotationTypes.GraphQLNonNull;
38
39 @GraphQLName(GqlEventList.TYPE_NAME)
40 @GraphQLNonNull
41 @GraphQLDescription("A list of events")
42 public class GqlEventList {
43
44 public static final String TYPE_NAME = "EventList";
45
46 protected final SearchResult<Event> searchResult;
47
48 public GqlEventList(SearchResult<Event> searchResult) {
49 this.searchResult = searchResult;
50 }
51
52 @GraphQLField
53 @GraphQLNonNull
54 public Long totalCount() {
55 return searchResult.getHitCount();
56 }
57
58 @GraphQLField
59 @GraphQLNonNull
60 public OffsetPageInfo pageInfo() {
61 return OffsetPageInfo.from(searchResult);
62 }
63
64 @GraphQLField
65 @GraphQLNonNull
66 public List<GqlEvent> nodes() {
67 return Arrays.stream(searchResult.getItems())
68 .map(SearchResultItem::getSource)
69 .map(GqlEvent::new)
70 .collect(Collectors.toList());
71 }
72
73 }