use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowsStatistics method updateWorkflow.
public void updateWorkflow(WorkflowStatistics workflowStatistics, List<WorkflowInstance> workflows) {
this.workflowStatistics = workflowStatistics;
for (WorkflowInstance wf : workflows) {
Long count = workflowCounts.get(wf.getTemplate());
if (count == null) {
workflowCounts.put(wf.getTemplate(), 1L);
} else {
workflowCounts.put(wf.getTemplate(), count++);
}
}
sendNotification(JmxUtil.createUpdateNotification(this, sequenceNumber++, "Workflow updated"));
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class CountWorkflowsTest method testHoldAndResume.
@Test
public void testHoldAndResume() throws Exception {
// Wait for all workflows to be in paused state
WorkflowStateListener listener = new WorkflowStateListener(WorkflowState.PAUSED);
service.addWorkflowListener(listener);
Map<String, String> initialProps = new HashMap<String, String>();
initialProps.put("testproperty", "foo");
WorkflowInstance workflow1 = null;
synchronized (listener) {
workflow1 = service.start(def, mp, initialProps);
listener.wait();
mp.setIdentifier(new UUIDIdBuilderImpl().createNew());
service.start(def, mp, initialProps);
listener.wait();
}
service.removeWorkflowListener(listener);
// Test for two paused workflows in "op1"
assertEquals(2, service.countWorkflowInstances());
assertEquals(2, service.countWorkflowInstances(WorkflowState.PAUSED, null));
assertEquals(2, service.countWorkflowInstances(null, "op1"));
assertEquals(2, service.countWorkflowInstances(WorkflowState.PAUSED, "op1"));
assertEquals(0, service.countWorkflowInstances(WorkflowState.SUCCEEDED, null));
assertEquals(0, service.countWorkflowInstances(null, "op2"));
assertEquals(0, service.countWorkflowInstances(WorkflowState.SUCCEEDED, "op1"));
// Continue one of the two workflows, waiting for success
listener = new WorkflowStateListener(WorkflowState.SUCCEEDED);
service.addWorkflowListener(listener);
synchronized (listener) {
service.resume(workflow1.getId());
listener.wait();
}
service.removeWorkflowListener(listener);
// Make sure one workflow is still on hold, the other is finished.
assertEquals(2, service.countWorkflowInstances());
assertEquals(1, service.countWorkflowInstances(WorkflowState.PAUSED, null));
assertEquals(1, service.countWorkflowInstances(WorkflowState.PAUSED, "op1"));
assertEquals(1, service.countWorkflowInstances(WorkflowState.SUCCEEDED, null));
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowOperationSkippingTest method startAndWait.
protected WorkflowInstance startAndWait(WorkflowDefinition definition, MediaPackage mp, Map<String, String> properties, WorkflowState stateToWaitFor) throws Exception {
WorkflowStateListener stateListener = new WorkflowStateListener(stateToWaitFor);
service.addWorkflowListener(stateListener);
WorkflowInstance instance = null;
synchronized (stateListener) {
instance = service.start(definition, mp, properties);
stateListener.wait();
}
service.removeWorkflowListener(stateListener);
return instance;
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplAuthzTest method testWorkflowWithSecurityPolicy.
@Test
public void testWorkflowWithSecurityPolicy() throws Exception {
// Create an ACL for the authorization service to return
AccessControlList acl = new AccessControlList();
acl.getEntries().add(new AccessControlEntry("ROLE_INSTRUCTOR", Permissions.Action.READ.toString(), true));
acl.getEntries().add(new AccessControlEntry("ROLE_INSTRUCTOR", Permissions.Action.WRITE.toString(), true));
// Mock up an authorization service that always returns "true" for hasPermission()
AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authzService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
EasyMock.replay(authzService);
service.setAuthorizationService(authzService);
dao.setAuthorizationService(authzService);
// Create the workflow and its dependent object graph
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.add(new WorkflowOperationDefinitionImpl("op1", "op1", null, true));
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
// As an instructor, create a workflow. We don't care if it passes or fails. We just care about access to it.
userResponder.setResponse(instructor1);
WorkflowInstance workflow = service.start(def, mp);
service.suspend(workflow.getId());
// Ensure that this instructor can access the workflow
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the organization admin can access that workflow
userResponder.setResponse(DEFAULT_ORG_ADMIN);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the global admin can access that workflow
userResponder.setResponse(globalAdmin);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the other instructor from this organization can also see the workflow, since this is specified in the
// security policy
userResponder.setResponse(instructor2);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// TODO change to answer show in episode or series how to do it. Cool stuff
// Ensure the instructor from a different org can not see the workflow, even though they share the same role
organizationResponder.setResponse(otherOrganization);
userResponder.setResponse(instructorFromDifferentOrg);
try {
service.getWorkflowById(workflow.getId());
fail();
} catch (Exception e) {
// expected
}
assertEquals(0, service.countWorkflowInstances());
}
Aggregations