use of org.opencastproject.assetmanager.api.query.AQueryBuilder 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());
}
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class DuplicateEventWorkflowOperationHandler method copyProperties.
private void copyProperties(String namespace, MediaPackage source, MediaPackage destination) {
final AQueryBuilder q = assetManager.createQuery();
final AResult properties = q.select(q.propertiesOf(namespace)).where(q.mediaPackageId(source.getIdentifier().toString())).run();
if (properties.getRecords().head().isNone()) {
logger.info("No properties to copy for media package {}.", source.getIdentifier(), namespace);
return;
}
for (final Property p : properties.getRecords().head().get().getProperties()) {
final PropertyId newPropId = PropertyId.mk(destination.getIdentifier().toString(), namespace, p.getId().getName());
assetManager.setProperty(Property.mk(newPropId, p.getValue()));
}
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class LiveScheduleServiceImpl method getSnapshot.
Snapshot getSnapshot(String mpId) throws LiveScheduleException {
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot()).where(query.mediaPackageId(mpId).and(query.version().isLatest())).run();
if (result.getSize() == 0) {
// Media package not archived?.
throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
}
Opt<ARecord> record = result.getRecords().head();
if (record.isNone()) {
// No snapshot?
throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
}
return record.get().getSnapshot().get();
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class AssetManagerDeleteWorkflowOperationHandler method start.
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
final MediaPackage mediaPackage = workflowInstance.getMediaPackage();
final String mpId = mediaPackage.getIdentifier().toString();
try {
final AQueryBuilder q = assetManager.createQuery();
final long deleted = q.delete(DEFAULT_OWNER, q.snapshot()).where(q.mediaPackageId(mpId)).run();
if (deleted == 0) {
logger.info(format("The asset manager does not contain episode %s", mpId));
} else {
logger.info(format("Successfully deleted %d version/s episode %s from the asset manager", deleted, mpId));
}
} catch (Exception e) {
logger.warn(format("Error deleting episode %s from the asset manager: %s", mpId, e));
throw new WorkflowOperationException("Unable to delete episode from the asset manager", e);
}
return createResult(mediaPackage, Action.CONTINUE);
}
use of org.opencastproject.assetmanager.api.query.AQueryBuilder in project opencast by opencast.
the class AssetManagerTest method testAssetManagerApiCompilation.
/**
* Does not run. Only to test compilation.
*/
@Test(expected = java.lang.NullPointerException.class)
public void testAssetManagerApiCompilation() {
AssetManager am = null;
AQueryBuilder q = am.createQuery();
//
// Selection
//
// Select all versions of media package "mp-id".
// Fetch media packages and associated metadata like version, creation date etc.
// Do not fetch any properties since the query does not contain a property target.
q.select(q.snapshot()).where(q.mediaPackageId("mp-id")).run();
// Select the latest version of "mp-id".
// Fetch the media package and associated metadata like version, creation date etc.
// Do not fetch any properties since the query does not contain a property target.
q.select(q.snapshot()).where(q.mediaPackageId("mp-id").and(q.version().isLatest())).run();
// Select the latest version of "mp-id".
// Fetch the media package and associated metadata like version, creation date etc.
// Also fetch _all_ properties of the media package.
q.select(q.snapshot(), q.properties()).where(q.mediaPackageId("some-mp-id").and(q.version().isLatest())).run();
// Select the latest version of "mp-id" only if it has properties of namespace "org.opencastproject.service" attached.
// Fetch only the media package and associated metadata like version, creation date etc.
q.select(q.snapshot()).where(q.mediaPackageId("mp-id").and(q.version().isLatest()).and(q.hasPropertiesOf("org.opencastproject.service"))).run();
// Select all versions of media package "mp-id" that are archived before now. Do not fetch associated properties.
// <- assume some real date here
final Date date = null;
q.select(q.snapshot()).where(q.mediaPackageId("mp-id").and(q.archived().lt(date))).run();
// does not compile because of a type error
// AssetResult r = q.select(q.mediaPackage("some-mp-id").and(q.archived().lt(q.val(Value.mk("bla"))))).fetchProperties(false).run();
// Select all versions of all media packages of series "series".
// Also fetch all of their properties.
q.select(q.snapshot()).where(q.seriesId().eq("series")).run();
// Select the latest version of each media package of series "series".
// Also fetch all of their properties.
q.select(q.snapshot()).where(q.seriesId().eq("series").and(q.version().isLatest())).run();
// Select all media packages and all of their versions that have boolean property "org.opencastproject.myservice:approved" set to true.
// Fetch media packages and associated metadata like version, creation date etc.
// Fetch all properties of namespace "org.opencastproject.myservice"
q.select(q.snapshot(), q.propertiesOf("org.opencastproject.myservice")).where(q.property(Value.BOOLEAN, "org.opencastproject.myservice", "approved").eq(true)).run();
// The above works but it's better to define and use a property schema!
final Props p = new Props(q);
// Select all versions of media packages that have boolean property "org.opencastproject.myservice:approved" set to true.
q.select(q.snapshot()).where(p.approved().eq(true)).run();
// Select all versions of media packages and properties of namespace "org.opencastproject.myservice" having a "count" property of less than 10.
q.select(q.snapshot(), q.propertiesOf(p.namespace())).where(p.count().lt(10L)).run();
// <- assume some version here
final Version v = null;
// Select all versions of all media packages having a younger version than "v".
// Order the result set after their archival date.
q.select(q.snapshot()).where(q.version().lt(v)).orderBy(q.archived().asc()).run();
// Select properties of namespace "org.opencastproject.myservice" of media package "mp-id".
q.select(p.allProperties()).where(q.mediaPackageId("mp-id")).run();
// Select property "org.opencastproject.myservice:count" of media package "mp-id".
q.select(p.count().target()).where(q.mediaPackageId("mp-id")).run();
// Select all media packages and their start property which start in the future.
q.select(q.snapshot(), p.start().target()).where(p.start().gt(new Date())).run();
//
// Deletion
//
// Delete all properties of all media packages.
q.delete("owner", q.properties()).run();
// Delete all properties of namespace "org.opencastproject.myservice" of all media packages.
q.delete("owner", q.propertiesOf("org.opencastproject.myservice")).run();
// Delete all properties of namespace "org.opencastproject.myservice" from media package "mp-id".
q.delete("owner", q.propertiesOf("org.opencastproject.myservice")).where(q.mediaPackageId("mp-id")).run();
// Delete property "org.opencastproject.myservice:prop" from media package "mp-id".
q.delete("owner", q.properties(PropertyName.mk("org.opencastproject.myservice", "prop"))).where(q.mediaPackageId("mp-id")).run();
// Delete properties "org.opencastproject.myservice:prop" and "org.opencastproject.myservice:prop2" from media package "mp-id".
q.delete("owner", q.properties(PropertyName.mk("org.opencastproject.myservice", "prop"), PropertyName.mk("org.opencastproject.myservice", "prop2"))).where(q.mediaPackageId("mp-id")).run();
// Delete all "org.opencastproject.myservice:approved" properties from all media package having a "org.opencastproject.myservice:count" greater 10.
q.delete("owner", p.approved().target()).where(p.count().gt(10L));
//
// Properties
//
// Set property "org.opencastproject.myservice:count" of media package "mp-id" to 10.
am.setProperty(Property.mk(PropertyId.mk("mp-id", "org.opencastproject.myservice", "count"), Value.mk(10L)));
// Set property "org.opencastproject.myservice:count" of media package "mp-id" to 10 using the schema definition.
am.setProperty(p.count().mk("mp-id", 10L));
}
Aggregations