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