Search in sources :

Example 46 with WorkflowOperationResult

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 47 with WorkflowOperationResult

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 48 with WorkflowOperationResult

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 49 with WorkflowOperationResult

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 50 with WorkflowOperationResult

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);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) JobCanceledException(org.opencastproject.util.JobCanceledException) WorkflowOperationAbortedException(org.opencastproject.workflow.api.WorkflowOperationAbortedException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException)

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