use of org.opencastproject.workflow.api.WorkflowInstanceImpl 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.WorkflowInstanceImpl 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.WorkflowInstanceImpl 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.WorkflowInstanceImpl in project opencast by opencast.
the class TagByDublinCoreTermWOHTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mp = builder.loadFromXml(this.getClass().getResourceAsStream("/archive_mediapackage.xml"));
mp.getCatalog("catalog-1").setURI(this.getClass().getResource("/dublincore.xml").toURI());
// set up the handler
operationHandler = new TagByDublinCoreTermWOH();
// Initialize the workflow
instance = new WorkflowInstanceImpl();
operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml"));
EasyMock.replay(workspace);
operationHandler.setWorkspace(workspace);
}
use of org.opencastproject.workflow.api.WorkflowInstanceImpl in project opencast by opencast.
the class WorkflowServiceImpl method getWorkflowById.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#getWorkflowById(long)
*/
@Override
public WorkflowInstanceImpl getWorkflowById(long id) throws WorkflowDatabaseException, NotFoundException, UnauthorizedException {
try {
Job job = serviceRegistry.getJob(id);
if (Status.DELETED.equals(job.getStatus())) {
throw new NotFoundException("Workflow '" + id + "' has been deleted");
}
if (JOB_TYPE.equals(job.getJobType()) && Operation.START_WORKFLOW.toString().equals(job.getOperation())) {
WorkflowInstanceImpl workflow = WorkflowParser.parseWorkflowInstance(job.getPayload());
assertPermission(workflow, Permissions.Action.READ.toString());
return workflow;
} else {
throw new NotFoundException("'" + id + "' is a job identifier, but it is not a workflow identifier");
}
} catch (WorkflowParsingException e) {
throw new IllegalStateException("The workflow job payload is malformed");
} catch (ServiceRegistryException e) {
throw new IllegalStateException("Error loading workflow job from the service registry");
} catch (MediaPackageException e) {
throw new IllegalStateException("Unable to read mediapackage from workflow " + id, e);
}
}
Aggregations