use of org.opencastproject.assetmanager.api.Asset 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.assetmanager.api.Asset in project opencast by opencast.
the class AssetManagerWithSecurity method isAuthorizedByAcl.
private boolean isAuthorizedByAcl(Version version, String mpId, String action) {
Opt<Asset> secAsset = super.getAsset(version, mpId, "security-policy-episode");
if (secAsset.isSome()) {
InputStream in = secAsset.get().getInputStream();
final AccessControlList acl = authSvc.getAclFromInputStream(in).getA();
return isAuthorizedByAcl(acl, action);
}
return false;
}
use of org.opencastproject.assetmanager.api.Asset in project opencast by opencast.
the class SchedulerServiceImpl method loadEpisodeDublinCoreFromAsset.
private Opt<DublinCoreCatalog> loadEpisodeDublinCoreFromAsset(Snapshot snapshot) {
Option<MediaPackageElement> dcCatalog = mlist(snapshot.getMediaPackage().getElements()).filter(MediaPackageSupport.Filters.isEpisodeDublinCore).headOpt();
if (dcCatalog.isNone())
return Opt.none();
Opt<Asset> asset = assetManager.getAsset(snapshot.getVersion(), snapshot.getMediaPackage().getIdentifier().compact(), dcCatalog.get().getIdentifier());
if (asset.isNone())
return Opt.none();
if (Availability.OFFLINE.equals(asset.get().getAvailability()))
return Opt.none();
InputStream inputStream = null;
try {
inputStream = asset.get().getInputStream();
return Opt.some(DublinCores.read(inputStream));
} finally {
IOUtils.closeQuietly(inputStream);
}
}
use of org.opencastproject.assetmanager.api.Asset in project opencast by opencast.
the class SchedulerServiceImpl method loadEpisodeAclFromAsset.
private Opt<AccessControlList> loadEpisodeAclFromAsset(Snapshot snapshot) {
Option<MediaPackageElement> acl = mlist(snapshot.getMediaPackage().getElements()).filter(MediaPackageSupport.Filters.isEpisodeAcl).headOpt();
if (acl.isNone())
return Opt.none();
Opt<Asset> asset = assetManager.getAsset(snapshot.getVersion(), snapshot.getMediaPackage().getIdentifier().compact(), acl.get().getIdentifier());
if (asset.isNone())
return Opt.none();
if (Availability.OFFLINE.equals(asset.get().getAvailability()))
return Opt.none();
InputStream inputStream = null;
try {
inputStream = asset.get().getInputStream();
return Opt.some(XACMLUtils.parseXacml(inputStream));
} catch (Exception e) {
logger.warn("Unable to parse access control list: {}", getStackTrace(e));
return Opt.none();
} finally {
IOUtils.closeQuietly(inputStream);
}
}
Aggregations