Search in sources :

Example 1 with ASelectQuery

use of org.opencastproject.assetmanager.api.query.ASelectQuery 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 ASelectQuery

use of org.opencastproject.assetmanager.api.query.ASelectQuery 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 ASelectQuery

use of org.opencastproject.assetmanager.api.query.ASelectQuery in project opencast by opencast.

the class DuplicateEventWorkflowOperationHandlerTest method mockDependencies.

private void mockDependencies(int numberOfCopies) throws Exception {
    clonedMediaPackages = Capture.newInstance(CaptureType.ALL);
    reset(workspace, assetManager, distributionService);
    URI uriDc = getClass().getResource("/dublincore.xml").toURI();
    for (int i = 0; i < numberOfCopies; i++) {
        expect(workspace.read(eq(URI.create("dublincore.xml")))).andReturn(new FileInputStream(new File(uriDc))).times(1);
    }
    expect(workspace.get(anyObject())).andReturn(new File(getClass().getResource("/av.mov").toURI())).anyTimes();
    expect(workspace.put(anyString(), anyString(), eq("dublincore.xml"), anyObject())).andReturn(uriDc).times(numberOfCopies);
    replay(workspace);
    final AResult qResult = createNiceMock(AResult.class);
    expect(qResult.getRecords()).andReturn(Stream.empty()).anyTimes();
    replay(qResult);
    final ASelectQuery qSelect = createNiceMock(ASelectQuery.class);
    expect(qSelect.where(anyObject())).andReturn(qSelect).anyTimes();
    expect(qSelect.run()).andReturn(qResult).anyTimes();
    replay(qSelect);
    final AQueryBuilder qBuilder = createNiceMock(AQueryBuilder.class);
    expect(qBuilder.select(anyObject())).andReturn(qSelect).anyTimes();
    replay(qBuilder);
    expect(assetManager.createQuery()).andReturn(qBuilder).anyTimes();
    expect(assetManager.takeSnapshot(eq(AssetManager.DEFAULT_OWNER), capture(clonedMediaPackages))).andReturn(createNiceMock(Snapshot.class)).times(numberOfCopies);
    replay(assetManager);
    final Job distributionJob = createNiceMock(Job.class);
    final Publication internalPub = (Publication) mp.getElementById("pub-int");
    final List<MediaPackageElement> internalPubElements = new ArrayList<>();
    Collections.addAll(internalPubElements, (internalPub.getAttachments()));
    Collections.addAll(internalPubElements, (internalPub.getCatalogs()));
    Collections.addAll(internalPubElements, (internalPub.getTracks()));
    expect(distributionJob.getStatus()).andReturn(Job.Status.FINISHED).anyTimes();
    for (MediaPackageElement e : internalPubElements) {
        expect(distributionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(e)).times(numberOfCopies);
    }
    replay(distributionJob);
    expect(distributionService.distribute(eq(InternalPublicationChannel.CHANNEL_ID), anyObject(), anyString())).andReturn(distributionJob).anyTimes();
    replay(distributionService);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList) AResult(org.opencastproject.assetmanager.api.query.AResult) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) Publication(org.opencastproject.mediapackage.Publication) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Job(org.opencastproject.job.api.Job) URI(java.net.URI) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with ASelectQuery

use of org.opencastproject.assetmanager.api.query.ASelectQuery in project opencast by opencast.

the class ASelectQueryDecoratorTest method testDecoration.

/**
 * Test that returned queries are also decorated.
 */
@Test
public void testDecoration() throws Exception {
    final ASelectQuery delegate = q.select();
    final ASelectQuery s = new ASelectQueryDecorator(delegate);
    assertThat(s.where(q.always()), instanceOf(ASelectQueryDecorator.class));
    assertThat(s.orderBy(q.organizationId().asc()), instanceOf(ASelectQueryDecorator.class));
    assertThat(s.page(0, 1), instanceOf(ASelectQueryDecorator.class));
    assertNotEquals(delegate.getClass(), s.getClass());
}
Also used : ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Test(org.junit.Test)

Example 5 with ASelectQuery

use of org.opencastproject.assetmanager.api.query.ASelectQuery in project opencast by opencast.

the class LiveScheduleServiceImplTest method setUpAssetManager.

private void setUpAssetManager(MediaPackage mp) {
    version = EasyMock.createNiceMock(Version.class);
    snapshot = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(snapshot.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId()).anyTimes();
    EasyMock.expect(snapshot.getVersion()).andReturn(version);
    ARecord aRec = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot)).anyTimes();
    Stream<ARecord> recStream = Stream.mk(aRec);
    Predicate p = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(p.and(p)).andReturn(p).anyTimes();
    AResult r = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(r.getSize()).andReturn(1L).anyTimes();
    EasyMock.expect(r.getRecords()).andReturn(recStream).anyTimes();
    Target t = EasyMock.createNiceMock(Target.class);
    ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery).anyTimes();
    EasyMock.expect(selectQuery.run()).andReturn(r).anyTimes();
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    EasyMock.expect(query.snapshot()).andReturn(t).anyTimes();
    EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p).anyTimes();
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery).anyTimes();
    VersionField v = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(v.isLatest()).andReturn(p).anyTimes();
    EasyMock.expect(query.version()).andReturn(v).anyTimes();
    EasyMock.expect(assetManager.createQuery()).andReturn(query).anyTimes();
    EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) Version(org.opencastproject.assetmanager.api.Version) 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)

Aggregations

ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)11 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)9 ARecord (org.opencastproject.assetmanager.api.query.ARecord)7 AResult (org.opencastproject.assetmanager.api.query.AResult)7 Predicate (org.opencastproject.assetmanager.api.query.Predicate)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Snapshot (org.opencastproject.assetmanager.api.Snapshot)4 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)4 IOException (java.io.IOException)3 Date (java.util.Date)3 ValidationException (net.fortuna.ical4j.model.ValidationException)3 VersionField (org.opencastproject.assetmanager.api.query.VersionField)3 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)3 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)3 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)3 AccessControlList (org.opencastproject.security.api.AccessControlList)3 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)3 SeriesException (org.opencastproject.series.api.SeriesException)3 Fn (com.entwinemedia.fn.Fn)2