Search in sources :

Example 51 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class AnnotationRestService method change.

@PUT
@Path("{id}")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "change", description = "Changes the value of an annotation specified by its identifier ", returnDescription = "The user annotation.", pathParameters = { @RestParameter(name = "id", description = "The annotation identifier", isRequired = true, type = Type.STRING) }, restParameters = { @RestParameter(name = "value", description = "The value of the annotation", isRequired = true, type = Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_CREATED, description = "The URL to this annotation is returned in the Location header, and an XML representation of the annotation itelf is returned in the response body.") })
public Response change(@PathParam("id") String idAsString, @FormParam("value") String value, @Context HttpServletRequest request) throws NotFoundException {
    Long id = null;
    try {
        id = Long.parseLong(idAsString);
    } catch (NumberFormatException e) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
    Annotation a = annotationService.getAnnotation(id);
    a.setValue(value);
    a = annotationService.changeAnnotation(a);
    URI uri;
    try {
        uri = new URI(UrlSupport.concat(new String[] { serverUrl, serviceUrl, Long.toString(a.getAnnotationId()), ".xml" }));
    } catch (URISyntaxException e) {
        throw new WebApplicationException(e);
    }
    return Response.created(uri).entity(a).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Annotation(org.opencastproject.annotation.api.Annotation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 52 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class AnnotationRestService method removeAnnotation.

@DELETE
@Path("{id}")
@RestQuery(name = "remove", description = "Remove an annotation", returnDescription = "Return status code", pathParameters = { @RestParameter(name = "id", description = "The annotation identifier", isRequired = false, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Annotation deleted."), @RestResponse(responseCode = SC_NO_CONTENT, description = "Annotation not found.") })
public Response removeAnnotation(@PathParam("id") String idAsString) throws NotFoundException {
    Long id = null;
    Annotation a;
    try {
        id = Long.parseLong(idAsString);
    } catch (NumberFormatException e) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
    a = (AnnotationImpl) annotationService.getAnnotation(id);
    boolean removed = annotationService.removeAnnotation(a);
    if (removed) {
        return Response.status(Status.OK).build();
    } else {
        return Response.status(Status.NO_CONTENT).build();
    }
}
Also used : Annotation(org.opencastproject.annotation.api.Annotation) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 53 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery 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 54 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery 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 55 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery 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)

Aggregations

RestQuery (org.opencastproject.util.doc.rest.RestQuery)228 Path (javax.ws.rs.Path)226 Produces (javax.ws.rs.Produces)172 GET (javax.ws.rs.GET)97 POST (javax.ws.rs.POST)89 WebApplicationException (javax.ws.rs.WebApplicationException)83 NotFoundException (org.opencastproject.util.NotFoundException)83 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 MediaPackage (org.opencastproject.mediapackage.MediaPackage)52 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)46 Event (org.opencastproject.index.service.impl.index.event.Event)34 ParseException (java.text.ParseException)33 JSONObject (org.json.simple.JSONObject)33 IOException (java.io.IOException)32 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)32 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)31 Job (org.opencastproject.job.api.Job)30 Date (java.util.Date)29 ArrayList (java.util.ArrayList)28 PUT (javax.ws.rs.PUT)28