Search in sources :

Example 21 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class IngestRestService method addMediaPackagePartialTrack.

@POST
@Produces(MediaType.TEXT_XML)
@Path("addPartialTrack")
@RestQuery(name = "addPartialTrackURL", description = "Add a partial media track to a given media package using an URL", restParameters = { @RestParameter(description = "The location of the media", isRequired = true, name = "url", type = RestParameter.Type.STRING), @RestParameter(description = "The kind of media", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "The start time in milliseconds", isRequired = true, name = "startTime", type = RestParameter.Type.INTEGER), @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackagePartialTrack(@FormParam("url") String url, @FormParam("flavor") String flavor, @FormParam("startTime") Long startTime, @FormParam("mediaPackage") String mpx) {
    logger.trace("add partial track with url: {} flavor: {} startTime: {} mediaPackage: {}", url, flavor, startTime, mpx);
    try {
        MediaPackage mp = factory.newMediaPackageBuilder().loadFromXml(mpx);
        if (MediaPackageSupport.sanityCheck(mp).isSome())
            return Response.serverError().status(Status.BAD_REQUEST).build();
        mp = ingestService.addPartialTrack(new URI(url), MediaPackageElementFlavor.parseFlavor(flavor), startTime, mp);
        return Response.ok(mp).build();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) URI(java.net.URI) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IngestException(org.opencastproject.ingest.api.IngestException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 22 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class IngestRestService method schedule.

@POST
@Path("schedule/{wdID}")
@RestQuery(name = "schedule", description = "Schedule an event based on the given media package", pathParameters = { @RestParameter(description = "Workflow definition id", isRequired = true, name = "wdID", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(description = "The media package", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Event scheduled", responseCode = HttpServletResponse.SC_CREATED), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response schedule(@PathParam("wdID") String wdID, MultivaluedMap<String, String> formData) {
    if (StringUtils.isBlank(wdID)) {
        logger.trace("workflow definition id is not specified");
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    Map<String, String> wfConfig = getWorkflowConfig(formData);
    if (StringUtils.isNotBlank(wdID)) {
        wfConfig.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, wdID);
    }
    logger.debug("Schedule with workflow definition '{}'", wfConfig.get(WORKFLOW_DEFINITION_ID_PARAM));
    String mediaPackageXml = formData.getFirst("mediaPackage");
    if (StringUtils.isBlank(mediaPackageXml)) {
        logger.debug("Rejected schedule without media package");
        return Response.status(Status.BAD_REQUEST).build();
    }
    MediaPackage mp = null;
    try {
        mp = factory.newMediaPackageBuilder().loadFromXml(mediaPackageXml);
        if (MediaPackageSupport.sanityCheck(mp).isSome()) {
            throw new MediaPackageException("Insane media package");
        }
    } catch (MediaPackageException e) {
        logger.debug("Rejected ingest with invalid media package {}", mp);
        return Response.status(Status.BAD_REQUEST).build();
    }
    MediaPackageElement[] mediaPackageElements = mp.getElementsByFlavor(MediaPackageElements.EPISODE);
    if (mediaPackageElements.length != 1) {
        logger.debug("There can be only one (and exactly one) episode dublin core catalog: https://youtu.be/_J3VeogFUOs");
        return Response.status(Status.BAD_REQUEST).build();
    }
    try {
        ingestService.schedule(mp, wdID, wfConfig);
        return Response.status(Status.CREATED).build();
    } catch (IngestException e) {
        return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
    } catch (SchedulerConflictException e) {
        return Response.status(Status.CONFLICT).entity(e.getMessage()).build();
    } catch (NotFoundException | UnauthorizedException | SchedulerException e) {
        return Response.serverError().build();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 23 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class IngestRestService method addMediaPackage.

@POST
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("addMediaPackage/{wdID}")
@RestQuery(name = "addMediaPackage", description = "<p>Create and ingest media package from media tracks with additional Dublin Core metadata. It is " + "mandatory to set a title for the recording. This can be done with the 'title' form field or by supplying a DC " + "catalog with a title included.  The identifier of the newly created media package will be taken from the " + "<em>identifier</em> field or the episode DublinCore catalog (deprecated<sup>*</sup>). If no identifier is " + "set, a newa randumm UUIDv4 will be generated. This endpoint is not meant to be used by capture agents for " + "scheduled recordings. It's primary use is for manual ingests with command line tools like curl.</p> " + "<p>Multiple tracks can be ingested by using multiple form fields. It's important, however, to always set the " + "flavor of the next media file <em>before</em> sending the media file itself.</p>" + "<b>(*)</b> The special treatment of the identifier field is deprecated any may be removed in future versions " + "without further notice in favor of a random UUID generation to ensure uniqueness of identifiers. " + "<h3>Example curl command:</h3>" + "<p>Ingest one video file:</p>" + "<p><pre>\n" + "curl -f -i --digest -u opencast_system_account:CHANGE_ME -H 'X-Requested-Auth: Digest' \\\n" + "    http://localhost:8080/ingest/addMediaPackage/fast -F creator='John Doe' -F title='Test Recording' \\\n" + "    -F 'flavor=presentation/source' -F 'BODY=@test-recording.mp4' \n" + "</pre></p>" + "<p>Ingest two video files:</p>" + "<p><pre>\n" + "curl -f -i --digest -u opencast_system_account:CHANGE_ME -H 'X-Requested-Auth: Digest' \\\n" + "    http://localhost:8080/ingest/addMediaPackage/fast -F creator='John Doe' -F title='Test Recording' \\\n" + "    -F 'flavor=presentation/source' -F 'BODY=@test-recording-vga.mp4' \\\n" + "    -F 'flavor=presenter/source' -F 'BODY=@test-recording-camera.mp4' \n" + "</pre></p>", pathParameters = { @RestParameter(description = "Workflow definition id", isRequired = true, name = "wdID", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(description = "The kind of media track. This has to be specified prior to each media track", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "abstract", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "accessRights", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "available", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "contributor", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "coverage", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "created", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "creator", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "date", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "description", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "extent", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "format", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "identifier", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "isPartOf", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "isReferencedBy", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "isReplacedBy", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "language", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "license", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "publisher", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "relation", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "replaces", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "rights", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "rightsHolder", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "source", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "spatial", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "subject", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "temporal", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "title", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "type", type = RestParameter.Type.STRING), @RestParameter(description = "URL of episode DublinCore Catalog", isRequired = false, name = "episodeDCCatalogUri", type = RestParameter.Type.STRING), @RestParameter(description = "Episode DublinCore Catalog", isRequired = false, name = "episodeDCCatalog", type = RestParameter.Type.STRING), @RestParameter(description = "URL of series DublinCore Catalog", isRequired = false, name = "seriesDCCatalogUri", type = RestParameter.Type.STRING), @RestParameter(description = "Series DublinCore Catalog", isRequired = false, name = "seriesDCCatalog", type = RestParameter.Type.STRING), @RestParameter(description = "URL of a media track file", isRequired = false, name = "mediaUri", type = RestParameter.Type.STRING) }, bodyParameter = @RestParameter(description = "The media track file", isRequired = true, name = "BODY", type = RestParameter.Type.FILE), reponses = { @RestResponse(description = "Ingest successfull. Returns workflow instance as XML", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Ingest failed due to invalid requests.", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "Ingest failed. Something went wrong internally. Please have a look at the log files", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackage(@Context HttpServletRequest request, @PathParam("wdID") String wdID) {
    logger.trace("add mediapackage as multipart-form-data with workflow definition id: {}", wdID);
    MediaPackageElementFlavor flavor = null;
    try {
        MediaPackage mp = ingestService.createMediaPackage();
        DublinCoreCatalog dcc = null;
        Map<String, String> workflowProperties = new HashMap<>();
        int seriesDCCatalogNumber = 0;
        int episodeDCCatalogNumber = 0;
        boolean hasMedia = false;
        if (ServletFileUpload.isMultipartContent(request)) {
            for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
                FileItemStream item = iter.next();
                if (item.isFormField()) {
                    String fieldName = item.getFieldName();
                    String value = Streams.asString(item.openStream(), "UTF-8");
                    logger.trace("form field {}: {}", fieldName, value);
                    /* Ignore empty fields */
                    if ("".equals(value)) {
                        continue;
                    }
                    /* “Remember” the flavor for the next media. */
                    if ("flavor".equals(fieldName)) {
                        flavor = MediaPackageElementFlavor.parseFlavor(value);
                    /* Fields for DC catalog */
                    } else if (dcterms.contains(fieldName)) {
                        if ("identifier".equals(fieldName)) {
                            /* Use the identifier for the mediapackage */
                            mp.setIdentifier(new IdImpl(value));
                        }
                        EName en = new EName(DublinCore.TERMS_NS_URI, fieldName);
                        if (dcc == null) {
                            dcc = dublinCoreService.newInstance();
                        }
                        dcc.add(en, value);
                    /* Episode metadata by URL */
                    } else if ("episodeDCCatalogUri".equals(fieldName)) {
                        try {
                            URI dcurl = new URI(value);
                            updateMediaPackageID(mp, dcurl);
                            ingestService.addCatalog(dcurl, MediaPackageElements.EPISODE, mp);
                            episodeDCCatalogNumber += 1;
                        } catch (java.net.URISyntaxException e) {
                            /* Parameter was not a valid URL: Return 400 Bad Request */
                            logger.warn(e.getMessage(), e);
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                    /* Episode metadata DC catalog (XML) as string */
                    } else if ("episodeDCCatalog".equals(fieldName)) {
                        InputStream is = new ByteArrayInputStream(value.getBytes("UTF-8"));
                        updateMediaPackageID(mp, is);
                        is.reset();
                        String fileName = "episode" + episodeDCCatalogNumber + ".xml";
                        episodeDCCatalogNumber += 1;
                        ingestService.addCatalog(is, fileName, MediaPackageElements.EPISODE, mp);
                    /* Series by URL */
                    } else if ("seriesDCCatalogUri".equals(fieldName)) {
                        try {
                            URI dcurl = new URI(value);
                            ingestService.addCatalog(dcurl, MediaPackageElements.SERIES, mp);
                        } catch (java.net.URISyntaxException e) {
                            /* Parameter was not a valid URL: Return 400 Bad Request */
                            logger.warn(e.getMessage(), e);
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                    /* Series DC catalog (XML) as string */
                    } else if ("seriesDCCatalog".equals(fieldName)) {
                        String fileName = "series" + seriesDCCatalogNumber + ".xml";
                        seriesDCCatalogNumber += 1;
                        InputStream is = new ByteArrayInputStream(value.getBytes("UTF-8"));
                        ingestService.addCatalog(is, fileName, MediaPackageElements.SERIES, mp);
                    /* Add media files by URL */
                    } else if ("mediaUri".equals(fieldName)) {
                        if (flavor == null) {
                            /* A flavor has to be specified in the request prior the media file */
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                        URI mediaUrl;
                        try {
                            mediaUrl = new URI(value);
                        } catch (java.net.URISyntaxException e) {
                            /* Parameter was not a valid URL: Return 400 Bad Request */
                            logger.warn(e.getMessage(), e);
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                        ingestService.addTrack(mediaUrl, flavor, mp);
                        hasMedia = true;
                    } else {
                        /* Tread everything else as workflow properties */
                        workflowProperties.put(fieldName, value);
                    }
                /* Media files as request parameter */
                } else {
                    if (flavor == null) {
                        /* A flavor has to be specified in the request prior the video file */
                        logger.debug("A flavor has to be specified in the request prior to the content BODY");
                        return Response.serverError().status(Status.BAD_REQUEST).build();
                    }
                    ingestService.addTrack(item.openStream(), item.getName(), flavor, mp);
                    hasMedia = true;
                }
            }
            /* Check if we got any media. Fail if not. */
            if (!hasMedia) {
                logger.warn("Rejected ingest without actual media.");
                return Response.serverError().status(Status.BAD_REQUEST).build();
            }
            /* Add episode mediapackage if metadata were send separately */
            if (dcc != null) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                dcc.toXml(out, true);
                InputStream in = new ByteArrayInputStream(out.toByteArray());
                ingestService.addCatalog(in, "dublincore.xml", MediaPackageElements.EPISODE, mp);
            /* Check if we have metadata for the episode */
            } else if (episodeDCCatalogNumber == 0) {
                logger.warn("Rejected ingest without episode metadata. At least provide a title.");
                return Response.serverError().status(Status.BAD_REQUEST).build();
            }
            WorkflowInstance workflow = (wdID == null) ? ingestService.ingest(mp) : ingestService.ingest(mp, wdID, workflowProperties);
            return Response.ok(workflow).build();
        }
        return Response.serverError().status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : EName(org.opencastproject.mediapackage.EName) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) AbstractJobProducerEndpoint(org.opencastproject.rest.AbstractJobProducerEndpoint) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IngestException(org.opencastproject.ingest.api.IngestException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 24 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class IngestServiceImpl method addCatalog.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addCatalog(java.io.InputStream, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addCatalog(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_CATALOG, null, null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding catalog {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        if (MediaPackageElements.SERIES.equals(flavor)) {
            updateSeries(newUrl);
        }
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Catalog, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getCatalog(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added catalog {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 25 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class IngestServiceImpl method addTrack.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addTrack(java.net.URI,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, String[] ,
 *      org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addTrack(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK_FROM_URI, Arrays.asList(uri.toString(), flavor == null ? null : flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding track {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getTrack(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (IOException e) {
        throw e;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)407 Test (org.junit.Test)180 NotFoundException (org.opencastproject.util.NotFoundException)108 Job (org.opencastproject.job.api.Job)89 Date (java.util.Date)82 IOException (java.io.IOException)77 URI (java.net.URI)74 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)72 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)70 ArrayList (java.util.ArrayList)69 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)60 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)59 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 Path (javax.ws.rs.Path)53 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)52 Track (org.opencastproject.mediapackage.Track)48 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)48 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)45 HashSet (java.util.HashSet)43