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