Search in sources :

Example 31 with ARecord

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

Example 32 with ARecord

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

the class SchedulerServiceImpl method findConflictingEvents.

private List<MediaPackage> findConflictingEvents(List<Period> periods, String captureAgentId, TimeZone tz) throws SchedulerException {
    notEmpty(captureAgentId, "captureAgentId");
    notNull(periods, "periods");
    requireTrue(periods.size() > 0, "periods");
    try {
        final ARecord[] alreadyScheduledEvents = getScheduledEvents(Opt.some(captureAgentId));
        final TimeZone utc = TimeZone.getTimeZone("utc");
        Set<MediaPackage> events = new HashSet<>();
        for (Period event : periods) {
            TimeZone.setDefault(utc);
            final Date startDate = event.getStart();
            final Date endDate = event.getEnd();
            events.addAll(findConflictingEvents(startDate, endDate, alreadyScheduledEvents));
        }
        TimeZone.setDefault(null);
        return new ArrayList<>(events);
    } catch (Exception e) {
        logger.error("Failed to search for conflicting events: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) DateTimeZone(org.joda.time.DateTimeZone) TimeZone(java.util.TimeZone) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ArrayList(java.util.ArrayList) Period(net.fortuna.ical4j.model.Period) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) 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) HashSet(java.util.HashSet)

Example 33 with ARecord

use of org.opencastproject.assetmanager.api.query.ARecord 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);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Recording(org.opencastproject.scheduler.api.Recording) 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)

Example 34 with ARecord

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

the class SchedulerServiceImpl method searchInternal.

/*
   * Returns a list of events which start and/or end within a given date range.  So you could search for things which
   * start on Tuesday between 0900 and 1000, and end between 1500 and 1600, and you could get an event which started at
   * Epoch and ended at 1559 on Tuesday.  This is *NOT* appropriate for conflict checking, and does not check for any
   * edge cases.  Use checkScheduleConflicts instead.
   */
private List<MediaPackage> searchInternal(Opt<Date> startsFrom, Opt<Date> startsTo, Opt<Date> endFrom, Opt<Date> endTo, ARecord[] records) {
    final List<ARecord> result = new ArrayList<>();
    for (final ARecord r : records) {
        final Date start = r.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
        final Date end = r.getProperties().apply(Properties.getDate(END_DATE_CONFIG));
        if (startsFrom.isSome() && start.before(startsFrom.get()) || startsTo.isSome() && start.after(startsTo.get()) || endFrom.isSome() && end.before(endFrom.get()) || endTo.isSome() && end.after(endTo.get())) {
            continue;
        }
        result.add(r);
    }
    result.sort(new Comparator<ARecord>() {

        @Override
        public int compare(ARecord o1, ARecord o2) {
            Date start1 = o1.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
            Date start2 = o2.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
            return start1.compareTo(start2);
        }
    });
    return Stream.mk(result).bind(recordToMp).toList();
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 35 with ARecord

use of org.opencastproject.assetmanager.api.query.ARecord 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());
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) AResult(org.opencastproject.assetmanager.api.query.AResult) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Date(java.util.Date) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Aggregations

ARecord (org.opencastproject.assetmanager.api.query.ARecord)35 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)31 AResult (org.opencastproject.assetmanager.api.query.AResult)29 NotFoundException (org.opencastproject.util.NotFoundException)24 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)22 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)22 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)21 IOException (java.io.IOException)20 ValidationException (net.fortuna.ical4j.model.ValidationException)20 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)20 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)20 SeriesException (org.opencastproject.series.api.SeriesException)20 ServiceException (org.osgi.framework.ServiceException)20 ConfigurationException (org.osgi.service.cm.ConfigurationException)20 Date (java.util.Date)14 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)10 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)9 Test (org.junit.Test)8 ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)7