use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class SchedulerServiceImpl method getWorkflowConfig.
@Override
public Map<String, String> getWorkflowConfig(String mediaPackageId) throws NotFoundException, SchedulerException {
notEmpty(mediaPackageId, "mediaPackageId");
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
AResult result = query.select(query.propertiesOf(WORKFLOW_NAMESPACE)).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId)).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace()))).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isNone())
throw new NotFoundException();
return record.get().getProperties().group(toKey, toValue);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to get workflow configuration of event '{}': {}", mediaPackageId, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class SchedulerServiceImpl method getKnownRecordings.
@Override
public Map<String, Recording> getKnownRecordings() throws SchedulerException {
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
AResult result = query.select(p.recordingStatus().target(), p.recordingLastHeard().target()).where(withOrganization(query).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace())).and(p.recordingStatus().exists()).and(p.recordingLastHeard().exists())).run();
Map<String, Recording> recordings = new HashMap<>();
for (ARecord record : result.getRecords()) {
String recordingState = record.getProperties().apply(Properties.getString(RECORDING_STATE_CONFIG));
Long lastHeard = record.getProperties().apply(Properties.getLong(RECORDING_LAST_HEARD_CONFIG));
recordings.put(record.getMediaPackageId(), new RecordingImpl(record.getMediaPackageId(), recordingState, lastHeard));
}
return recordings;
} catch (Exception e) {
logger.error("Failed to get known recording states: {}", getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class SchedulerServiceImplTest method removeScheduledRecordingsBeforeBufferInputOneEvent.
@Test
public void removeScheduledRecordingsBeforeBufferInputOneEvent() throws Exception {
Date start = new Date(System.currentTimeMillis() - 160000);
Date end = new Date(System.currentTimeMillis() - 60000);
String captureDeviceID = "demo";
MediaPackage mp = generateEvent(Opt.<String>none());
DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
addDublinCore(Opt.<String>none(), mp, event);
Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
// Store event
schedSvc.addEvent(start, end, captureDeviceID, Collections.<String>emptySet(), mp, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
schedSvc.removeScheduledRecordingsBeforeBuffer(0);
try {
schedSvc.getMediaPackage(mp.getIdentifier().compact());
Assert.fail();
} catch (NotFoundException e) {
Assert.assertNotNull(e);
}
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact())).and(query.version().isLatest())).run();
Opt<ARecord> record = result.getRecords().head();
assertFalse(record.isSome());
}
Aggregations