Search in sources :

Example 21 with AResult

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

the class SchedulerServiceImpl method getReviewStatus.

@Override
public ReviewStatus getReviewStatus(String mediaPackageId) throws NotFoundException, SchedulerException {
    notEmpty(mediaPackageId, "mediaPackageId");
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(p.reviewStatus().target()).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().apply(getStringOpt(REVIEW_STATUS_CONFIG)).map(toReviewStatus).getOr(UNSENT);
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to get review status 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) 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 22 with AResult

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

the class SchedulerServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) {
    notEmpty(indexName, "indexName");
    final String destinationId = SchedulerItem.SCHEDULER_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            int current = 1;
            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.optOut().target(), p.presenters().target(), p.reviewDate().target(), p.reviewStatus().target(), p.recordingStatus().target(), p.recordingLastHeard().target(), query.propertiesOf(CA_NAMESPACE)).where(withOrganization(query).and(query.hasPropertiesOf(p.namespace())).and(withVersion(query))).run();
            final int total = (int) Math.min(result.getSize(), Integer.MAX_VALUE);
            logger.info("Re-populating '{}' index with scheduled events. There are {} scheduled events to add to the index.", indexName, total);
            final int responseInterval = (total < 100) ? 1 : (total / 100);
            try {
                for (ARecord record : result.getRecords()) {
                    String agentId = record.getProperties().apply(Properties.getString(AGENT_CONFIG));
                    boolean optOut = record.getProperties().apply(Properties.getBoolean(OPTOUT_CONFIG));
                    Date start = record.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
                    Date end = record.getProperties().apply(Properties.getDate(END_DATE_CONFIG));
                    Set<String> presenters = getPresenters(record.getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
                    boolean blacklisted = isBlacklisted(record.getMediaPackageId(), start, end, agentId, presenters);
                    Map<String, String> caMetadata = record.getProperties().filter(filterByNamespace._2(CA_NAMESPACE)).group(toKey, toValue);
                    ReviewStatus reviewStatus = record.getProperties().apply(getStringOpt(REVIEW_STATUS_CONFIG)).map(toReviewStatus).getOr(UNSENT);
                    Date reviewDate = record.getProperties().apply(Properties.getDateOpt(REVIEW_DATE_CONFIG)).orNull();
                    Opt<String> recordingStatus = record.getProperties().apply(Properties.getStringOpt(RECORDING_STATE_CONFIG));
                    Opt<Long> lastHeard = record.getProperties().apply(Properties.getLongOpt(RECORDING_LAST_HEARD_CONFIG));
                    Opt<AccessControlList> acl = loadEpisodeAclFromAsset(record.getSnapshot().get());
                    Opt<DublinCoreCatalog> dublinCore = loadEpisodeDublinCoreFromAsset(record.getSnapshot().get());
                    sendUpdateAddEvent(record.getMediaPackageId(), acl, dublinCore, Opt.some(start), Opt.some(end), Opt.some(presenters), Opt.some(agentId), Opt.some(caMetadata), Opt.some(optOut));
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SchedulerItem.updateBlacklist(record.getMediaPackageId(), blacklisted));
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SchedulerItem.updateReviewStatus(record.getMediaPackageId(), reviewStatus, reviewDate));
                    if (((current % responseInterval) == 0) || (current == total)) {
                        messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Scheduler, total, current));
                    }
                    if (recordingStatus.isSome() && lastHeard.isSome())
                        sendRecordingUpdate(new RecordingImpl(record.getMediaPackageId(), recordingStatus.get(), lastHeard.get()));
                    current++;
                }
            } catch (Exception e) {
                logger.warn("Unable to index scheduled instances:", e);
                throw new ServiceException(e.getMessage());
            }
        }
    });
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Scheduler));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Set(java.util.Set) HashSet(java.util.HashSet) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) 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) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Opt(com.entwinemedia.fn.data.Opt) Properties.getStringOpt(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) SchedulerUtil.toReviewStatus(org.opencastproject.scheduler.impl.SchedulerUtil.toReviewStatus) AResult(org.opencastproject.assetmanager.api.query.AResult) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 23 with AResult

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

the class SchedulerServiceImplTest method testTransactionCommit.

@Test
public void testTransactionCommit() throws Exception {
    Date start = new Date();
    Date end = new Date(System.currentTimeMillis() + 60000);
    String captureDeviceID = "demo";
    String seriesId = "series1";
    Set<String> userIds = new HashSet<>();
    userIds.add("user1");
    userIds.add("user2");
    MediaPackage mp = generateEvent(Opt.<String>none());
    mp.setSeries(seriesId);
    DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
    addDublinCore(Opt.<String>none(), mp, event);
    Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
    try {
        schedSvc.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.<Boolean>none(), Opt.some("new"), "new");
    } catch (SchedulerTransactionLockException e) {
        fail("Transaction create lock not working!");
    }
    SchedulerTransaction trx = schedSvc.createTransaction("new");
    assertEquals("new", trx.getSource());
    AQueryBuilder query = assetManager.createQuery();
    AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    assertEquals(1, result.getSize());
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    assertEquals(2, result.getSize());
    trx.commit();
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact())).and(query.hasPropertiesOf(SchedulerServiceImpl.TRX_NAMESPACE).not())).run();
    assertEquals(1, result.getSize());
    ARecord record = result.getRecords().head2();
    assertEquals(VersionImpl.mk(1), record.getSnapshot().get().getVersion());
    try {
        schedSvc.getTransaction(trx.getId());
        fail("Deleted transaction found!");
    } catch (NotFoundException e) {
        assertNotNull(e);
    }
}
Also used : AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) Date(java.util.Date) ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) AResult(org.opencastproject.assetmanager.api.query.AResult) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) HashSet(java.util.HashSet) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 24 with AResult

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

the class SchedulerServiceImplTest method testTransactionCleanup.

@Test
public void testTransactionCleanup() throws Exception {
    Date start = new Date();
    Date end = new Date(System.currentTimeMillis() + 60000);
    String captureDeviceID = "demo";
    String seriesId = "series1";
    Set<String> userIds = new HashSet<>();
    userIds.add("user1");
    userIds.add("user2");
    MediaPackage mp = generateEvent(Opt.<String>none());
    mp.setSeries(seriesId);
    DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
    addDublinCore(Opt.<String>none(), mp, event);
    Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
    SchedulerTransaction trx = schedSvc.createTransaction("new");
    assertEquals("new", trx.getSource());
    AQueryBuilder query = assetManager.createQuery();
    AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    Opt<ARecord> record = result.getRecords().head();
    assertFalse(record.isSome());
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    record = result.getRecords().head();
    assertTrue(record.isSome());
    schedSvc.transactionOffsetMillis = 0;
    schedSvc.cleanupTransactions();
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    record = result.getRecords().head();
    assertFalse(record.isSome());
    try {
        schedSvc.getTransaction(trx.getId());
        fail("Deleted transaction found!");
    } catch (NotFoundException e) {
        assertNotNull(e);
    }
}
Also used : AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) Date(java.util.Date) ARecord(org.opencastproject.assetmanager.api.query.ARecord) MediaPackage(org.opencastproject.mediapackage.MediaPackage) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) AResult(org.opencastproject.assetmanager.api.query.AResult) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) HashSet(java.util.HashSet) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 25 with AResult

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

the class SchedulerServiceImplTest method testTransactionRollback.

@Test
public void testTransactionRollback() throws Exception {
    Date start = new Date();
    Date end = new Date(System.currentTimeMillis() + 60000);
    String captureDeviceID = "demo";
    String seriesId = "series1";
    Set<String> userIds = new HashSet<>();
    userIds.add("user1");
    userIds.add("user2");
    MediaPackage mp = generateEvent(Opt.<String>none());
    mp.setSeries(seriesId);
    DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
    addDublinCore(Opt.<String>none(), mp, event);
    Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
    try {
        schedSvc.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none(), Opt.some(SchedulerService.ORIGIN), SchedulerService.ORIGIN);
    } catch (SchedulerTransactionLockException e) {
        fail("Unable to add event!");
    }
    SchedulerTransaction trx = schedSvc.createTransaction("new");
    assertEquals("new", trx.getSource());
    AQueryBuilder query = assetManager.createQuery();
    AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    assertEquals(1, result.getSize());
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    assertEquals(2, result.getSize());
    trx.rollback();
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    assertEquals(1, result.getSize());
    try {
        schedSvc.getTransaction(trx.getId());
        fail("Deleted transaction found!");
    } catch (NotFoundException e) {
        assertNotNull(e);
    }
    trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
    assertEquals(2, result.getSize());
    assertEquals(new VersionImpl(2), result.getRecords().tail().head2().getSnapshot().get().getVersion());
    assertEquals(new VersionImpl(0), result.getRecords().head2().getSnapshot().get().getVersion());
    try {
        schedSvc.getMediaPackage(mp.getIdentifier().compact());
    } catch (NotFoundException e) {
        fail("Detection of second last element doesn't work!");
    }
}
Also used : AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) Date(java.util.Date) VersionImpl(org.opencastproject.assetmanager.impl.VersionImpl) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) AResult(org.opencastproject.assetmanager.api.query.AResult) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) HashSet(java.util.HashSet) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Aggregations

AResult (org.opencastproject.assetmanager.api.query.AResult)46 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)37 ARecord (org.opencastproject.assetmanager.api.query.ARecord)29 NotFoundException (org.opencastproject.util.NotFoundException)27 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)20 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)20 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)20 IOException (java.io.IOException)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)19 ValidationException (net.fortuna.ical4j.model.ValidationException)18 Test (org.junit.Test)18 SeriesException (org.opencastproject.series.api.SeriesException)18 ServiceException (org.osgi.framework.ServiceException)18 ConfigurationException (org.osgi.service.cm.ConfigurationException)18 Date (java.util.Date)16 RichAResult (org.opencastproject.assetmanager.api.query.RichAResult)14 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)11 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)10