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.index.service.api;
23  
24  import org.opencastproject.elasticsearch.api.SearchIndexException;
25  import org.opencastproject.elasticsearch.index.ElasticsearchIndex;
26  import org.opencastproject.elasticsearch.index.objects.event.Event;
27  import org.opencastproject.elasticsearch.index.objects.series.Series;
28  import org.opencastproject.event.comment.EventComment;
29  import org.opencastproject.index.service.exception.IndexServiceException;
30  import org.opencastproject.index.service.exception.UnsupportedAssetException;
31  import org.opencastproject.index.service.impl.util.EventHttpServletRequest;
32  import org.opencastproject.ingest.api.IngestException;
33  import org.opencastproject.mediapackage.MediaPackage;
34  import org.opencastproject.mediapackage.MediaPackageElementFlavor;
35  import org.opencastproject.mediapackage.MediaPackageException;
36  import org.opencastproject.metadata.dublincore.EventCatalogUIAdapter;
37  import org.opencastproject.metadata.dublincore.MetadataList;
38  import org.opencastproject.metadata.dublincore.SeriesCatalogUIAdapter;
39  import org.opencastproject.scheduler.api.SchedulerException;
40  import org.opencastproject.security.api.AccessControlList;
41  import org.opencastproject.security.api.UnauthorizedException;
42  import org.opencastproject.series.api.SeriesException;
43  import org.opencastproject.util.NotFoundException;
44  import org.opencastproject.workflow.api.WorkflowDatabaseException;
45  
46  import org.json.simple.JSONObject;
47  
48  import java.io.IOException;
49  import java.text.ParseException;
50  import java.util.List;
51  import java.util.Map;
52  import java.util.Optional;
53  
54  import javax.servlet.http.HttpServletRequest;
55  
56  public interface IndexService {
57    enum Source {
58      ARCHIVE, WORKFLOW, SCHEDULE
59    };
60  
61    enum SourceType {
62      UPLOAD, UPLOAD_LATER, SCHEDULE_SINGLE, SCHEDULE_MULTIPLE
63    }
64  
65    enum EventRemovalResult {
66      SUCCESS, GENERAL_FAILURE, NOT_FOUND, RETRACTING
67    }
68  
69    /**
70     * Get a single event
71     *
72     * @param id
73     *          the mediapackage id
74     * @param index
75     *          The index to get the event from.
76     * @return an event or none if not found wrapped in an option
77     * @throws SearchIndexException
78     *           Thrown if the index cannot be read
79     */
80    Optional<Event> getEvent(String id, ElasticsearchIndex index) throws SearchIndexException;
81  
82    /**
83     * Creates a new event based on a request.
84     *
85     * @param request
86     *          The request containing the data to create the event.
87     * @return The event's id (or a comma seperated list of event ids if it was a group of events)
88     * @throws IndexServiceException
89     *           Thrown if there was an internal server error while creating the event.
90     * @throws IllegalArgumentException
91     *           Thrown if the provided request was inappropriate.
92     * @throws UnsupportedAssetException
93     *           Thrown if the provided asset file type is not accepted.
94     */
95    String createEvent(HttpServletRequest request) throws IndexServiceException, IllegalArgumentException, UnsupportedAssetException;
96  
97    /**
98     * Create a new event using a {@link EventHttpServletRequest}.
99     *
100    * @param eventHttpServletRequest
101    *          The {@link EventHttpServletRequest} containing all of the necessary information to create a new event.
102    * @return The id or ids created by the {@link EventHttpServletRequest}.
103    * @throws ParseException
104    *           Thrown if unable to parse the start and end UTC date and time.
105    * @throws IOException
106    *           Thrown if unable to update the event's DublinCoreCatalog
107    * @throws MediaPackageException
108    *           Thrown if unable to update the event's {@link MediaPackage}
109    * @throws IngestException
110    *           Thrown if unable to update the ingest service with the new Event.
111    * @throws NotFoundException
112    *           Thrown if the specified workflow definition cannot be found.
113    * @throws SchedulerException
114    *           Thrown if unable to schedule the new event.
115    * @throws UnauthorizedException
116    *           Thrown if the current user is unable to create the new event.
117    */
118   String createEvent(EventHttpServletRequest eventHttpServletRequest) throws ParseException, IOException,
119           MediaPackageException, IngestException, NotFoundException, SchedulerException, UnauthorizedException;
120 
121   /**
122    * Removes an event and retracts it if necessary.
123    *
124    * @param event
125    *          The event to remove.
126    * @param retractWorkflowId
127    *          The id of the workflow to use to retract the event if necessary.
128    * @return A result which tells if the event was removed, removal failed, or the event is being retracted and will be removed later.
129    * @throws UnauthorizedException
130    *           Thrown if the action is unauthorized
131    * @throws WorkflowDatabaseException
132    *           Thrown if the workflow database is not reachable. This may be a temporary problem.
133    * @throws NotFoundException
134    *           If the configured retract workflow cannot be found. This is most likely a configuration issue.
135    */
136   EventRemovalResult removeEvent(Event event, String retractWorkflowId) throws UnauthorizedException,
137           WorkflowDatabaseException, NotFoundException;
138 
139   /**
140    * Removes an event.
141    *
142    * @param id
143    *          The id for the event to remove.
144    * @return true if the event was found and removed.
145    * @throws NotFoundException
146    *           Thrown if the group was not found
147    * @throws UnauthorizedException
148    *           Thrown if the action is unauthorized
149    */
150   boolean removeEvent(String id) throws NotFoundException, UnauthorizedException;
151 
152   /**
153    * Create or Update an existing event asset.
154    *
155    * The request contains a JSON describing asset type,
156    *  flavor, subflavor, the mpId, a workflow description id to initiate on the event,
157    *  and the asset file streams in a multipart form.
158    *  Existing type-flavor matches are updated, otherwise the asset is added.
159    *
160    * @param request
161    *          The http servlet request containing metadata, workflow id, and file streams
162    * @param mp
163    *          The mediapackage to update
164    * @return the workflow instance id that was started
165    * @throws ParseException
166    *           Thrown if unable to parse the start and end UTC date and time.
167    * @throws IOException
168    *           Thrown if unable to update the event's DublinCoreCatalog
169    * @throws MediaPackageException
170    *           Thrown if unable to update the event's {@link MediaPackage}
171    * @throws NotFoundException
172    *           Thrown if the specified workflow definition cannot be found.
173    * @throws UnauthorizedException
174    *           Thrown if the current user is unable to create the new event.
175    * @throws IndexServiceException
176    *            Thrown if the update assets workflow cannot be started
177    * @throws UnsupportedAssetException
178    *           Thrown if the provided asset file type is not accepted.
179    */
180   String updateEventAssets(MediaPackage mp, HttpServletRequest request) throws ParseException, IOException,
181           MediaPackageException, NotFoundException, UnauthorizedException, IndexServiceException, UnsupportedAssetException;
182 
183   /**
184    * Update an event's metadata using a {@link MetadataList}
185    *
186    * @param id
187    *          The id of the event.
188    * @param metadataList
189    *          The {@link MetadataList} with the new metadata.
190    * @param index
191    *          The index used to process this update.
192    * @return The {@link MetadataList} with the updated fields.
193    * @throws IndexServiceException
194    *           Thrown if unable to update the event with the index.
195    * @throws SearchIndexException
196    *           Thrown if there was a problem getting the event.
197    * @throws NotFoundException
198    *           Thrown if unable to find the event.
199    * @throws UnauthorizedException
200    *           Thrown if the current user is unable to edit the event.
201    */
202   MetadataList updateEventMetadata(String id, MetadataList metadataList, ElasticsearchIndex index)
203           throws IndexServiceException, SearchIndexException, NotFoundException, UnauthorizedException;
204 
205   /**
206    * Update the event metadata in all available catalogs.
207    *
208    * @param id
209    *          The id of the event to update.
210    * @param metadataJSON
211    *          The metadata to update in json format.
212    * @param index
213    *          The index to update the event in.
214    * @return A metadata list of the updated fields.
215    * @throws IllegalArgumentException
216    *           Thrown if the metadata was not formatted correctly.
217    * @throws IndexServiceException
218    *           Thrown if there was an error updating the event.
219    * @throws SearchIndexException
220    *           Thrown if there was an error searching the search index.
221    * @throws NotFoundException
222    *           Thrown if the {@link Event} could not be found.
223    * @throws UnauthorizedException
224    *           Thrown if the current user is unable to update the event.
225    */
226   MetadataList updateAllEventMetadata(String id, String metadataJSON, ElasticsearchIndex index)
227           throws IllegalArgumentException, IndexServiceException, SearchIndexException, NotFoundException,
228           UnauthorizedException;
229 
230   /**
231    * Remove catalogs from the event with the given flavor.
232    *
233    * @param event
234    *          The event who will have the catalog removed.
235    * @param flavor
236    *          The flavor to use to find the catalogs.
237    * @throws IndexServiceException
238    *           Thrown if there was a problem getting the catalog for the event.
239    * @throws NotFoundException
240    *           Thrown if unable to find a catalog that matches the flavor.
241    * @throws UnauthorizedException
242    *           Thrown if the action is unauthorized.
243    */
244   void removeCatalogByFlavor(Event event, MediaPackageElementFlavor flavor)
245           throws IndexServiceException, NotFoundException, UnauthorizedException;
246 
247   /**
248    * Update the event's {@link AccessControlList}.
249    *
250    * @param id
251    *          The id of the event to update.
252    * @param acl
253    *          The {@link AccessControlList} that this event will get updated with.
254    * @param index
255    *          The index to update the event in.
256    * @return The updated {@link AccessControlList}.
257    * @throws IllegalArgumentException
258    *           Thrown if the event is currently processing as a workflow so unable to update the ACL as we may have
259    *           already distributed it.
260    * @throws IndexServiceException
261    *           Thrown if there was a problem updating the ACL for an event.
262    * @throws SearchIndexException
263    *           Thrown if there was an error searching the search index.
264    * @throws NotFoundException
265    *           Thrown if the event cannot be found to update.
266    * @throws UnauthorizedException
267    *           Thrown if the action is unauthorized.
268    */
269   AccessControlList updateEventAcl(String id, AccessControlList acl, ElasticsearchIndex index)
270           throws IllegalArgumentException, IndexServiceException, SearchIndexException, NotFoundException,
271           UnauthorizedException;
272 
273   // TODO remove when it is no longer needed by AbstractEventEndpoint.
274   MediaPackage getEventMediapackage(Event event) throws IndexServiceException;
275 
276   // TODO remove when it is no longer needed by AbstractEventEndpoint
277   Source getEventSource(Event event);
278 
279   void updateCommentCatalog(Event event, List<EventComment> comments) throws Exception;
280 
281   MetadataList getMetadataListWithAllSeriesCatalogUIAdapters();
282 
283   MetadataList getMetadataListWithAllEventCatalogUIAdapters();
284 
285   /**
286    * @return A {@link List} of {@link EventCatalogUIAdapter} that provide the metadata to the front end.
287    */
288   List<EventCatalogUIAdapter> getEventCatalogUIAdapters();
289 
290   /**
291    * @return A {@link List} of extended {@link EventCatalogUIAdapter} that provide the metadata to the front end.
292    * Does not contain the common {@link EventCatalogUIAdapter}.
293    */
294   List<EventCatalogUIAdapter> getExtendedEventCatalogUIAdapters();
295 
296   /**
297    * @return the common {@link EventCatalogUIAdapter}
298    */
299   EventCatalogUIAdapter getCommonEventCatalogUIAdapter();
300 
301   /**
302    * Create a new series.
303    *
304    * @param metadata
305    *          The json metadata to create the new series.
306    * @return The series id.
307    * @throws IllegalArgumentException
308    *           Thrown if the metadata is incomplete or malformed.
309    * @throws IndexServiceException
310    *           Thrown if there are issues with processing the request.
311    * @throws UnauthorizedException
312    *           Thrown if the user cannot create a new series.
313    */
314   String createSeries(JSONObject metadata) throws IllegalArgumentException, IndexServiceException, UnauthorizedException;
315 
316   /**
317    * Create a series from a set of metadata and options.
318    *
319    * @param metadataList
320    *          The metadata for the series
321    * @param options
322    *          Options for the series
323    * @param optAcl
324    *          ACLs for the series
325    * @param optThemeId
326    *          Themes for the series
327    * @return The series id.
328    * @throws IndexServiceException
329    *           Thrown if there are issues with processing the request.
330    */
331   String createSeries(MetadataList metadataList, Map<String, String> options, Optional<AccessControlList> optAcl,
332           Optional<Long> optThemeId) throws IndexServiceException;
333 
334   /**
335    * Remove a series.
336    *
337    * @param id
338    *          The id of the series to remove.
339    * @throws NotFoundException
340    *           Thrown if the series is not found
341    * @throws SeriesException
342    *           Thrown if an error removing the series
343    * @throws UnauthorizedException
344    *           Thrown if the activity is unauthorized
345    */
346   void removeSeries(String id) throws NotFoundException, SeriesException, UnauthorizedException;
347 
348   /**
349    * @return the common {@link SeriesCatalogUIAdapter}
350    */
351   SeriesCatalogUIAdapter getCommonSeriesCatalogUIAdapter();
352 
353   /**
354    * @return A {@link List} of {@link SeriesCatalogUIAdapter} that provide the metadata to the front end.
355    */
356   List<SeriesCatalogUIAdapter> getSeriesCatalogUIAdapters();
357 
358   /**
359    * Update the series metadata in all available catalogs.
360    *
361    * @param id
362    *          The id of the series to update.
363    * @param metadataJSON
364    *          The metadata to update in json format.
365    * @param index
366    *          The index to update the series in.
367    * @return A metadata list of the updated fields.
368    * @throws IllegalArgumentException
369    *           Thrown if the metadata was not formatted correctly.
370    * @throws IndexServiceException
371    *           Thrown if there was an error updating the event.
372    * @throws NotFoundException
373    *           Thrown if the {@link Event} could not be found.
374    * @throws UnauthorizedException
375    *           Thrown if the current user is unable to update the event.
376    */
377   MetadataList updateAllSeriesMetadata(String id, String metadataJSON, ElasticsearchIndex index)
378           throws IllegalArgumentException, IndexServiceException, NotFoundException, UnauthorizedException;
379 
380   /**
381    * Update the series metadata in all available catalogs by providing a complete {@link MetadataList}
382    *
383    * @param id
384    *          The id of the series
385    * @param metadataList
386    *          The complete {@link MetadataList}
387    * @param index
388    *          The index that will be used to find the series.
389    * @return The updated {@link MetadataList}
390    * @throws IndexServiceException
391    *           Thrown if unable to query the index for the series.
392    * @throws NotFoundException
393    *           Thrown if unable to find the series to update the metadata for.
394    * @throws UnauthorizedException
395    *           Thrown if the user is unable to update the series.
396    */
397   MetadataList updateAllSeriesMetadata(String id, MetadataList metadataList, ElasticsearchIndex index)
398           throws IndexServiceException, NotFoundException, UnauthorizedException;
399 
400   /**
401    * Remove a catalog from the series that matches the given flavor.
402    *
403    * @param series
404    *          The series to remove the catalog from.
405    * @param flavor
406    *          The flavor that will match the catalog.
407    * @throws IndexServiceException
408    *           Thrown if there was an error reading the given event.
409    * @throws NotFoundException
410    *           Thrown if the catalog cannot be found.
411    */
412   void removeCatalogByFlavor(Series series, MediaPackageElementFlavor flavor)
413           throws IndexServiceException, NotFoundException;
414 
415   Map<String,Map<String,String>> getEventWorkflowProperties(List<String> eventIds);
416 
417 }