use of org.opencastproject.assetmanager.api.query.AResult in project opencast by opencast.
the class SchedulerServiceImpl method isBlacklisted.
@Override
public boolean isBlacklisted(String mediaPackageId) throws NotFoundException, SchedulerException {
notEmpty(mediaPackageId, "mediaPackageId");
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
AResult result = query.select(query.snapshot(), p.agent().target(), p.start().target(), p.end().target(), p.presenters().target()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId).and(withVersion(query)).and(query.hasPropertiesOf(p.namespace())))).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isNone())
throw new NotFoundException();
Opt<MediaPackage> mp = record.bind(recordToMp);
if (mp.isNone())
throw new NotFoundException();
String agentId = record.get().getProperties().apply(Properties.getString(AGENT_CONFIG));
Date start = record.get().getProperties().apply(Properties.getDate(START_DATE_CONFIG));
Date end = record.get().getProperties().apply(Properties.getDate(END_DATE_CONFIG));
Set<String> presenters = getPresenters(record.get().getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
return isBlacklisted(mediaPackageId, start, end, agentId, presenters);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to get blacklist status of event with mediapackage '{}': {}", mediaPackageId, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.assetmanager.api.query.AResult in project opencast by opencast.
the class SchedulerServiceImpl method addEventInternal.
private void addEventInternal(Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Map<String, String> wfProperties, Map<String, String> caMetadata, String modificationOrigin, Opt<Boolean> optOutStatus, Opt<String> schedulingSource, Opt<String> trxId) throws SchedulerException {
notNull(startDateTime, "startDateTime");
notNull(endDateTime, "endDateTime");
notEmpty(captureAgentId, "captureAgentId");
notNull(userIds, "userIds");
notNull(mediaPackage, "mediaPackage");
notNull(wfProperties, "wfProperties");
notNull(caMetadata, "caMetadata");
notEmpty(modificationOrigin, "modificationOrigin");
notNull(optOutStatus, "optOutStatus");
notNull(schedulingSource, "schedulingSource");
notNull(trxId, "trxId");
if (endDateTime.before(startDateTime))
throw new IllegalArgumentException("The end date is before the start date");
final String mediaPackageId = mediaPackage.getIdentifier().compact();
try {
AQueryBuilder query = assetManager.createQuery();
// TODO this query runs twice if called from SchedulerTransactionImpl#addEvent
AResult result = query.select(query.nothing()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId).and(query.version().isLatest()))).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isSome()) {
logger.warn("Mediapackage with id '{}' already exists!", mediaPackageId);
throw new SchedulerConflictException("Mediapackage with id '" + mediaPackageId + "' already exists!");
}
Opt<String> seriesId = Opt.nul(StringUtils.trimToNull(mediaPackage.getSeries()));
// Get opt out status
boolean optOut = getOptOutStatus(seriesId, optOutStatus);
if (trxId.isNone()) {
// Check for locked transactions
if (schedulingSource.isSome() && persistence.hasTransaction(schedulingSource.get())) {
logger.warn("Unable to add event '{}', source '{}' is currently locked due to an active transaction!", mediaPackageId, schedulingSource.get());
throw new SchedulerTransactionLockException("Unable to add event, locked source " + schedulingSource.get());
}
// Check for conflicting events if not opted out
if (!optOut) {
List<MediaPackage> conflictingEvents = findConflictingEvents(captureAgentId, startDateTime, endDateTime);
if (conflictingEvents.size() > 0) {
logger.info("Unable to add event {}, conflicting events found: {}", mediaPackageId, conflictingEvents);
throw new SchedulerConflictException("Unable to add event, conflicting events found for event " + mediaPackageId);
}
}
}
// Load dublincore and acl for update
Opt<DublinCoreCatalog> dublinCore = DublinCoreUtil.loadEpisodeDublinCore(workspace, mediaPackage);
Option<AccessControlList> acl = authorizationService.getAcl(mediaPackage, AclScope.Episode);
// Get updated agent properties
Map<String, String> finalCaProperties = getFinalAgentProperties(caMetadata, wfProperties, captureAgentId, seriesId, dublinCore);
// Persist asset
String checksum = calculateChecksum(workspace, getEventCatalogUIAdapterFlavors(), startDateTime, endDateTime, captureAgentId, userIds, mediaPackage, dublinCore, wfProperties, finalCaProperties, optOut, acl.toOpt().getOr(new AccessControlList()));
persistEvent(mediaPackageId, modificationOrigin, checksum, Opt.some(startDateTime), Opt.some(endDateTime), Opt.some(captureAgentId), Opt.some(userIds), Opt.some(mediaPackage), Opt.some(wfProperties), Opt.some(finalCaProperties), Opt.some(optOut), schedulingSource, trxId);
if (trxId.isNone()) {
// Send updates
sendUpdateAddEvent(mediaPackageId, acl.toOpt(), dublinCore, Opt.some(startDateTime), Opt.some(endDateTime), Opt.some(userIds), Opt.some(captureAgentId), Opt.some(finalCaProperties), Opt.some(optOut));
// Update last modified
touchLastEntry(captureAgentId);
}
} catch (SchedulerException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to create event with id '{}': {}", mediaPackageId, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.assetmanager.api.query.AResult in project opencast by opencast.
the class SchedulerServiceImpl method getRecordingState.
@Override
public Recording getRecordingState(String id) throws NotFoundException, SchedulerException {
notEmpty(id, "id");
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.mediaPackageId(id)).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace())).and(p.recordingStatus().exists()).and(p.recordingLastHeard().exists())).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isNone() || record.get().getProperties().isEmpty())
throw new NotFoundException();
String recordingState = record.get().getProperties().apply(Properties.getString(RECORDING_STATE_CONFIG));
Long lastHeard = record.get().getProperties().apply(Properties.getLong(RECORDING_LAST_HEARD_CONFIG));
return new RecordingImpl(id, recordingState, lastHeard);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to get recording status of event with mediapackage '{}': {}", id, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.assetmanager.api.query.AResult 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.AResult 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);
}
}
Aggregations