Search in sources :

Example 21 with RestQuery

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

the class SeriesRestService method getAllSeriesIdTitle.

@GET
@Path("allSeriesIdTitle.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getAll", description = "Returns a list of identifier and title of all series", returnDescription = "Json list of identifier and title of all series", reponses = { @RestResponse(responseCode = SC_OK, description = "A list with series"), @RestResponse(responseCode = SC_FORBIDDEN, description = "A user is not allowed to list all series"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response getAllSeriesIdTitle() {
    try {
        Map<String, String> allSeries = seriesService.getIdTitleMapOfAllSeries();
        JSONArray seriesJsonArr = new JSONArray();
        for (String seriesId : allSeries.keySet()) {
            JSONObject seriesJsonObj = new JSONObject();
            seriesJsonObj.put("identifier", seriesId);
            seriesJsonObj.put("title", allSeries.get(seriesId));
            seriesJsonArr.add(seriesJsonObj);
        }
        JSONObject resultJson = new JSONObject();
        resultJson.put("series", seriesJsonArr);
        return Response.ok(resultJson.toJSONString()).build();
    } catch (SeriesException ex) {
        return R.serverError();
    } catch (UnauthorizedException ex) {
        return R.forbidden();
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) SeriesException(org.opencastproject.series.api.SeriesException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 22 with RestQuery

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

the class SeriesRestService method getSeriesElements.

@GET
@Path("{seriesId}/elements.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getSeriesElements", description = "Returns all the element types of a series", returnDescription = "Returns a JSON array with all the types of elements of the given series.", pathParameters = { @RestParameter(name = "seriesId", description = "The series identifier", type = STRING, isRequired = true) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Series found"), @RestResponse(responseCode = SC_NOT_FOUND, description = "Series not found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response getSeriesElements(@PathParam("seriesId") String seriesId) {
    try {
        Opt<Map<String, byte[]>> optSeriesElements = seriesService.getSeriesElements(seriesId);
        if (optSeriesElements.isSome()) {
            Map<String, byte[]> seriesElements = optSeriesElements.get();
            JValue jsonArray = Jsons.arr(Stream.$(seriesElements.keySet()).map(Jsons.Functions.stringToJValue));
            return Response.ok(new SimpleSerializer().toJson(jsonArray)).build();
        } else {
            return R.notFound();
        }
    } catch (SeriesException e) {
        logger.warn("Error while retrieving elements for sieres '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
        return R.serverError();
    }
}
Also used : SimpleSerializer(com.entwinemedia.fn.data.json.SimpleSerializer) JValue(com.entwinemedia.fn.data.json.JValue) SeriesException(org.opencastproject.series.api.SeriesException) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 23 with RestQuery

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

the class SeriesRestService method putSeriesElement.

@PUT
@Path("{seriesId}/elements/{elementType}")
@RestQuery(name = "updateSeriesElement", description = "Updates an existing series element", returnDescription = "An empty response", pathParameters = { @RestParameter(name = "seriesId", description = "The series identifier", type = STRING, isRequired = true), @RestParameter(name = "elementType", description = "The element type", type = STRING, isRequired = true) }, reponses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "Series element updated"), @RestResponse(responseCode = SC_CREATED, description = "Series element created"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response putSeriesElement(@Context HttpServletRequest request, @PathParam("seriesId") String seriesId, @PathParam("elementType") String elementType) {
    InputStream is = null;
    try {
        is = request.getInputStream();
        final byte[] data = IOUtils.toByteArray(is);
        if (seriesService.getSeriesElementData(seriesId, elementType).isSome()) {
            if (seriesService.updateSeriesElement(seriesId, elementType, data)) {
                return R.noContent();
            } else {
                return R.serverError();
            }
        } else {
            if (seriesService.addSeriesElement(seriesId, elementType, data)) {
                return R.created(URI.create(UrlSupport.concat(serverUrl, serviceUrl, seriesId, "elements", elementType)));
            } else {
                return R.serverError();
            }
        }
    } catch (IOException e) {
        logger.error("Error while trying to read from request: {}", ExceptionUtils.getStackTrace(e));
        return R.serverError();
    } catch (SeriesException e) {
        logger.warn("Error while adding element to series '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
        return R.serverError();
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) SeriesException(org.opencastproject.series.api.SeriesException) Path(javax.ws.rs.Path) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 24 with RestQuery

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

the class SeriesRestService method getSeriesPropertiesAsJson.

@SuppressWarnings("unchecked")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/properties.json")
@RestQuery(name = "getSeriesProperties", description = "Returns the series properties", returnDescription = "Returns the series properties as JSON", pathParameters = { @RestParameter(name = "id", description = "ID of series", isRequired = true, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public Response getSeriesPropertiesAsJson(@PathParam("id") String seriesId) throws UnauthorizedException, NotFoundException {
    if (StringUtils.isBlank(seriesId)) {
        logger.warn("Series id parameter is blank '{}'.", seriesId);
        return Response.status(BAD_REQUEST).build();
    }
    try {
        Map<String, String> properties = seriesService.getSeriesProperties(seriesId);
        JSONArray jsonProperties = new JSONArray();
        for (String name : properties.keySet()) {
            JSONObject property = new JSONObject();
            property.put(name, properties.get(name));
            jsonProperties.add(property);
        }
        return Response.ok(jsonProperties.toString()).build();
    } catch (UnauthorizedException e) {
        throw e;
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.warn("Could not perform search query: {}", e.getMessage());
    }
    throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
Also used : JSONObject(org.json.simple.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) JSONArray(org.json.simple.JSONArray) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 25 with RestQuery

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

the class ComposerRestService method parallelencode.

/**
 * Encodes a track to multiple tracks in parallel.
 *
 * @param sourceTrackAsXml
 *          The source track
 * @param profileId
 *          The profile to use in encoding this track
 * @return A response containing the job for this encoding job in the response body.
 * @throws Exception
 */
@POST
@Path("parallelencode")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "parallelencode", description = "Starts an encoding process, based on the specified encoding profile ID and the track", pathParameters = {}, restParameters = { @RestParameter(description = "The track containing the stream", isRequired = true, name = "sourceTrack", type = Type.TEXT, defaultValue = "${this.videoTrackDefault}"), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING, defaultValue = "mp4-medium.http") }, reponses = { @RestResponse(description = "Results in an xml document containing the job for the encoding task", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
public Response parallelencode(@FormParam("sourceTrack") String sourceTrackAsXml, @FormParam("profileId") String profileId) throws Exception {
    // Ensure that the POST parameters are present
    if (sourceTrackAsXml == null || profileId == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack and profileId must not be null").build();
    }
    // Deserialize the track
    MediaPackageElement sourceTrack = MediaPackageElementParser.getFromXml(sourceTrackAsXml);
    if (!Track.TYPE.equals(sourceTrack.getElementType())) {
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack element must be of type track").build();
    }
    // Asynchronously encode the specified tracks
    Job job = composerService.parallelEncode((Track) sourceTrack, profileId);
    if (job == null)
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Encoding failed").build();
    return Response.ok().entity(new JaxbJob(job)).build();
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) 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