use of org.opencastproject.workflow.api.WorkflowOperationInstanceImpl in project opencast by opencast.
the class ImageToVideoWorkflowOperationHandlerTest method getWorkflowOperationResult.
private WorkflowOperationResult getWorkflowOperationResult(MediaPackage mp, Map<String, String> configurations) throws WorkflowOperationException {
// Add the mediapackage to a workflow instance
WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
workflowInstance.setId(1);
workflowInstance.setState(WorkflowState.RUNNING);
workflowInstance.setMediaPackage(mp);
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", OperationState.RUNNING);
operation.setTemplate(PROFILE_ID);
operation.setState(OperationState.RUNNING);
for (String key : configurations.keySet()) {
operation.setConfiguration(key, configurations.get(key));
}
List<WorkflowOperationInstance> operationsList = new ArrayList<WorkflowOperationInstance>();
operationsList.add(operation);
workflowInstance.setOperations(operationsList);
// Run the media package through the operation handler, ensuring that metadata gets added
return operationHandler.start(workflowInstance, null);
}
use of org.opencastproject.workflow.api.WorkflowOperationInstanceImpl in project opencast by opencast.
the class AttachTranscriptionOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// Media package set up
URI mediaPackageURI = StartTranscriptionOperationHandlerTest.class.getResource("/mp.xml").toURI();
mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
URI dfxpURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_dfxp.xml").toURI();
String dfxpXml = FileUtils.readFileToString(new File(dfxpURI));
Attachment captionDfxp = (Attachment) MediaPackageElementParser.getFromXml(dfxpXml);
URI vttURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_vtt.xml").toURI();
String vttXml = FileUtils.readFileToString(new File(vttURI));
Attachment captionVtt = (Attachment) MediaPackageElementParser.getFromXml(vttXml);
// Service registry set up
job1 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job1.getId()).andReturn(1L);
EasyMock.expect(job1.getPayload()).andReturn(dfxpXml).anyTimes();
EasyMock.expect(job1.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job1.getDateCreated()).andReturn(new Date());
EasyMock.expect(job1.getDateStarted()).andReturn(new Date());
EasyMock.expect(job1.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job1);
job2 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job2.getId()).andReturn(2L);
EasyMock.expect(job2.getPayload()).andReturn(vttXml).anyTimes();
EasyMock.expect(job2.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job2.getDateCreated()).andReturn(new Date());
EasyMock.expect(job2.getDateStarted()).andReturn(new Date());
EasyMock.expect(job2.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job2);
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1);
EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job2);
EasyMock.replay(serviceRegistry);
// Transcription service set up
service = EasyMock.createStrictMock(TranscriptionService.class);
EasyMock.expect(service.getGeneratedTranscription("mpId1", "transcriptionJob")).andReturn(captionDfxp);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.expect(service.getGeneratedTranscription("mpId2", "transcriptionJob")).andReturn(captionVtt);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.replay(service);
// Caption service set up
captionService = EasyMock.createNiceMock(CaptionService.class);
// Workspace set up
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo(EasyMock.anyObject(URI.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(// just something valid
new URI("http://opencast.server.com/captions.xml"));
EasyMock.replay(workspace);
// Workflow set up
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("DCE-start-transcription");
def.setPublished(true);
workflowInstance = new WorkflowInstanceImpl(def, mediaPackage, null, null, null, null);
workflowInstance.setId(1);
operation = new WorkflowOperationInstanceImpl("attach-transcript", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(operation);
workflowInstance.setOperations(operationList);
// Operation handler set up
operationHandler = new AttachTranscriptionOperationHandler();
operationHandler.setTranscriptionService(service);
operationHandler.setServiceRegistry(serviceRegistry);
operationHandler.setCaptionService(captionService);
operationHandler.setWorkspace(workspace);
operationHandler.setJobBarrierPollingInterval(1L);
}
use of org.opencastproject.workflow.api.WorkflowOperationInstanceImpl in project opencast by opencast.
the class SeriesWorkflowOperationHandlerTest method testAclOnly.
@Test
public void testAclOnly() throws Exception {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
operation.setConfiguration(SeriesWorkflowOperationHandler.SERIES_PROPERTY, "series1");
operation.setConfiguration(SeriesWorkflowOperationHandler.ATTACH_PROPERTY, "");
operation.setConfiguration(SeriesWorkflowOperationHandler.APPLY_ACL_PROPERTY, "true");
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
}
use of org.opencastproject.workflow.api.WorkflowOperationInstanceImpl in project opencast by opencast.
the class SeriesWorkflowOperationHandlerTest method testChangeSeries.
@Test
public void testChangeSeries() throws Exception {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
MediaPackage clone = (MediaPackage) mp.clone();
operation.setConfiguration(SeriesWorkflowOperationHandler.SERIES_PROPERTY, "series1");
operation.setConfiguration(SeriesWorkflowOperationHandler.ATTACH_PROPERTY, "*");
operation.setConfiguration(SeriesWorkflowOperationHandler.APPLY_ACL_PROPERTY, "false");
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage resultingMediapackage = result.getMediaPackage();
Assert.assertEquals("series1", resultingMediapackage.getSeries());
Assert.assertEquals("Series 1", resultingMediapackage.getSeriesTitle());
Assert.assertEquals(clone.getElements().length + 1, resultingMediapackage.getElements().length);
}
use of org.opencastproject.workflow.api.WorkflowOperationInstanceImpl in project opencast by opencast.
the class SeriesWorkflowOperationHandlerTest method testExtraMetadataDefaultNS.
@Test
public void testExtraMetadataDefaultNS() throws WorkflowOperationException {
final EName customProperty = new EName(DublinCores.OC_PROPERTY_NS_URI, "my-custom-property");
final String customValue = "my-custom-value";
// Add extra metadata to the series catalog.
seriesCatalog.set(DublinCore.PROPERTY_LANGUAGE, "Opencastian");
seriesCatalog.set(DublinCore.PROPERTY_CONTRIBUTOR, Arrays.asList(new DublinCoreValue[] { DublinCoreValue.mk("Mr. Contry Bute"), DublinCoreValue.mk("Mrs. Jane Doe") }));
seriesCatalog.set(customProperty, customValue);
// Prepare "copy metadata" property
// All field names without namespace
// However, in the series metadata, the third one has a different NS than the other two
String[] extraMetadata = { DublinCore.PROPERTY_LANGUAGE.getLocalName(), DublinCore.PROPERTY_CONTRIBUTOR.getLocalName(), customProperty.getLocalName() };
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
MediaPackage clone = (MediaPackage) mp.clone();
operation.setConfiguration(SeriesWorkflowOperationHandler.SERIES_PROPERTY, "series1");
operation.setConfiguration(SeriesWorkflowOperationHandler.ATTACH_PROPERTY, "*");
operation.setConfiguration(SeriesWorkflowOperationHandler.APPLY_ACL_PROPERTY, "false");
operation.setConfiguration(SeriesWorkflowOperationHandler.COPY_METADATA_PROPERTY, StringUtils.join(extraMetadata, ", "));
// Set the namespace of the third, custom property as the default
operation.setConfiguration(SeriesWorkflowOperationHandler.DEFAULT_NS_PROPERTY, DublinCores.OC_PROPERTY_NS_URI);
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage resultingMediapackage = result.getMediaPackage();
Assert.assertEquals("series1", resultingMediapackage.getSeries());
Assert.assertEquals("Series 1", resultingMediapackage.getSeriesTitle());
Assert.assertEquals(clone.getElements().length + 1, resultingMediapackage.getElements().length);
// Get episode DublinCore
DublinCoreCatalog episodeCatalog = DublinCores.read(capturedStream.getValue());
// Only the later metadatum should have been resolved. The other had a different namespace.
Assert.assertFalse(episodeCatalog.hasValue(DublinCore.PROPERTY_CONTRIBUTOR));
Assert.assertFalse(episodeCatalog.hasValue(DublinCore.PROPERTY_LANGUAGE));
Assert.assertTrue(episodeCatalog.hasValue(customProperty));
Assert.assertEquals(seriesCatalog.get(customProperty), episodeCatalog.get(customProperty));
}
Aggregations