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