use of org.opencastproject.util.doc.rest.RestQuery 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();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class PaellaConfigRest method getMyInfo.
@GET
@Path("config.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "config.json", description = "Paella configuration file", reponses = { @RestResponse(description = "Returns the paella configuration file", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
@SuppressWarnings("unchecked")
public String getMyInfo() throws IOException {
// Add the current user's organizational information
Organization org = securityService.getOrganization();
File configFile = new File(PathSupport.concat(new String[] { paellaConfigFolder, org.getId(), "config.json" }));
String configContent = FileUtils.readFileToString(configFile);
return configContent;
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class StaticFileRestService method getStaticFile.
@GET
@Path("{uuid}")
@RestQuery(name = "getStaticFile", description = "Returns a static file resource", pathParameters = { @RestParameter(description = "Static File Universal Unique Id", isRequired = true, name = "uuid", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a static file resource", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No file by the given uuid found", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "")
public Response getStaticFile(@PathParam("uuid") String uuid) throws NotFoundException {
try {
final InputStream file = staticFileService.getFile(uuid);
final String filename = staticFileService.getFileName(uuid);
final Long length = staticFileService.getContentLength(uuid);
// It is safe to pass the InputStream without closing it, JAX-RS takes care of that
return RestUtil.R.ok(file, getMimeType(filename), Option.some(length), Option.some(filename));
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.warn("Unable to retrieve file with uuid {} because: {}", uuid, ExceptionUtils.getStackTrace(e));
return Response.serverError().build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class SmilServiceRest method createNewSmil.
@POST
@Path("create")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "create", description = "Create new SMIL. Add some MediaPackage metadata.", restParameters = { @RestParameter(name = "mediaPackage", description = "MediaPackage for metadata.", isRequired = false, type = RestParameter.Type.TEXT) }, returnDescription = "Returns new SmilResponse with SMIL document inside.", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Create new SMIL successfull"), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Given mediaPackage is not valid") })
public Response createNewSmil(@FormParam("mediaPackage") String mediaPackage) {
SmilResponse smilResponse = null;
try {
if (mediaPackage != null && !mediaPackage.isEmpty()) {
MediaPackage mp = MediaPackageParser.getFromXml(mediaPackage);
smilResponse = smilService.createNewSmil(mp);
} else {
smilResponse = smilService.createNewSmil();
}
return Response.ok(smilResponse).build();
} catch (MediaPackageException ex) {
logger.info(ex.getMessage(), ex);
return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("MediaPackage not valid.").build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class SmilServiceRest method addClips.
@POST
@Path("addClips")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "addClips", description = "Add new media elements based on given Tracks information and start / duration parameters. " + "ParentId specifies where to put the new media.", restParameters = { @RestParameter(name = "smil", description = "SMIL document where to add new media elements.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "parentId", description = "An element Id, were to add new media. ", isRequired = false, type = RestParameter.Type.STRING), @RestParameter(name = "tracks", description = "Tracks (MediaPackageElements) to add as media elements." + "Some information like Track source and flavor will be stored in ParamGroup (in SMIL Head) " + "and referenced by paramGroup media element attribute.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "start", description = "Track start position in milliseconds. " + "The start position will be applied to each media element.", isRequired = true, type = RestParameter.Type.INTEGER), @RestParameter(name = "duration", description = "Clip duration in milliseconds (should be positive). " + "The duration will be applied to each media element.", isRequired = true, type = RestParameter.Type.INTEGER) }, returnDescription = "Returns new Smil with new media elements inside " + "(the new media and metadata elements will be returned as response entities).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Add media elements to SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Tracks are not valid."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document doesn't contain an element with given parentId."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Start plus duration is bigger than Track length.") })
public Response addClips(@FormParam("smil") String smil, @FormParam("parentId") String parentId, @FormParam("tracks") String tracks, @FormParam("start") long start, @FormParam("duration") long duration) {
SmilResponse smilResponse = null;
List<Track> tracksList = null;
try {
smilResponse = smilService.fromXml(smil);
tracksList = (List<Track>) MediaPackageElementParser.getArrayFromXml(tracks);
} catch (SmilException ex) {
logger.info(ex.getMessage(), ex);
return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
} catch (MediaPackageException ex) {
logger.error(ex.getMessage(), ex);
return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("Tracks are not valid.").build();
}
Track[] tracksArr = tracksList.toArray(new Track[tracksList.size()]);
try {
smilResponse = smilService.addClips(smilResponse.getSmil(), parentId, tracksArr, start, duration);
return Response.ok(smilResponse).build();
} catch (SmilException ex) {
logger.info(ex.getMessage(), ex);
return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document doesn't contain an element with given parentId.").build();
}
}
Aggregations