Search in sources :

Example 26 with WorkflowOperationInstanceImpl

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);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Example 27 with WorkflowOperationInstanceImpl

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);
}
Also used : TranscriptionService(org.opencastproject.transcription.api.TranscriptionService) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Attachment(org.opencastproject.mediapackage.Attachment) URI(java.net.URI) Date(java.util.Date) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) CaptionService(org.opencastproject.caption.api.CaptionService) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 28 with WorkflowOperationInstanceImpl

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());
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 29 with WorkflowOperationInstanceImpl

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);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 30 with WorkflowOperationInstanceImpl

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));
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Aggregations

WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)35 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)33 ArrayList (java.util.ArrayList)32 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)31 Test (org.junit.Test)11 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)11 Before (org.junit.Before)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)7 URI (java.net.URI)4 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)4 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)4 Workspace (org.opencastproject.workspace.api.Workspace)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Job (org.opencastproject.job.api.Job)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 File (java.io.File)2 Date (java.util.Date)2 Incident (org.opencastproject.job.api.Incident)2