Search in sources :

Example 71 with WorkflowOperationResult

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

the class DuplicateEventWorkflowOperationHandlerTest method testSuccessfulCreate.

@Test
public void testSuccessfulCreate() throws Exception {
    final int numCopies = 2;
    mockDependencies(numCopies);
    // operation configuration
    Map<String, String> configurations = new HashMap<>();
    configurations.put(SOURCE_FLAVORS_PROPERTY, "*/*");
    configurations.put(SOURCE_TAGS_PROPERTY, "archive");
    configurations.put(TARGET_TAGS_PROPERTY, "");
    configurations.put(NUMBER_PROPERTY, "" + numCopies);
    configurations.put(MAX_NUMBER_PROPERTY, "" + 10);
    configurations.put(PROPERTY_NAMESPACES_PROPERTY, "org.opencastproject.assetmanager.security");
    configurations.put(COPY_NUMBER_PREFIX_PROPERTY, "copy");
    // run the operation handler
    WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
    Assert.assertEquals(Action.CONTINUE, result.getAction());
    Assert.assertEquals(numCopies, clonedMediaPackages.getValues().size());
    for (int i = 1; i <= numCopies; i++) {
        final String expectedTitle = mp.getTitle() + " (" + configurations.get(COPY_NUMBER_PREFIX_PROPERTY) + " " + i + ")";
        Assert.assertEquals(expectedTitle, clonedMediaPackages.getValues().get(i - 1).getTitle());
    }
}
Also used : HashMap(java.util.HashMap) EasyMock.anyString(org.easymock.EasyMock.anyString) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 72 with WorkflowOperationResult

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

the class ImportWorkflowPropertiesWOHTest method testStartOp.

@Test
public void testStartOp() throws Exception {
    final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
    expect(woi.getConfiguration("source-flavor")).andStubReturn(FLAVOR);
    expect(woi.getConfiguration("keys")).andStubReturn("chapter, presenter_position, cover_marker_in_s");
    replay(woi);
    final Attachment att = new AttachmentImpl();
    att.setURI(new URI(WF_PROPS_ATT_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);
    replay(wi);
    try (InputStream is = ImportWorkflowPropertiesWOHTest.class.getResourceAsStream("/workflow-properties.xml")) {
        Files.copy(is, tmpPropsFile, StandardCopyOption.REPLACE_EXISTING);
    }
    final Workspace workspace = createNiceMock(Workspace.class);
    expect(workspace.get(new URI(WF_PROPS_ATT_URI))).andStubReturn(tmpPropsFile.toFile());
    replay(workspace);
    final ImportWorkflowPropertiesWOH woh = new ImportWorkflowPropertiesWOH();
    woh.setWorkspace(workspace);
    WorkflowOperationResult result = woh.start(wi, null);
    Map<String, String> properties = result.getProperties();
    Assert.assertTrue(properties.containsKey("chapter"));
    Assert.assertEquals("true", properties.get("chapter"));
    Assert.assertTrue(properties.containsKey("presenter_position"));
    Assert.assertEquals("left", properties.get("presenter_position"));
    Assert.assertTrue(properties.containsKey("cover_marker_in_s"));
    Assert.assertEquals("30.674", properties.get("cover_marker_in_s"));
    verify(wi);
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 73 with WorkflowOperationResult

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

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

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

WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)101 Test (org.junit.Test)85 HashMap (java.util.HashMap)46 MediaPackage (org.opencastproject.mediapackage.MediaPackage)35 Track (org.opencastproject.mediapackage.Track)34 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)28 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)26 ArrayList (java.util.ArrayList)19 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)19 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)17 Job (org.opencastproject.job.api.Job)13 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)11 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)11 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)11 Catalog (org.opencastproject.mediapackage.Catalog)10 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)9 URI (java.net.URI)7 File (java.io.File)6 Attachment (org.opencastproject.mediapackage.Attachment)6 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)6