use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method testTranscriptionError.
@Test
public void testTranscriptionError() throws Exception {
InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PUSHED_TRANSCRIPTION_FILE);
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
JSONObject obj = (JSONObject) jsonParser.parse(new InputStreamReader(stream));
service.transcriptionError(MP_ID, obj);
// Check if status and date in db was updated
TranscriptionJobControl job = database.findByJob(JOB_ID);
Assert.assertNotNull(job);
Assert.assertEquals(TranscriptionJobControl.Status.Error.name(), job.getStatus());
Assert.assertNull(job.getDateCompleted());
EasyMock.verify(smtpService);
}
use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method testTranscriptionDone.
@Test
public void testTranscriptionDone() throws Exception {
InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PUSHED_TRANSCRIPTION_FILE);
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
JSONObject obj = (JSONObject) jsonParser.parse(new InputStreamReader(stream));
Capture<String> capturedCollection = Capture.newInstance();
Capture<String> capturedFileName = Capture.newInstance();
EasyMock.expect(workspace.putInCollection(EasyMock.capture(capturedCollection), EasyMock.capture(capturedFileName), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://anything"));
EasyMock.replay(workspace);
long before = System.currentTimeMillis();
service.transcriptionDone(MP_ID, obj);
long after = System.currentTimeMillis();
// Check if status and date in db was updated
TranscriptionJobControl job = database.findByJob(JOB_ID);
Assert.assertNotNull(job);
Assert.assertEquals(TranscriptionJobControl.Status.TranscriptionComplete.name(), job.getStatus());
Assert.assertNotNull(job.getDateCompleted());
Assert.assertTrue(before <= job.getDateCompleted().getTime() && job.getDateCompleted().getTime() <= after);
// Check if results were saved into a collection
Assert.assertEquals(IBMWatsonTranscriptionService.TRANSCRIPT_COLLECTION, capturedCollection.getValue());
Assert.assertEquals(JOB_ID + ".json", capturedFileName.getValue());
}
use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class IBMWatsonTranscriptionService method transcriptionError.
@Override
public void transcriptionError(String mpId, Object obj) throws TranscriptionServiceException {
JSONObject jsonObj = null;
String jobId = null;
try {
jsonObj = (JSONObject) obj;
jobId = (String) jsonObj.get("id");
// Update state in database
database.updateJobControl(jobId, TranscriptionJobControl.Status.Error.name());
TranscriptionJobControl jobControl = database.findByJob(jobId);
logger.warn(String.format("Error callback received for media package %s, job id %s", jobControl.getMediaPackageId(), jobId));
// Send notification email
sendEmail("Transcription ERROR", String.format("There was a transcription error for for media package %s, job id %s.", jobControl.getMediaPackageId(), jobId));
} catch (TranscriptionDatabaseException e) {
logger.warn("Transcription error. State in db could not be updated to error for mpId {}, jobId {}", mpId, jobId);
throw new TranscriptionServiceException("Could not update transcription job control db", e);
}
}
use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunProgressState.
@Test
public void testWorkflowDispatcherRunProgressState() throws Exception {
InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PULLED_TRANSCRIPTION_FILE);
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), 0);
database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
EasyMock.expect(workspace.putInCollection(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://anything"));
EasyMock.replay(workspace);
HttpEntity httpEntity = EasyMock.createNiceMock(HttpEntity.class);
EasyMock.expect(httpEntity.getContent()).andReturn(stream);
CloseableHttpResponse response = EasyMock.createNiceMock(CloseableHttpResponse.class);
StatusLine status = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(response.getStatusLine()).andReturn(status).anyTimes();
EasyMock.expect(response.getEntity()).andReturn(httpEntity).anyTimes();
EasyMock.expect(status.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
EasyMock.replay(httpEntity, response, status);
Capture<HttpGet> capturedGet = Capture.newInstance();
EasyMock.expect(httpClient.execute(EasyMock.capture(capturedGet))).andReturn(response);
EasyMock.replay(httpClient);
// enrich(q.select(q.snapshot()).where(q.mediaPackageId(mpId).and(q.version().isLatest())).run()).getSnapshots();
// 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 it called the external service to get the results
Assert.assertEquals("https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions/" + JOB_ID, capturedGet.getValue().getURI().toString());
// 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 testUpdateJobControl.
@Test
public void testUpdateJobControl() 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.updateJobControl(JOB_ID, STATUS2);
j = database.findByJob(JOB_ID);
Assert.assertNotNull(j);
Assert.assertEquals(MP_ID, j.getMediaPackageId());
Assert.assertEquals(TRACK_ID, j.getTrackId());
Assert.assertEquals(STATUS2, j.getStatus());
}
Aggregations