def createWorkItems(self, activity_ids, source, content_object=None): """Creates a new workitem for the activity with the given name. Raises UnknownActivityError if one or more of the given activities do not exist. """ if not activity_ids: return () utils.logger.log( logging.DEBUG, 'Creating workitems %r in %r' % (activity_ids, source)) self._creating += 1 try: passed_activities = self._veto_workitem_creation( activity_ids, source) new_ids, new = self._create_workitems_helper( passed_activities, source, content_object) source.generated_workitems += tuple(new_ids) for wi in new: controller = ILifeCycleController(wi) controller.start( "Work item was created and automatically started.") self.notifyWorkItemStateChange() finally: self._creating -= 1 # We need to explicitly check for completeness here again, because we # blocked the checks during creation. self._check_complete(self.getWorkItems('active')) return new_ids
def test_definition(self): portal = self.portal wftool = getToolByName(portal, 'workflow_manager') doc = self._init_object() instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals(controller.state, "active") wis = instance.getWorkItems() # one is the edit and one is the alarm self.assertEquals(len(wis), 2) alarm_wi = self._getAlarmWorkItem(wis) self.failUnless(alarm_wi) self.assertEquals(alarm_wi.getStatusInfo(), "deadline not yet reached") self.assertEquals(ILifeCycleController(alarm_wi).state, "active") # we're testing if the deadline is not reached now = DateTime() datestring = '%d.%m.%Y %H:' # one minute in the future doc.deadline = now + 1 / 1440.0 wftool.pingCronItems() self.assertEquals(alarm_wi.getStatusInfo(), "deadline not yet reached") self.assertEquals(ILifeCycleController(alarm_wi).state, "active") self.assertEquals(alarm_wi.getGeneratedWorkItems(), []) # create a new DateTime() object to get a date one minute in the # past doc.deadline = now - 1 / 1440.0 wftool.pingCronItems() self.assertEquals(ILifeCycleController(alarm_wi).state, "ended") self.assertEquals(alarm_wi.getStatusInfo(), "deadline exceeded") self.assertEquals(len(alarm_wi.getGeneratedWorkItems()), 0) # test failure on error for new wf instance instance.getWorkItems('active')[0].complete( 'complete') # complete wf first wftool.pingCronItems() doc.assignProcess(self.test_process) # assign new process doc.deadline = 'gaak' instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") wis = instance.getWorkItems() alarm_wi = self._getAlarmWorkItem(wis) wftool.pingCronItems() self.assertEquals(ILifeCycleController(alarm_wi).state, "failed") self.assertEquals(controller.state, "failed") self.assertEquals(len(alarm_wi.getGeneratedWorkItems()), 0)
def test_recursive(self): doc = self._init_object('workflows/termination_recursive.alf') instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") task = instance.getWorkItems()[0] task.complete(exit="complete") self.assertEquals('ended', controller.state) self.assertEquals(True, controller.completed)
def test_object_deletion(self): doc = self._init_object('workflows/termination_delete.alf') instance = doc.getInstance() container = doc.getParentNode() id = doc.getId() assert id in container.objectIds() controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals('ended', controller.state) self.assertEquals(True, controller.completed) self.assert_(id not in container.objectIds())
def test_fallout_startActivity(self): # test for fix of bug #2666 self.loginAsPortalOwner() self._create_test_users() self._import_wf('workflows/fallout_startActivity.alf') doc1 = self.create(self.portal, 'DummyContent', 'doc1') doc1.assignProcess(self.test_process) instance = doc1.getInstance() controller = ILifeCycleController(instance) controller.start('test') self.assertEqual('failed', controller.state) fallout_workitems = instance.getWorkItems('failed') self.assertEqual(1, len(fallout_workitems)) self.assertEqual('become_fallout', fallout_workitems[0].activity_id)
def test_termination(self): doc = self._init_object('workflows/termination.alf') instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals('ended', controller.state) self.assertEquals(True, controller.completed) workitems = instance.getWorkItems(state='ended') self.assertEquals(2, len(workitems)) if INTaskWorkItem.providedBy(workitems[0]): task, termination = workitems else: termination, task = workitems self.assertEquals(False, ILifeCycleController(task).completed) self.assertEquals(True, ILifeCycleController(termination).completed)
def test_grouped_schema(self): self._create_test_users() self._import_wf('workflows/multi_review.alf') portal = self.portal alf = getToolByName(portal, 'workflow_manager') portal.invokeFactory("DummyContent", "doc") doc = portal.doc doc.assignProcess(self.test_process) instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start('test') wis = instance.getWorkItems() self.assertEqual(1, len(wis)) gs = wis[0].getGroupedSchema() act_ids_expected = ['write_document'] act_ids_expected.sort() act_ids_got = [ g.activity_id for g in gs ] act_ids_got.sort() self.assertEquals(act_ids_expected, act_ids_got) self.assertEquals(gs[0].Title(), 'Dokument schreiben')
def manage_action( self, action, REQUEST, comment="no comment", ): """Multiplexes the actions.""" controller = ILifeCycleController(self) if action == "start": controller.start(comment) elif action == "reset": controller.reset(comment) elif action == "terminate": controller.terminate(comment) elif action == "restart": controller.reset(comment) controller.start(comment) elif action == "recover": controller.recover(comment) elif action == "fail": controller.fail(comment) else: raise KeyError("Not a valid action.") REQUEST.RESPONSE.redirect(self.absolute_url() + "/manage_overview")
def test_parent(self): self._import_wf('workflows/parent.alf') portal = self.portal portal.invokeFactory('DummyContent', 'doc1') doc = portal.doc1 notes = [] def setRoute(route): doc.route = route def note(note): notes.append(note) doc.setRoute = setRoute doc.note = note doc.manage_addLocalRoles('manager', ['Manager']) doc.assignProcess(self.test_process) doc.route = 'escalate' instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start('testing') # escalate again self.assertEquals('active', controller.state) ntask = doc.getWorkItemsForCurrentUser()[0].complete('escalate') self.assertEquals('active', controller.state) ntask = doc.getWorkItemsForCurrentUser()[0].complete('finish') self.assertEquals('ended', controller.state) self.assertEquals([ 'start', 'escalate', 'start', 'normal', 'escalate', 'normal', 'finish' ], notes)
##parameters=process_uid # Copyright (c) 2004-2006 gocept gmbh & co. kg # See also LICENSE.txt # af_assign_process.py,v 1.5.6.2 2005/05/02 10:08:52 zagy Exp from Products.CMFCore.utils import getToolByName from Products.Archetypes.config import UID_CATALOG from Products.AlphaFlow.interfaces import ILifeCycleController request = context.REQUEST uids = getToolByName(context, UID_CATALOG) process = uids(UID=process_uid)[0].getObject() context.assignProcess(process.current()) instance = ILifeCycleController(context.getInstance()) instance.start("started through plone ui") context.af_redirect_to_workitem_view( context.translate("Workflow started.", domain="alphaflow"))
def test_definition_(self): # Creates a simple workflow portal = self.portal self._create_test_users() self.loginAsPortalOwner() wftool = getToolByName(portal, 'workflow_manager') # Create a new process definition wftool.processes["myProcess"] = Process('myProcess') wftool.processes["myProcess"].editable(ProcessVersion()) wftool.processes["myProcess"].update() process = wftool.processes['myProcess'].current() process.setTitle("My demo process") process.setDescription("A process that demonstrates the new" "workflow tool") process.startActivity = ("write_document",) def add_activity(process, id, name): factory = zope.component.getUtility(IActivityClass, name=name) process[id] = factory() activity = process[id] activity.id = id return activity # "task" is a special kind of activity to ask people to do # something write_document = add_activity(process, "write_document", "ntask") cp_complete = ExitDefinition() cp_complete.activities = ("check_document", ) cp_complete.id = "complete" write_document._setObject("complete", cp_complete) # "vote" is an activity, that asks people if something should # proceed or not check_document = add_activity(process, "check_document", "decision") check_document.decision_modus = 'all_yes' check_document.decision_notice = u'Decide something!' # Let's create some content portal.createObject("testdocument", "DummyContent") # Initialize the process doc = portal.testdocument # error on not existing process id self.assertRaises(AttributeError, doc.assignProcess, 'not existing processId') doc.assignProcess(wftool.processes['myProcess'].current()) instance = doc.getInstance() instance.edit(write_document_assignees="author", write_document_task="Bitte eine" "Pressemitteilung zum Thema Drogenpraevention 2004 schreiben", check_document_assignees=["editor1", "editor2"]) controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals(controller.state, "active") # Check for the correct error if an non-existing activity is created self.assertRaises(UnknownActivityError, instance.createWorkItems, ['nonexistent'], instance) wftool.processes["other_process"] = Process('other_process') wftool.processes["other_process"].editable(ProcessVersion()) wftool.processes["other_process"].update() # If a process is already assigned, we can not assign another: self.assertRaises(Exception, doc.assignProcess, wftool.processes['other_process'].current()) new_instance = doc.getInstance() self.failUnless(instance.aq_base is new_instance.aq_base) self.login("author") write_document_wi = doc.getWorkItemsForCurrentUser()[0] # Test for instance.getWorkItems with optional activity_id parameter instance = doc.getInstance() self.assertEquals([], instance.getWorkItems(activity_id="michgibtsnich")) self.assertEquals([write_document_wi], instance.getWorkItems(activity_id="write_document")) write_document_wi.complete('complete') self.login("editor1") doc.getWorkItemsForCurrentUser()[0].accept() self.login("editor2") doc.getWorkItemsForCurrentUser()[0].accept() self.loginAsPortalOwner() self.assertEquals(0, len(instance.getWorkItems())) self.assertEquals(False, doc.hasInstanceAssigned())