use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectSnapshotAndProperties.
@Test
public void testSelectSnapshotAndProperties() throws Exception {
final MediaPackage mp1 = mkMediaPackage(mkCatalog());
am.takeSnapshot(OWNER, mp1);
// only select snapshots
{
final AResult r = q.select(q.snapshot()).run();
assertEquals("One record should be found", 1, r.getSize());
assertEquals("One snapshot should be found", 1, r.getRecords().bind(getSnapshot).toList().size());
assertEquals("No properties should be found", 0, r.getRecords().bind(getProperties).toList().size());
}
// select snapshots and properties
{
final AResult r = q.select(q.snapshot(), p.allProperties()).run();
assertEquals("One record should be found", 1, r.getSize());
assertEquals("One snapshot should be found", 1, r.getRecords().bind(getSnapshot).toList().size());
assertEquals("No properties should be found", 0, r.getRecords().bind(getProperties).toList().size());
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectSnapshots.
@Test
public void testSelectSnapshots() throws Exception {
final MediaPackage mp = mkMediaPackage();
final MediaPackageElement mpe = mkCatalog();
mp.add(mpe);
final Snapshot snapshot = am.takeSnapshot(OWNER, mp);
final Version version = snapshot.getVersion();
assertThat("Archival date should not be in the future", snapshot.getArchivalDate(), lessThanOrEqualTo(new Date()));
assertThat("Snapshot should be available", snapshot.getAvailability(), equalTo(Availability.ONLINE));
assertThat("Snapshot should belong to the default organization", snapshot.getOrganizationId(), equalTo(DefaultOrganization.DEFAULT_ORGANIZATION_ID));
final Opt<Asset> asset = am.getAsset(version, mp.getIdentifier().toString(), mpe.getIdentifier());
assertTrue("Asset should be found", asset.isSome());
assertEquals("Media package element part of the asset ID should equal the element's ID", mpe.getIdentifier(), asset.get().getId().getMediaPackageElementId());
assertEquals("Mime types should equal", mpe.getMimeType(), asset.get().getMimeType().get());
assertFalse("Asset should not be found", am.getAsset(version, "id", "id").isSome());
// try to find the catalog of the media package by checksum
final MediaPackage mpCopy = MediaPackageSupport.copy(mp);
am.calcChecksumsForMediaPackageElements(AbstractAssetManager.assetsOnly(mpCopy));
assertEquals("Media package should be set up with a single catalog", 1, mpCopy.getCatalogs().length);
final String checksum = mpCopy.getCatalogs()[0].getChecksum().toString();
assertTrue("Media package element should be retrievable by checksum", am.getDb().findAssetByChecksum(checksum).isSome());
// issue some queries
{
logger.info("Run a failing query");
assertEquals("The result should not contain any records", 0, q.select(q.snapshot()).where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).where(q.mediaPackageId("12")).run().getSize());
}
{
logger.info("Run query to find snapshot");
final AResult r = q.select(q.snapshot()).where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).run();
assertEquals("The result set should contain exactly one record", 1, r.getSize());
assertEquals("The media package IDs should be equal", mp.getIdentifier().toString(), r.getRecords().head2().getMediaPackageId());
assertTrue("The snapshot should be contained in the record", r.getRecords().head2().getSnapshot().isSome());
assertEquals("The media package IDs should be equal", mp.getIdentifier(), r.getRecords().head2().getSnapshot().get().getMediaPackage().getIdentifier());
}
{
final AResult r = q.select().where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).run();
assertEquals("The result should contain one record", 1, r.getSize());
assertTrue("The result should not contain a snapshot", r.getRecords().head2().getSnapshot().isNone());
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectByVersion.
@Test
public void testSelectByVersion() throws Exception {
final MediaPackage mp1 = mkMediaPackage(mkCatalog());
logger.info("Create 4 versions");
am.takeSnapshot(OWNER, mp1);
am.takeSnapshot(OWNER, mp1);
am.takeSnapshot(OWNER, mp1);
am.takeSnapshot(OWNER, mp1);
assertEquals("4 records should be found", 4, q.select(q.snapshot()).run().getSize());
assertEquals("4 records should be found", 4, q.select().run().getSize());
final Version latest;
{
AResult r = q.select(q.snapshot()).where(q.version().isLatest()).run();
assertEquals("1 latest record should be found", 1, r.getSize());
latest = r.getRecords().head2().getSnapshot().get().getVersion();
}
final Version first;
{
AResult r = q.select(q.snapshot()).where(q.version().isFirst()).run();
assertEquals("1 first record should be found", 1, r.getSize());
first = r.getRecords().head2().getSnapshot().get().getVersion();
}
assertTrue("The first version should be older", first.isOlder(latest));
assertTrue("The last version should be younger", latest.isYounger(first));
assertFalse("The versions should not be equal", latest.equals(first));
//
assertEquals("Three older records should be found", 3, q.select(q.snapshot()).where(q.version().lt(latest)).run().getSize());
assertEquals("4 records should be found", 4, q.select(q.snapshot()).where(q.version().le(latest)).run().getSize());
assertEquals("Three younger records should be found", 3, q.select(q.snapshot()).where(q.version().gt(first)).run().getSize());
assertEquals("4 records should be found", 4, q.select(q.snapshot()).where(q.version().ge(first)).run().getSize());
assertEquals("2 intermediate records should be found", 2, q.select(q.snapshot()).where(q.version().gt(first).and(q.version().lt(latest))).run().getSize());
//
logger.info("Now add another media package");
am.takeSnapshot(OWNER, mkMediaPackage(mkCatalog()));
assertEquals("Three older records should be found", 3, q.select(q.snapshot()).where(q.version().lt(latest).and(q.mediaPackageId(mp1.getIdentifier().toString()))).run().getSize());
assertEquals("Two latest versions should be found", 2, q.select(q.snapshot()).where(q.version().isLatest()).run().getSize());
assertEquals("Two first versions should be found", 2, q.select(q.snapshot()).where(q.version().isFirst()).run().getSize());
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IngestRestService method addMediaPackageCatalog.
@POST
@Produces(MediaType.TEXT_XML)
@Path("addCatalog")
@RestQuery(name = "addCatalogURL", description = "Add a metadata catalog to a given media package using an URL", restParameters = { @RestParameter(description = "The location of the catalog", isRequired = true, name = "url", type = RestParameter.Type.STRING), @RestParameter(description = "The kind of catalog", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackageCatalog(@FormParam("url") String url, @FormParam("flavor") String flavor, @FormParam("mediaPackage") String mpx) {
logger.trace("add catalog with url: {} flavor: {} mediaPackage: {}", url, flavor, mpx);
try {
MediaPackage mp = factory.newMediaPackageBuilder().loadFromXml(mpx);
if (MediaPackageSupport.sanityCheck(mp).isSome())
return Response.serverError().status(Status.BAD_REQUEST).build();
MediaPackage resultingMediaPackage = ingestService.addCatalog(new URI(url), MediaPackageElementFlavor.parseFlavor(flavor), mp);
return Response.ok(resultingMediaPackage).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IngestRestService method addDCCatalog.
/**
* Adds a dublinCore metadata catalog to the MediaPackage and returns the grown mediaPackage. JQuery Ajax functions
* doesn't support multipart/form-data encoding.
*
* @param mp
* MediaPackage
* @param dc
* DublinCoreCatalog
* @return grown MediaPackage XML
*/
@POST
@Produces(MediaType.TEXT_XML)
@Path("addDCCatalog")
@RestQuery(name = "addDCCatalog", description = "Add a dublincore episode catalog to a given media package using an url", restParameters = { @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT), @RestParameter(description = "DublinCore catalog as XML", isRequired = true, name = "dublinCore", type = RestParameter.Type.TEXT), @RestParameter(defaultValue = "dublincore/episode", description = "DublinCore Flavor", isRequired = false, name = "flavor", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addDCCatalog(@FormParam("mediaPackage") String mp, @FormParam("dublinCore") String dc, @FormParam("flavor") String flavor) {
logger.trace("add DC catalog: {} with flavor: {} to media package: {}", dc, flavor, mp);
MediaPackageElementFlavor dcFlavor = MediaPackageElements.EPISODE;
if (flavor != null) {
try {
dcFlavor = MediaPackageElementFlavor.parseFlavor(flavor);
} catch (IllegalArgumentException e) {
logger.warn("Unable to set dublin core flavor to {}, using {} instead", flavor, MediaPackageElements.EPISODE);
}
}
MediaPackage mediaPackage;
/* Check if we got a proper mediapackage and try to parse it */
try {
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mp);
} catch (MediaPackageException e) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
if (MediaPackageSupport.sanityCheck(mediaPackage).isSome()) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
/* Check if we got a proper catalog */
if (StringUtils.isBlank(dc)) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
InputStream in = null;
try {
in = IOUtils.toInputStream(dc, "UTF-8");
mediaPackage = ingestService.addCatalog(in, "dublincore.xml", dcFlavor, mediaPackage);
} catch (MediaPackageException e) {
return Response.serverError().status(Status.BAD_REQUEST).build();
} catch (IOException e) {
/* Return an internal server error if we could not write to disk */
logger.error("Could not write catalog to disk: {}", e.getMessage());
return Response.serverError().build();
} catch (Exception e) {
logger.error(e.getMessage());
return Response.serverError().build();
} finally {
IOUtils.closeQuietly(in);
}
return Response.ok(mediaPackage).build();
}
Aggregations