Search in sources :

Example 6 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SmilResponseImplTest method testGetSmil.

/**
 * Test of getSmil method, of class SmilResponseImpl.
 */
@Test
public void testGetSmil() {
    Smil smil = new SmilImpl();
    SmilResponse response = new SmilResponseImpl(smil);
    assertEquals(smil, response.getSmil());
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilImpl(org.opencastproject.smil.entity.SmilImpl) Smil(org.opencastproject.smil.entity.api.Smil) Test(org.junit.Test)

Example 7 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SmilResponseImplTest method testGetEntities.

/**
 * Test of getEntities method, of class SmilResponseImpl.
 */
@Test
public void testGetEntities() throws Exception {
    Smil smil = new SmilImpl();
    SmilResponse response = new SmilResponseImpl(smil);
    try {
        response.getEntities();
        fail("getEntities should fail, if entity count is zero");
    } catch (SmilException ex) {
    }
    response = new SmilResponseImpl(smil, smil.getBody());
    try {
        SmilObject[] entities = response.getEntities();
        assertSame(1, entities.length);
        assertSame(smil.getBody(), entities[0]);
    } catch (SmilException ex) {
        fail("getEntities should not throw an Exception if some entities are set");
    }
    response = new SmilResponseImpl(smil, new SmilObject[] { smil.getHead(), smil.getBody() });
    try {
        SmilObject[] entities = response.getEntities();
        assertSame(2, entities.length);
        assertSame(smil.getHead(), entities[0]);
        assertSame(smil.getBody(), entities[1]);
    } catch (SmilException ex) {
        fail("getEntities should not throw an Exception if some entities are set");
    }
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilImpl(org.opencastproject.smil.entity.SmilImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject) Smil(org.opencastproject.smil.entity.api.Smil) SmilException(org.opencastproject.smil.api.SmilException) Test(org.junit.Test)

Example 8 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse 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 9 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse 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)

Example 10 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SmilServiceRest method addMeta.

@POST
@Path("addMeta")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "addMeta", description = "Add a meta element to SMIL head.", restParameters = { @RestParameter(name = "smil", description = "SMIL document where to add an meta element.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "name", description = "Value of meta name attribute.", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "content", description = "Value of meta content attribute.", isRequired = true, type = RestParameter.Type.STRING) }, returnDescription = "Returns SmilResponse with a new meta element inside " + "(the new meta will be returned as response entity).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Add par to SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid.") })
public Response addMeta(@FormParam("smil") String smil, @FormParam("name") String metaName, @FormParam("content") String metaContent) {
    SmilResponse smilResponse = null;
    try {
        smilResponse = smilService.fromXml(smil);
    } catch (SmilException ex) {
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
    }
    smilResponse = smilService.addMeta(smilResponse.getSmil(), metaName, metaContent);
    return Response.ok(smilResponse).build();
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilException(org.opencastproject.smil.api.SmilException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

SmilResponse (org.opencastproject.smil.api.SmilResponse)30 Test (org.junit.Test)16 Smil (org.opencastproject.smil.entity.api.Smil)11 SmilMediaContainer (org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)10 SmilException (org.opencastproject.smil.api.SmilException)8 URI (java.net.URI)7 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)7 Track (org.opencastproject.mediapackage.Track)7 SmilMediaElement (org.opencastproject.smil.entity.media.element.api.SmilMediaElement)7 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)6 VideoStreamImpl (org.opencastproject.mediapackage.track.VideoStreamImpl)6 SmilObject (org.opencastproject.smil.entity.api.SmilObject)6 SmilMediaObject (org.opencastproject.smil.entity.media.api.SmilMediaObject)6 ArrayList (java.util.ArrayList)5 POST (javax.ws.rs.POST)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 SmilImpl (org.opencastproject.smil.entity.SmilImpl)5 SmilMediaParamGroup (org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup)4