use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testSingleSourceFlavor.
@Test
public void testSingleSourceFlavor() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "presentation/source");
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "*/target");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("presentation/target");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 1);
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testTagsAsSourceSelector.
@Test
public void testTagsAsSourceSelector() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_SOURCE_TAGS, "first");
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "*/target");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("*/target");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 1);
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testSpecificTargetFlavorType.
@Test
public void testSpecificTargetFlavorType() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source");
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "targettype/target");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("targettype/target");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 2);
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testNoSourceFlavor.
@Test
public void testNoSourceFlavor() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "*/target");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.SKIP, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("*/target");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 0);
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class WorkflowOperationWorker method start.
/**
* Starts executing the workflow operation.
*
* @return the workflow operation result
* @throws WorkflowOperationException
* if executing the workflow operation handler fails
* @throws WorkflowException
* if there is a problem processing the workflow
*/
public WorkflowOperationResult start() throws WorkflowOperationException, WorkflowException, UnauthorizedException {
final WorkflowOperationInstance operation = workflow.getCurrentOperation();
// Do we need to execute the operation?
// if
final String executionCondition = operation.getExecutionCondition();
final boolean execute;
if (executionCondition == null) {
execute = true;
} else {
final Result<Boolean> parsed = booleanExpressionEvaluator.eval(executionCondition);
if (parsed.isDefined() && parsed.getRest().isEmpty()) {
execute = parsed.getResult();
} else {
operation.setState(OperationState.FAILED);
throw new WorkflowOperationException(format("Unable to parse execution condition '%s'. Result is '%s'", executionCondition, parsed.toString()));
}
}
operation.setState(OperationState.RUNNING);
service.update(workflow);
try {
WorkflowOperationResult result = null;
if (execute) {
if (handler == null) {
// If there is no handler for the operation, yet we are supposed to run it, we must fail
logger.warn("No handler available to execute operation '{}'", operation.getTemplate());
throw new IllegalStateException("Unable to find a workflow handler for '" + operation.getTemplate() + "'");
}
result = handler.start(workflow, null);
} else {
// Allow for null handlers when we are skipping an operation
if (handler != null) {
result = handler.skip(workflow, null);
result.setAction(Action.SKIP);
}
}
return result;
} catch (Exception e) {
operation.setState(OperationState.FAILED);
if (e instanceof WorkflowOperationException)
throw (WorkflowOperationException) e;
throw new WorkflowOperationException(e);
}
}
Aggregations