@Test public void testStartWebVtt() throws Exception { EasyMock.expect(captionService.convert(EasyMock.anyObject(Attachment.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(job2); EasyMock.replay(captionService); operation.setConfiguration(AttachTranscriptionOperationHandler.TRANSCRIPTION_JOB_ID, "transcriptionJob"); operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_TAG, "tag1,tag2"); operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_CAPTION_FORMAT, "vtt"); WorkflowOperationResult result = operationHandler.start(workflowInstance, null); Assert.assertEquals(Action.CONTINUE, result.getAction()); MediaPackage updatedMp = result.getMediaPackage(); Attachment[] attachments = updatedMp.getAttachments(MediaPackageElementFlavor.parseFlavor("captions/vtt+en")); Assert.assertNotNull(attachments); Assert.assertEquals(1, attachments.length); Assert.assertNotNull(attachments[0].getTags()); Assert.assertEquals(3, attachments[0].getTags().length); Assert.assertEquals("lang:en", attachments[0].getTags()[0]); Assert.assertEquals("tag1", attachments[0].getTags()[1]); Assert.assertEquals("tag2", attachments[0].getTags()[2]); }
@Override public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance operation = workflowInstance.getCurrentOperation(); logger.debug("Attach transcription for mediapackage {} started", mediaPackage); String jobId = StringUtils.trimToNull(operation.getConfiguration(TRANSCRIPTION_JOB_ID)); if (jobId == null) throw new WorkflowOperationException(TRANSCRIPTION_JOB_ID + " missing"); String targetTagOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_TAG)); String targetFlavorOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_FLAVOR)); String captionFormatOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_CAPTION_FORMAT)); if (targetFlavorOption == null && captionFormatOption == null) throw new WorkflowOperationException(TARGET_FLAVOR + " missing"); MediaPackageElementFlavor flavor = null; if (targetFlavorOption != null) flavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption); try { MediaPackageElement original = service.getGeneratedTranscription(mediaPackage.getIdentifier().toString(), jobId); MediaPackageElement transcription = original; if (captionFormatOption != null) { Job job = captionService.convert(transcription, "ibm-watson", captionFormatOption, service.getLanguage()); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Transcription format conversion job did not complete successfully"); } transcription = MediaPackageElementParser.getFromXml(job.getPayload()); } if (flavor != null) transcription.setFlavor(flavor); if (targetTagOption != null) { for (String tag : asList(targetTagOption)) { if (StringUtils.trimToNull(tag) != null) transcription.addTag(tag); } } mediaPackage.add(transcription); String uri = transcription.getURI().toString(); String ext = uri.substring(uri.lastIndexOf(".")); transcription.setURI(workspace.moveTo(transcription.getURI(), mediaPackage.getIdentifier().toString(), transcription.getIdentifier(), "captions." + ext)); } catch (Exception e) { throw new WorkflowOperationException(e); } return createResult(mediaPackage, Action.CONTINUE); }
AttachTranscriptionOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance operation = workflowInstance.getCurrentOperation(); logger.debug("Attach transcription for mediapackage {} started", mediaPackage); String jobId = StringUtils.trimToNull(operation.getConfiguration(TRANSCRIPTION_JOB_ID)); if (jobId == null) throw new WorkflowOperationException(TRANSCRIPTION_JOB_ID + " missing"); String targetTagOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_TAG)); String targetFlavorOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_FLAVOR)); String captionFormatOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_CAPTION_FORMAT)); if (targetFlavorOption == null && captionFormatOption == null) throw new WorkflowOperationException(TARGET_FLAVOR + " missing"); MediaPackageElementFlavor flavor = null; if (targetFlavorOption != null) flavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption); try { MediaPackageElement original = service.getGeneratedTranscription(mediaPackage.getIdentifier().toString(), jobId); MediaPackageElement transcription = original; if (captionFormatOption != null) { Job job = captionService.convert(transcription, "ibm-watson", captionFormatOption, service.getLanguage()); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Transcription format conversion job did not complete successfully"); } transcription = MediaPackageElementParser.getFromXml(job.getPayload()); } if (flavor != null) transcription.setFlavor(flavor); if (targetTagOption != null) { for (String tag : asList(targetTagOption)) { if (StringUtils.trimToNull(tag) != null) transcription.addTag(tag); } } mediaPackage.add(transcription); String uri = transcription.getURI().toString(); String ext = uri.substring(uri.lastIndexOf(".")); transcription.setURI(workspace.moveTo(transcription.getURI(), mediaPackage.getIdentifier().toString(), transcription.getIdentifier(), "captions." + ext)); } catch (Exception e) { throw new WorkflowOperationException(e); } return createResult(mediaPackage, Action.CONTINUE); } }
AttachTranscriptionOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance operation = workflowInstance.getCurrentOperation(); logger.debug("Attach transcription for mediapackage {} started", mediaPackage); String jobId = StringUtils.trimToNull(operation.getConfiguration(TRANSCRIPTION_JOB_ID)); if (jobId == null) throw new WorkflowOperationException(TRANSCRIPTION_JOB_ID + " missing"); String targetTagOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_TAG)); String targetFlavorOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_FLAVOR)); String captionFormatOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_CAPTION_FORMAT)); if (targetFlavorOption == null && captionFormatOption == null) throw new WorkflowOperationException(TARGET_FLAVOR + " missing"); MediaPackageElementFlavor flavor = null; if (targetFlavorOption != null) flavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption); try { MediaPackageElement original = service.getGeneratedTranscription(mediaPackage.getIdentifier().toString(), jobId); MediaPackageElement transcription = original; if (captionFormatOption != null) { Job job = captionService.convert(transcription, "ibm-watson", captionFormatOption, service.getLanguage()); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Transcription format conversion job did not complete successfully"); } transcription = MediaPackageElementParser.getFromXml(job.getPayload()); } if (flavor != null) transcription.setFlavor(flavor); if (targetTagOption != null) { for (String tag : asList(targetTagOption)) { if (StringUtils.trimToNull(tag) != null) transcription.addTag(tag); } } mediaPackage.add(transcription); String uri = transcription.getURI().toString(); String ext = uri.substring(uri.lastIndexOf(".")); transcription.setURI(workspace.moveTo(transcription.getURI(), mediaPackage.getIdentifier().toString(), transcription.getIdentifier(), "captions." + ext)); } catch (Exception e) { throw new WorkflowOperationException(e); } return createResult(mediaPackage, Action.CONTINUE); }  }
AttachTranscriptionOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance operation = workflowInstance.getCurrentOperation(); logger.debug("Attach transcription for mediapackage {} started", mediaPackage); String jobId = StringUtils.trimToNull(operation.getConfiguration(TRANSCRIPTION_JOB_ID)); if (jobId == null) throw new WorkflowOperationException(TRANSCRIPTION_JOB_ID + " missing"); String targetTagOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_TAG)); String targetFlavorOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_FLAVOR)); String captionFormatOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_CAPTION_FORMAT)); if (targetFlavorOption == null && captionFormatOption == null) throw new WorkflowOperationException(TARGET_FLAVOR + " missing"); MediaPackageElementFlavor flavor = null; if (targetFlavorOption != null) flavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption); try { MediaPackageElement original = service.getGeneratedTranscription(mediaPackage.getIdentifier().toString(), jobId); MediaPackageElement transcription = original; if (captionFormatOption != null) { Job job = captionService.convert(transcription, "ibm-watson", captionFormatOption, service.getLanguage()); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Transcription format conversion job did not complete successfully"); } transcription = MediaPackageElementParser.getFromXml(job.getPayload()); } if (flavor != null) transcription.setFlavor(flavor); if (targetTagOption != null) { for (String tag : asList(targetTagOption)) { if (StringUtils.trimToNull(tag) != null) transcription.addTag(tag); } } mediaPackage.add(transcription); String uri = transcription.getURI().toString(); String ext = uri.substring(uri.lastIndexOf(".")); transcription.setURI(workspace.moveTo(transcription.getURI(), mediaPackage.getIdentifier().toString(), transcription.getIdentifier(), "captions." + ext)); } catch (Exception e) { throw new WorkflowOperationException(e); } return createResult(mediaPackage, Action.CONTINUE); }  @Override WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context); void setTranscriptionService(TranscriptionService service); void setWorkspace(Workspace service); void setCaptionService(CaptionService service); }
AttachTranscriptionOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance operation = workflowInstance.getCurrentOperation(); logger.debug("Attach transcription for mediapackage {} started", mediaPackage); String jobId = StringUtils.trimToNull(operation.getConfiguration(TRANSCRIPTION_JOB_ID)); if (jobId == null) throw new WorkflowOperationException(TRANSCRIPTION_JOB_ID + " missing"); String targetTagOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_TAG)); String targetFlavorOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_FLAVOR)); String captionFormatOption = StringUtils.trimToNull(operation.getConfiguration(TARGET_CAPTION_FORMAT)); if (targetFlavorOption == null && captionFormatOption == null) throw new WorkflowOperationException(TARGET_FLAVOR + " missing"); MediaPackageElementFlavor flavor = null; if (targetFlavorOption != null) flavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption); try { MediaPackageElement original = service.getGeneratedTranscription(mediaPackage.getIdentifier().toString(), jobId); MediaPackageElement transcription = original; if (captionFormatOption != null) { Job job = captionService.convert(transcription, "ibm-watson", captionFormatOption, service.getLanguage()); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Transcription format conversion job did not complete successfully"); } transcription = MediaPackageElementParser.getFromXml(job.getPayload()); } if (flavor != null) transcription.setFlavor(flavor); if (targetTagOption != null) { for (String tag : asList(targetTagOption)) { if (StringUtils.trimToNull(tag) != null) transcription.addTag(tag); } } mediaPackage.add(transcription); String uri = transcription.getURI().toString(); String ext = uri.substring(uri.lastIndexOf(".")); transcription.setURI(workspace.moveTo(transcription.getURI(), mediaPackage.getIdentifier().toString(), transcription.getIdentifier(), "captions." + ext)); } catch (Exception e) { throw new WorkflowOperationException(e); } return createResult(mediaPackage, Action.CONTINUE); }  @Override WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context); void setTranscriptionService(TranscriptionService service); void setWorkspace(Workspace service); void setCaptionService(CaptionService service);  }