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.capture.admin.api;
23
24 import org.opencastproject.list.api.DefaultResourceListQuery;
25 import org.opencastproject.list.api.ResourceListFilter;
26 import org.opencastproject.list.api.ResourceListFilter.SourceType;
27 import org.opencastproject.list.util.FiltersUtils;
28
29 import java.util.Optional;
30
31 /**
32 * Query for the capture-agents list.
33 *
34 * The following filters can be used:
35 * <ul>
36 * <li>name</li>
37 * <li>status</li>
38 * </ul>
39 */
40 public class AgentsListQuery extends DefaultResourceListQuery {
41
42 public static final String FILTER_NAME_NAME = "Name";
43 private static final String FILTER_NAME_LABEL = "FILTERS.AGENTS.NAME.LABEL";
44
45 public static final String FILTER_STATUS_NAME = "Status";
46 private static final String FILTER_STATUS_LABEL = "FILTERS.AGENTS.STATUS.LABEL";
47
48 public static final String FILTER_LAST_UPDATED = "LastUpdated";
49
50 public static final String FILTER_TEXT_NAME = "textFilter";
51
52 public AgentsListQuery() {
53 super();
54 this.availableFilters.add(createStatusFilter(Optional.<String> empty()));
55 }
56
57 /**
58 * Add a {@link ResourceListFilter} filter to the query with the given name
59 *
60 * @param name
61 * the name to filter for
62 */
63 public void withName(String name) {
64 this.addFilter(createNameFilter(Optional.ofNullable(name)));
65 }
66
67 /**
68 * Returns an {@link Optional} containing the name used to filter if set
69 *
70 * @return an {@link Optional} containing the name or none.
71 */
72 public Optional<String> getName() {
73 return this.getFilterValue(FILTER_NAME_NAME);
74 }
75
76 /**
77 * Add a {@link ResourceListFilter} filter to the query with the given status
78 *
79 * @param status
80 * the status to filter for
81 */
82 public void withStatus(String status) {
83 this.addFilter(createStatusFilter(Optional.ofNullable(status)));
84 }
85
86 /**
87 * Returns an {@link Optional} containing the status used to filter if set
88 *
89 * @return an {@link Optional} containing the status or none.
90 */
91 public Optional<String> getStatus() {
92 return this.getFilterValue(FILTER_STATUS_NAME);
93 }
94
95 /**
96 * Create a new {@link ResourceListFilter} based on a name
97 *
98 * @param name
99 * the name to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
100 * @return a new {@link ResourceListFilter} for a name based query
101 */
102 public static ResourceListFilter<String> createNameFilter(Optional<String> name) {
103 return FiltersUtils.generateFilter(name, FILTER_NAME_NAME, FILTER_NAME_LABEL, SourceType.SELECT,
104 Optional.of(AgentsListProvider.NAME));
105 }
106
107 /**
108 * Create a new {@link ResourceListFilter} based on a state
109 *
110 * @param status
111 * the status to filter on wrapped in an {@link Optional} or {@link Optional#empty()}
112 * @return a new {@link ResourceListFilter} for a status based query
113 */
114 public static ResourceListFilter<String> createStatusFilter(Optional<String> status) {
115 return FiltersUtils.generateFilter(status, FILTER_STATUS_NAME, FILTER_STATUS_LABEL, SourceType.SELECT,
116 Optional.of(AgentsListProvider.STATUS));
117 }
118 }