Search in sources :

Example 56 with RestQuery

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();
    }
}
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 57 with RestQuery

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;
}
Also used : Organization(org.opencastproject.security.api.Organization) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 58 with RestQuery

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();
    }
}
Also used : ProgressInputStream(org.opencastproject.util.ProgressInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) ConfigurationException(org.osgi.service.cm.ConfigurationException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 59 with RestQuery

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();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SmilResponse(org.opencastproject.smil.api.SmilResponse) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 60 with RestQuery

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();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilException(org.opencastproject.smil.api.SmilException) 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)

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