Search in sources :

Example 16 with AQueryBuilder

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

the class SchedulerServiceImpl method removeEvent.

@Override
public synchronized void removeEvent(String mediaPackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
    notEmpty(mediaPackageId, "mediaPackageId");
    try {
        // Check if there are properties only from scheduler
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(p.agent().target(), p.source().target()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId)).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace()))).run();
        Opt<ARecord> recordOpt = result.getRecords().head();
        long deletedProperties = 0;
        if (recordOpt.isSome()) {
            // Check for locked transactions
            Opt<String> source = recordOpt.get().getProperties().apply(Properties.getStringOpt(SOURCE_CONFIG));
            if (source.isSome() && persistence.hasTransaction(source.get())) {
                logger.warn("Unable to remove event '{}', source '{}' is currently locked due to an active transaction!", mediaPackageId, source.get());
                throw new SchedulerTransactionLockException("Unable to remove event, locked source " + source.get());
            }
            String agentId = recordOpt.get().getProperties().apply(Properties.getString(AGENT_CONFIG));
            // Delete all properties
            deletedProperties = query.delete(SNAPSHOT_OWNER, query.propertiesOf(p.namespace(), WORKFLOW_NAMESPACE, CA_NAMESPACE)).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId))).name("delete all properties").run();
            if (StringUtils.isNotEmpty(agentId))
                touchLastEntry(agentId);
        }
        // Delete scheduler snapshot
        long deletedSnapshots = query.delete(SNAPSHOT_OWNER, query.snapshot()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId))).name("delete episode").run();
        if (deletedProperties + deletedSnapshots == 0)
            throw new NotFoundException();
        messageSender.sendObjectMessage(SchedulerItem.SCHEDULER_QUEUE, MessageSender.DestinationType.Queue, SchedulerItem.delete(mediaPackageId));
    } catch (NotFoundException | SchedulerException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not remove event '{}' from persistent storage: {}", mediaPackageId, e);
        throw new SchedulerException(e);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) 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) ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) AResult(org.opencastproject.assetmanager.api.query.AResult)

Example 17 with AQueryBuilder

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

the class SchedulerServiceImpl method getCaptureAgentConfiguration.

@Override
public Map<String, String> getCaptureAgentConfiguration(String mediaPackageId) throws NotFoundException, SchedulerException {
    notEmpty(mediaPackageId, "mediaPackageId");
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(query.propertiesOf(CA_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 capture agent contiguration 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 18 with AQueryBuilder

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

the class SchedulerServiceImpl method getAccessControlList.

@Override
public AccessControlList getAccessControlList(String mediaPackageId) throws NotFoundException, SchedulerException {
    notEmpty(mediaPackageId, "mediaPackageId");
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(query.snapshot()).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<AccessControlList> acl = loadEpisodeAclFromAsset(record.get().getSnapshot().get());
        if (acl.isNone())
            return null;
        return acl.get();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to get access control list of event '{}': {}", mediaPackageId, getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) 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 19 with AQueryBuilder

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

the class SchedulerServiceImpl method hasActiveTransaction.

@Override
public boolean hasActiveTransaction(String mediaPackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
    notEmpty(mediaPackageId, "mediaPackageId");
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        TrxProps trxP = new TrxProps(query);
        AResult result = query.select(p.source().target(), trxP.source().target()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId)).and(query.version().isLatest())).run();
        Opt<ARecord> record = result.getRecords().head();
        if (record.isNone())
            throw new NotFoundException();
        // Check for active transactions
        Opt<String> source = record.get().getProperties().apply(Properties.getStringOpt(SOURCE_CONFIG));
        if (source.isSome() && persistence.hasTransaction(source.get()))
            return true;
        return false;
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to check for active transaction of event with mediapackage '{}': {}", 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) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) 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 20 with AQueryBuilder

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

the class SchedulerServiceImpl method getEventMediaPackage.

private Opt<MediaPackage> getEventMediaPackage(String mediaPackageId) {
    AQueryBuilder query = assetManager.createQuery();
    Props p = new Props(query);
    AResult result = query.select(query.snapshot()).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())
        return Opt.none();
    return record.bind(recordToMp);
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult)

Aggregations

AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)48 AResult (org.opencastproject.assetmanager.api.query.AResult)37 ARecord (org.opencastproject.assetmanager.api.query.ARecord)31 NotFoundException (org.opencastproject.util.NotFoundException)31 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)24 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)23 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)23 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)23 IOException (java.io.IOException)22 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)22 ValidationException (net.fortuna.ical4j.model.ValidationException)21 SeriesException (org.opencastproject.series.api.SeriesException)21 ServiceException (org.osgi.framework.ServiceException)21 ConfigurationException (org.osgi.service.cm.ConfigurationException)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)18 Date (java.util.Date)17 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)14 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)14 Test (org.junit.Test)12 Predicate (org.opencastproject.assetmanager.api.query.Predicate)10