View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.list.common.query;
23  
24  import org.opencastproject.capture.admin.api.AgentsListProvider;
25  import org.opencastproject.list.api.DefaultResourceListQuery;
26  import org.opencastproject.list.api.ResourceListFilter;
27  import org.opencastproject.list.api.ResourceListFilter.SourceType;
28  import org.opencastproject.list.common.provider.ContributorsListProvider;
29  import org.opencastproject.list.common.provider.EventsListProvider;
30  import org.opencastproject.list.common.provider.SeriesListProvider;
31  import org.opencastproject.list.util.FiltersUtils;
32  import org.opencastproject.util.data.Tuple;
33  
34  import java.util.Date;
35  import java.util.Optional;
36  
37  /**
38   * Query for the events list.
39   *
40   * The following filters can be used:
41   * <ul>
42   * <li>series</li>
43   * <li>presenters</li>
44   * <li>presenter's usernames</li>
45   * <li>contributors</li>
46   * <li>location</li>
47   * <li>agent</li>
48   * <li>language</li>
49   * <li>startDate</li>
50   * <li>status</li>
51   * </ul>
52   */
53  public class EventListQuery extends DefaultResourceListQuery {
54  
55    public static final String FILTER_SERIES_NAME = "series";
56    private static final String FILTER_SERIES_LABEL = "FILTERS.EVENTS.SERIES.LABEL";
57  
58    public static final String FILTER_PRESENTERS_BIBLIOGRAPHIC_NAME = "presentersBibliographic";
59    private static final String FILTER_PRESENTERS_BIBLIOGRAPHIC_LABEL = "FILTERS.EVENTS.PRESENTERS_BIBLIOGRAPHIC.LABEL";
60  
61    public static final String FILTER_PRESENTERS_TECHNICAL_NAME = "presentersTechnical";
62    private static final String FILTER_PRESENTERS_TECHNICAL_LABEL = "FILTERS.EVENTS.PRESENTERS_TECHNICAL.LABEL";
63  
64    public static final String FILTER_CONTRIBUTORS_NAME = "contributors";
65    private static final String FILTER_CONTRIBUTORS_LABEL = "FILTERS.EVENTS.CONTRIBUTORS.LABEL";
66  
67    public static final String FILTER_LOCATION_NAME = "location";
68    private static final String FILTER_LOCATION_LABEL = "FILTERS.EVENTS.LOCATION.LABEL";
69  
70    public static final String FILTER_AGENT_NAME = "agent";
71    private static final String FILTER_AGENT_LABEL = "FILTERS.EVENTS.AGENT_ID.LABEL";
72  
73    public static final String FILTER_LANGUAGE_NAME = "language";
74    private static final String FILTER_LANGUAGE_LABEL = "FILTERS.EVENTS.LANGUAGE.LABEL";
75  
76    public static final String FILTER_STARTDATE_NAME = "startDate";
77    private static final String FILTER_STARTDATE_LABEL = "FILTERS.EVENTS.START_DATE.LABEL";
78  
79    public static final String FILTER_STATUS_NAME = "status";
80    private static final String FILTER_STATUS_LABEL = "FILTERS.EVENTS.STATUS.LABEL";
81  
82    public static final String FILTER_COMMENTS_NAME = "comments";
83    private static final String FILTER_COMMENTS_LABEL = "FILTERS.EVENTS.COMMENTS.LABEL";
84  
85    public static final String FILTER_PUBLISHER_NAME = "publisher";
86    private static final String FILTER_PUBLISHER_LABEL = "FILTERS.EVENTS.PUBLISHER.LABEL";
87  
88    public static final String FILTER_TEXT_NAME = "textFilter";
89  
90    public static final String FILTER_IS_PUBLISHED_NAME = "isPublished";
91    public static final String FILTER_IS_PUBLISHED_LABEL = "FILTERS.EVENTS.IS_PUBLISHED.LABEL";
92  
93    public static final String FILTER_READ_ACCESS_NAME = "readAccess";
94    public static final String FILTER_READ_ACCESS_LABEL = "FILTERS.EVENTS.READ_ACCESS.LABEL";
95  
96    public static final String FILTER_WRITE_ACCESS_NAME = "writeAccess";
97    public static final String FILTER_WRITE_ACCESS_LABEL = "FILTERS.EVENTS.WRITE_ACCESS.LABEL";
98  
99    public EventListQuery() {
100     super();
101     this.availableFilters.add(createSeriesFilter(Optional.empty()));
102     this.availableFilters.add(createLocationFilter(Optional.empty()));
103     this.availableFilters.add(createAgentFilter(Optional.empty()));
104     this.availableFilters.add(createLanguageFilter(Optional.empty()));
105     this.availableFilters.add(createStartDateFilter(Optional.empty()));
106     this.availableFilters.add(createStatusFilter(Optional.empty()));
107     this.availableFilters.add(createCommentsFilter(Optional.empty()));
108     this.availableFilters.add(createIsPublishedFilter(Optional.empty()));
109     this.availableFilters.add(createReadAccessFilter(Optional.empty()));
110     this.availableFilters.add(createWriteAccessFilter(Optional.empty()));
111   }
112 
113   /**
114    * Add a {@link ResourceListFilter} filter to the query with the given seriesId
115    *
116    * @param seriesId
117    *          the seriesId to filter with
118    */
119   public void withSeriesId(String seriesId) {
120     this.addFilter(createSeriesFilter(Optional.ofNullable(seriesId)));
121   }
122 
123   /**
124    * Returns an {@link Optional} containing the seriesId used to filter if set
125    *
126    * @return an {@link Optional} containing the seriesId or none.
127    */
128   public Optional<String> getSeriesId() {
129     return this.getFilterValue(FILTER_SERIES_NAME);
130   }
131 
132   /**
133    * Add a {@link ResourceListFilter} filter to the query with the given presenter
134    *
135    * @param presenter
136    *          the presenter to filter for
137    */
138   public void withPresenter(String presenter) {
139     this.addFilter(createPresentersFilter(Optional.ofNullable(presenter)));
140   }
141 
142   /**
143    * Returns an {@link Optional} containing the presenter used to filter if set
144    *
145    * @return an {@link Optional} containing the presenter or none.
146    */
147   public Optional<String> getPresenter() {
148     return this.getFilterValue(FILTER_PRESENTERS_BIBLIOGRAPHIC_NAME);
149   }
150 
151   /**
152    * Add a {@link ResourceListFilter} filter to the query with the given technical presenter's username
153    *
154    * @param presenter
155    *          presenter's username the presenter's username to filter for
156    */
157   public void withTechnicalPresenter(String presenter) {
158     this.addFilter(createTechnicalPresentersFilter(Optional.ofNullable(presenter)));
159   }
160 
161   /**
162    * Returns an {@link Optional} containing the technical presenter's username used to filter if set
163    *
164    * @return an {@link Optional} containing the presenter or none.
165    */
166   public Optional<String> getTechnicalPresenter() {
167     return this.getFilterValue(FILTER_PRESENTERS_TECHNICAL_NAME);
168   }
169 
170   /**
171    * Add a {@link ResourceListFilter} filter to the query with the given contributor
172    *
173    * @param contributor
174    *          the contributor to filter for
175    */
176   public void withContributor(String contributor) {
177     this.addFilter(createContributorsFilter(Optional.ofNullable(contributor)));
178   }
179 
180   /**
181    * Returns an {@link Optional} containing the contributor used to filter if set
182    *
183    * @return an {@link Optional} containing the contributor or none.
184    */
185   public Optional<String> getContributor() {
186     return this.getFilterValue(FILTER_CONTRIBUTORS_NAME);
187   }
188 
189   /**
190    * Add a {@link ResourceListFilter} filter to the query with the given subject
191    *
192    * @param location
193    *          the subject to filter for
194    */
195   public void withLocation(String location) {
196     this.addFilter(createLocationFilter(Optional.ofNullable(location)));
197   }
198 
199   /**
200    * Returns an {@link Optional} containing the location used to filter if set
201    *
202    * @return an {@link Optional} containing the location or none.
203    */
204   public Optional<String> getLocation() {
205     return this.getFilterValue(FILTER_LOCATION_NAME);
206   }
207 
208   /**
209    * Add a {@link ResourceListFilter} filter to the query with the given subject
210    *
211    * @param agent
212    *          the agent to filter for
213    */
214   public void withAgent(String agent) {
215     this.addFilter(createAgentFilter(Optional.ofNullable(agent)));
216   }
217 
218   /**
219    * Returns an {@link Optional} containing the agent used to filter if set
220    *
221    * @return an {@link Optional} containing the agent or none.
222    */
223   public Optional<String> getAgent() {
224     return this.getFilterValue(FILTER_AGENT_NAME);
225   }
226 
227   /**
228    * Add a {@link ResourceListFilter} filter to the query with the given subject
229    *
230    * @param language
231    *          the subject to filter for
232    */
233   public void withLanguage(String language) {
234     this.addFilter(createLanguageFilter(Optional.ofNullable(language)));
235   }
236 
237   /**
238    * Returns an {@link Optional} containing the language used to filter if set
239    *
240    * @return an {@link Optional} containing the language or none.
241    */
242   public Optional<String> getLanguage() {
243     return this.getFilterValue(FILTER_LANGUAGE_NAME);
244   }
245 
246   /**
247    * Add a {@link ResourceListFilter} filter to the query with the given start date period
248    *
249    * @param startDate
250    *          the start date period as {@link Tuple} with two {@link Date}.
251    */
252   public void withStartDate(Tuple<Date, Date> startDate) {
253     this.addFilter(createStartDateFilter(Optional.ofNullable(startDate)));
254   }
255 
256   /**
257    * Returns an {@link Optional} containing the start date period used to filter if set
258    *
259    * @return an {@link Optional} containing the start date period or none.
260    */
261   public Optional<Tuple<Date, Date>> getStartDate() {
262     return this.getFilterValue(FILTER_STARTDATE_NAME);
263   }
264 
265   /**
266    * Add a {@link ResourceListFilter} filter to the query with the given status
267    *
268    * @param status
269    *          the status to filter for
270    */
271   public void withStatus(String status) {
272     this.addFilter(createStatusFilter(Optional.ofNullable(status)));
273   }
274 
275   /**
276    * Returns an {@link Optional} containing the status used to filter if set
277    *
278    * @return an {@link Optional} containing the status or none.
279    */
280   public Optional<String> getStatus() {
281     return this.getFilterValue(FILTER_STATUS_NAME);
282   }
283 
284   /**
285    * Add a {@link ResourceListFilter} filter to the query with the given comments
286    *
287    * @param comments
288    *          the comments to filter for
289    */
290   public void withComments(String comments) {
291     this.addFilter(createCommentsFilter(Optional.ofNullable(comments)));
292   }
293 
294   /**
295    * Returns an {@link Optional} containing the comments used to filter if set
296    *
297    * @return an {@link Optional} containing the comments or none.
298    */
299   public Optional<String> getComments() {
300     return this.getFilterValue(FILTER_COMMENTS_NAME);
301   }
302 
303   /**
304    * Add a {@link ResourceListFilter} filter to the query with the given publishers
305    *
306    * @param publishers
307    *          the publishers to filter for
308    */
309   public void withPublishers(String publishers) {
310     this.addFilter(createPublisherFilter(Optional.ofNullable(publishers)));
311   }
312 
313   /**
314    * Returns an {@link Optional} containing the publisher used to filter if set
315    *
316    * @return an {@link Optional} containing the publisher or none.
317    */
318   public Optional<String> getPublisher() {
319     return this.getFilterValue(FILTER_PUBLISHER_NAME);
320   }
321 
322   /**
323    * Create a new {@link ResourceListFilter} based on the Series id
324    *
325    * @param seriesId
326    *          the series id to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
327    * @return a new {@link ResourceListFilter} for the Series name based query
328    */
329   public static ResourceListFilter<String> createSeriesFilter(Optional<String> seriesId) {
330     return FiltersUtils.generateFilter(seriesId, FILTER_SERIES_NAME, FILTER_SERIES_LABEL, SourceType.SELECT,
331             Optional.of(SeriesListProvider.PROVIDER_PREFIX));
332   }
333 
334   /**
335    * Create a new {@link ResourceListFilter} based on a presenter's full name
336    *
337    * @param presenter's
338    *          name the presenters to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
339    * @return a new {@link ResourceListFilter} for a presenters based query
340    */
341   public static ResourceListFilter<String> createPresentersFilter(Optional<String> presenter) {
342     return FiltersUtils.generateFilter(presenter, FILTER_PRESENTERS_BIBLIOGRAPHIC_NAME,
343             FILTER_PRESENTERS_BIBLIOGRAPHIC_LABEL, SourceType.SELECT, Optional.of(ContributorsListProvider.DEFAULT));
344   }
345 
346   /**
347    * Create a new {@link ResourceListFilter} based on a presenter's user name
348    *
349    * @param presenter
350    *          the presenters to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
351    * @return a new {@link ResourceListFilter} for a presenters based query
352    */
353   public static ResourceListFilter<String> createTechnicalPresentersFilter(Optional<String> presenter) {
354     return FiltersUtils.generateFilter(presenter, FILTER_PRESENTERS_TECHNICAL_NAME, FILTER_PRESENTERS_TECHNICAL_LABEL,
355             SourceType.SELECT, Optional.of(ContributorsListProvider.USERNAMES));
356   }
357 
358   /**
359    * Create a new {@link ResourceListFilter} based on a contributor
360    *
361    * @param contributor
362    *          the series id to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
363    * @return a new {@link ResourceListFilter} for a contributor based query
364    */
365   public static ResourceListFilter<String> createContributorsFilter(Optional<String> contributor) {
366     return FiltersUtils.generateFilter(contributor, FILTER_CONTRIBUTORS_NAME, FILTER_CONTRIBUTORS_LABEL,
367             SourceType.SELECT, Optional.of(ContributorsListProvider.DEFAULT));
368   }
369 
370   /**
371    * Create a new {@link ResourceListFilter} based on a location
372    *
373    * @param location
374    *          the location to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
375    * @return a new {@link ResourceListFilter} for a location based query
376    */
377   public static ResourceListFilter<String> createLocationFilter(Optional<String> location) {
378     return FiltersUtils.generateFilter(location, FILTER_LOCATION_NAME, FILTER_LOCATION_LABEL, SourceType.SELECT,
379             Optional.of(EventsListProvider.LOCATION));
380   }
381 
382   /**
383    * Create a new {@link ResourceListFilter} based on an agent
384    *
385    * @param agent
386    *          the agent to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
387    * @return a new {@link ResourceListFilter} for a location based query
388    */
389   public static ResourceListFilter<String> createAgentFilter(Optional<String> agent) {
390     return FiltersUtils.generateFilter(agent, FILTER_AGENT_NAME, FILTER_AGENT_LABEL, SourceType.SELECT,
391             Optional.of(AgentsListProvider.NAME));
392   }
393 
394   /**
395    * Create a new {@link ResourceListFilter} based on a language
396    *
397    * @param language
398    *          the language to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
399    * @return a new {@link ResourceListFilter} for a language based query
400    */
401   public static ResourceListFilter<String> createLanguageFilter(Optional<String> language) {
402     return FiltersUtils.generateFilter(language, FILTER_LANGUAGE_NAME, FILTER_LANGUAGE_LABEL, SourceType.SELECT,
403             Optional.of("LANGUAGES"));
404   }
405 
406   /**
407    * Create a new {@link ResourceListFilter} based on start date period
408    *
409    * @param period
410    *          the period to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
411    * @return a new {@link ResourceListFilter} for the given period
412    */
413   public static ResourceListFilter<Tuple<Date, Date>> createStartDateFilter(Optional<Tuple<Date, Date>> period) {
414     return FiltersUtils.generateFilter(period, FILTER_STARTDATE_NAME, FILTER_STARTDATE_LABEL, SourceType.PERIOD,
415             Optional.empty());
416   }
417 
418   /**
419    * Create a new {@link ResourceListFilter} based on stats
420    *
421    * @param status
422    *          the status to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
423    * @return a new {@link ResourceListFilter} for progress based query
424    */
425   public static ResourceListFilter<String> createStatusFilter(Optional<String> status) {
426     return FiltersUtils.generateFilter(status, FILTER_STATUS_NAME, FILTER_STATUS_LABEL, SourceType.SELECT,
427             Optional.of(EventsListProvider.STATUS));
428   }
429 
430   /**
431    * Create a new {@link ResourceListFilter} based on comments
432    *
433    * @param comments
434    *          the comments to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
435    * @return a new {@link ResourceListFilter} for progress based query
436    */
437   public static ResourceListFilter<String> createCommentsFilter(Optional<String> comments) {
438     return FiltersUtils.generateFilter(comments, FILTER_COMMENTS_NAME, FILTER_COMMENTS_LABEL, SourceType.SELECT,
439             Optional.of(EventsListProvider.COMMENTS));
440   }
441 
442   /**
443    * Create a new {@link ResourceListFilter} based on publishers
444    *
445    * @param publisher
446    *          the publisher to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
447    * @return a new {@link ResourceListFilter} for progress based query
448    */
449   public static ResourceListFilter<String> createPublisherFilter(Optional<String> publisher) {
450     return FiltersUtils.generateFilter(publisher, FILTER_PUBLISHER_NAME, FILTER_PUBLISHER_LABEL, SourceType.SELECT,
451             Optional.of(EventsListProvider.PUBLISHER));
452   }
453 
454   /**
455    * Create a new {@link ResourceListFilter} based on is published
456    * @param isPublished
457    *          the is published status to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
458    * @return a new {@link ResourceListFilter} for progress based query
459    */
460   public static ResourceListFilter<String> createIsPublishedFilter(Optional<String> isPublished) {
461     return FiltersUtils.generateFilter(isPublished, FILTER_IS_PUBLISHED_NAME, FILTER_IS_PUBLISHED_LABEL,
462         SourceType.SELECT, Optional.of(EventsListProvider.ISPUBLISHED));
463   }
464 
465   /**
466    * Create a new {@link ResourceListFilter} based on a read role
467    *
468    * @param readAccess
469    *          the read role to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
470    * @return a new {@link ResourceListFilter} for a read role based query
471    */
472   public static ResourceListFilter<String> createReadAccessFilter(Optional<String> readAccess) {
473     return FiltersUtils.generateFilter(readAccess, FILTER_READ_ACCESS_NAME, FILTER_READ_ACCESS_LABEL,
474         SourceType.FREETEXT, Optional.of("ROLES.TARGET.ACL"));
475   }
476 
477   /**
478    * Create a new {@link ResourceListFilter} based on a write role
479    *
480    * @param writeAccess
481    *          the write role to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
482    * @return a new {@link ResourceListFilter} for a write role based query
483    */
484   public static ResourceListFilter<String> createWriteAccessFilter(Optional<String> writeAccess) {
485     return FiltersUtils.generateFilter(writeAccess, FILTER_WRITE_ACCESS_NAME, FILTER_WRITE_ACCESS_LABEL,
486         SourceType.FREETEXT, Optional.of("ROLES.TARGET.ACL"));
487   }
488 
489 }