Search in sources :

Example 1 with Snapshot

use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method getActiveAclForEpisode.

private Either<AccessControlList, Tuple<ManagedAcl, AclScope>> getActiveAclForEpisode(AclService aclService, String episodeId) {
    final AQueryBuilder q = getAssetManager().createQuery();
    final ASelectQuery sq = q.select(q.snapshot()).where(q.mediaPackageId(episodeId).and(q.version().isLatest()));
    for (Snapshot snapshot : enrich(sq.run()).getSnapshots().head()) {
        // get active ACL of found media package
        final Tuple<AccessControlList, AclScope> activeAcl = getAuthorizationService().getActiveAcl(snapshot.getMediaPackage());
        // find corresponding managed ACL
        for (ManagedAcl macl : matchAcls(aclService, activeAcl.getA())) {
            return right(tuple(macl, activeAcl.getB()));
        }
        return left(activeAcl.getA());
    }
    // episode does not exist
    logger.warn("Episode {} cannot be found in Archive", episodeId);
    return left(EMPTY_ACL);
}
Also used : JsonConv.fullAccessControlList(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList) AccessControlList(org.opencastproject.security.api.AccessControlList) Snapshot(org.opencastproject.assetmanager.api.Snapshot) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) JsonConv.digestManagedAcl(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.digestManagedAcl) Util.getManagedAcl(org.opencastproject.authorization.xacml.manager.impl.Util.getManagedAcl) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AclScope(org.opencastproject.security.api.AclScope) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery)

Example 2 with Snapshot

use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.

the class TestRestService method newAssetManager.

private static AssetManager newAssetManager() {
    Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
    try {
        EasyMock.expect(snapshot.getMediaPackage()).andReturn(new MediaPackageBuilderImpl().createNew()).anyTimes();
    } catch (MediaPackageException e) {
        throw new RuntimeException(e);
    }
    ARecord record = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(record.getSnapshot()).andReturn(Opt.some(snapshot)).anyTimes();
    AResult result = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(result.getRecords()).andReturn($(record)).anyTimes();
    ASelectQuery select = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(select.where(EasyMock.anyObject(Predicate.class))).andReturn(select).anyTimes();
    EasyMock.expect(select.run()).andReturn(result).anyTimes();
    Predicate predicate = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(predicate.and(EasyMock.anyObject(Predicate.class))).andReturn(predicate).anyTimes();
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    VersionField version = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(query.version()).andReturn(version).anyTimes();
    EasyMock.expect(query.mediaPackageId(EasyMock.anyString())).andReturn(predicate).anyTimes();
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(select).anyTimes();
    AssetManager assetManager = EasyMock.createNiceMock(AssetManager.class);
    EasyMock.expect(assetManager.createQuery()).andReturn(query).anyTimes();
    EasyMock.replay(assetManager, version, query, predicate, select, result, record, snapshot);
    return assetManager;
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ARecord(org.opencastproject.assetmanager.api.query.ARecord) AssetManager(org.opencastproject.assetmanager.api.AssetManager) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) VersionField(org.opencastproject.assetmanager.api.query.VersionField) AResult(org.opencastproject.assetmanager.api.query.AResult) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Predicate(org.opencastproject.assetmanager.api.query.Predicate)

Example 3 with Snapshot

use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.

the class AssetManagerWithSecurityTest method testGetAsset.

/* ------------------------------------------------------------------------------------------------------------------ */
/**
 * Media package is created under the admin of the default organization.
 */
@Test
@Parameters
public void testGetAsset(final AccessControlList acl, User user, boolean assertAccess) throws Exception {
    // create a snapshot
    final Snapshot snapshot = createSnapshot(acl);
    // get an asset of the snapshot
    runWith(user, assertAccess, new P1Lazy<Unit>() {

        @Override
        public Unit get1() {
            assertTrue(am.getAsset(snapshot.getVersion(), snapshot.getMediaPackage().getIdentifier().toString(), snapshot.getMediaPackage().getElements()[0].getIdentifier()).isSome());
            return Unit.unit;
        }
    });
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Unit(com.entwinemedia.fn.Unit) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 4 with Snapshot

use of org.opencastproject.assetmanager.api.Snapshot 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 5 with Snapshot

use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.

the class ArchiveToAssetManagerMigrationTest method testMigration.

@Test
@Parameters
public void testMigration(String testData, Stream<String> seriesIds) throws Exception {
    // setup database and apply the DDL migration
    penv.tx(runStatements("/mysql-reset.sql"));
    penv.tx(runStatements("/mysql-archive-schema.sql"));
    // insert test data since it makes a difference to migrate a database with or without data
    penv.tx(runStatements(testData));
    // schema migration pre-processing
    penv.tx(runStatements("/mysql-migration-1.sql"));
    // data migration
    penv.tx(runStatements("/mysql-migration-2.sql"));
    // schema migration post-processing and cleanup
    penv.tx(runStatements("/mysql-migration-3.sql"));
    // 
    // compare actual and expected DDL
    final String showCreateTables = $("oc_assets_snapshot", "oc_assets_asset", "oc_assets_properties", "oc_assets_version_claim", "SEQUENCE").map(Strings.wrap("SHOW CREATE TABLE ", "")).bind(findAll).map(take(1)).mkString(";\n\n").concat(";");
    logger.info("+ " + showCreateTables);
    assertEquals("Migrated database should be equal to DDL in Ansible playbook", IoSupport.loadFileFromClassPathAsString("/mysql-assetmanager-schema.sql").get().trim(), showCreateTables);
    // check sequence table migration
    assertTrue("Sequence table should be updated", penv.tx(Queries.sql.findSingle("SELECT * FROM SEQUENCE WHERE SEQ_NAME='seq_oc_assets_asset'")).isSome());
    assertTrue("Sequence table should be updated", penv.tx(Queries.sql.findSingle("SELECT * FROM SEQUENCE WHERE SEQ_NAME='seq_oc_assets_snapshot'")).isSome());
    // 
    // if the migration completed successfully the asset manager should be able to run some operations
    final AQueryBuilder q = am.createQuery();
    {
        // run series checks
        for (String seriesId : seriesIds) {
            final RichAResult r = enrich(q.select(q.snapshot()).where(q.seriesId().eq(seriesId)).run());
            assertTrue(r.getSize() > 0);
            for (Snapshot e : r.getSnapshots()) {
                assertEquals(seriesId, e.getMediaPackage().getSeries());
            }
        }
    }
    // add some media packages
    final String[] mp = createAndAddMediaPackagesSimple(5, 1, 1);
    for (String id : mp) {
        am.setProperty(p.agent.mk(id, "agent"));
    }
    {
        final RichAResult r = enrich(q.select(q.snapshot(), q.properties()).run());
        assertEquals(59, r.getSize());
        assertEquals(59, r.countSnapshots());
        assertEquals(5, r.countProperties());
    }
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

Snapshot (org.opencastproject.assetmanager.api.Snapshot)26 Test (org.junit.Test)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)10 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)9 AResult (org.opencastproject.assetmanager.api.query.AResult)7 URI (java.net.URI)6 Set (java.util.Set)5 ARecord (org.opencastproject.assetmanager.api.query.ARecord)5 ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)5 Parameters (junitparams.Parameters)4 Version (org.opencastproject.assetmanager.api.Version)4 Predicate (org.opencastproject.assetmanager.api.query.Predicate)4 Unit (com.entwinemedia.fn.Unit)3 Target (org.opencastproject.assetmanager.api.query.Target)3 VersionField (org.opencastproject.assetmanager.api.query.VersionField)3 Database (org.opencastproject.assetmanager.impl.persistence.Database)3 Job (org.opencastproject.job.api.Job)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2