use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class LiveScheduleServiceImpl method createLiveEvent.
boolean createLiveEvent(String mpId, DublinCoreCatalog episodeDC) throws LiveScheduleException {
try {
logger.info("Creating live media package {}", mpId);
// Get latest mp from the asset manager
Snapshot snapshot = getSnapshot(mpId);
// Temporary mp
MediaPackage tempMp = (MediaPackage) snapshot.getMediaPackage().clone();
// Set duration (used by live tracks)
setDuration(tempMp, episodeDC);
// Add live tracks to media package
addLiveTracks(tempMp, episodeDC.getFirst(DublinCore.PROPERTY_SPATIAL));
// Add and distribute catalogs/acl, this creates a new mp object
MediaPackage mp = addAndDistributeElements(snapshot);
// Add tracks from tempMp
for (Track t : tempMp.getTracks()) mp.add(t);
// Publish mp to engage search index
publish(mp);
// Add engage-live publication channel to archived mp
Organization currentOrg = null;
try {
currentOrg = organizationService.getOrganization(snapshot.getOrganizationId());
} catch (NotFoundException e) {
logger.warn("Organization in snapshot not found: {}", snapshot.getOrganizationId());
}
MediaPackage archivedMp = snapshot.getMediaPackage();
addLivePublicationChannel(currentOrg, archivedMp);
// Take a snapshot with the publication added and put its version in our local cache
// so that we ignore notifications for this snapshot version.
snapshotVersionCache.put(mpId, assetManager.takeSnapshot(archivedMp).getVersion());
return true;
} catch (Exception e) {
throw new LiveScheduleException(e);
}
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunTranscriptionCompletedState.
@Test
public void testWorkflowDispatcherRunTranscriptionCompletedState() throws Exception {
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
database.updateJobControl(JOB_ID, TranscriptionJobControl.Status.TranscriptionComplete.name());
// Mocks for query, result, etc
Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
ARecord aRec = EasyMock.createNiceMock(ARecord.class);
EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
Stream<ARecord> recStream = Stream.mk(aRec);
Predicate p = EasyMock.createNiceMock(Predicate.class);
EasyMock.expect(p.and(p)).andReturn(p);
AResult r = EasyMock.createNiceMock(AResult.class);
EasyMock.expect(r.getSize()).andReturn(1L);
EasyMock.expect(r.getRecords()).andReturn(recStream);
Target t = EasyMock.createNiceMock(Target.class);
ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
EasyMock.expect(selectQuery.run()).andReturn(r);
AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
EasyMock.expect(query.snapshot()).andReturn(t);
EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
VersionField v = EasyMock.createNiceMock(VersionField.class);
EasyMock.expect(v.isLatest()).andReturn(p);
EasyMock.expect(query.version()).andReturn(v);
EasyMock.expect(assetManager.createQuery()).andReturn(query);
EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
Capture<Set<String>> capturedMpIds = Capture.newInstance();
WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
wfList.add(new WorkflowInstanceImpl());
Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
Workflows wfs = EasyMock.createNiceMock(Workflows.class);
EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
service.setWfUtil(wfs);
EasyMock.replay(wfService, wfs);
WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
dispatcher.run();
// Check if only one mp has a workflow created for it
Assert.assertEquals(1, capturedMpIds.getValue().size());
// And if it was the correct one
Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
// Check if status in db was updated
TranscriptionJobControl job = database.findByJob(JOB_ID);
Assert.assertNotNull(job);
Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class SchedulerServiceImpl method persistEvent.
private synchronized void persistEvent(final String mpId, final String modificationOrigin, final String checksum, final Opt<Date> startDateTime, final Opt<Date> endDateTime, final Opt<String> captureAgentId, final Opt<Set<String>> userIds, final Opt<MediaPackage> mediaPackage, final Opt<Map<String, String>> wfProperties, final Opt<Map<String, String>> caProperties, final Opt<Boolean> optOut, final Opt<String> schedulingSource, final Opt<String> trxId) {
AQueryBuilder query = assetManager.createQuery();
final Props p;
final String workflowNamespace;
final String caNamespace;
if (trxId.isNone()) {
p = new Props(query);
workflowNamespace = WORKFLOW_NAMESPACE;
caNamespace = CA_NAMESPACE;
} else {
p = new TrxProps(query);
workflowNamespace = TRX_WORKFLOW_NAMESPACE;
caNamespace = TRX_CA_NAMESPACE;
}
// Store scheduled mediapackage
for (MediaPackage mpToUpdate : mediaPackage) {
Snapshot snapshot = assetManager.takeSnapshot(SNAPSHOT_OWNER, mpToUpdate);
assetManager.setProperty(p.version().mk(mpId, snapshot.getVersion()));
}
// Store scheduled start date
for (Date start : startDateTime) {
assetManager.setProperty(p.start().mk(mpId, start));
}
// Store scheduled end date
for (Date end : endDateTime) {
assetManager.setProperty(p.end().mk(mpId, end));
}
// Store capture agent id
for (String agent : captureAgentId) {
assetManager.setProperty(p.agent().mk(mpId, agent));
}
// Store the user identifiers
for (Set<String> users : userIds) {
assetManager.setProperty(p.presenters().mk(mpId, StringUtils.join(users, ",")));
}
// Store opt out status
for (Boolean optOutToUpdate : optOut) {
assetManager.setProperty(p.optOut().mk(mpId, optOutToUpdate));
}
// Store capture agent properties
for (Map<String, String> props : caProperties) {
Properties.removeProperties(assetManager, SNAPSHOT_OWNER, securityService.getOrganization().getId(), mpId, caNamespace);
for (Entry<String, String> entry : props.entrySet()) {
assetManager.setProperty(Property.mk(PropertyId.mk(mpId, caNamespace, entry.getKey()), Value.mk(entry.getValue())));
}
}
// Store workflow properties
for (Map<String, String> props : wfProperties) {
Properties.removeProperties(assetManager, SNAPSHOT_OWNER, securityService.getOrganization().getId(), mpId, workflowNamespace);
for (Entry<String, String> entry : props.entrySet()) {
assetManager.setProperty(Property.mk(PropertyId.mk(mpId, workflowNamespace, entry.getKey()), Value.mk(entry.getValue())));
}
}
// Store scheduling source
for (String source : schedulingSource) {
assetManager.setProperty(p.source().mk(mpId, source));
}
// Store last modified source/date and checksum
assetManager.setProperty(p.lastModifiedOrigin().mk(mpId, modificationOrigin));
assetManager.setProperty(p.lastModifiedDate().mk(mpId, new Date()));
assetManager.setProperty(p.checksum().mk(mpId, checksum));
// Remove last conflicts
if (trxId.isNone()) {
final AQueryBuilder q = assetManager.createQuery();
q.delete(SNAPSHOT_OWNER, new Props(q).lastConflict().target()).where(withOrganization(q).and(q.mediaPackageId(mpId))).run();
}
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class SchedulerServiceImplTest method mkAssetManager.
AssetManager mkAssetManager() throws Exception {
final PersistenceEnv penv = PersistenceEnvs.mk(mkEntityManagerFactory("org.opencastproject.assetmanager.impl"));
final Database db = new Database(penv);
return new AbstractAssetManager() {
@Override
public HttpAssetProvider getHttpAssetProvider() {
// identity provider
return new HttpAssetProvider() {
@Override
public Snapshot prepareForDelivery(Snapshot snapshot) {
return snapshot;
}
};
}
@Override
public Database getDb() {
return db;
}
@Override
protected Workspace getWorkspace() {
return workspace;
}
@Override
public AssetStore getAssetStore() {
return mkAssetStore();
}
@Override
protected String getCurrentOrgId() {
return DefaultOrganization.DEFAULT_ORGANIZATION_ID;
}
};
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class LiveScheduleServiceImpl method retractLiveEvent.
boolean retractLiveEvent(MediaPackage mp) throws LiveScheduleException {
if (!isLive(mp)) {
logger.debug("Media package {} is not live. Not retracting.", mp.getIdentifier().compact());
return false;
}
retract(mp);
// Get latest mp from the asset manager if there to remove the publication
try {
String mpId = mp.getIdentifier().toString();
Snapshot snapshot = getSnapshot(mpId);
MediaPackage archivedMp = snapshot.getMediaPackage();
removeLivePublicationChannel(archivedMp);
logger.debug("Removed live pub channel from archived media package {}", mp);
// Take a snapshot with the publication removed and put its version in our local cache
// so that we ignore notifications for this snapshot version.
snapshotVersionCache.put(mpId, assetManager.takeSnapshot(archivedMp).getVersion());
} catch (LiveScheduleException e) {
// It was not found in asset manager. This is ok.
}
return true;
}
Aggregations