Search in sources :

Example 6 with JaxbJob

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

the class ServiceRegistryInMemoryImpl method updateJob.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.serviceregistry.api.ServiceRegistry#updateJob(org.opencastproject.job.api.Job)
 */
@Override
public Job updateJob(Job job) throws NotFoundException, ServiceRegistryException {
    if (job == null)
        throw new IllegalArgumentException("Job cannot be null");
    Job updatedJob = null;
    synchronized (jobs) {
        try {
            updatedJob = updateInternal(job);
            jobs.put(updatedJob.getId(), JobParser.toXml(new JaxbJob(updatedJob)));
        } catch (IOException e) {
            throw new IllegalStateException("Error serializing job", e);
        }
    }
    return updatedJob;
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) IOException(java.io.IOException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job)

Example 7 with JaxbJob

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

the class StreamingDistributionRestService method distribute.

@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementIds", isRequired = true, description = "The elements to distribute as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response distribute(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementIds") String elementIds) throws Exception {
    Job job = null;
    try {
        Gson gson = new Gson();
        Set<String> setElementIds = gson.fromJson(elementIds, new TypeToken<Set<String>>() {
        }.getType());
        MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.distribute(channelId, mediapackage, setElementIds);
        if (job == null)
            return Response.noContent().build();
        return Response.ok(new JaxbJob(job)).build();
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to distribute element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Error distributing element", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Gson(com.google.gson.Gson) 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 8 with JaxbJob

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

the class StreamingDistributionRestService method retract.

@POST
@Path("/retract")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "retract", description = "Retract a media package element from this distribution channel", returnDescription = "The job that can be used to track the retraction", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementIds", isRequired = true, description = "The elements to retract as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementIds") String elementIds) throws Exception {
    Job job = null;
    try {
        Gson gson = new Gson();
        Set<String> setElementIds = gson.fromJson(elementIds, new TypeToken<Set<String>>() {
        }.getType());
        MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.retract(channelId, mediapackage, setElementIds);
        if (job == null)
            return Response.noContent().build();
        return Response.ok(new JaxbJob(job)).build();
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to retract element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Unable to retract mediapackage '{}' from streaming channel: {}", mediaPackageXml, e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Gson(com.google.gson.Gson) 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 9 with JaxbJob

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

the class AwsS3DistributionRestService method distribute.

@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementId", isRequired = true, description = "The element to distribute", type = Type.STRING), @RestParameter(name = "checkAvailability", isRequired = false, description = "If the service should try to access the distributed element", type = Type.BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job") })
public Response distribute(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementId") String elementId, @DefaultValue("true") @FormParam("checkAvailability") boolean checkAvailability) throws Exception {
    Job job = null;
    try {
        Gson gson = new Gson();
        Set<String> setElementIds = gson.fromJson(elementId, new TypeToken<Set<String>>() {
        }.getType());
        MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.distribute(channelId, mediapackage, setElementIds, checkAvailability);
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to distribute element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Unable to distribute media package {}, element {} to aws s3 channel: {}", mediaPackageXml, elementId, e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
    return Response.ok(new JaxbJob(job)).build();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Gson(com.google.gson.Gson) 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 10 with JaxbJob

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

the class DownloadDistributionRestService method distribute.

@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementId", isRequired = true, description = "The element to distribute. The Id or multiple Ids as JSON Array ( ['IdOne','IdTwo'] )", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job") })
public Response distribute(@FormParam("mediapackage") String mediaPackageXml, @FormParam("elementId") String elementId, @FormParam("channelId") String channelId, @DefaultValue("true") @FormParam("checkAvailability") boolean checkAvailability, @DefaultValue("false") @FormParam("preserveReference") boolean preserveReference) throws Exception {
    try {
        Gson gson = new Gson();
        Set<String> setElementIds = gson.fromJson(elementId, new TypeToken<Set<String>>() {
        }.getType());
        final MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        final Job job = service.distribute(channelId, mediapackage, setElementIds, checkAvailability, preserveReference);
        return ok(new JaxbJob(job));
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to distribute element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Error distributing element", e);
        return serverError();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Gson(com.google.gson.Gson) 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)

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