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.series.api;
23
24 import org.opencastproject.metadata.dublincore.DublinCoreCatalog;
25 import org.opencastproject.security.api.AccessControlList;
26 import org.opencastproject.security.api.UnauthorizedException;
27 import org.opencastproject.util.NotFoundException;
28
29 import com.entwinemedia.fn.data.Opt;
30
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Optional;
35
36 /**
37 * Series service API for creating, removing and searching over series.
38 *
39 */
40 public interface SeriesService {
41
42 /**
43 * Identifier for service registration and location
44 */
45 String JOB_TYPE = "org.opencastproject.series";
46
47 /**
48 * Adds or updates series. IllegalArgumentException is thrown if dc argument is null.
49 *
50 * @param dc
51 * {@link DublinCoreCatalog} representing series
52 * @return Dublin Core catalog of newly created series or null if series Dublin Core was just updated
53 * @throws SeriesException
54 * if adding or updating fails
55 * @throws UnauthorizedException
56 * if the current user is not authorized to perform this action
57 */
58 DublinCoreCatalog updateSeries(DublinCoreCatalog dc) throws SeriesException, UnauthorizedException;
59
60
61 /**
62 * Updates access control rules for specified series. Not specifying series ID or trying to update
63 * series with null value will throw IllegalArgumentException.
64 *
65 * @param seriesID
66 * series to be updated
67 * @param accessControl
68 * {@link AccessControlList} defining access control rules
69 * @return true if ACL was updated and false it if was created
70 * @throws NotFoundException
71 * if series with given ID cannot be found
72 * @throws UnauthorizedException
73 * if the current user is not authorized to perform this action
74 * @throws SeriesException
75 * if exception occurred
76 */
77 boolean updateAccessControl(String seriesID, AccessControlList accessControl) throws NotFoundException,
78 SeriesException, UnauthorizedException;
79
80 /**
81 * Updates access control rules for specified series. Allows to set the override parameter that
82 * controls whether the episode ACLs of the contained media packages will be removed on update.
83 * Not specifying series ID or trying to update series with null value will throw
84 * IllegalArgumentException.
85 *
86 * @param seriesID
87 * series to be updated
88 * @param accessControl
89 * {@link AccessControlList} defining access control rules
90 * @param overrideEpisodeAcl
91 * Whether the new series acl should override the episode acl
92 * @return true if ACL was updated and false it if was created
93 * @throws NotFoundException
94 * if series with given ID cannot be found
95 * @throws UnauthorizedException
96 * if the current user is not authorized to perform this action
97 * @throws SeriesException
98 * if exception occurred
99 */
100 boolean updateAccessControl(String seriesID, AccessControlList accessControl, boolean overrideEpisodeAcl)
101 throws NotFoundException, SeriesException, UnauthorizedException;
102
103 /**
104 * Removes series
105 *
106 * @param seriesID
107 * ID of the series to be removed
108 * @throws SeriesException
109 * if deleting fails
110 * @throws NotFoundException
111 * if series with specified ID does not exist
112 * @throws UnauthorizedException
113 * if the current user is not authorized to perform this action
114 */
115 void deleteSeries(String seriesID) throws SeriesException, NotFoundException, UnauthorizedException;
116
117 /**
118 * Returns Dublin core representing series by series ID.
119 *
120 * @param seriesID
121 * series to be retrieved
122 * @return {@link DublinCoreCatalog} representing series
123 * @throws SeriesException
124 * if retrieving fails
125 * @throws UnauthorizedException
126 * if the current user is not authorized to perform this action
127 */
128 DublinCoreCatalog getSeries(String seriesID) throws SeriesException, NotFoundException, UnauthorizedException;
129
130 /**
131 * Returns access control rules for series with given ID.
132 *
133 * @param seriesID
134 * ID of the series for which access control rules will be retrieved
135 * @return {@link AccessControlList} defining access control rules
136 * @throws NotFoundException
137 * if series with given ID cannot be found
138 * @throws SeriesException
139 * if exception occurred
140 */
141 AccessControlList getSeriesAccessControl(String seriesID) throws NotFoundException, SeriesException;
142
143 /**
144 * Returns all series (including deleted ones!) that have been modified in the
145 * given date range {@code from} (inclusive) -- {@code to} (exclusive). At
146 * most {@code limit} many series are returned. ACLs/permissions are NOT
147 * checked as this is only intended to be used in an administrative context.
148 */
149 List<Series> getAllForAdministrativeRead(Date from, Optional<Date> to, int limit)
150 throws SeriesException, UnauthorizedException;
151
152 /**
153 * Updates the extended metadata of a series from a Dublin Core catalog.
154 *
155 * @param seriesId
156 * the series identifier
157 * @param type
158 * the type of dublin core catalog
159 * @param dc
160 * the dublin core catalog with extended metadata
161 *
162 * @return true if the extended metadata could be updated
163 * @throws SeriesException
164 * if an error occurred during updating of the extended metadata
165 */
166 boolean updateExtendedMetadata(String seriesId, String type, DublinCoreCatalog dc) throws SeriesException;
167
168 /**
169 * Returns all the elements of a series in a map. The key of the map marks the element type. If
170 * the series does not contain any elements, an empty map is returned. If the series does not
171 * exist, {@code Opt.none()} is returned.
172 *
173 * @param seriesId
174 * the series identifier
175 * @return the map of elements
176 * @throws SeriesException
177 * if an error occurred during loading the series elements
178 */
179 Opt<Map<String, byte[]>> getSeriesElements(String seriesId) throws SeriesException;
180
181 /**
182 * Returns the element data of the series with the given type. If the series or the element with
183 * the given type do not exist, {@code Opt.none()} is returned.
184 *
185 * @param seriesId
186 * the series identifier
187 * @param type
188 * the element type
189 * @return the series element data
190 * @throws SeriesException
191 * if an error occurred during loading the series element
192 */
193 Opt<byte[]> getSeriesElementData(String seriesId, String type) throws SeriesException;
194
195 /**
196 * Creates or updates an element of a series.
197 *
198 * @param seriesId
199 * the series identifier
200 * @param type
201 * the type of the element
202 * @param data
203 * the data of the element
204 * @return true if the element could be created or updated
205 * @throws SeriesException
206 * if an error occurs while updating the element
207 */
208 boolean updateSeriesElement(String seriesId, String type, byte[] data) throws SeriesException;
209
210 /**
211 * Deletes an element from a series.
212 *
213 * @param seriesId
214 * the series identifier
215 * @param type
216 * the element type
217 * @return true if the element could be deleted; false if no such element/series exists
218 * @throws SeriesException
219 * if an error occurs while deleting the element
220 */
221 boolean deleteSeriesElement(String seriesId, String type) throws SeriesException;
222
223 int getSeriesCount() throws SeriesException;
224
225 /**
226 * Returns the properties for a series.
227 *
228 * @param seriesID
229 * series to be retrieved
230 * @return representing series properties
231 * @throws SeriesException
232 * if retrieving fails
233 * @throws NotFoundException
234 * Thrown if the series or property cannot be found.
235 * @throws UnauthorizedException
236 * if the current user is not authorized to perform this action
237 */
238 Map<String, String> getSeriesProperties(String seriesID) throws SeriesException, NotFoundException,
239 UnauthorizedException;
240
241 /**
242 * Get a series property.
243 *
244 * @param seriesID
245 * The id of the series to get the property from.
246 * @param propertyName
247 * The name of the property to retrieve
248 * @return The string value of the property.
249 * @throws SeriesException
250 * Thrown for all other exceptions.
251 * @throws NotFoundException
252 * Thrown if the series or property cannot be found.
253 * @throws UnauthorizedException
254 * Thrown if the user is not able to read the series' properties.
255 */
256 String getSeriesProperty(String seriesID, String propertyName) throws SeriesException, NotFoundException,
257 UnauthorizedException;
258
259 /**
260 * Update a series property or create a new one if it doesn't exist.
261 *
262 * @param seriesID
263 * The series to attach the property to.
264 * @param propertyName
265 * The unique name of the series property
266 * @param propertyValue
267 * The value to assign the series property
268 * @throws SeriesException
269 * Thrown for all other exceptions.
270 * @throws NotFoundException
271 * Thrown if the series or property cannot be found.
272 * @throws UnauthorizedException
273 * Thrown if the user is not able to write the series' properties.
274 */
275 void updateSeriesProperty(String seriesID, String propertyName, String propertyValue) throws SeriesException,
276 NotFoundException, UnauthorizedException;
277
278 /**
279 *
280 * @param seriesID
281 * The series to attach the property to.
282 * @param propertyName
283 * The unique name of the series property
284 * @throws SeriesException
285 * Thrown for all other exceptions.
286 * @throws NotFoundException
287 * Thrown if the series or property cannot be found.
288 * @throws UnauthorizedException
289 * Thrown if the user is not able to write the series' properties.
290 */
291 void deleteSeriesProperty(String seriesID, String propertyName) throws SeriesException, NotFoundException,
292 UnauthorizedException;
293 }