Search in sources :

Example 81 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance 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 82 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance 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)

Example 83 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class DefaultsWorkflowOperationHandlerTest method getWorkflowOperationResult.

private WorkflowOperationResult getWorkflowOperationResult(MediaPackage mp, Map<String, String> workflowConfiguration, Map<String, String> operationConfiguration) throws WorkflowOperationException {
    // Add the mediapackage to a workflow instance
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    // Apply the workflow configuration
    for (Map.Entry<String, String> entry : workflowConfiguration.entrySet()) {
        workflowInstance.setConfiguration(entry.getKey(), entry.getValue());
    }
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl();
    operation.setTemplate("defaults");
    operation.setState(OperationState.RUNNING);
    // Apply the workflow operation configuration
    for (Map.Entry<String, String> entry : operationConfiguration.entrySet()) {
        operation.setConfiguration(entry.getKey(), entry.getValue());
    }
    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
    WorkflowOperationResult result = operationHandler.start(workflowInstance, null);
    Assert.assertEquals(result.getAction(), Action.CONTINUE);
    return result;
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult)

Example 84 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class ExportWorkflowPropertiesWOHTest method testExport.

@Test
public void testExport() throws Exception {
    final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
    expect(woi.getConfiguration("target-flavor")).andStubReturn(FLAVOR);
    expect(woi.getConfiguration("target-tags")).andStubReturn("archive");
    expect(woi.getConfiguration("keys")).andStubReturn("chapter,presenter_position");
    replay(woi);
    final Attachment att = new AttachmentImpl();
    att.setURI(uri);
    att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.add(att);
    WorkflowInstance wi = createMock(WorkflowInstance.class);
    expect(wi.getCurrentOperation()).andStubReturn(woi);
    expect(wi.getMediaPackage()).andStubReturn(mp);
    Set<String> keys = new HashSet<>();
    keys.add("presenter_position");
    keys.add("cover_marker_in_s");
    expect(wi.getConfigurationKeys()).andStubReturn(keys);
    expect(wi.getConfiguration("presenter_position")).andStubReturn("right");
    expect(wi.getConfiguration("cover_marker_in_s")).andStubReturn("30.674");
    replay(wi);
    final ExportWorkflowPropertiesWOH woh = new ExportWorkflowPropertiesWOH();
    woh.setWorkspace(workspace);
    WorkflowOperationResult result = woh.start(wi, null);
    Attachment[] attachments = result.getMediaPackage().getAttachments();
    Assert.assertTrue(attachments.length == 1);
    Attachment attachment = attachments[0];
    assertEquals("processing/defaults", attachment.getFlavor().toString());
    assertEquals("archive", attachment.getTags()[0]);
    Assert.assertNotNull(attachment.getURI());
    File file = workspace.get(attachment.getURI());
    Properties props = new Properties();
    try (InputStream is = new FileInputStream(file)) {
        props.loadFromXML(is);
    }
    assertEquals("30.674", props.get("cover_marker_in_s"));
    assertEquals("right", props.get("presenter_position"));
    Assert.assertFalse(props.contains("chapter"));
    verify(wi);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Properties(java.util.Properties) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) FileInputStream(java.io.FileInputStream) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class ProbeResolutionWorkflowOperationHandlerTest method testStart.

@Test
public void testStart() throws MediaPackageException, WorkflowOperationException {
    MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    VideoStreamImpl videoStream = new VideoStreamImpl("234");
    videoStream.setFrameWidth(1280);
    videoStream.setFrameHeight(720);
    TrackImpl track = new TrackImpl();
    track.setFlavor(MediaPackageElementFlavor.parseFlavor("presenter/source"));
    track.addStream(videoStream);
    JobContext jobContext = EasyMock.createMock(JobContext.class);
    EasyMock.replay(jobContext);
    WorkflowOperationInstance operationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
    String[][] config = { { ProbeResolutionWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "aspect", "1280x720,1280x700" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAL_PREFIX + "aspect", "16/9" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "is_720", "1280x720,1280x700" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "is_1080", "1920x1080" } };
    Set<String> keys = new HashSet<>();
    for (String[] cfg : config) {
        keys.add(cfg[0]);
        EasyMock.expect(operationInstance.getConfiguration(cfg[0])).andReturn(cfg[1]).anyTimes();
    }
    EasyMock.expect(operationInstance.getConfigurationKeys()).andReturn(keys).anyTimes();
    EasyMock.replay(operationInstance);
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
    EasyMock.replay(workflowInstance);
    // With no matching track
    assertEquals(null, operationHandler.start(workflowInstance, jobContext).getProperties());
    // With matching track
    mediaPackage.add(track);
    WorkflowOperationResult workflowOperationResult = operationHandler.start(workflowInstance, jobContext);
    Map<String, String> properties = workflowOperationResult.getProperties();
    String[][] props = { { "presenter_source_aspect", "16/9" }, { "presenter_source_is_720", "true" }, { "presenter_source_is_1080", null } };
    for (String[] prop : props) {
        assertEquals(prop[1], properties.get(prop[0]));
    }
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JobContext(org.opencastproject.job.api.JobContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)104 ArrayList (java.util.ArrayList)51 MediaPackage (org.opencastproject.mediapackage.MediaPackage)48 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)37 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)33 Test (org.junit.Test)32 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)31 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)28 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)24 Job (org.opencastproject.job.api.Job)23 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)19 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)19 URI (java.net.URI)18 NotFoundException (org.opencastproject.util.NotFoundException)16 Track (org.opencastproject.mediapackage.Track)14 IOException (java.io.IOException)13 File (java.io.File)12 HashMap (java.util.HashMap)12 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)11 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)10