GoogleSpeechTranscriptionService extends AbstractJobProducer implements TranscriptionService { @Override public void transcriptionDone(String mpId, Object obj) throws TranscriptionServiceException { JSONObject jsonObj = null; String jobId = null; String token = INVALID_TOKEN; try { token = getRefreshAccessToken(); } catch (IOException ex) { logger.error("Unable to create access token, error: {}", ex.toString()); } if (token.equals(INVALID_TOKEN)) { throw new TranscriptionServiceException("Invalid access token"); } try { jsonObj = (JSONObject) obj; jobId = (String) jsonObj.get("name"); logger.info("Transcription done for mpId {}, jobId {}", mpId, jobId); JSONArray resultsArray = getTranscriptionResult(jsonObj); database.updateJobControl(jobId, TranscriptionJobControl.Status.TranscriptionComplete.name()); deleteStorageFile(mpId, token); if (resultsArray != null) { saveResults(jobId, jsonObj); } } catch (IOException e) { if (jsonObj == null) { logger.warn("Could not save transcription results file for mpId {}, jobId {}: null", mpId, jobId); } else { logger.warn("Could not save transcription results file for mpId {}, jobId {}: {}", mpId, jobId, jsonObj.toJSONString()); } throw new TranscriptionServiceException("Could not save transcription results file", e); } catch (TranscriptionDatabaseException e) { logger.warn("Transcription results file were saved but state in db not updated for mpId {}, jobId {}", mpId, jobId); throw new TranscriptionServiceException("Could not update transcription job control db", e); } } GoogleSpeechTranscriptionService(); void activate(ComponentContext cc); @Override Job startTranscription(String mpId, Track track, String language); @Override Job startTranscription(String mpId, Track track); @Override void transcriptionDone(String mpId, Object obj); @Override String getLanguage(); @Override void transcriptionError(String mpId, Object obj); String getTranscriptionResults(String jobId); @Override MediaPackageElement getGeneratedTranscription(String mpId, String jobId); String getTranscriptionStatus(String mpId); 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); static final String DEFAULT_WF_DEF; static final String ENABLED_CONFIG; static final String GOOGLE_SPEECH_LANGUAGE; static final String PROFANITY_FILTER; 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 GOOGLE_CLOUD_CLIENT_ID; static final String GOOGLE_CLOUD_CLIENT_SECRET; static final String GOOGLE_CLOUD_REFRESH_TOKEN; static final String GOOGLE_CLOUD_BUCKET; static final String GOOGLE_CLOUD_TOKEN_ENDPOINT_URL; static final String ENCODING_EXTENSION; }
@Test public void testTranscriptionDone() throws Exception { InputStream stream = GoogleSpeechTranscriptionServiceTest.class.getResourceAsStream("/" + PULLED_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(GoogleSpeechTranscriptionService.TRANSCRIPT_COLLECTION, capturedCollection.getValue()); Assert.assertEquals(JOB_ID + ".json", capturedFileName.getValue()); }