use of org.opencastproject.workflow.api.WorkflowSet in project opencast by opencast.
the class JobEndpoint method getTasksAsJSON.
/**
* Returns the list of tasks matching the given query as JSON Object
*
* @param query
* The worklfow query
* @return The list of matching tasks as JSON Object
* @throws JobEndpointException
* @throws NotFoundException
*/
public JObject getTasksAsJSON(WorkflowQuery query) throws JobEndpointException, NotFoundException {
// Get results
WorkflowSet workflowInstances = null;
long totalWithoutFilters = 0;
List<JValue> jsonList = new ArrayList<>();
try {
workflowInstances = workflowService.getWorkflowInstances(query);
totalWithoutFilters = workflowService.countWorkflowInstances();
} catch (WorkflowDatabaseException e) {
throw new JobEndpointException(String.format("Not able to get the list of job from the database: %s", e), e.getCause());
}
WorkflowInstance[] items = workflowInstances.getItems();
for (WorkflowInstance instance : items) {
long instanceId = instance.getId();
String series = instance.getMediaPackage().getSeriesTitle();
// Retrieve submission date with the workflow instance main job
Date created;
try {
created = serviceRegistry.getJob(instanceId).getDateCreated();
} catch (ServiceRegistryException e) {
throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", instanceId, e), e.getCause());
}
jsonList.add(obj(f("id", v(instanceId)), f("title", v(nul(instance.getMediaPackage().getTitle()).getOr(""))), f("series", v(series, Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("status", v(instance.getState().toString())), f("submitted", v(created != null ? DateTimeSupport.toUTC(created.getTime()) : ""))));
}
JObject json = obj(f("results", arr(jsonList)), f("count", v(workflowInstances.getTotalCount())), f("offset", v(query.getStartPage())), f("limit", v(jsonList.size())), f("total", v(totalWithoutFilters)));
return json;
}
use of org.opencastproject.workflow.api.WorkflowSet 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.WorkflowSet 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.WorkflowSet 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.WorkflowSet 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