IBMWatsonTranscriptionService extends AbstractJobProducer implements TranscriptionService { @Override public void transcriptionDone(String mpId, Object obj) throws TranscriptionServiceException { JSONObject jsonObj = null; String jobId = null; try { jsonObj = (JSONObject) obj; jobId = (String) jsonObj.get("id"); if (jsonObj.get("results") instanceof JSONArray) { JSONArray resultsArray = (JSONArray) jsonObj.get("results"); if (resultsArray != null && resultsArray.size() > 0) { String error = (String) ((JSONObject) resultsArray.get(0)).get("error"); if (!StringUtils.isEmpty(error)) { retryOrError(jobId, mpId, String.format("Transcription completed with error for mpId %s, jobId %s: %s", mpId, jobId, error)); return; } } } logger.info("Transcription done for mpId {}, jobId {}", mpId, jobId); database.updateJobControl(jobId, TranscriptionJobControl.Status.TranscriptionComplete.name()); if (jsonObj.get("results") != null) saveResults(jobId, jsonObj); } catch (IOException e) { logger.warn("Could not save transcription results file for mpId {}, jobId {}: {}", mpId, jobId, jsonObj == null ? "null" : jsonObj.toJSONString()); throw new TranscriptionServiceException("Could not save transcription results file", e); } catch (TranscriptionDatabaseException e) { logger.warn("Error when updating state in database for mpId {}, jobId {}", mpId, jobId); throw new TranscriptionServiceException("Could not update transcription job control db", e); } } IBMWatsonTranscriptionService(); void activate(ComponentContext cc); @Override Job startTranscription(String mpId, Track track); @Override Job startTranscription(String mpId, Track track, String language); @Override void transcriptionDone(String mpId, Object obj); @Override void transcriptionError(String mpId, Object obj); @Override String getLanguage(); @Override MediaPackageElement getGeneratedTranscription(String mpId, String jobId); boolean isCallbackAlreadyRegistered(); void setServiceRegistry(ServiceRegistry serviceRegistry); void setSecurityService(SecurityService securityService); void setUserDirectoryService(UserDirectoryService userDirectoryService); void setOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService); void setSmtpService(SmtpService service); void setWorkspace(Workspace ws); void setWorkingFileRepository(WorkingFileRepository wfr); void setDatabase(TranscriptionDatabase service); void setAssetManager(AssetManager service); void setWorkflowService(WorkflowService service); boolean isEnabled(); static final String DEFAULT_WF_DEF; static final String ADMIN_URL_PROPERTY; static final float DEFAULT_START_TRANSCRIPTION_JOB_LOAD; static final String START_TRANSCRIPTION_JOB_LOAD_KEY; static final String ENABLED_CONFIG; static final String IBM_WATSON_SERVICE_URL_CONFIG; static final String IBM_WATSON_USER_CONFIG; static final String IBM_WATSON_PSW_CONFIG; static final String IBM_WATSON_API_KEY_CONFIG; static final String IBM_WATSON_MODEL_CONFIG; static final String WORKFLOW_CONFIG; static final String DISPATCH_WORKFLOW_INTERVAL_CONFIG; static final String COMPLETION_CHECK_BUFFER_CONFIG; static final String MAX_PROCESSING_TIME_CONFIG; static final String NOTIFICATION_EMAIL_CONFIG; static final String CLEANUP_RESULTS_DAYS_CONFIG; static final String MAX_ATTEMPTS_CONFIG; static final String RETRY_WORKLFOW_CONFIG; }
@Test public void testTranscriptionDone() throws Exception { service.activate(cc); InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PUSHED_TRANSCRIPTION_FILE); database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.InProgress.name(), TRACK_DURATION, DATE_EXPECTED, PROVIDER); 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: EasyMock.replay(workspace); long before = System.currentTimeMillis(); service.transcriptionDone(MP_ID, obj); long after = System.currentTimeMillis(); 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); Assert.assertEquals(IBMWatsonTranscriptionService.TRANSCRIPT_COLLECTION, capturedCollection.getValue()); Assert.assertEquals(JOB_ID + ".json", capturedFileName.getValue()); }