Search in sources :

Example 6 with RichAResult

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

the class AbstractAssetManagerDeletePropertyTest method testDeleteByValue.

@Test
public void testDeleteByValue() throws Exception {
    final String[] mp = createAndAddMediaPackagesSimple(3, 1, 1);
    am.setProperty(p.agent.mk(mp[0], "agent-1"));
    am.setProperty(p.legacyId.mk(mp[0], "id"));
    am.setProperty(p.agent.mk(mp[1], "agent-2"));
    am.setProperty(p.agent.mk(mp[2], "agent-2"));
    assertTotals(3, 3, 4);
    assertEquals(0, q.delete(OWNER, p.agent.target()).where(p.agent.eq("unknown-agent")).run());
    assertTotals(3, 3, 4);
    assertEquals(2, q.delete(OWNER, p.agent.target()).where(p.agent.eq("agent-2")).run());
    assertEquals(1, q.delete(OWNER, p.legacyId.target()).where(p.agent.eq("agent-1")).run());
    assertTotals(3, 3, 1);
    final RichAResult r = enrich(q.select(q.properties()).where(q.mediaPackageId(mp[0])).run());
    assertEquals("Media package " + mp[0] + " should still have the agent property", p.agent.name(), r.getProperties().head2().getId().getFqn());
    assertEquals("The media package itself should be found", 1, r.getSize());
}
Also used : RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Test(org.junit.Test)

Example 7 with RichAResult

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

Example 8 with RichAResult

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

the class AbstractAssetManagerSelectTest method testSelect1.

@Test
public void testSelect1() throws Exception {
    logger.info("Testing a select that caused an issue.");
    final MediaPackage mp = mkMediaPackage(mkCatalog());
    am.takeSnapshot(OWNER, mp);
    final String mpId = mp.getIdentifier().toString();
    RichAResult r = enrich(q.select(p.count.target(), p.approved.target()).where(q.organizationId(DefaultOrganization.DEFAULT_ORGANIZATION_ID).and(q.mediaPackageId(mpId).and(q.version().isLatest()))).run());
    assertEquals(1, r.getSize());
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Test(org.junit.Test)

Example 9 with RichAResult

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

the class AbstractAssetManagerSelectTest method testSelectWithMultiplePredicates_CERV_696.

@Test
public void testSelectWithMultiplePredicates_CERV_696() {
    final String[] mp = createAndAddMediaPackagesSimple(2, 1, 1);
    am.setProperty(p.agent.mk(mp[0], "agent-id"));
    final Predicate p1 = q.organizationId(DefaultOrganization.DEFAULT_ORGANIZATION_ID).and(q.version().isLatest());
    {
        final RichAResult r = enrich(q.select(q.snapshot()).where(p1).run());
        assertEquals("Two records should be found", 2, r.getSize());
        assertEquals("Two snapshots should be contained", 2, r.countSnapshots());
        assertEquals("No properties should be found since they haven't been selected", 0, r.countProperties());
    }
    // But when adding an additional predicate on a property (e.g. agent):
    final Predicate p2 = p1.and(p.agent.eq("agent-id"));
    {
        final RichAResult r = enrich(q.select(q.snapshot()).where(p2).run());
        assertEquals("Only one record should be found now", 1, r.getSize());
        assertEquals("One snapshots should be found", 1, r.countSnapshots());
        assertEquals("No properties should be found since they haven't been selected", 0, r.countProperties());
    }
}
Also used : RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Predicate(org.opencastproject.assetmanager.api.query.Predicate) Test(org.junit.Test)

Example 10 with RichAResult

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

the class AbstractAssetManagerSelectTest method testSelectMultiplePropertyNamespaces_CERV_695.

@Test
public void testSelectMultiplePropertyNamespaces_CERV_695() throws Exception {
    final String[] mp = createAndAddMediaPackagesSimple(5, 1, 1);
    // 
    logger.info("Add properties to only one of the media packages");
    am.setProperty(p.approved.mk(mp[0], true));
    am.setProperty(p.count.mk(mp[0], 10L));
    am.setProperty(p.start.mk(mp[0], new Date()));
    // 
    am.setProperty(Property.mk(PropertyId.mk(mp[0], "org.opencastproject.scheduler", "start"), Value.mk(new Date())));
    am.setProperty(Property.mk(PropertyId.mk(mp[0], "org.opencastproject.scheduler", "end"), Value.mk(new Date())));
    am.setProperty(Property.mk(PropertyId.mk(mp[0], "org.opencastproject.scheduler", "enabled"), Value.mk(true)));
    // 
    am.setProperty(Property.mk(PropertyId.mk(mp[0], "org.opencastproject.annotation", "annotation"), Value.mk("some text")));
    // 
    am.setProperty(Property.mk(PropertyId.mk(mp[0], "org.opencastproject.distribution", "channel"), Value.mk("engage")));
    {
        final RichAResult r = enrich(q.select(q.snapshot(), p.count.target(), p.approved.target(), q.propertiesOf("org.opencastproject.annotation", "org.opencastproject.scheduler"), p.legacyId.target()).run());
        assertEquals("Five records should be found since there is no filtering", 5, r.getSize());
        assertEquals("There should be 6 properties total", 6, r.countProperties());
        assertEquals("There should be 2 properties in the 'service' namespace, 'count' and 'approved'", 2, sizeOf(r.getProperties().filter(Properties.byNamespace(p.namespace()))));
        assertEquals("There should be 3 properties in the 'scheduler' namespace", 3, sizeOf(r.getProperties().filter(Properties.byNamespace("org.opencastproject.scheduler"))));
        assertEquals("There should be 1 property in the 'annotation' namespace", 1, sizeOf(r.getProperties().filter(Properties.byNamespace("org.opencastproject.annotation"))));
        assertEquals("There should be 5 snapshots", 5, r.countSnapshots());
        assertEquals("Only one record should have properties", 1, sizeOf(r.getRecords().filter(ARecords.hasProperties)));
        assertEquals("The record with properties should have media package ID " + mp[0], mp[0], r.getRecords().filter(ARecords.hasProperties).map(ARecords.getMediaPackageId).head().get());
    }
    {
        final RichAResult r = enrich(q.select(q.snapshot(), p.count.target(), p.approved.target(), q.propertiesOf("org.opencastproject.annotation", "org.opencastproject.scheduler"), p.legacyId.target()).where(q.organizationId(DefaultOrganization.DEFAULT_ORGANIZATION_ID).and(q.mediaPackageId(mp[0])).and(q.version().isLatest())).run());
        assertEquals("Only one record should be found since a media package predicate is given", 1, r.getSize());
    }
}
Also used : RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 RichAResult (org.opencastproject.assetmanager.api.query.RichAResult)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)5 Date (java.util.Date)3 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)2 FnX (com.entwinemedia.fn.FnX)1 P2 (com.entwinemedia.fn.P2)1 Parameters (junitparams.Parameters)1 Ignore (org.junit.Ignore)1 Snapshot (org.opencastproject.assetmanager.api.Snapshot)1 Predicate (org.opencastproject.assetmanager.api.query.Predicate)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1 NotFoundException (org.opencastproject.util.NotFoundException)1