1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.opencastproject.elasticsearch.index.objects.theme;
24
25 import org.opencastproject.elasticsearch.api.SearchTerms;
26 import org.opencastproject.elasticsearch.impl.AbstractSearchQuery;
27 import org.opencastproject.elasticsearch.impl.IndexSchema;
28 import org.opencastproject.security.api.User;
29 import org.opencastproject.util.requests.SortCriterion.Order;
30
31 import org.apache.commons.lang3.StringUtils;
32
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.List;
36 import java.util.Map;
37
38
39
40
41 public class ThemeSearchQuery extends AbstractSearchQuery {
42
43 protected List<Long> identifiers = new ArrayList<Long>();
44 private User user = null;
45 private String organization = null;
46 private String creator = null;
47 private Date createdFrom = null;
48 private Date createdTo = null;
49 private Boolean isDefault = null;
50 private String description = null;
51 private String name = null;
52 private Boolean bumperActive = null;
53 private String bumperFile = null;
54 private Boolean licenseSlideActive = null;
55 private String licenseSlideBackground = null;
56 private String licenseSlideDescription = null;
57 private Boolean trailerActive = null;
58 private String trailerFile = null;
59 private Boolean titleSlideActive = null;
60 private String titleSlideBackground = null;
61 private String titleSlideMetadata = null;
62 private Boolean watermarkActive = null;
63 private String watermarkFile = null;
64 private String watermarkPosition = null;
65
66 private static final Map<String, String> SORT_FIELDS = Map.of(
67 ThemeIndexSchema.CREATOR, ThemeIndexSchema.CREATOR.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
68 ThemeIndexSchema.NAME, ThemeIndexSchema.NAME.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION),
69 ThemeIndexSchema.DESCRIPTION, ThemeIndexSchema.DESCRIPTION.concat(IndexSchema.SORT_FIELD_NAME_EXTENSION)
70 );
71
72 @SuppressWarnings("unused")
73 private ThemeSearchQuery() {
74 }
75
76 @Override
77 protected String sortOrderFieldName(String field) {
78 if (SORT_FIELDS.containsKey(field)) {
79 return SORT_FIELDS.get(field);
80 }
81 return field;
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95 public ThemeSearchQuery(String organization, User user) {
96 super(IndexTheme.DOCUMENT_TYPE);
97
98 if (organization == null) {
99 throw new IllegalStateException("The organization for this query was null.");
100 }
101
102 if (user == null) {
103 throw new IllegalStateException("The user for this query was null.");
104 }
105
106 this.organization = organization;
107 this.user = user;
108 if (!user.getOrganization().getId().equals(organization)) {
109 throw new IllegalStateException("User's organization must match search organization");
110 }
111 }
112
113
114
115
116
117
118
119
120
121
122 public ThemeSearchQuery withIdentifier(long id) {
123 this.identifiers.add(id);
124 return this;
125 }
126
127
128
129
130
131
132 public Long[] getIdentifiers() {
133 return identifiers.toArray(new Long[identifiers.size()]);
134 }
135
136
137
138
139
140
141
142
143 public ThemeSearchQuery withDescription(String description) {
144 this.description = description;
145 return this;
146 }
147
148
149
150
151
152
153 public String getDescription() {
154 return description;
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 ThemeSearchQuery withCreator(String creator) {
183 this.creator = creator;
184 return this;
185 }
186
187
188
189
190
191
192 public String getCreator() {
193 return creator;
194 }
195
196
197
198
199
200
201
202
203 public ThemeSearchQuery withCreatedFrom(Date createdFrom) {
204 this.createdFrom = createdFrom;
205 return this;
206 }
207
208
209
210
211 public Date getCreatedFrom() {
212 return createdFrom;
213 }
214
215
216
217
218
219
220
221
222 public ThemeSearchQuery withCreatedTo(Date createdTo) {
223 this.createdTo = createdTo;
224 return this;
225 }
226
227
228
229
230 public Date getCreatedTo() {
231 return createdTo;
232 }
233
234
235
236
237
238
239
240
241 public ThemeSearchQuery withIsDefault(Boolean isDefault) {
242 this.isDefault = isDefault;
243 return this;
244 }
245
246
247
248
249
250
251 public Boolean getIsDefault() {
252 return isDefault;
253 }
254
255
256
257
258
259
260
261
262 public ThemeSearchQuery withName(String name) {
263 this.name = name;
264 return this;
265 }
266
267
268
269
270
271
272 public String getName() {
273 return name;
274 }
275
276
277
278
279
280
281
282
283 public ThemeSearchQuery withBumperActive(Boolean bumperActive) {
284 this.bumperActive = bumperActive;
285 return this;
286 }
287
288
289
290
291
292
293 public Boolean getBumperActive() {
294 return bumperActive;
295 }
296
297
298
299
300
301
302
303
304 public ThemeSearchQuery withBumperFile(String bumperFile) {
305 this.bumperFile = bumperFile;
306 return this;
307 }
308
309
310
311
312
313
314 public String getBumperFile() {
315 return bumperFile;
316 }
317
318
319
320
321
322
323
324
325 public ThemeSearchQuery withLicenseSlideActive(Boolean licenseSlideActive) {
326 this.licenseSlideActive = licenseSlideActive;
327 return this;
328 }
329
330
331
332
333
334
335 public Boolean getLicenseSlideActive() {
336 return licenseSlideActive;
337 }
338
339
340
341
342
343
344
345
346 public ThemeSearchQuery withLicenseSlideBackground(String licenseSlideBackground) {
347 this.licenseSlideBackground = licenseSlideBackground;
348 return this;
349 }
350
351
352
353
354
355
356 public String getLicenseSlideBackground() {
357 return licenseSlideBackground;
358 }
359
360
361
362
363
364
365
366
367 public ThemeSearchQuery withLicenseSlideDescription(String licenseSlideDescription) {
368 this.licenseSlideDescription = licenseSlideDescription;
369 return this;
370 }
371
372
373
374
375
376
377 public String getLicenseSlideDescription() {
378 return licenseSlideDescription;
379 }
380
381
382
383
384
385
386
387
388 public ThemeSearchQuery withTrailerActive(Boolean trailerActive) {
389 this.trailerActive = trailerActive;
390 return this;
391 }
392
393
394
395
396
397
398 public Boolean getTrailerActive() {
399 return trailerActive;
400 }
401
402
403
404
405
406
407
408
409 public ThemeSearchQuery withTrailerFile(String trailerFile) {
410 this.trailerFile = trailerFile;
411 return this;
412 }
413
414
415
416
417
418
419 public String getTrailerFile() {
420 return trailerFile;
421 }
422
423
424
425
426
427
428
429
430 public ThemeSearchQuery withTitleSlideActive(Boolean titleSlideActive) {
431 this.titleSlideActive = titleSlideActive;
432 return this;
433 }
434
435
436
437
438
439
440 public Boolean getTitleSlideActive() {
441 return titleSlideActive;
442 }
443
444
445
446
447
448
449
450
451 public ThemeSearchQuery withTitleSlideMetadata(String titleSlideMetadata) {
452 this.titleSlideMetadata = titleSlideMetadata;
453 return this;
454 }
455
456
457
458
459
460
461 public String getTitleSlideMetadata() {
462 return titleSlideMetadata;
463 }
464
465
466
467
468
469
470
471
472 public ThemeSearchQuery withTitleSlideBackground(String titleSlideBackground) {
473 this.titleSlideBackground = titleSlideBackground;
474 return this;
475 }
476
477
478
479
480 public String getTitleSlideBackground() {
481 return titleSlideBackground;
482 }
483
484
485
486
487
488
489
490
491 public ThemeSearchQuery withWatermarkActive(Boolean watermarkActive) {
492 this.watermarkActive = watermarkActive;
493 return this;
494 }
495
496
497
498
499 public Boolean getWatermarkActive() {
500 return watermarkActive;
501 }
502
503
504
505
506
507
508
509
510 public ThemeSearchQuery withWatermarkFile(String watermarkFile) {
511 this.watermarkFile = watermarkFile;
512 return this;
513 }
514
515
516
517
518 public String getWatermarkFile() {
519 return watermarkFile;
520 }
521
522
523
524
525
526
527
528
529 public ThemeSearchQuery withLicense(String watermarkPosition) {
530 this.watermarkPosition = watermarkPosition;
531 return this;
532 }
533
534
535
536
537 public String getWatermarkPosition() {
538 return watermarkPosition;
539 }
540
541
542
543
544
545
546
547
548 public ThemeSearchQuery sortByCreator(Order order) {
549 withSortOrder(ThemeIndexSchema.CREATOR, order);
550 return this;
551 }
552
553
554
555
556
557
558 public Order getThemeCreatorSortOrder() {
559 return getSortOrder(ThemeIndexSchema.CREATOR);
560 }
561
562
563
564
565
566
567
568
569 public ThemeSearchQuery sortByCreatedDateTime(Order order) {
570 withSortOrder(ThemeIndexSchema.CREATION_DATE, order);
571 return this;
572 }
573
574
575
576
577
578
579
580
581 public ThemeSearchQuery sortByDefault(Order order) {
582 withSortOrder(ThemeIndexSchema.DEFAULT, order);
583 return this;
584 }
585
586
587
588
589
590
591 public Order getSeriesDateSortOrder() {
592 return getSortOrder(ThemeIndexSchema.CREATION_DATE);
593 }
594
595
596
597
598
599
600
601
602 public ThemeSearchQuery sortByName(Order order) {
603 withSortOrder(ThemeIndexSchema.NAME, order);
604 return this;
605 }
606
607
608
609
610
611
612 public Order getThemeNameSortOrder() {
613 return getSortOrder(ThemeIndexSchema.NAME);
614 }
615
616
617
618
619
620
621
622
623 public ThemeSearchQuery sortByDescription(Order order) {
624 withSortOrder(ThemeIndexSchema.DESCRIPTION, order);
625 return this;
626 }
627
628
629
630
631
632
633 public Order getThemeDescriptionSortOrder() {
634 return getSortOrder(ThemeIndexSchema.DESCRIPTION);
635 }
636
637 @Override
638 public String toString() {
639 StringBuilder sb = new StringBuilder();
640 sb.append(ThemeSearchQuery.class.getSimpleName() + " ");
641
642 if (identifiers.size() > 0) {
643 sb.append("ids:'" + identifiers.toString() + "' ");
644 }
645
646 if (StringUtils.trimToNull(organization) != null) {
647 sb.append("organization:'" + organization + "' ");
648 }
649
650 if (StringUtils.trimToNull(creator) != null) {
651 sb.append("creator:'" + creator + "' ");
652 }
653
654 if (createdFrom != null) {
655 sb.append("Created From:'" + createdFrom + "' ");
656 }
657
658 if (createdTo != null) {
659 sb.append("Created To:'" + createdTo + "' ");
660 }
661
662 sb.append("Is Default:'" + isDefault + "' ");
663
664 if (StringUtils.trimToNull(description) != null) {
665 sb.append("description:'" + description + "' ");
666 }
667
668 if (StringUtils.trimToNull(name) != null) {
669 sb.append("name:'" + name + "' ");
670 }
671
672 sb.append("bumper active:'" + bumperActive + "' ");
673
674 if (StringUtils.trimToNull(bumperFile) != null) {
675 sb.append("bumper file:'" + bumperFile + "' ");
676 }
677
678 sb.append("license slide active:'" + licenseSlideActive + "' ");
679
680 if (StringUtils.trimToNull(licenseSlideBackground) != null) {
681 sb.append("license slide background:'" + licenseSlideBackground + "' ");
682 }
683
684 if (StringUtils.trimToNull(licenseSlideDescription) != null) {
685 sb.append("license slide description:'" + licenseSlideDescription + "' ");
686 }
687
688 sb.append("trailer active:'" + trailerActive + "' ");
689
690 if (StringUtils.trimToNull(trailerFile) != null) {
691 sb.append("trailer file:'" + trailerFile + "' ");
692 }
693
694 sb.append("title slide active:'" + titleSlideActive + "' ");
695
696 if (StringUtils.trimToNull(titleSlideBackground) != null) {
697 sb.append("title slide background:'" + titleSlideBackground + "' ");
698 }
699
700 if (StringUtils.trimToNull(titleSlideMetadata) != null) {
701 sb.append("title slide metadata:'" + titleSlideMetadata + "' ");
702 }
703
704 sb.append("watermark active:'" + watermarkActive + "' ");
705
706 if (StringUtils.trimToNull(watermarkFile) != null) {
707 sb.append("watermark file:'" + watermarkFile + "' ");
708 }
709
710 if (StringUtils.trimToNull(watermarkPosition) != null) {
711 sb.append("watermark position:'" + watermarkPosition + "' ");
712 }
713
714 if (getTerms().size() > 0) {
715 sb.append("Text:");
716 for (SearchTerms<String> searchTerm : getTerms()) {
717 sb.append("'" + searchTerm.getTerms() + "' ");
718 }
719 }
720 return sb.toString();
721 }
722 }