Search in sources :

Example 1 with WorkflowQuery

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

the class WorkflowServiceImpl method getHoldWorkflows.

private List<WorkflowInstance> getHoldWorkflows() throws WorkflowDatabaseException {
    List<WorkflowInstance> workflows = new ArrayList<WorkflowInstance>();
    Organization organization = securityService.getOrganization();
    try {
        for (Organization org : organizationDirectoryService.getOrganizations()) {
            securityService.setOrganization(org);
            WorkflowQuery workflowQuery = new WorkflowQuery().withState(WorkflowInstance.WorkflowState.PAUSED).withCount(Integer.MAX_VALUE);
            WorkflowSet workflowSet = getWorkflowInstances(workflowQuery);
            workflows.addAll(Arrays.asList(workflowSet.getItems()));
        }
    } finally {
        securityService.setOrganization(organization);
    }
    return workflows;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Example 2 with WorkflowQuery

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

the class WorkflowServiceImplTest method testRemove.

/**
 * Test for {@link WorkflowServiceImpl#remove(long)}
 *
 * @throws Exception
 *           if anything fails
 */
@Test
public void testRemove() throws Exception {
    WorkflowInstance wi1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    WorkflowInstance wi2 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    // reload instances, because operations have no id before
    wi1 = service.getWorkflowById(wi1.getId());
    wi2 = service.getWorkflowById(wi2.getId());
    service.remove(wi1.getId());
    assertEquals(1, service.getWorkflowInstances(new WorkflowQuery()).size());
    for (WorkflowOperationInstance op : wi1.getOperations()) {
        assertEquals(0, serviceRegistry.getChildJobs(op.getId()).size());
    }
    service.remove(wi2.getId());
    assertEquals(0, service.getWorkflowInstances(new WorkflowQuery()).size());
}
Also used : WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 3 with WorkflowQuery

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

the class WorkflowServiceImplTest method testGetAllWorkflowInstances.

@Test
public void testGetAllWorkflowInstances() throws Exception {
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery()).size());
    startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    WorkflowSet workflowsInDb = service.getWorkflowInstances(new WorkflowQuery());
    Assert.assertEquals(2, workflowsInDb.getItems().length);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Example 4 with WorkflowQuery

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

the class WorkflowServiceImplTest method testPagedGetWorkflowByText.

@Test
public void testPagedGetWorkflowByText() throws Exception {
    // Ensure that the database doesn't have any workflow instances
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(100).withStartPage(0)).size());
    List<WorkflowInstance> instances = new ArrayList<WorkflowInstance>();
    instances.add(startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED));
    instances.add(startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED));
    instances.add(startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED));
    instances.add(startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED));
    instances.add(startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED));
    Assert.assertEquals(5, service.countWorkflowInstances());
    Assert.assertEquals(5, service.getWorkflowInstances(new WorkflowQuery()).getItems().length);
    // We should get the first two workflows
    WorkflowSet firstTwoWorkflows = service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(2).withStartPage(0));
    Assert.assertEquals(2, firstTwoWorkflows.getItems().length);
    // The total, non-paged number of results should be three
    Assert.assertEquals(3, firstTwoWorkflows.getTotalCount());
    // We should get the last workflow
    WorkflowSet lastWorkflow = service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(1).withStartPage(2));
    Assert.assertEquals(1, lastWorkflow.getItems().length);
    // The total, non-paged number of results should be three
    Assert.assertEquals(3, lastWorkflow.getTotalCount());
    // We should get the first linguistics (mediapackage2) workflow
    WorkflowSet firstLinguisticsWorkflow = service.getWorkflowInstances(new WorkflowQuery().withText("Linguistics").withCount(1).withStartPage(0));
    Assert.assertEquals(1, firstLinguisticsWorkflow.getItems().length);
    // The total, non-paged number of results should
    Assert.assertEquals(2, firstLinguisticsWorkflow.getTotalCount());
    // be two
    // We should get the second linguistics (mediapackage2) workflow
    WorkflowSet secondLinguisticsWorkflow = service.getWorkflowInstances(new WorkflowQuery().withText("Linguistics").withCount(1).withStartPage(1));
    Assert.assertEquals(1, secondLinguisticsWorkflow.getItems().length);
    // The total, non-paged number of results should
    Assert.assertEquals(2, secondLinguisticsWorkflow.getTotalCount());
// be two
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 5 with WorkflowQuery

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

the class WorkflowServiceImplTest method testGetWorkflowByMediaPackageId.

@Test
public void testGetWorkflowByMediaPackageId() throws Exception {
    // Ensure that the database doesn't have a workflow instance with this media package
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediapackage1.getIdentifier().toString())).size());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediapackage2.getIdentifier().toString())).size());
    WorkflowInstance instance = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    WorkflowInstance instance3 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance.getId()).getState());
    Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance2.getId()).getState());
    Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance3.getId()).getState());
    Assert.assertEquals(mediapackage1.getIdentifier().toString(), service.getWorkflowById(instance.getId()).getMediaPackage().getIdentifier().toString());
    Assert.assertEquals(mediapackage2.getIdentifier().toString(), service.getWorkflowById(instance2.getId()).getMediaPackage().getIdentifier().toString());
    Assert.assertEquals(mediapackage2.getIdentifier().toString(), service.getWorkflowById(instance3.getId()).getMediaPackage().getIdentifier().toString());
    WorkflowSet workflowsInDb = service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediapackage1.getIdentifier().toString()));
    Assert.assertEquals(1, workflowsInDb.getItems().length);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Aggregations

WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)30 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)18 Test (org.junit.Test)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)16 NotFoundException (org.opencastproject.util.NotFoundException)9 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)8 ArrayList (java.util.ArrayList)5 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)5 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)4 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Organization (org.opencastproject.security.api.Organization)3 User (org.opencastproject.security.api.User)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 WorkflowException (org.opencastproject.workflow.api.WorkflowException)3 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)3 IOException (java.io.IOException)2