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.elasticsearch.index.objects.event;
23
24 import static org.opencastproject.security.api.SecurityConstants.GLOBAL_ADMIN_ROLE;
25
26 import org.opencastproject.elasticsearch.impl.AbstractSearchQuery;
27 import org.opencastproject.elasticsearch.impl.IndexSchema;
28 import org.opencastproject.security.api.Permissions;
29 import org.opencastproject.security.api.Permissions.Action;
30 import org.opencastproject.security.api.User;
31 import org.opencastproject.util.requests.SortCriterion.Order;
32
33 import org.apache.commons.lang3.StringUtils;
34
35 import java.util.ArrayList;
36 import java.util.Date;
37 import java.util.HashMap;
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Set;
42
43
44
45
46 public class EventSearchQuery extends AbstractSearchQuery {
47
48 private final List<String> identifiers = new ArrayList<String>();
49 private String organization = null;
50 private User user = null;
51 private String title = null;
52 private String description = null;
53 private final Set<String> actions = new HashSet<String>();
54 private final List<String> presenters = new ArrayList<String>();
55 private final List<String> contributors = new ArrayList<String>();
56 private String subject = null;
57 private Map<String, Map<String, List<String>>> extendedMetadata = new HashMap<>();
58 private String location = null;
59 private String seriesId = null;
60 private String seriesName = null;
61 private String language = null;
62 private String source = null;
63 private String created = null;
64 private Date startFrom = null;
65 private Date startTo = null;
66 private Date technicalStartFrom = null;
67 private Date technicalStartTo = null;
68 private String creator = null;
69 private String publisher = null;
70 private String license = null;
71 private String rights = null;
72 private String accessPolicy = null;
73 private String managedAcl = null;
74 private String workflowState = null;
75 private Long workflowId = null;
76 private String workflowDefinition = null;
77 private Long duration = null;
78 private String startDate = null;
79 private String eventStatus = null;
80 private Boolean hasComments = null;
81 private Boolean hasOpenComments = null;
82 private final List<String> comments = new ArrayList<>();
83 private Boolean needsCutting = null;
84 private final List<String> publications = new ArrayList<String>();
85 private Boolean isPublished = null;
86 private Long archiveVersion = null;
87 private String agentId = null;
88 private Date technicalStartTime = null;
89 private Date technicalEndTime = null;
90 private final List<String> technicalPresenters = new ArrayList<String>();
91
92 private static final Map<String, String> SORT_FIELDS = Map.of(
93 EventIndexSchema.TITLE, EventIndexSchema.TITLE.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
94 EventIndexSchema.CONTRIBUTOR, EventIndexSchema.CONTRIBUTOR.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
95 EventIndexSchema.PRESENTER, EventIndexSchema.PRESENTER.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
96 EventIndexSchema.SUBJECT, EventIndexSchema.SUBJECT.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
97 EventIndexSchema.DESCRIPTION, EventIndexSchema.DESCRIPTION.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
98 EventIndexSchema.LOCATION, EventIndexSchema.LOCATION.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
99 EventIndexSchema.SERIES_NAME, EventIndexSchema.SERIES_NAME.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
100 EventIndexSchema.CREATOR, EventIndexSchema.CREATOR.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
101 EventIndexSchema.PUBLISHER, EventIndexSchema.PUBLISHER.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION)
102 );
103
104 @SuppressWarnings("unused")
105 private EventSearchQuery() {
106 }
107
108 @Override
109 protected String sortOrderFieldName(String field) {
110 if (SORT_FIELDS.containsKey(field)) {
111 return SORT_FIELDS.get(field);
112 }
113 return field;
114 }
115
116
117
118
119 public EventSearchQuery(String organization, User user) {
120 super(Event.DOCUMENT_TYPE);
121 this.organization = organization;
122 this.user = user;
123 this.actions.add(Permissions.Action.READ.toString());
124 if (!user.hasRole(GLOBAL_ADMIN_ROLE)) {
125 if (!user.getOrganization().getId().equals(organization)) {
126 throw new IllegalStateException("User's organization must match search organization");
127 }
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140 public EventSearchQuery withIdentifier(String id) {
141 if (StringUtils.isBlank(id)) {
142 throw new IllegalArgumentException("Identifier cannot be null");
143 }
144 this.identifiers.add(id);
145 return this;
146 }
147
148
149
150
151
152
153 public String[] getIdentifier() {
154 return identifiers.toArray(new String[identifiers.size()]);
155 }
156
157
158
159
160
161
162 public String getOrganization() {
163 return organization;
164 }
165
166
167
168
169
170
171 public User getUser() {
172 return user;
173 }
174
175
176
177
178
179
180
181
182 public EventSearchQuery withTitle(String title) {
183 this.title = title;
184 return this;
185 }
186
187
188
189
190
191
192 public String getTitle() {
193 return title;
194 }
195
196
197
198
199
200
201 public EventSearchQuery withoutActions() {
202 this.actions.clear();
203 return this;
204 }
205
206
207
208
209
210
211
212
213
214
215 public EventSearchQuery withAction(Action action) {
216 if (action == null) {
217 throw new IllegalArgumentException("Action cannot be null");
218 }
219 this.actions.add(action.toString());
220 return this;
221 }
222
223
224
225
226
227
228 public String[] getActions() {
229 return actions.toArray(new String[actions.size()]);
230 }
231
232
233
234
235
236
237
238
239
240
241 public EventSearchQuery withPresenter(String presenter) {
242 if (StringUtils.isBlank(presenter)) {
243 throw new IllegalArgumentException("Presenter cannot be null");
244 }
245 this.presenters.add(presenter);
246 return this;
247 }
248
249
250
251
252
253
254 public String[] getPresenters() {
255 return presenters.toArray(new String[presenters.size()]);
256 }
257
258
259
260
261
262
263
264
265
266
267 public EventSearchQuery withContributor(String contributor) {
268 if (StringUtils.isBlank(contributor)) {
269 throw new IllegalArgumentException("Contributor cannot be null");
270 }
271 this.contributors.add(contributor);
272 return this;
273 }
274
275
276
277
278
279
280 public String[] getContributors() {
281 return contributors.toArray(new String[contributors.size()]);
282 }
283
284
285
286
287
288
289
290
291 public EventSearchQuery withSubject(String subject) {
292 this.subject = subject;
293 return this;
294 }
295
296
297
298
299
300
301 public String getSubject() {
302 return subject;
303 }
304
305
306
307
308
309
310
311
312
313
314
315
316 public EventSearchQuery withExtendedMetadata(String flavor, String key, String value) {
317 this.extendedMetadata.computeIfAbsent(flavor, h -> new HashMap<>())
318 .computeIfAbsent(key, a -> new ArrayList<>())
319 .add(value);
320 return this;
321 }
322
323
324
325
326
327
328 public Map<String, Map<String, List<String>>> getExtendedMetadata() {
329 return extendedMetadata;
330 }
331
332
333
334
335
336
337
338
339 public EventSearchQuery withDescription(String description) {
340 this.description = description;
341 return this;
342 }
343
344
345
346
347
348
349 public String getDescription() {
350 return description;
351 }
352
353
354
355
356
357
358
359
360 public EventSearchQuery withLocation(String location) {
361 this.location = location;
362 return this;
363 }
364
365
366
367
368
369
370 public String getLocation() {
371 return location;
372 }
373
374
375
376
377
378
379
380
381 public EventSearchQuery withSeriesId(String seriesId) {
382 this.seriesId = seriesId;
383 return this;
384 }
385
386
387
388
389
390
391 public String getSeriesId() {
392 return seriesId;
393 }
394
395
396
397
398
399
400
401
402 public EventSearchQuery withSeriesName(String seriesName) {
403 this.seriesName = seriesName;
404 return this;
405 }
406
407
408
409
410
411
412 public String getSeriesName() {
413 return seriesName;
414 }
415
416
417
418
419
420
421
422
423 public EventSearchQuery withLanguage(String language) {
424 this.language = language;
425 return this;
426 }
427
428
429
430
431
432
433 public String getLanguage() {
434 return language;
435 }
436
437
438
439
440
441
442
443
444 public EventSearchQuery withSource(String source) {
445 this.source = source;
446 return this;
447 }
448
449
450
451
452
453
454 public String getSource() {
455 return source;
456 }
457
458
459
460
461
462
463
464
465 public EventSearchQuery withCreated(String created) {
466 this.created = created;
467 return this;
468 }
469
470
471
472
473
474
475 public String getCreated() {
476 return created;
477 }
478
479
480
481
482
483
484
485
486 public EventSearchQuery withStartFrom(Date startFrom) {
487 this.startFrom = startFrom;
488 return this;
489 }
490
491
492
493
494 public Date getStartFrom() {
495 return startFrom;
496 }
497
498
499
500
501
502
503
504
505 public EventSearchQuery withStartTo(Date startTo) {
506 this.startTo = startTo;
507 return this;
508 }
509
510
511
512
513 public Date getStartTo() {
514 return startTo;
515 }
516
517
518
519
520
521
522
523
524 public EventSearchQuery withTechnicalStartFrom(Date startFrom) {
525 this.technicalStartFrom = startFrom;
526 return this;
527 }
528
529
530
531
532 public Date getTechnicalStartFrom() {
533 return technicalStartFrom;
534 }
535
536
537
538
539
540
541
542
543 public EventSearchQuery withTechnicalStartTo(Date startTo) {
544 this.technicalStartTo = startTo;
545 return this;
546 }
547
548
549
550
551 public Date getTechnicalStartTo() {
552 return technicalStartTo;
553 }
554
555
556
557
558
559
560
561
562 public EventSearchQuery withCreator(String creator) {
563 this.creator = creator;
564 return this;
565 }
566
567
568
569
570
571
572 public String getCreator() {
573 return creator;
574 }
575
576
577
578
579
580
581
582
583 public EventSearchQuery withPublisher(String publisher) {
584 this.publisher = publisher;
585 return this;
586 }
587
588
589
590
591
592
593 public String getPublisher() {
594 return publisher;
595 }
596
597
598
599
600
601
602
603
604 public EventSearchQuery withLicense(String license) {
605 this.license = license;
606 return this;
607 }
608
609
610
611
612
613
614 public String getLicense() {
615 return license;
616 }
617
618
619
620
621
622
623
624
625 public EventSearchQuery withRights(String rights) {
626 this.rights = rights;
627 return this;
628 }
629
630
631
632
633
634
635 public String getRights() {
636 return rights;
637 }
638
639
640
641
642
643
644
645
646 public EventSearchQuery withAccessPolicy(String accessPolicy) {
647 this.accessPolicy = accessPolicy;
648 return this;
649 }
650
651
652
653
654
655
656 public String getAccessPolicy() {
657 return accessPolicy;
658 }
659
660
661
662
663
664
665
666
667 public EventSearchQuery withManagedAcl(String managedAcl) {
668 this.managedAcl = managedAcl;
669 return this;
670 }
671
672
673
674
675
676
677 public String getManagedAcl() {
678 return managedAcl;
679 }
680
681
682
683
684
685
686
687
688 public EventSearchQuery withWorkflowState(String workflowState) {
689 this.workflowState = workflowState;
690 return this;
691 }
692
693
694
695
696
697
698 public String getWorkflowState() {
699 return workflowState;
700 }
701
702
703
704
705
706
707
708
709 public EventSearchQuery withWorkflowId(long workflowId) {
710 this.workflowId = workflowId;
711 return this;
712 }
713
714
715
716
717
718
719 public Long getWorkflowId() {
720 return workflowId;
721 }
722
723
724
725
726
727
728
729
730 public EventSearchQuery withWorkflowDefinition(String workflowDefinition) {
731 this.workflowDefinition = workflowDefinition;
732 return this;
733 }
734
735
736
737
738
739
740 public String getWorkflowDefinition() {
741 return workflowDefinition;
742 }
743
744
745
746
747
748
749
750
751 public EventSearchQuery withStartDate(String startDate) {
752 this.startDate = startDate;
753 return this;
754 }
755
756
757
758
759
760
761 public String getStartDate() {
762 return startDate;
763 }
764
765
766
767
768
769
770
771
772 public EventSearchQuery withDuration(long duration) {
773 this.duration = duration;
774 return this;
775 }
776
777
778
779
780
781
782 public Long getDuration() {
783 return duration;
784 }
785
786
787
788
789
790
791
792
793 public EventSearchQuery withEventStatus(String eventStatus) {
794 this.eventStatus = eventStatus;
795 return this;
796 }
797
798
799
800
801
802
803 public String getEventStatus() {
804 return eventStatus;
805 }
806
807
808
809
810
811
812
813
814 public EventSearchQuery withComments(boolean hasComments) {
815 this.hasComments = hasComments;
816 return this;
817 }
818
819
820
821
822
823
824
825
826 public EventSearchQuery withOpenComments(boolean hasOpenComments) {
827 this.hasOpenComments = hasOpenComments;
828 return this;
829 }
830
831
832
833
834
835
836
837
838 public EventSearchQuery withNeedsCutting(boolean needsCutting) {
839 this.needsCutting = needsCutting;
840 return this;
841 }
842
843
844
845
846
847
848 public Boolean getHasComments() {
849 return hasComments;
850 }
851
852
853
854
855
856
857 public Boolean getHasOpenComments() {
858 return hasOpenComments;
859 }
860
861 public EventSearchQuery withComments(String comment) {
862 if (StringUtils.isBlank(comment)) {
863 throw new IllegalArgumentException("Comment cannot be null");
864 }
865 this.comments.add(comment);
866 return this;
867 }
868
869 public String[] getComments() {
870 return comments.toArray(new String[comments.size()]);
871 }
872
873
874
875
876
877
878 public Boolean needsCutting() {
879 return needsCutting;
880 }
881
882
883
884
885
886
887
888
889
890
891 public EventSearchQuery withPublications(String publication) {
892 if (StringUtils.isBlank(publication)) {
893 throw new IllegalArgumentException("Publication cannot be null");
894 }
895 this.publications.add(publication);
896 return this;
897 }
898
899
900
901
902
903
904 public String[] getPublications() {
905 return publications.toArray(new String[publications.size()]);
906 }
907
908
909
910
911
912
913
914
915 public EventSearchQuery withIsPublished(boolean isPublished) {
916 this.isPublished = isPublished;
917 return this;
918 }
919
920
921
922
923
924
925 public Boolean getIsPublished() {
926 return isPublished;
927 }
928
929
930
931
932
933
934
935
936 public EventSearchQuery withArchiveVersion(long archiveVersion) {
937 this.archiveVersion = archiveVersion;
938 return this;
939 }
940
941
942
943
944
945
946 public Long getArchiveVersion() {
947 return archiveVersion;
948 }
949
950
951
952
953
954
955
956
957 public EventSearchQuery withAgentId(String agentId) {
958 this.agentId = agentId;
959 return this;
960 }
961
962
963
964
965
966
967 public String getAgentId() {
968 return agentId;
969 }
970
971
972
973
974
975
976
977
978 public EventSearchQuery withTechnicalStartTime(Date technicalStartTime) {
979 this.technicalStartTime = technicalStartTime;
980 return this;
981 }
982
983
984
985
986
987
988 public Date getTechnicalStartTime() {
989 return technicalStartTime;
990 }
991
992
993
994
995
996
997
998
999
1000 public EventSearchQuery withTechnicalEndTime(Date technicalEndTime) {
1001 this.technicalEndTime = technicalEndTime;
1002 return this;
1003 }
1004
1005
1006
1007
1008
1009
1010 public Date getTechnicalEndTime() {
1011 return technicalEndTime;
1012 }
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023 public EventSearchQuery withTechnicalPresenters(String presenter) {
1024 if (StringUtils.isBlank(presenter)) {
1025 throw new IllegalArgumentException("Presenter cannot be null");
1026 }
1027 this.technicalPresenters.add(presenter);
1028 return this;
1029 }
1030
1031
1032
1033
1034
1035
1036 public String[] getTechnicalPresenters() {
1037 return technicalPresenters.toArray(new String[technicalPresenters.size()]);
1038 }
1039
1040
1041
1042
1043
1044
1045
1046
1047 public EventSearchQuery sortByStartDate(Order order) {
1048 withSortOrder(EventIndexSchema.START_DATE, order);
1049 return this;
1050 }
1051
1052
1053
1054
1055
1056
1057 public Order getStartDateSortOrder() {
1058 return getSortOrder(EventIndexSchema.START_DATE);
1059 }
1060
1061
1062
1063
1064
1065
1066
1067
1068 public EventSearchQuery sortByTechnicalStartDate(Order order) {
1069 withSortOrder(EventIndexSchema.TECHNICAL_START, order);
1070 return this;
1071 }
1072
1073
1074
1075
1076
1077
1078 public Order getTechnicalStartDateSortOrder() {
1079 return getSortOrder(EventIndexSchema.TECHNICAL_START);
1080 }
1081
1082
1083
1084
1085
1086
1087
1088
1089 public EventSearchQuery sortByEndDate(Order order) {
1090 withSortOrder(EventIndexSchema.END_DATE, order);
1091 return this;
1092 }
1093
1094
1095
1096
1097
1098
1099 public Order getEndDateSortOrder() {
1100 return getSortOrder(EventIndexSchema.END_DATE);
1101 }
1102
1103
1104
1105
1106
1107
1108
1109
1110 public EventSearchQuery sortByTechnicalEndDate(Order order) {
1111 withSortOrder(EventIndexSchema.TECHNICAL_END, order);
1112 return this;
1113 }
1114
1115
1116
1117
1118
1119
1120 public Order getTechnicalEndDateSortOrder() {
1121 return getSortOrder(EventIndexSchema.TECHNICAL_END);
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131 public EventSearchQuery sortByDate(Order order) {
1132 withSortOrder(EventIndexSchema.END_DATE, order);
1133 return this;
1134 }
1135
1136
1137
1138
1139
1140
1141 public Order getDateSortOrder() {
1142 return getSortOrder(EventIndexSchema.END_DATE);
1143 }
1144
1145
1146
1147
1148
1149
1150
1151
1152 public EventSearchQuery sortByTitle(Order order) {
1153 withSortOrder(EventIndexSchema.TITLE, order);
1154 return this;
1155 }
1156
1157
1158
1159
1160
1161
1162 public Order getTitleSortOrder() {
1163 return getSortOrder(EventIndexSchema.TITLE);
1164 }
1165
1166 public EventSearchQuery sortByUID(Order order) {
1167 withSortOrder(EventIndexSchema.UID, order);
1168 return this;
1169 }
1170
1171 public Order getUIDSortOrder() {
1172 return getSortOrder(EventIndexSchema.UID);
1173 }
1174
1175
1176
1177
1178
1179
1180
1181
1182 public EventSearchQuery sortByPresenter(Order order) {
1183 withSortOrder(EventIndexSchema.PRESENTER, order);
1184 return this;
1185 }
1186
1187
1188
1189
1190
1191
1192 public Order getPresentersSortOrder() {
1193 return getSortOrder(EventIndexSchema.PRESENTER);
1194 }
1195
1196
1197
1198
1199
1200
1201
1202
1203 public EventSearchQuery sortByLocation(Order order) {
1204 withSortOrder(EventIndexSchema.LOCATION, order);
1205 return this;
1206 }
1207
1208
1209
1210
1211
1212
1213 public Order getLocationSortOrder() {
1214 return getSortOrder(EventIndexSchema.LOCATION);
1215 }
1216
1217
1218
1219
1220
1221
1222
1223
1224 public EventSearchQuery sortBySeriesName(Order order) {
1225 withSortOrder(EventIndexSchema.SERIES_NAME, order);
1226 return this;
1227 }
1228
1229
1230
1231
1232
1233
1234 public Order getSeriesNameSortOrder() {
1235 return getSortOrder(EventIndexSchema.SERIES_NAME);
1236 }
1237
1238
1239
1240
1241
1242
1243
1244
1245 public EventSearchQuery sortByManagedAcl(Order order) {
1246 withSortOrder(EventIndexSchema.MANAGED_ACL, order);
1247 return this;
1248 }
1249
1250
1251
1252
1253
1254
1255 public Order getManagedAclSortOrder() {
1256 return getSortOrder(EventIndexSchema.MANAGED_ACL);
1257 }
1258
1259
1260
1261
1262
1263
1264
1265
1266 public EventSearchQuery sortByWorkflowState(Order order) {
1267 withSortOrder(EventIndexSchema.WORKFLOW_STATE, order);
1268 return this;
1269 }
1270
1271
1272
1273
1274
1275
1276 public Order getWorkflowStateSortOrder() {
1277 return getSortOrder(EventIndexSchema.WORKFLOW_STATE);
1278 }
1279
1280
1281
1282
1283
1284
1285
1286
1287 public EventSearchQuery sortByEventStatus(Order order) {
1288 withSortOrder(EventIndexSchema.EVENT_STATUS, order);
1289 return this;
1290 }
1291
1292
1293
1294
1295
1296
1297 public Order getEventStatusSortOrder() {
1298 return getSortOrder(EventIndexSchema.EVENT_STATUS);
1299 }
1300
1301
1302
1303
1304
1305
1306
1307
1308 public EventSearchQuery sortByPublicationIgnoringInternal(Order order) {
1309
1310 withSortOrder(EventIndexSchema.PUBLICATION, order);
1311 return this;
1312 }
1313
1314
1315
1316
1317
1318
1319 public Order getPublicationSortOrder() {
1320
1321 return getSortOrder(EventIndexSchema.PUBLICATION);
1322 }
1323 }