Search in sources :

Example 46 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SchedulerServiceImplTest method testEventManagement.

@Test
public void testEventManagement() throws Exception {
    MediaPackage mediaPackage = generateEvent(Opt.<String>none());
    DublinCoreCatalog event = generateEvent("testdevice", new Date(System.currentTimeMillis() - 2000), new Date(System.currentTimeMillis() + 60000));
    event.set(PROPERTY_TITLE, "Demotitle");
    event.add(PROPERTY_CREATOR, "creator2");
    String catalogId = addDublinCore(Opt.<String>none(), mediaPackage, event);
    Map<String, String> caProperties = generateCaptureAgentMetadata("testdevice");
    schedSvc.addEvent(new Date(System.currentTimeMillis() - 2000), new Date(System.currentTimeMillis() + 60000), "testdevice", Collections.<String>emptySet(), mediaPackage, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
    // test iCalender export
    CalendarBuilder calBuilder = new CalendarBuilder();
    Calendar cal;
    try {
        String icalString = schedSvc.getCalendar(Opt.<String>none(), Opt.<String>none(), Opt.<Date>none());
        cal = calBuilder.build(IOUtils.toInputStream(icalString, "UTF-8"));
        ComponentList vevents = cal.getComponents(VEVENT);
        for (int i = 0; i < vevents.size(); i++) {
            PropertyList attachments = ((VEvent) vevents.get(i)).getProperties(Property.ATTACH);
            for (int j = 0; j < attachments.size(); j++) {
                String attached = ((Property) attachments.get(j)).getValue();
                String filename = ((Property) attachments.get(j)).getParameter("X-APPLE-FILENAME").getValue();
                attached = new String(Base64.decodeBase64(attached));
                if ("org.opencastproject.capture.agent.properties".equals(filename)) {
                    Assert.assertTrue(attached.contains("capture.device.id=testdevice"));
                }
                if ("episode.xml".equals(filename)) {
                    Assert.assertTrue(attached.contains("Demotitle"));
                }
            }
        }
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    } catch (ParserException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
    // test for upcoming events (it should not be in there).
    List<MediaPackage> upcoming = schedSvc.search(Opt.<String>none(), Opt.some(new Date(System.currentTimeMillis())), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    Assert.assertTrue(upcoming.isEmpty());
    List<MediaPackage> all = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(1, all.size());
    all = schedSvc.search(Opt.some("somedevice"), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    Assert.assertTrue(all.isEmpty());
    // update event
    event.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(new Date(System.currentTimeMillis() + 180000), new Date(System.currentTimeMillis() + 600000)), Precision.Second));
    addDublinCore(Opt.some(catalogId), mediaPackage, event);
    schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.some(new Date(System.currentTimeMillis() + 180000)), Opt.some(new Date(System.currentTimeMillis() + 600000)), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.some(wfPropertiesUpdated), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
    // test for upcoming events (now it should be there)
    upcoming = schedSvc.search(Opt.<String>none(), Opt.some(new Date(System.currentTimeMillis())), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(1, upcoming.size());
    // delete event
    schedSvc.removeEvent(mediaPackage.getIdentifier().compact());
    try {
        schedSvc.getMediaPackage(mediaPackage.getIdentifier().compact());
        Assert.fail();
    } catch (NotFoundException e) {
        Assert.assertNotNull(e);
    }
    upcoming = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(0, upcoming.size());
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) ParserException(net.fortuna.ical4j.data.ParserException) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) NotFoundException(org.opencastproject.util.NotFoundException) ComponentList(net.fortuna.ical4j.model.ComponentList) IOException(java.io.IOException) Date(java.util.Date) PropertyList(net.fortuna.ical4j.model.PropertyList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Property(net.fortuna.ical4j.model.Property) Test(org.junit.Test)

Example 47 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SchedulerServiceImplTest method testUpdateExpiredEvent.

/**
 * Test for failure updating past events
 */
@Test(expected = SchedulerException.class)
public void testUpdateExpiredEvent() throws Exception {
    long currentTime = System.currentTimeMillis();
    final String initialTitle = "Recording 1";
    final MediaPackage mediaPackage = generateEvent(Opt.<String>none());
    final Date startDateTime = new Date(currentTime - 20 * 1000);
    final Date endTime = new Date(currentTime - 10 * 1000);
    final DublinCoreCatalog initalEvent = generateEvent("Device A", Opt.<String>none(), Opt.some(initialTitle), startDateTime, endTime);
    String catalogId = addDublinCore(Opt.<String>none(), mediaPackage, initalEvent);
    Map<String, String> caMetadata = map(tuple("org.opencastproject.workflow.config.archiveOp", "true"), tuple("org.opencastproject.workflow.definition", "full"));
    schedSvc.addEvent(startDateTime, endTime, "Device A", Collections.<String>emptySet(), mediaPackage, wfProperties, caMetadata, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
    MediaPackage mp = schedSvc.getMediaPackage(mediaPackage.getIdentifier().compact());
    Assert.assertEquals(mediaPackage, mp);
    // test single update
    final String updatedTitle1 = "Recording 2";
    final DublinCoreCatalog updatedEvent1 = generateEvent("Device A", Opt.some(mediaPackage.getIdentifier().compact()), Opt.some(updatedTitle1), startDateTime, endTime);
    addDublinCore(Opt.some(catalogId), mediaPackage, updatedEvent1);
    schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.some(wfPropertiesUpdated), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
    Assert.fail("Schedule should not update a recording that has ended (single)");
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Date(java.util.Date) Test(org.junit.Test)

Example 48 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SchedulerServiceImplTest method testCreateAndUpdateConflictingEvents.

@Test
public void testCreateAndUpdateConflictingEvents() throws Exception {
    Date start = new Date();
    Date end = new Date(System.currentTimeMillis() + 60000);
    final long currentTime = System.currentTimeMillis();
    final MediaPackage mediaPackageA = generateEvent(Opt.<String>none());
    final MediaPackage mediaPackageB = generateEvent(Opt.<String>none());
    DublinCoreCatalog event = generateEvent("captureId", start, end);
    addDublinCore(Opt.<String>none(), mediaPackageB, event);
    // 
    schedSvc.addEvent(new Date(currentTime), new Date(currentTime + hours(1) + seconds(10)), "Device A", Collections.<String>emptySet(), mediaPackageA, wfProperties, Collections.<String, String>emptyMap(), Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
    schedSvc.addEvent(new Date(currentTime + hours(2)), new Date(currentTime + hours(25)), "Device A", Collections.<String>emptySet(), mediaPackageB, wfProperties, Collections.<String, String>emptyMap(), Opt.some(true), Opt.<String>none(), SchedulerService.ORIGIN);
    {
        List<MediaPackage> allEvents = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
        assertEquals(2, allEvents.size());
    }
    // Update opted out event to a conflicting time
    schedSvc.updateEvent(mediaPackageB.getIdentifier().compact(), Opt.some(new Date(currentTime)), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
    // Update opted out status
    try {
        schedSvc.updateEvent(mediaPackageB.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.some(Opt.some(false)), SchedulerService.ORIGIN);
        fail("Conflict not detected!");
    } catch (SchedulerConflictException e) {
        Assert.assertNotNull(e);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) PropertyList(net.fortuna.ical4j.model.PropertyList) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List) ComponentList(net.fortuna.ical4j.model.ComponentList) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Date(java.util.Date) Test(org.junit.Test)

Example 49 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog 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)

Example 50 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SchedulerServiceImplTest method testEventStatus.

@Test
public void testEventStatus() throws Exception {
    final long currentTime = System.currentTimeMillis();
    final String initialTitle = "Recording 1";
    MediaPackage mediaPackage = generateEvent(Opt.<String>none());
    final DublinCoreCatalog initalEvent = generateEvent("Device A", Opt.<String>none(), Opt.some(initialTitle), new Date(currentTime + 10 * 1000), new Date(currentTime + 3610000));
    addDublinCore(Opt.<String>none(), mediaPackage, initalEvent);
    Map<String, String> caProperties = map(tuple("org.opencastproject.workflow.config.archiveOp", "true"), tuple("org.opencastproject.workflow.definition", "full"));
    schedSvc.addEvent(new Date(currentTime + 10 * 1000), new Date(currentTime + 3610000), "Device A", Collections.<String>emptySet(), mediaPackage, wfProperties, caProperties, Opt.some(false), Opt.<String>none(), SchedulerService.ORIGIN);
    final Map<String, String> initalCaProps = schedSvc.getCaptureAgentConfiguration(mediaPackage.getIdentifier().compact());
    checkEvent(mediaPackage.getIdentifier().compact(), initalCaProps, initialTitle);
    Assert.assertFalse(schedSvc.isOptOut(mediaPackage.getIdentifier().compact()));
    Assert.assertFalse(schedSvc.isBlacklisted(mediaPackage.getIdentifier().compact()));
    // do opt out update
    schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.some(Opt.some(true)), SchedulerService.ORIGIN);
    Assert.assertTrue(schedSvc.isOptOut(mediaPackage.getIdentifier().compact()));
// TODO blacklist
// // do blacklist update
// schedSvc.updateBlacklist(null);
// Assert.assertTrue(schedSvc.isBlacklisted(mediaPackage.getIdentifier().compact()));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)117 MediaPackage (org.opencastproject.mediapackage.MediaPackage)51 NotFoundException (org.opencastproject.util.NotFoundException)46 Test (org.junit.Test)44 Date (java.util.Date)40 IOException (java.io.IOException)30 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)29 URI (java.net.URI)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 SeriesException (org.opencastproject.series.api.SeriesException)20 ArrayList (java.util.ArrayList)18 Catalog (org.opencastproject.mediapackage.Catalog)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)18 EName (org.opencastproject.mediapackage.EName)17 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)15 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)15 InputStream (java.io.InputStream)14 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)14