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;
}
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());
}
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);
}
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
}
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);
}
Aggregations