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();
}
}
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();
}
}
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);
}
}
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);
}
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();
}
Aggregations