Search in sources :

Example 26 with JaxbJob

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

the class OaiPmhPublicationRestService method retract.

@POST
@Path("/retract")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "retract", description = "Retract a media package element from this publication channel", returnDescription = "The job that can be used to track the retraction", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The media package", type = Type.TEXT), @RestParameter(name = "channel", isRequired = true, description = "The OAI-PMH channel to retract from", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channel") String channel) throws Exception {
    Job job = null;
    MediaPackage mediaPackage = null;
    try {
        mediaPackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.retract(mediaPackage, channel);
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to create an retract job", e);
        return Response.status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Unable to retract media package '{}' from the OAI-PMH channel {}", mediaPackage != null ? mediaPackage.getIdentifier().compact() : "<parsing error>", channel, 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 27 with JaxbJob

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

the class YouTubePublicationRestService method publish.

@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "publish", description = "Publish a media package element to youtube publication channel", returnDescription = "The job that can be used to track the publication", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "elementId", isRequired = true, description = "The element to publish", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the publication job"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "elementId does not reference a track") })
public Response publish(@FormParam("mediapackage") final String mediaPackageXml, @FormParam("elementId") final String elementId) {
    final Job job;
    try {
        final MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        final Track track = mediapackage.getTrack(elementId);
        if (track != null) {
            job = service.publish(mediapackage, track);
        } else {
            return badRequest();
        }
    } catch (Exception e) {
        logger.warn("Error publishing element '{}' to YouTube", elementId, e);
        return serverError();
    }
    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) Track(org.opencastproject.mediapackage.Track) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 28 with JaxbJob

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

the class SoxRestServiceTest method testAnalyze.

@Test
public void testAnalyze() throws Exception {
    Response response = restService.analyze(MediaPackageElementParser.getAsXml(audioTrack));
    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 29 with JaxbJob

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

the class SoxRestServiceTest method testNormalize.

@Test
public void testNormalize() throws Exception {
    Response response = restService.normalize(MediaPackageElementParser.getAsXml(audioTrack), -30f);
    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 30 with JaxbJob

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

the class TextAnalysisRestEndpoint method analyze.

@POST
@Produces(MediaType.TEXT_XML)
@Path("")
@RestQuery(name = "analyze", description = "Submit a track for analysis.", restParameters = { @RestParameter(description = "The image to analyze for text.", isRequired = true, name = "image", type = RestParameter.Type.FILE) }, reponses = { @RestResponse(description = "OK, The receipt to use when polling for the resulting mpeg7 catalog.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "The argument cannot be parsed into a media package element.", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "The service is unavailable at the moment.", responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE) }, returnDescription = "The receipt to use when polling for the resulting mpeg7 catalog.")
public Response analyze(@FormParam("image") String image) {
    if (service == null)
        throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
    try {
        MediaPackageElement element = MediaPackageElementParser.getFromXml(image);
        if (!(element instanceof Attachment))
            throw new WebApplicationException(Status.BAD_REQUEST);
        Job job = service.extract((Attachment) element);
        return Response.ok(new JaxbJob(job)).build();
    } catch (Exception e) {
        logger.info(e.getMessage(), e);
        return Response.serverError().build();
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) Attachment(org.opencastproject.mediapackage.Attachment) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) WebApplicationException(javax.ws.rs.WebApplicationException) 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