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.ingest.api;
23  
24  import org.opencastproject.job.api.JobProducer;
25  import org.opencastproject.mediapackage.MediaPackage;
26  import org.opencastproject.mediapackage.MediaPackageElementFlavor;
27  import org.opencastproject.mediapackage.MediaPackageException;
28  import org.opencastproject.scheduler.api.SchedulerException;
29  import org.opencastproject.security.api.UnauthorizedException;
30  import org.opencastproject.util.ConfigurationException;
31  import org.opencastproject.util.NotFoundException;
32  import org.opencastproject.workflow.api.WorkflowInstance;
33  
34  import java.io.IOException;
35  import java.io.InputStream;
36  import java.net.URI;
37  import java.util.Map;
38  
39  /**
40   * Generates {@link MediaPackage}s from media, metadata, and attachments.
41   */
42  public interface IngestService extends JobProducer {
43  
44    String UTC_DATE_FORMAT = "yyyyMMdd'T'HHmmss'Z'";
45    String START_DATE_KEY = "ingest_start_date";
46  
47    /**
48     * Ingests the compressed mediapackage and starts the workflow as defined by <code>workflowDefinitionID</code>. The
49     * properties specified in <code>properties</code> will be submitted as configuration data to the workflow.
50     *
51     * @param zippedMediaPackage
52     *          A zipped file containing manifest, tracks, catalogs and attachments
53     * @param workflowDefinitionID
54     *          workflow to be used with this media package
55     * @param wfConfig
56     *          configuration parameters for the workflow
57     * @return Workflow instance.
58     * @throws MediaPackageException
59     *           if the mediapackage contained in the zip stream is invalid
60     * @throws IOException
61     *           if reading from the input stream fails
62     * @throws IngestException
63     *           if an unexpected error occurs
64     * @throws NotFoundException
65     *           if the workflow definition was not found
66     */
67    WorkflowInstance addZippedMediaPackage(InputStream zippedMediaPackage, String workflowDefinitionID,
68            Map<String, String> wfConfig) throws MediaPackageException, IOException, IngestException, NotFoundException;
69  
70    /**
71     * Ingests the compressed mediapackage and starts the workflow as defined by <code>workflowDefinitionID</code>. The
72     * properties specified in <code>properties</code> will be submitted as configuration data to the workflow.
73     * <p>
74     * The steps defined in that workflow will be appended to the already running workflow instance
75     * <code>workflowId</code>. If that workflow can't be found, a {@link NotFoundException} will be thrown. If the
76     * <code>workflowId</code> is null, a new {@link WorkflowInstance} is created.
77     *
78     * @param zippedMediaPackage
79     *          A zipped file containing manifest, tracks, catalogs and attachments
80     * @param workflowDefinitionID
81     *          workflow to be used with this media package
82     * @param wfConfig
83     *          configuration parameters for the workflow
84     * @param workflowId
85     *          the workflow instance
86     * @return Workflow instance.
87     * @throws MediaPackageException
88     *           if the mediapackage contained in the zip stream is invalid
89     * @throws IOException
90     *           if reading from the input stream fails
91     * @throws IngestException
92     *           if an unexpected error occurs
93     * @throws NotFoundException
94     *           if either one of the workflow definition or workflow instance was not found
95     * @throws UnauthorizedException
96     *           if the current user does not have {@link org.opencastproject.security.api.Permissions.Action#READ} on the
97     *           workflow instance's mediapackage.
98     *
99     * @deprecated As of release 2.4, the scheduler service is able to store a mediapackage. Thereby the concept of the
100    *             pre-procesing workflow is obsolete and there is no more need to resume such a workflow by this method.
101    */
102   @Deprecated
103   WorkflowInstance addZippedMediaPackage(InputStream zippedMediaPackage, String workflowDefinitionID,
104           Map<String, String> wfConfig, Long workflowId) throws MediaPackageException, IOException, IngestException,
105           NotFoundException, UnauthorizedException;
106 
107   /**
108    * Create a new MediaPackage in the repository.
109    *
110    * @return The created MediaPackage
111    * @throws MediaPackageException
112    * @throws ConfigurationException
113    * @throws IOException
114    * @throws IngestException
115    *           if an unexpected error occurs
116    */
117   MediaPackage createMediaPackage() throws MediaPackageException, ConfigurationException, IOException, IngestException;
118 
119  /**
120    * Create a new MediaPackage in the repository.
121    * @param  mediaPackageID
122    *   The Id for the new Mediapackage
123    * @return The created MediaPackage
124    * @throws MediaPackageException
125    * @throws ConfigurationException
126    * @throws IOException
127    * @throws IngestException
128    *           if an unexpected error occurs
129    */
130   MediaPackage createMediaPackage(String mediaPackageID) throws MediaPackageException, ConfigurationException,
131           IOException, IngestException;
132 
133     /**
134    * Add a media track to an existing MediaPackage in the repository
135    *
136    * @param uri
137    *          The URL of the file to add
138    * @param flavor
139    *          The flavor of the media that is being added
140    * @param tags
141    *           Tags to add to the Track 
142    * @param mediaPackage
143    *          The specific Opencast MediaPackage to which Media is being added
144    * @return MediaPackageManifest The manifest of a specific Opencast MediaPackage element
145    * @throws MediaPackageException
146    * @throws IOException
147    * @throws IngestException
148    *           if an unexpected error occurs
149    */
150   MediaPackage addTrack(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage)
151           throws MediaPackageException, IOException, IngestException;
152 
153   /**
154    * Add a media track to an existing MediaPackage in the repository
155    *
156    * @param mediaFile
157    *          The media file to add
158    * @param flavor
159    *          The flavor of the media that is being added
160    * @param mediaPackage
161    *          The specific Opencast MediaPackage to which Media is being added
162    * @return MediaPackage The updated Opencast MediaPackage element
163    * @throws MediaPackageException
164    * @throws IOException
165    * @throws IngestException
166    *           if an unexpected error occurs
167    */
168   MediaPackage addTrack(InputStream mediaFile, String fileName, MediaPackageElementFlavor flavor,
169           MediaPackage mediaPackage) throws MediaPackageException, IOException, IngestException;
170 
171    /**
172    * Add a media track to an existing MediaPackage in the repository
173    *
174    * @param mediaFile
175    *          The media file to add
176    * @param flavor
177    *          The flavor of the media that is being added
178    * @param tags
179    *          Tags to Add to the Track
180    * @param mediaPackage
181    *          The specific Opencast MediaPackage to which Media is being added
182    * @return MediaPackage The updated Opencast MediaPackage element
183    * @throws MediaPackageException
184    * @throws IOException
185    * @throws IngestException
186    *           if an unexpected error occurs
187    */
188   MediaPackage addTrack(InputStream mediaFile, String fileName, MediaPackageElementFlavor flavor, String [] tags,
189           MediaPackage mediaPackage) throws MediaPackageException, IOException, IngestException;
190 
191   /**
192    * Adds a partial media track to the existing MediaPackage in the repository
193    *
194    * @param uri
195    *          the URL of the file to add
196    * @param flavor
197    *          the flavor of the media that is being added
198    * @param startTime
199    *          the start time
200    * @param mediaPackage
201    *          the mediapackage
202    * @return the updated mediapackage
203    * @throws IOException
204    *           if reading or writing of the partial track fails
205    * @throws IngestException
206    *           if an unexpected error occurs
207    */
208   MediaPackage addPartialTrack(URI uri, MediaPackageElementFlavor flavor, long startTime, MediaPackage mediaPackage)
209           throws IOException, IngestException;
210 
211   /**
212    * Adds a partial media track to the existing MediaPackage in the repository
213    *
214    * @param mediaFile
215    *          the media file to add
216    * @param fileName
217    *          the file name
218    * @param flavor
219    *          the flavor of the media that is being added
220    * @param startTime
221    *          the start time
222    * @param mediaPackage
223    *          the mediapackage
224    * @return the updated mediapackage
225    * @throws IOException
226    *           if reading or writing of the partial track fails
227    * @throws IngestException
228    *           if an unexpected error occurs
229    */
230   MediaPackage addPartialTrack(InputStream mediaFile, String fileName, MediaPackageElementFlavor flavor,
231           long startTime, MediaPackage mediaPackage) throws IOException, IngestException;
232 
233   /**
234    * Add a [metadata catalog] to an existing MediaPackage in the repository
235    *
236    * @param uri
237    *          The URL of the file to add
238    * @param flavor
239    *          The flavor of the media that is being added
240    * @param tags
241    *           Tags to add to the catalog
242    * @param mediaPackage
243    *          The specific Opencast MediaPackage to which Media is being added
244    * @return MediaPackage The updated Opencast MediaPackage element
245    * @throws MediaPackageException
246    * @throws IOException
247    * @throws IngestException
248    *           if an unexpected error occurs
249    */
250   MediaPackage addCatalog(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage)
251           throws MediaPackageException, IOException, IngestException;
252 
253   /**
254    * Add a [metadata catalog] to an existing MediaPackage in the repository
255    *
256    * @param catalog
257    *          The catalog file to add
258    * @param flavor
259    *          The flavor of the media that is being added
260    * @param mediaPackage
261    *          The specific Opencast MediaPackage to which Media is being added
262    * @return MediaPackage The updated Opencast MediaPackage element
263    * @throws MediaPackageException
264    * @throws IOException
265    * @throws IngestException
266    *           if an unexpected error occurs
267    */
268   MediaPackage addCatalog(InputStream catalog, String fileName, MediaPackageElementFlavor flavor,
269           MediaPackage mediaPackage) throws MediaPackageException, IOException, IngestException;
270 
271     /**
272    * Add a [metadata catalog] to an existing MediaPackage in the repository
273    *
274    * @param catalog
275    *          The catalog file to add
276    * @param flavor
277    *          The flavor of the media that is being added
278    * @param  tags
279    *          The tags for the media that is being added:
280    * @param mediaPackage
281    *          The specific Opencast MediaPackage to which Media is being added
282    * @return MediaPackage The updated Opencast MediaPackage element
283    * @throws IllegalArgumentException
284      *         if the data passed to this method are not valid
285    * @throws IOException
286    * @throws IngestException
287    *           if an unexpected error occurs
288    */
289   MediaPackage addCatalog(InputStream catalog, String fileName, MediaPackageElementFlavor flavor, String[] tags,
290           MediaPackage mediaPackage) throws IllegalArgumentException, IOException, IngestException;
291 
292   /**
293    * Add an attachment to an existing MediaPackage in the repository
294    *
295    * @param uri
296    *          The URL of the file to add
297    * @param flavor
298    *          The flavor of the media that is being added
299    * @param tags
300    *           Tags to add to the attachment
301    * @param mediaPackage
302    *          The specific Opencast MediaPackage to which Media is being added
303    * @return MediaPackage The updated Opencast MediaPackage element
304    * @throws MediaPackageException
305    * @throws IOException
306    * @throws IngestException
307    *           if an unexpected error occurs
308    */
309   MediaPackage addAttachment(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage)
310           throws MediaPackageException, IOException, IngestException;
311 
312   /**
313    * Add an attachment to an existing MediaPackage in the repository
314    *
315    * @param file
316    *          The file to add
317    * @param flavor
318    *          The flavor of the media that is being added
319    * @param mediaPackage
320    *          The specific Opencast MediaPackage to which Media is being added
321    * @return MediaPackage The updated Opencast MediaPackage element
322    * @throws MediaPackageException
323    * @throws IOException
324    * @throws IngestException
325    *           if an unexpected error occurs
326    */
327   MediaPackage addAttachment(InputStream file, String fileName, MediaPackageElementFlavor flavor,
328           MediaPackage mediaPackage) throws MediaPackageException, IOException, IngestException;
329 
330     /**
331    * Add an attachment to an existing MediaPackage in the repository
332    *
333    * @param file
334    *          The file to add
335    * @param flavor
336    *          The flavor of the media that is being added
337    * @param tags
338    *          The tags of the media thas is being added
339    * @param mediaPackage
340    *          The specific Opencast MediaPackage to which Media is being added
341    * @return MediaPackage The updated Opencast MediaPackage element
342    * @throws MediaPackageException
343    * @throws IOException
344    * @throws IngestException
345    *           if an unexpected error occurs
346    */
347   MediaPackage addAttachment(InputStream file, String fileName, MediaPackageElementFlavor flavor, String[] tags,
348           MediaPackage mediaPackage) throws MediaPackageException, IOException, IngestException;
349 
350   /**
351    * Ingests the mediapackage and starts the default workflow as defined by the
352    * <code>org.opencastproject.workflow.default.definition</code> key, found in the system configuration.
353    *
354    * @param mediaPackage
355    *          The specific Opencast MediaPackage being ingested
356    * @return Workflow instance id.
357    * @throws IngestException
358    *           if an unexpected error occurs
359    */
360   WorkflowInstance ingest(MediaPackage mediaPackage) throws IllegalStateException, IngestException;
361 
362   /**
363    * Ingests the mediapackage and starts the workflow as defined by <code>workflowDefinitionID</code>. The properties
364    * specified in <code>properties</code> will be submitted as configuration data to the workflow.
365    *
366    * @param mediaPackage
367    *          The specific Opencast MediaPackage being ingested
368    * @param workflowDefinitionID
369    *          workflow to be used with this media package
370    * @param properties
371    *          configuration properties for the workflow
372    * @return Workflow instance id.
373    * @throws IngestException
374    *           if an unexpected error occurs
375    * @throws NotFoundException
376    *           if the workflow defintion can't be found
377    */
378   WorkflowInstance ingest(MediaPackage mediaPackage, String workflowDefinitionID, Map<String, String> properties)
379           throws IllegalStateException, IngestException, NotFoundException;
380 
381   /**
382    * Ingests the mediapackage and starts the workflow as defined by <code>workflowDefinitionID</code>. The properties
383    * specified in <code>properties</code> will be submitted as configuration data to the workflow.
384    * <p>
385    * The steps defined in that workflow will be appended to the already running workflow instance
386    * <code>workflowId</code>. If that workflow can't be found, a {@link NotFoundException} will be thrown. If the
387    * <code>workflowId</code> is null, a new {@link WorkflowInstance} is created.
388    *
389    * @param mediaPackage
390    *          The specific Opencast MediaPackage being ingested
391    * @param workflowDefinitionID
392    *          workflow to be used with this media package
393    * @param properties
394    *          configuration properties for the workflow
395    * @param workflowId
396    *          the workflow identifier
397    * @return Workflow instance id.
398    * @throws IngestException
399    *           if an unexpected error occurs
400    * @throws NotFoundException
401    *           if either one of the workflow definition or workflow instance was not found
402    * @throws UnauthorizedException
403    *           if the current user does not have {@link org.opencastproject.security.api.Permissions.Action#READ} on the
404    *           workflow instance's mediapackage.
405    *
406    * @deprecated As of release 2.4, the scheduler service is able to store a mediapackage. Thereby the concept of the
407    *             pre-procesing workflow is obsolete and there is no more need to resume such a workflow by this method.
408    */
409   @Deprecated
410   WorkflowInstance ingest(MediaPackage mediaPackage, String workflowDefinitionID, Map<String, String> properties,
411           Long workflowId) throws IllegalStateException, IngestException, NotFoundException, UnauthorizedException;
412 
413   /**
414    * Schedule an event with a given media package.
415    *
416    * @param mediaPackage
417    *          The specific Opencast MediaPackage being ingested
418    * @param workflowDefinitionID
419    *          workflow to be used with this media package
420    * @param properties
421    *          configuration properties for the workflow
422    * @throws IngestException
423    *           if an unexpected error occurs
424    * @throws NotFoundException
425    *           if the workflow defintion can't be found
426    */
427   void schedule(MediaPackage mediaPackage, String workflowDefinitionID, Map<String, String> properties)
428           throws IllegalStateException, IngestException, NotFoundException, UnauthorizedException, SchedulerException;
429 
430   /**
431    * Delete an existing MediaPackage and any linked files from the temporary ingest filestore.
432    *
433    * @param mediaPackage
434    *          The specific Opencast MediaPackage
435    * @throws IngestException
436    *           if an unexpected error occurs
437    */
438   void discardMediaPackage(MediaPackage mediaPackage) throws IOException, IngestException;
439 }