Search in sources :

Example 6 with AResult

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

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

the class IndexServiceImpl method getEventMediapackage.

@Override
public MediaPackage getEventMediapackage(Event event) throws IndexServiceException {
    switch(getEventSource(event)) {
        case WORKFLOW:
            Opt<WorkflowInstance> currentWorkflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
            if (currentWorkflowInstance.isNone()) {
                logger.error("No workflow instance for event {} found!", event.getIdentifier());
                throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
            }
            return currentWorkflowInstance.get().getMediaPackage();
        case ARCHIVE:
            final AQueryBuilder q = assetManager.createQuery();
            final AResult r = q.select(q.snapshot()).where(q.mediaPackageId(event.getIdentifier()).and(q.version().isLatest())).run();
            if (r.getSize() > 0) {
                logger.debug("Found event in archive with id {}", event.getIdentifier());
                return enrich(r).getSnapshots().head2().getMediaPackage();
            }
            logger.error("No event with id {} found from archive!", event.getIdentifier());
            throw new IndexServiceException("No archived event found with id " + event.getIdentifier());
        case SCHEDULE:
            try {
                MediaPackage mediaPackage = schedulerService.getMediaPackage(event.getIdentifier());
                logger.debug("Found event in scheduler with id {}", event.getIdentifier());
                return mediaPackage;
            } catch (NotFoundException e) {
                logger.error("No scheduled event with id {} found!", event.getIdentifier());
                throw new IndexServiceException(e.getMessage(), e);
            } catch (UnauthorizedException e) {
                logger.error("Unauthorized to get event with id {} from scheduler because {}", event.getIdentifier(), getStackTrace(e));
                throw new IndexServiceException(e.getMessage(), e);
            } catch (SchedulerException e) {
                logger.error("Unable to get event with id {} from scheduler because {}", event.getIdentifier(), getStackTrace(e));
                throw new IndexServiceException(e.getMessage(), e);
            }
        default:
            throw new IllegalStateException("Unknown event type!");
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 8 with AResult

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

the class AbstractAssetManager method takeSnapshot.

@Override
public Snapshot takeSnapshot(MediaPackage mediaPackage) {
    final String mediaPackageId = mediaPackage.getIdentifier().toString();
    AQueryBuilder queryBuilder = createQuery();
    AResult result = queryBuilder.select(queryBuilder.snapshot()).where(queryBuilder.mediaPackageId(mediaPackageId).and(queryBuilder.version().isLatest())).run();
    Opt<ARecord> record = result.getRecords().head();
    if (record.isSome()) {
        Opt<Snapshot> snapshot = record.get().getSnapshot();
        if (snapshot.isSome()) {
            return takeSnapshot(snapshot.get().getOwner(), mediaPackage);
        }
    }
    return takeSnapshot(DEFAULT_OWNER, mediaPackage);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult)

Example 9 with AResult

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

Example 10 with AResult

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

the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunTranscriptionCompletedState.

@Test
public void testWorkflowDispatcherRunTranscriptionCompletedState() throws Exception {
    database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.updateJobControl(JOB_ID, TranscriptionJobControl.Status.TranscriptionComplete.name());
    // Mocks for query, result, etc
    Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
    ARecord aRec = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
    Stream<ARecord> recStream = Stream.mk(aRec);
    Predicate p = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(p.and(p)).andReturn(p);
    AResult r = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(r.getSize()).andReturn(1L);
    EasyMock.expect(r.getRecords()).andReturn(recStream);
    Target t = EasyMock.createNiceMock(Target.class);
    ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
    EasyMock.expect(selectQuery.run()).andReturn(r);
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    EasyMock.expect(query.snapshot()).andReturn(t);
    EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
    VersionField v = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(v.isLatest()).andReturn(p);
    EasyMock.expect(query.version()).andReturn(v);
    EasyMock.expect(assetManager.createQuery()).andReturn(query);
    EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
    Capture<Set<String>> capturedMpIds = Capture.newInstance();
    WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
    EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
    List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
    wfList.add(new WorkflowInstanceImpl());
    Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
    Workflows wfs = EasyMock.createNiceMock(Workflows.class);
    EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
    service.setWfUtil(wfs);
    EasyMock.replay(wfService, wfs);
    WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
    dispatcher.run();
    // Check if only one mp has a workflow created for it
    Assert.assertEquals(1, capturedMpIds.getValue().size());
    // And if it was the correct one
    Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
    // Check if status in db was updated
    TranscriptionJobControl job = database.findByJob(JOB_ID);
    Assert.assertNotNull(job);
    Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
Also used : TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) Set(java.util.Set) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) Workflows(org.opencastproject.assetmanager.util.Workflows) VersionField(org.opencastproject.assetmanager.api.query.VersionField) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowDispatcher(org.opencastproject.transcription.ibmwatson.IBMWatsonTranscriptionService.WorkflowDispatcher) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) ConfiguredWorkflow(org.opencastproject.workflow.api.ConfiguredWorkflow) Predicate(org.opencastproject.assetmanager.api.query.Predicate) Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) AResult(org.opencastproject.assetmanager.api.query.AResult) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Test(org.junit.Test)

Aggregations

AResult (org.opencastproject.assetmanager.api.query.AResult)46 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)37 ARecord (org.opencastproject.assetmanager.api.query.ARecord)29 NotFoundException (org.opencastproject.util.NotFoundException)27 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)20 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)20 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)20 IOException (java.io.IOException)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)19 ValidationException (net.fortuna.ical4j.model.ValidationException)18 Test (org.junit.Test)18 SeriesException (org.opencastproject.series.api.SeriesException)18 ServiceException (org.osgi.framework.ServiceException)18 ConfigurationException (org.osgi.service.cm.ConfigurationException)18 Date (java.util.Date)16 RichAResult (org.opencastproject.assetmanager.api.query.RichAResult)14 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)11 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)10