Search in sources :

Example 11 with Predicate

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

the class SchedulerServiceImpl method preCollisionEventCheck.

private List<String> preCollisionEventCheck(String trxId, String schedulingSource) throws SchedulerException {
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        TrxProps trxP = new TrxProps(query);
        Predicate isSourceWithTrx = trxP.source().eq(schedulingSource).and(trxP.transactionId().eq(trxId));
        Predicate hasProperties = p.agent().exists().and(p.start().exists()).and(p.end().exists());
        Predicate isNotSource = p.source().eq(schedulingSource).not().and(hasProperties);
        Predicate isNotOptedOut = p.optOut().eq(false).or(trxP.optOut().eq(false));
        ASelectQuery select = query.select(trxP.optOut().target(), p.optOut().target(), p.agent().target(), p.start().target(), p.end().target(), trxP.agent().target(), trxP.start().target(), trxP.end().target(), trxP.transactionId().target()).where(withOrganization(query).and(isSourceWithTrx.or(isNotSource)).and(query.version().isLatest()).and(isNotOptedOut));
        AResult result = select.run();
        // Check for conflicts
        List<String> conflictingRecords = new ArrayList<>();
        Map<String, List<Interval>> invervalMap = new HashMap<>();
        for (ARecord record : result.getRecords()) {
            String agentId;
            Date start;
            Date end;
            Opt<String> optTrxId = record.getProperties().apply(Properties.getStringOpt(TRANSACTION_ID_CONFIG));
            if (optTrxId.isSome() && trxId.equals(optTrxId.get())) {
                agentId = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getString(AGENT_CONFIG));
                start = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getDate(START_DATE_CONFIG));
                end = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getDate(END_DATE_CONFIG));
            } else {
                agentId = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getString(AGENT_CONFIG));
                start = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getDate(START_DATE_CONFIG));
                end = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getDate(END_DATE_CONFIG));
            }
            Interval currentInterval = new Interval(start.getTime(), end.getTime());
            List<Interval> intervals = invervalMap.get(agentId);
            if (intervals == null)
                intervals = new ArrayList<>();
            boolean overlaps = false;
            for (Interval i : intervals) {
                if (!i.overlaps(currentInterval))
                    continue;
                overlaps = true;
                break;
            }
            if (!overlaps) {
                intervals.add(currentInterval);
            } else {
                conflictingRecords.add(record.getMediaPackageId());
            }
            invervalMap.put(agentId, intervals);
        }
        return conflictingRecords;
    } catch (Exception e) {
        logger.error("Failed to search for conflicting events: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Predicate(org.opencastproject.assetmanager.api.query.Predicate) ARecord(org.opencastproject.assetmanager.api.query.ARecord) AResult(org.opencastproject.assetmanager.api.query.AResult) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List) LinkedList(java.util.LinkedList) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Interval(org.joda.time.Interval)

Example 12 with Predicate

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

the class SchedulerServiceImpl method removeRecording.

@Override
public void removeRecording(String id) throws NotFoundException, SchedulerException {
    notEmpty(id, "id");
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(query.nothing()).where(withOrganization(query).and(query.mediaPackageId(id).and(query.version().isLatest())).and(query.hasPropertiesOf(p.namespace()))).run();
        Opt<ARecord> record = result.getRecords().head();
        if (record.isNone())
            throw new NotFoundException();
        query = assetManager.createQuery();
        p = new Props(query);
        final Predicate predicate = withOrganization(query).and(query.mediaPackageId(id));
        query.delete(SNAPSHOT_OWNER, p.recordingStatus().target()).where(predicate).run();
        query.delete(SNAPSHOT_OWNER, p.recordingLastHeard().target()).where(predicate).run();
        messageSender.sendObjectMessage(SchedulerItem.SCHEDULER_QUEUE, MessageSender.DestinationType.Queue, SchedulerItem.deleteRecordingState(id));
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to delete recording status of event with mediapackage '{}': {}", id, getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Predicate(org.opencastproject.assetmanager.api.query.Predicate)

Aggregations

Predicate (org.opencastproject.assetmanager.api.query.Predicate)12 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)10 AResult (org.opencastproject.assetmanager.api.query.AResult)8 ARecord (org.opencastproject.assetmanager.api.query.ARecord)7 ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)5 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)5 NotFoundException (org.opencastproject.util.NotFoundException)5 IOException (java.io.IOException)4 ValidationException (net.fortuna.ical4j.model.ValidationException)4 Snapshot (org.opencastproject.assetmanager.api.Snapshot)4 VersionField (org.opencastproject.assetmanager.api.query.VersionField)4 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)4 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)4 SeriesException (org.opencastproject.series.api.SeriesException)4 ServiceException (org.osgi.framework.ServiceException)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3