use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class IBMWatsonTranscriptionService method getGeneratedTranscription.
@Override
public MediaPackageElement getGeneratedTranscription(String mpId, String jobId) throws TranscriptionServiceException {
try {
// If jobId is unknown, look for all jobs associated to that mpId
if (jobId == null || "null".equals(jobId)) {
jobId = null;
for (TranscriptionJobControl jc : database.findByMediaPackage(mpId)) {
if (TranscriptionJobControl.Status.Closed.name().equals(jc.getStatus()) || TranscriptionJobControl.Status.TranscriptionComplete.name().equals(jc.getStatus()))
jobId = jc.getTranscriptionJobId();
}
}
if (jobId == null)
throw new TranscriptionServiceException("No completed or closed transcription job found in database for media package " + mpId);
// Results already saved?
URI uri = workspace.getCollectionURI(TRANSCRIPT_COLLECTION, buildResultsFileName(jobId));
try {
workspace.get(uri);
} catch (Exception e) {
// Not saved yet so call the ibm watson service to get the results
getAndSaveJobResults(jobId);
}
MediaPackageElementBuilder builder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
return builder.elementFromURI(uri, Attachment.TYPE, new MediaPackageElementFlavor("captions", "ibm-watson-json"));
} catch (TranscriptionDatabaseException e) {
throw new TranscriptionServiceException("Job id not informed and could not find transcription", e);
}
}
use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl 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.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class TranscriptionDatabaseTest method testUpdateJobControlToTranscriptionComplete.
@Test
public void testUpdateJobControlToTranscriptionComplete() throws Exception {
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, STATUS, TRACK_DURATION);
TranscriptionJobControl j = database.findByJob(JOB_ID);
Assert.assertNotNull(j);
Assert.assertEquals(MP_ID, j.getMediaPackageId());
Assert.assertEquals(TRACK_ID, j.getTrackId());
Assert.assertEquals(STATUS, j.getStatus());
Assert.assertNull(j.getDateCompleted());
long dt1 = System.currentTimeMillis();
database.updateJobControl(JOB_ID, TranscriptionJobControl.Status.TranscriptionComplete.name());
long dt2 = System.currentTimeMillis();
j = database.findByJob(JOB_ID);
Assert.assertNotNull(j);
Assert.assertEquals(MP_ID, j.getMediaPackageId());
Assert.assertEquals(TRACK_ID, j.getTrackId());
Assert.assertEquals(TranscriptionJobControl.Status.TranscriptionComplete.name(), j.getStatus());
long completed = j.getDateCompleted().getTime();
Assert.assertTrue(dt1 <= completed && completed <= dt2);
}
use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class TranscriptionDatabaseTest method testFindByJob.
@Test
public void testFindByJob() throws Exception {
long dt1 = System.currentTimeMillis();
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, STATUS, TRACK_DURATION);
long dt2 = System.currentTimeMillis();
TranscriptionJobControl j = database.findByJob(JOB_ID);
Assert.assertNotNull(j);
Assert.assertEquals(MP_ID, j.getMediaPackageId());
Assert.assertEquals(TRACK_ID, j.getTrackId());
Assert.assertEquals(STATUS, j.getStatus());
long created = j.getDateCreated().getTime();
Assert.assertTrue(dt1 <= created && created <= dt2);
}
use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class TranscriptionDatabaseTest method testDeleteJobControl.
@Test
public void testDeleteJobControl() throws Exception {
long dt1 = System.currentTimeMillis();
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, STATUS, TRACK_DURATION);
long dt2 = System.currentTimeMillis();
TranscriptionJobControl j = database.findByJob(JOB_ID);
Assert.assertNotNull(j);
Assert.assertEquals(MP_ID, j.getMediaPackageId());
Assert.assertEquals(TRACK_ID, j.getTrackId());
Assert.assertEquals(STATUS, j.getStatus());
long created = j.getDateCreated().getTime();
Assert.assertTrue(dt1 <= created && created <= dt2);
database.deleteJobControl(JOB_ID);
Assert.assertNull(database.findByJob(JOB_ID));
}
Aggregations