Search in sources :

Example 1 with Asset

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());
    }
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecords.getSnapshot(org.opencastproject.assetmanager.api.fn.ARecords.getSnapshot) Version(org.opencastproject.assetmanager.api.Version) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Asset(org.opencastproject.assetmanager.api.Asset) AResult(org.opencastproject.assetmanager.api.query.AResult) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Asset

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;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) InputStream(java.io.InputStream) Asset(org.opencastproject.assetmanager.api.Asset)

Example 3 with Asset

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);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) InputStream(java.io.InputStream) Asset(org.opencastproject.assetmanager.api.Asset)

Example 4 with Asset

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);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) InputStream(java.io.InputStream) Asset(org.opencastproject.assetmanager.api.Asset) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

Asset (org.opencastproject.assetmanager.api.Asset)4 InputStream (java.io.InputStream)3 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)3 IOException (java.io.IOException)1 Date (java.util.Date)1 ValidationException (net.fortuna.ical4j.model.ValidationException)1 Test (org.junit.Test)1 Snapshot (org.opencastproject.assetmanager.api.Snapshot)1 Version (org.opencastproject.assetmanager.api.Version)1 ARecords.getSnapshot (org.opencastproject.assetmanager.api.fn.ARecords.getSnapshot)1 AResult (org.opencastproject.assetmanager.api.query.AResult)1 RichAResult (org.opencastproject.assetmanager.api.query.RichAResult)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)1 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)1 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)1 SeriesException (org.opencastproject.series.api.SeriesException)1