use of org.opencastproject.assetmanager.api.query.AQueryBuilder 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!");
}
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder 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);
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder 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);
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder 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());
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class SchedulerServiceImpl method persistEvent.
private synchronized void persistEvent(final String mpId, final String modificationOrigin, final String checksum, final Opt<Date> startDateTime, final Opt<Date> endDateTime, final Opt<String> captureAgentId, final Opt<Set<String>> userIds, final Opt<MediaPackage> mediaPackage, final Opt<Map<String, String>> wfProperties, final Opt<Map<String, String>> caProperties, final Opt<Boolean> optOut, final Opt<String> schedulingSource, final Opt<String> trxId) {
AQueryBuilder query = assetManager.createQuery();
final Props p;
final String workflowNamespace;
final String caNamespace;
if (trxId.isNone()) {
p = new Props(query);
workflowNamespace = WORKFLOW_NAMESPACE;
caNamespace = CA_NAMESPACE;
} else {
p = new TrxProps(query);
workflowNamespace = TRX_WORKFLOW_NAMESPACE;
caNamespace = TRX_CA_NAMESPACE;
}
// Store scheduled mediapackage
for (MediaPackage mpToUpdate : mediaPackage) {
Snapshot snapshot = assetManager.takeSnapshot(SNAPSHOT_OWNER, mpToUpdate);
assetManager.setProperty(p.version().mk(mpId, snapshot.getVersion()));
}
// Store scheduled start date
for (Date start : startDateTime) {
assetManager.setProperty(p.start().mk(mpId, start));
}
// Store scheduled end date
for (Date end : endDateTime) {
assetManager.setProperty(p.end().mk(mpId, end));
}
// Store capture agent id
for (String agent : captureAgentId) {
assetManager.setProperty(p.agent().mk(mpId, agent));
}
// Store the user identifiers
for (Set<String> users : userIds) {
assetManager.setProperty(p.presenters().mk(mpId, StringUtils.join(users, ",")));
}
// Store opt out status
for (Boolean optOutToUpdate : optOut) {
assetManager.setProperty(p.optOut().mk(mpId, optOutToUpdate));
}
// Store capture agent properties
for (Map<String, String> props : caProperties) {
Properties.removeProperties(assetManager, SNAPSHOT_OWNER, securityService.getOrganization().getId(), mpId, caNamespace);
for (Entry<String, String> entry : props.entrySet()) {
assetManager.setProperty(Property.mk(PropertyId.mk(mpId, caNamespace, entry.getKey()), Value.mk(entry.getValue())));
}
}
// Store workflow properties
for (Map<String, String> props : wfProperties) {
Properties.removeProperties(assetManager, SNAPSHOT_OWNER, securityService.getOrganization().getId(), mpId, workflowNamespace);
for (Entry<String, String> entry : props.entrySet()) {
assetManager.setProperty(Property.mk(PropertyId.mk(mpId, workflowNamespace, entry.getKey()), Value.mk(entry.getValue())));
}
}
// Store scheduling source
for (String source : schedulingSource) {
assetManager.setProperty(p.source().mk(mpId, source));
}
// Store last modified source/date and checksum
assetManager.setProperty(p.lastModifiedOrigin().mk(mpId, modificationOrigin));
assetManager.setProperty(p.lastModifiedDate().mk(mpId, new Date()));
assetManager.setProperty(p.checksum().mk(mpId, checksum));
// Remove last conflicts
if (trxId.isNone()) {
final AQueryBuilder q = assetManager.createQuery();
q.delete(SNAPSHOT_OWNER, new Props(q).lastConflict().target()).where(withOrganization(q).and(q.mediaPackageId(mpId))).run();
}
}
Aggregations