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);
}
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));
}
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;
}
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);
}
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]));
}
}
Aggregations