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