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