Search in sources :

Example 51 with DublinCoreCatalog

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

the class SchedulerServiceImplTest method testTransactionCommitConflict.

@Test
public void testTransactionCommitConflict() 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 extendedEvent = generateExtendedEvent(Opt.<String>none(), "extended");
    addDublinCore(Opt.<String>none(), mp, extendedEvent);
    DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
    addDublinCore(Opt.<String>none(), mp, event);
    addAcl(Opt.<String>none(), mp, acl);
    Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
    SchedulerTransaction trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.<Boolean>none());
    try {
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    Opt<ARecord> record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(0), record.get().getSnapshot().get().getVersion());
    schedSvc.updateEvent(mp.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);
    // Update with same checksum
    trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
    try {
        // works because of same checksum
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
    assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
    // Update with different checksum
    schedSvc.updateEvent(mp.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);
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("checksum")).isSome());
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
    trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
    try {
        // creates conflict
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
    // Commit again with no changes
    trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
    try {
        // ignores conflict
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
    // Commit again with changes
    trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, "newdevice", userIds, mp, wfProperties, caProperties, Opt.some(true));
    try {
        // override from existing
        // creates new conflict
        testConflictHandler.setStrategy(Strategy.OLD);
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals("demo", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("agent")));
    assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
    // Commit again with new changes
    trx = schedSvc.createTransaction("new");
    trx.addEvent(start, end, "newdevice", userIds, mp, wfProperties, caProperties, Opt.some(false));
    try {
        // override from transaction
        testConflictHandler.setStrategy(Strategy.NEW);
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(5), record.get().getSnapshot().get().getVersion());
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
    assertEquals("newdevice", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("agent")));
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
    // Commit again with new changes
    trx = schedSvc.createTransaction("new2");
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
    try {
        // merge opt out only and keep agent id
        testConflictHandler.setStrategy(Strategy.MERGED);
        trx.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    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());
    record = result.getRecords().head();
    assertTrue(record.isSome());
    assertEquals(new VersionImpl(7), record.get().getSnapshot().get().getVersion());
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
    assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
    assertEquals(captureDeviceID, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("agent")));
    assertEquals("new2", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
    assertEquals("new2", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
}
Also used : SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) Date(java.util.Date) VersionImpl(org.opencastproject.assetmanager.impl.VersionImpl) 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 52 with DublinCoreCatalog

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

the class SchedulerServiceImplTest method testTransactionCommitCleanup.

@Test
public void testTransactionCommitCleanup() 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");
    MediaPackage mp2 = generateEvent(Opt.<String>none());
    SchedulerTransaction trx = schedSvc.createTransaction("new");
    assertEquals("new", trx.getSource());
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
    AQueryBuilder query = assetManager.createQuery();
    AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.version().isLatest())).run();
    assertEquals(1, result.getSize());
    trx.commit();
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.version().isLatest())).run();
    assertEquals(1, result.getSize());
    trx = schedSvc.createTransaction("new");
    assertEquals("new", trx.getSource());
    trx.addEvent(start, end, captureDeviceID, userIds, mp2, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.version().isLatest())).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.version().isLatest())).run();
    assertEquals(1, result.getSize());
    try {
        schedSvc.getTransaction(trx.getId());
        fail("Deleted transaction found!");
    } catch (NotFoundException e) {
        assertNotNull(e);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) Date(java.util.Date) HashSet(java.util.HashSet) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 53 with DublinCoreCatalog

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

the class SchedulerServiceImplTest method testTransactionCommitCollision.

@Test
public void testTransactionCommitCollision() 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");
    MediaPackage mp2 = generateEvent(Opt.<String>none());
    try {
        schedSvc.addEvent(start, end, captureDeviceID, userIds, mp2, wfPropertiesUpdated, caProperties, Opt.some(false), Opt.some("existing"), SchedulerService.ORIGIN);
    } catch (SchedulerTransactionLockException e) {
        fail("Transaction create lock not working!");
    }
    /* Test transaction collision of already existing event and new transaction 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();
    Opt<ARecord> record = result.getRecords().head();
    assertFalse(record.isSome());
    trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.some(false));
    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());
    try {
        trx.commit();
        fail("Pre-conflict detection not working!");
    } catch (SchedulerConflictException e) {
        assertNotNull(e);
    }
    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());
    try {
        schedSvc.getTransaction(trx.getId());
    } catch (NotFoundException e) {
        fail("Transaction found!");
    }
    /* Test transaction collision of already existing event and new opted out transaction event */
    MediaPackage mp4 = (MediaPackage) mp.clone();
    mp4.setIdentifier(new IdImpl("newuuid"));
    SchedulerTransaction trx2 = schedSvc.createTransaction("optedout");
    assertEquals("optedout", trx2.getSource());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp4.getIdentifier().compact()))).run();
    record = result.getRecords().head();
    assertFalse(record.isSome());
    trx2.addEvent(start, end, captureDeviceID, userIds, mp4, wfPropertiesUpdated, caProperties, Opt.some(true));
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp4.getIdentifier().compact()))).run();
    record = result.getRecords().head();
    assertTrue(record.isSome());
    try {
        trx2.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
    /* Test transaction collision of two transaction events */
    schedSvc.removeEvent(mp2.getIdentifier().compact());
    MediaPackage mp3 = generateEvent(Opt.<String>none());
    trx.addEvent(start, end, captureDeviceID, userIds, mp3, wfPropertiesUpdated, caProperties, Opt.some(false));
    try {
        trx.commit();
        fail("Pre-conflict detection not working!");
    } catch (SchedulerConflictException e) {
        assertNotNull(e);
    }
    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());
    try {
        schedSvc.getTransaction(trx.getId());
    } catch (NotFoundException e) {
        fail("Transaction found!");
    }
    /* Test transaction collision of two transaction events but one opted out */
    MediaPackage mp5 = (MediaPackage) mp.clone();
    mp5.setIdentifier(new IdImpl("newuuid2"));
    SchedulerTransaction trx3 = schedSvc.createTransaction("optedout2");
    assertEquals("optedout2", trx3.getSource());
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp5.getIdentifier().compact()))).run();
    record = result.getRecords().head();
    assertFalse(record.isSome());
    trx3.addEvent(start, end, captureDeviceID, userIds, mp5, wfPropertiesUpdated, caProperties, Opt.some(false));
    query = assetManager.createQuery();
    result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp5.getIdentifier().compact()))).run();
    record = result.getRecords().head();
    assertTrue(record.isSome());
    MediaPackage mp6 = generateEvent(Opt.<String>none());
    trx.addEvent(start, end, captureDeviceID, userIds, mp6, wfPropertiesUpdated, caProperties, Opt.some(true));
    try {
        trx3.commit();
    } catch (SchedulerConflictException e) {
        fail("Pre-conflict detection not working!");
    }
}
Also used : SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) 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 54 with DublinCoreCatalog

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

the class SchedulerServiceImplTest method generateExtendedEvent.

protected static DublinCoreCatalog generateExtendedEvent(Opt<String> eventId, String flavorType) {
    DublinCoreCatalog dc = DublinCores.mkStandard();
    final Map<String, String> prefixToUri = new HashMap<>();
    prefixToUri.put("", "http://test.com/video/opencast");
    prefixToUri.put("extended", "http://test.com/video/metadata");
    dc.addBindings(new XmlNamespaceContext(prefixToUri));
    dc.setRootTag(new EName("http://test.com/video/opencast", "extended"));
    dc.setFlavor(new MediaPackageElementFlavor(flavorType, "episode"));
    dc.set(PROPERTY_IDENTIFIER, eventId.getOr("1"));
    dc.set(PROPERTY_EXTENT, "demo");
    return dc;
}
Also used : XmlNamespaceContext(org.opencastproject.util.XmlNamespaceContext) EName(org.opencastproject.mediapackage.EName) HashMap(java.util.HashMap) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 55 with DublinCoreCatalog

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

the class SchedulerServiceImplTest method testRemoveEventSimple.

@Test
public void testRemoveEventSimple() throws Exception {
    final Date start = new Date(System.currentTimeMillis() - 160000);
    final Date end = new Date(System.currentTimeMillis() - 60000);
    final String captureDeviceID = "demo";
    final MediaPackage mp = generateEvent(Opt.<String>none());
    final String mpId = mp.getIdentifier().toString();
    final DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
    addDublinCore(Opt.<String>none(), mp, event);
    final Map<String, String> caProperties = generateCaptureAgentMetadata(captureDeviceID);
    final AQueryBuilder q = assetManager.createQuery();
    // make sure that the asset manager is empty
    assertEquals("The asset manager should not contain any episodes", 0, q.select(q.snapshot()).run().getSize());
    // store event
    schedSvc.addEvent(start, end, captureDeviceID, Collections.<String>emptySet(), mp, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
    {
        final RichAResult r = enrich(q.select(q.snapshot(), q.properties()).run());
        assertEquals("The asset manager should contain one episode", 1, r.getSize());
        assertEquals("Episode ID", mpId, r.getRecords().head2().getMediaPackageId());
        assertFalse("The episode should have some properties", r.getProperties().isEmpty());
    }
    // remove event
    schedSvc.removeEvent(mpId);
    try {
        schedSvc.getMediaPackage(mpId);
        Assert.fail("No media package should be found since it has been deleted before");
    } catch (NotFoundException ignore) {
    }
    {
        final RichAResult r = enrich(q.select(q.snapshot(), q.properties()).run());
        assertTrue("The asset manager should not contain any properties anymore", r.getProperties().isEmpty());
        assertTrue("The asset manager should not contain any episodes anymore", r.getSnapshots().isEmpty());
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) 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