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 import org.opencastproject.elasticsearch.index.objects.event.Event;
25 import org.opencastproject.graphql.datafetcher.event.CommonEventMetadataDataFetcher;
26 import org.opencastproject.graphql.datafetcher.event.CommonEventMetadataV2DataFetcher;
27 import org.opencastproject.graphql.datafetcher.series.SeriesDataFetcher;
28 import org.opencastproject.graphql.execution.context.OpencastContextManager;
29 import org.opencastproject.graphql.series.GqlSeries;
30 import org.opencastproject.graphql.type.DateTimeFunction;
31 import org.opencastproject.graphql.type.DurationFunction;
32 import org.opencastproject.graphql.type.output.GqlCommonEventMetadata;
33 import org.opencastproject.graphql.type.output.GqlCommonEventMetadataV2;
34 import org.opencastproject.graphql.type.output.GqlPublication;
35 import org.opencastproject.workflow.api.WorkflowService;
36
37 import java.util.Arrays;
38 import java.util.List;
39 import java.util.Objects;
40 import java.util.stream.Collectors;
41
42 import graphql.annotations.annotationTypes.GraphQLDataFetcher;
43 import graphql.annotations.annotationTypes.GraphQLDescription;
44 import graphql.annotations.annotationTypes.GraphQLField;
45 import graphql.annotations.annotationTypes.GraphQLID;
46 import graphql.annotations.annotationTypes.GraphQLName;
47 import graphql.annotations.annotationTypes.GraphQLNonNull;
48 import graphql.annotations.annotationTypes.GraphQLType;
49 import graphql.schema.DataFetchingEnvironment;
50
51 @GraphQLName(GqlEvent.TYPE_NAME)
52 @GraphQLDescription("A Event.")
53 public class GqlEvent {
54
55 public static final String TYPE_NAME = "Event";
56
57 private final Event event;
58
59 public GqlEvent(Event event) {
60 this.event = event;
61 }
62
63 @GraphQLID
64 @GraphQLField
65 @GraphQLNonNull
66 public String id() {
67 return this.event.getIdentifier();
68 }
69
70 @GraphQLField
71 @GraphQLNonNull
72 public String title() {
73 return this.event.getTitle();
74 }
75
76 @GraphQLField
77 public String description() {
78 return this.event.getDescription();
79 }
80
81 @GraphQLField
82 public List<String> presenters() {
83 return this.event.getPresenters();
84 }
85
86 @GraphQLField
87 public List<String> contributors() {
88 return this.event.getContributors();
89 }
90
91 @GraphQLField
92 public String publisher() {
93 return this.event.getPublisher();
94 }
95
96 @GraphQLField
97 public String location() {
98 return this.event.getLocation();
99 }
100
101 @GraphQLField
102 public String license() {
103 return this.event.getLicense();
104 }
105
106 @GraphQLField
107 public String creator() {
108 return this.event.getCreator();
109 }
110
111 @GraphQLField
112 @GraphQLType(DateTimeFunction.class)
113 public String created() {
114 return this.event.getCreated();
115 }
116
117 @GraphQLField
118 @GraphQLNonNull
119 @GraphQLType(DurationFunction.class)
120 public Long duration() {
121 return this.event.getDuration();
122 }
123
124 @GraphQLField
125 @GraphQLType(DateTimeFunction.class)
126 public String startDate() {
127 return this.event.getRecordingStartDate();
128 }
129
130 @GraphQLField
131 @GraphQLType(DateTimeFunction.class)
132 public String endDate() {
133 return this.event.getRecordingEndDate();
134 }
135
136 @GraphQLField
137 public String technicalStartTime() {
138 return this.event.getTechnicalStartTime();
139 }
140
141 @GraphQLField
142 public String technicalEndTime() {
143 return this.event.getTechnicalEndTime();
144 }
145
146 @GraphQLField
147 @GraphQLNonNull
148 public String eventStatus() {
149 return this.event.getEventStatus();
150 }
151
152 @GraphQLField
153 public String displayableStatus() {
154 var workflowService = OpencastContextManager.getCurrentContext().getService(WorkflowService.class);
155 if (workflowService != null) {
156 return this.event.getDisplayableStatus(workflowService.getWorkflowStateMappings());
157 }
158 return null;
159 }
160
161 @GraphQLField
162 @GraphQLDescription("Return publications filterable by channel and tags")
163 public List<GqlPublication> publications(
164 @GraphQLName("channel") String channel,
165 @GraphQLName("tags") List<String> tags) {
166 return event.getPublications().stream()
167 .filter(e -> !Objects.equals(e.getChannel(), "internal"))
168 .filter(e -> channel == null || Objects.equals(e.getChannel(), channel))
169 .filter(e -> tags == null || Arrays.stream(e.getTags()).anyMatch(tags::contains))
170 .map(GqlPublication::new)
171 .collect(Collectors.toList());
172 }
173
174 @GraphQLField
175 public String seriesId() {
176 return this.event.getSeriesId();
177 }
178
179 @GraphQLField
180 public String seriesName() {
181 return this.event.getSeriesName();
182 }
183
184 @GraphQLField
185 public GqlSeries series(final DataFetchingEnvironment environment) {
186 var seriesId = this.event.getSeriesId();
187 if (seriesId == null) {
188 return null;
189 } else {
190 return new SeriesDataFetcher(this.event.getSeriesId()).get(environment);
191 }
192 }
193
194 @GraphQLField
195 @GraphQLNonNull
196 public Boolean hasPreview() {
197 return this.event.hasPreview();
198 }
199
200 @GraphQLField
201 @GraphQLNonNull
202 @GraphQLDescription("Common metadata of the event.")
203 @GraphQLDataFetcher(CommonEventMetadataDataFetcher.class)
204 public GqlCommonEventMetadata commonMetadata(final DataFetchingEnvironment environment) {
205 return null;
206 }
207
208 @GraphQLField
209 @GraphQLNonNull
210 @GraphQLDescription("Common metadata of the event.")
211 @GraphQLDataFetcher(CommonEventMetadataV2DataFetcher.class)
212 public GqlCommonEventMetadataV2 commonMetadataV2(final DataFetchingEnvironment environment) {
213 return null;
214 }
215
216 public Event getEvent() {
217 return event;
218 }
219
220 }