Search in sources :

Example 21 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestService method concat.

/**
 * Concat multiple tracks having the same codec to a single track.
 *
 * @param sourceTracksXml
 *          an array of track to concat in order of the array as XML
 * @param profileId
 *          The encoding profile to use
 * @param outputDimension
 *          The output dimension as JSON
 * @return A {@link Response} with the resulting track in the response body
 * @throws Exception
 */
@POST
@Path("concat")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "concat", description = "Starts a video concating process from multiple videos, based on the specified encoding profile ID and the source tracks", restParameters = { @RestParameter(description = "The source tracks to concat as XML", isRequired = true, name = "sourceTracks", type = Type.TEXT), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING), @RestParameter(description = "The resolution dimension of the concat video as JSON", isRequired = false, name = "outputDimension", type = Type.STRING), @RestParameter(description = "The  frame rate of the concat video (should be positive, e.g. 25.0). Negative values and zero will deactivate frame rate operation.", isRequired = false, name = "outputFrameRate", type = Type.STRING) }, reponses = { @RestResponse(description = "Results in an xml document containing the video track", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "If required parameters aren't set or if sourceTracks aren't from the type Track or not at least two tracks are present", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response concat(@FormParam("sourceTracks") String sourceTracksXml, @FormParam("profileId") String profileId, @FormParam("outputDimension") String outputDimension, @FormParam("outputFrameRate") String outputFrameRate) throws Exception {
    // Ensure that the POST parameters are present
    if (StringUtils.isBlank(sourceTracksXml) || StringUtils.isBlank(profileId))
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTracks and profileId must not be null").build();
    // Deserialize the source track
    List<? extends MediaPackageElement> tracks = MediaPackageElementParser.getArrayFromXml(sourceTracksXml);
    if (tracks.size() < 2)
        return Response.status(Response.Status.BAD_REQUEST).entity("At least two tracks must be set to concat").build();
    for (MediaPackageElement elem : tracks) {
        if (!Track.TYPE.equals(elem.getElementType()))
            return Response.status(Response.Status.BAD_REQUEST).entity("sourceTracks must be of type track").build();
    }
    float fps = NumberUtils.toFloat(outputFrameRate, -1.0f);
    try {
        // Asynchronously concat the specified tracks together
        Dimension dimension = null;
        if (StringUtils.isNotBlank(outputDimension)) {
            dimension = Serializer.dimension(JsonObj.jsonObj(outputDimension));
        }
        Job job = null;
        if (fps > 0) {
            job = composerService.concat(profileId, dimension, fps, tracks.toArray(new Track[tracks.size()]));
        } else {
            job = composerService.concat(profileId, dimension, tracks.toArray(new Track[tracks.size()]));
        }
        return Response.ok().entity(new JaxbJob(job)).build();
    } catch (EncoderException e) {
        logger.warn("Unable to concat videos: " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) Dimension(org.opencastproject.composer.layout.Dimension) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) 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 JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestServiceTest method testMux.

@Test
public void testMux() throws Exception {
    Response response = restService.mux(generateAudioTrack(), generateVideoTrack(), profileId);
    Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Assert.assertEquals(new JaxbJob(job), response.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) JaxbJob(org.opencastproject.job.api.JaxbJob) Test(org.junit.Test)

Example 23 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestServiceTest method testEncode.

@Test
public void testEncode() throws Exception {
    Response response = restService.encode(generateVideoTrack(), profileId);
    Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Assert.assertEquals(new JaxbJob(job), response.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) JaxbJob(org.opencastproject.job.api.JaxbJob) Test(org.junit.Test)

Example 24 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class OaiPmhPublicationRestService method updateMetadata.

@POST
@Path("/updateMetadata")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "update", description = "Update metadata of an published media package. " + "This endpoint does not update any media files. If you want to update the whole media package, use the " + "publish endpoint.", returnDescription = "The job that can be used to update the metadata of an media package", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The updated media package", type = Type.TEXT), @RestParameter(name = "channel", isRequired = true, description = "The channel name", type = Type.STRING), @RestParameter(name = "flavors", isRequired = true, description = "The element flavors to be updated, separated by ';;'", type = Type.STRING), @RestParameter(name = "tags", isRequired = true, description = "The element tags to be updated, separated by ';;'", type = Type.STRING), @RestParameter(name = "checkAvailability", isRequired = false, description = "Whether to check for availability", type = Type.BOOLEAN, defaultValue = "true") }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the publication job") })
public Response updateMetadata(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channel") String channel, @FormParam("flavors") String flavors, @FormParam("tags") String tags, @FormParam("checkAvailability") @DefaultValue("true") boolean checkAvailability) throws Exception {
    final Job job;
    try {
        final MediaPackage mediaPackage = MediaPackageParser.getFromXml(mediaPackageXml);
        final Set<String> flavorsSet = Collections.set(StringUtils.split(flavors, ";;"));
        final Set<String> tagsSet = Collections.set(StringUtils.split(tags, ";;"));
        job = service.updateMetadata(mediaPackage, channel, flavorsSet, tagsSet, checkAvailability);
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to create an update metadata job", e);
        return Response.status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Error publishing element", e);
        return Response.serverError().build();
    }
    return Response.ok(new JaxbJob(job)).build();
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 25 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class OaiPmhPublicationRestService method publish.

@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "publish", description = "Publish a media package element to this publication channel", returnDescription = "The job that can be used to track the publication", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The media package", type = Type.TEXT), @RestParameter(name = "channel", isRequired = true, description = "The channel name", type = Type.STRING), @RestParameter(name = "downloadElementIds", isRequired = true, description = "The elements to publish to download seperated by ';;'", type = Type.STRING), @RestParameter(name = "streamingElementIds", isRequired = true, description = "The elements to publish to streaming seperated by ';;'", type = Type.STRING), @RestParameter(name = "checkAvailability", isRequired = false, description = "Whether to check for availability", type = Type.BOOLEAN, defaultValue = "true") }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the publication job") })
public Response publish(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channel") String channel, @FormParam("downloadElementIds") String downloadElementIds, @FormParam("streamingElementIds") String streamingElementIds, @FormParam("checkAvailability") @DefaultValue("true") boolean checkAvailability) throws Exception {
    final Job job;
    try {
        Set<String> download = new HashSet<>();
        Set<String> streaming = new HashSet<>();
        final MediaPackage mediaPackage = MediaPackageParser.getFromXml(mediaPackageXml);
        final String[] downloadElements = StringUtils.split(downloadElementIds, ";;");
        final String[] streamingElements = StringUtils.split(streamingElementIds, ";;");
        if (downloadElements != null)
            download = set(downloadElements);
        if (streamingElements != null)
            streaming = set(streamingElements);
        job = service.publish(mediaPackage, channel, download, streaming, checkAvailability);
    } catch (IllegalArgumentException e) {
        logger.warn("Unable to create an publication job", e);
        return Response.status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Error publishing element", e);
        return Response.serverError().build();
    }
    return Response.ok(new JaxbJob(job)).build();
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

JaxbJob (org.opencastproject.job.api.JaxbJob)35 Job (org.opencastproject.job.api.Job)31 POST (javax.ws.rs.POST)26 Path (javax.ws.rs.Path)26 Produces (javax.ws.rs.Produces)26 RestQuery (org.opencastproject.util.doc.rest.RestQuery)26 MediaPackage (org.opencastproject.mediapackage.MediaPackage)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)10 TypeToken (com.google.gson.reflect.TypeToken)8 Gson (com.google.gson.Gson)7 Test (org.junit.Test)6 EncoderException (org.opencastproject.composer.api.EncoderException)6 Track (org.opencastproject.mediapackage.Track)5 Response (javax.ws.rs.core.Response)4 JobImpl (org.opencastproject.job.api.JobImpl)3 NotFoundException (org.opencastproject.util.NotFoundException)3 IOException (java.io.IOException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Dimension (org.opencastproject.composer.layout.Dimension)2 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)2