--------------------------------
Shoobx WfMC-based Process Engine
--------------------------------
.. image:: https://github.com/Shoobx/shoobx.wfmc/actions/workflows/test.yml/badge.svg
:target: https://github.com/Shoobx/shoobx.wfmc/actions
.. image:: https://coveralls.io/repos/github/Shoobx/shoobx.wfmc/badge.svg?branch=master
:target: https://coveralls.io/github/Shoobx/shoobx.wfmc?branch=master
.. image:: https://img.shields.io/pypi/v/shoobx.wfmc.svg
:target: https://pypi.python.org/pypi/shoobx.wfmc
.. image:: https://img.shields.io/pypi/pyversions/shoobx.wfmc.svg
:target: https://pypi.python.org/pypi/shoobx.wfmc/
.. image:: https://api.codeclimate.com/v1/badges/f3c23e8e1b19a03a37e1/maintainability
:target: https://codeclimate.com/github/Shoobx/shoobx.wfmc/maintainability
:alt: Maintainability
This package provides an implementation of a Workflow-Management
Coalition (WFMC) workflow engine. The engine is provided as a
collection of workflow process components. Workflow processes can be
defined in Python or via the XML Process-Definition Language, XPDL.
Detailed Documentation
++++++++++++++++++++++
Workflow-Management Coalition Workflow Engine
=============================================
This package provides an implementation of a Workflow-Management
Coalition (WFMC) workflow engine. The engine is provided as a
collection of workflow process components. Workflow processes can be
defined in Python or via the XML Process-Definition Language, XPDL.
In this document, we'll look at Python-defined process definitions:
>>> from shoobx.wfmc import process
>>> pd = process.ProcessDefinition('sample')
The argument to the process is a process id.
A process has a number of parts. Let's look at a sample review
process::
-----------
-->| Publish |
---------- ---------- / -----------
| Author |-->| Review |- ----------
---------- ---------- \-->| Reject |
----------
Here we have a single start activity and 2 end activities. We could
have modeled this with a single end activity, but that is not
required. A single start activity *is* required. A process definition
has a set of activities, with transitions between them. Let's define
the activities for our process definition:
>>> pd.defineActivities(
... author = process.ActivityDefinition(),
... review = process.ActivityDefinition(),
... publish = process.ActivityDefinition(),
... reject = process.ActivityDefinition(),
... )
We supply activities as keyword arguments. The argument names provide
activity ids that we'll use when defining transitions:
>>> pd.defineTransitions(
... process.TransitionDefinition('author', 'review'),
... process.TransitionDefinition('review', 'publish'),
... process.TransitionDefinition('review', 'reject'),
... )
Each transition is constructed with an identifier for a starting
activity, and an identifier for an ending activity.
Before we can use a workflow definition, we have to register it as a
utility. This is necessary so that process instances can find their
definitions. In addition, the utility name must match the process id:
>>> import zope.component
>>> from shoobx.wfmc.process import StaticProcessDefinitionFactory
>>> pdfactory = StaticProcessDefinitionFactory()
>>> zope.component.provideUtility(pdfactory)
>>> pdfactory.register(pd)
Now, with this definition, we can execute our workflow. We haven't
defined any work yet, but we can see the workflow execute. We'll see
the workflow executing by registering a subscriber that logs workflow
events:
>>> def log_workflow(event):
... print (event)
>>> import zope.event
>>> zope.event.subscribers.append(log_workflow)
To use the workflow definition, we need to create an instance:
>>> proc = pd()
Now, if we start the workflow:
>>> proc.start()
ProcessStarted(Process('sample'))
Transition(None, Activity('sample.author'))
ActivityStarted(Activity('sample.author'))
ActivityFinished(Activity('sample.author'))
Transition(Activity('sample.author'), Activity('sample.review'))
ActivityStarted(Activity('sample.review'))
ActivityFinished(Activity('sample.review'))
Transition(Activity('sample.review'), Activity('sample.publish'))
ActivityStarted(Activity('sample.publish'))
ActivityFinished(Activity('sample.publish'))
ProcessFinished(Process('sample'))
we see that we transition immediately into the author activity, then
into review and publish. Normally, we'd need to do some work in each
activity, and transitions would continue only after work had been
done, however, in this case, we didn't define any work, so each
activity completed immediately.
Note that we didn't transition into the rejected activity. By
default, when an activity is completed, the first transition for which
its condition evaluates to `True` is used. By default, transitions
have boolean conditions that evaluate to `True`, so the transition
to `publish` is used because it was defined before the transition to
`reject`. What we want is to transition to `publish` if a reviewer
approves the content for publication, but to `reject` if the reviewer
rejects the content for publication. We can use a condition for this:
>>> pd = process.ProcessDefinition('sample')
>>> pdfactory.register(pd)
>>> pd.defineActivities(
... author = process.ActivityDefinition(),
... review = process.ActivityDefinition(),
... publish = process.ActivityDefinition(),
... reject = process.ActivityDefinition(),
... )
>>> pd.defineTransitions(
... process.TransitionDefinition('author', 'review'),
... process.TransitionDefinition(
... 'review', 'publish',
... condition=lambda proc: proc.workflowRelevantData.publish),
... process.TransitionDefinition('review', 'reject'),
... )
We redefined the workflow process, specifying a condition for the
transition to `publish`. Boolean conditions are just callable objects that
take a data object and return a boolean value. The data object is
called "workflow-relevant data". A process instance has a data object
containing this data. In the example, above, the condition simply
returned the value of the `publish` attribute. How does this attribute
get set? It needs to be set by the review activity. To do that, we
need to arrange for the activity to set the data. This brings us to
applications.
Process definitions are meant to be used with different
applications. For this reason, process definitions don't include
application logic. What they do include is a specifications of the
applications to be invoked and the flow of work-flow-relevant data to
and from the application. Now, we can define our applications:
>>> pd.defineApplications(
... author = process.Application(),
... review = process.Application(
... process.OutputParameter('publish')),
... publish = process.Application(),
... reject = process.Application(),
... )
We used the same names for the applications that we used for our
activities. This isn't required, but is a common practice. Note that
the `review` application includes a specification of an output
parameter. Now that we've defined our applications, we need to modify
our activities to use them:
>>> pd.activities['author'].addApplication('author')
>>> pd.activities['review'].addApplication('review', ['publish'])
>>> pd.activities['publish'].addApplication('publish')
>>> pd.activities['reject'].addApplication('reject')
An activity can use many applications, so we call `addApplication`.
In the application definition for the 'review' application, we
provided the name of a workflow-relevent data variable corresponding
to the output parameter defined for the application. When using an
application in an activity, a workflow-relevent data variable name
must be provided for each of the parameters in the identified
applications's signature. When an application is used in an activity,
workflow-relevent data are passed for each of the input parameters and
are set by each of the output parameters. In this example, the output
parameter, will be used to add a `publish` attribute to the workflow
relevant data.
Participants
------------
We've declared some applications, and we've wired them up to
activities, but we still haven't specified any application code. Before
we can specify application code, we need to consider who will be
performing the application. Workflow applications are normally
executed by people, or other external actors. As with applications,
process definitions allow participants in the workflow to be declared
and identified with activities. We declare participants much as we
declare applications, except without parameters:
>>> pd.defineParticipants(
... author = process.Participant(),
... reviewer = process.Participant(),
... )
In this case, we happened to reuse an activity name for one, but
not both of the participants. Having defined these participants, we
can associate them with activities:
>>> pd.activities['author'].definePerformer('author')
>>> pd.activities['review'].definePerformer('reviewer')
Application Integration
-----------------------
To use a process definition to control application logic, we need to
associate it with an "integration" object.
When a process needs to get a participant, it calls createParticipant
on its integration attribute, passing the process id and the
performer id. If an activity doesn't have a
performer, then the procedure above is used with an empty performer id.
Similarly, when a process needs a work item, it calls createWorkItem
on its integration attribute, passing the process id and the
application id.
Work items provide a `start` method, which is used to start the work
and pass input arguments. It is the responsibility of the work item,
at some later time, to call the `workItemFinished` method on the
activity, to notify the activity that the work item was
completed. Output parameters are passed to the `workItemFinished`
method.
A simple way to create integration objects is with
`shoobx.wfmc.attributeintegration.AttributeIntegration`.
>>> from shoobx.wfmc.attributeintegration import AttributeIntegration
>>> integration = AttributeIntegration()
>>> pd.integration = integration
We'll start by defining a simple Participant class:
>>> import zope.interface
>>> from shoobx.wfmc import interfaces
>>> @zope.interface.implementer(interfaces.IParticipant)
... class Participant(object):
... zope.component.adapts(interfaces.IActivity)
...
... def __init__(self, activity, process):
... self.activity = activity
We set attributes on the integration for each participant:
>>> integration.authorParticipant = Participant
>>> integration.reviewerParticipant = Participant
We also define an attribute for participants for activities that don't
have performers:
>>> integration.Participant = Participant
Now we'll define our work-items. First we'll define some classes:
>>> work_list = []
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class ApplicationBase:
... zope.component.adapts(interfaces.IParticipant)
...
... def __init__(self, participant, process, activity):
... self.participant = participant
... work_list.append(self)
...
... def start(self, args):
... pass
...
... def finish(self):
... self.participant.activity.workItemFinished(self)
>>> class Review(ApplicationBase):
... def finish(self, publish):
... output = {'publish': publish}
... self.participant.activity.workItemFinished(self, output)
>>> class Publish(ApplicationBase):
... def start(self, args):
... print ("Published")
... self.finish()
>>> class Reject(ApplicationBase):
... def start(self, args):
... print ("Rejected")
... self.finish()
and then we'll hook them up with the integration object:
>>> integration.authorWorkItem = ApplicationBase
>>> integration.reviewWorkItem = Review
>>> integration.publishWorkItem = Publish
>>> integration.rejectWorkItem = Reject
Using workflow processes
------------------------
To use a process definition, instantiate it and call its start method
to start execution:
>>> proc = pd()
>>> proc.start()
... # doctest: +NORMALIZE_WHITESPACE
ProcessStarted(Process('sample'))
Transition(None, Activity('sample.author'))
ActivityStarted(Activity('sample.author'))
WorkItemStarting('author')
WorkItemStarted('author')
We transition into the author activity and wait for work to get done.
To move forward, we need to get at the authoring work item, so we can
finish it. Our work items add themselves to a work list, so we can
get the item from the list.
>>> item = work_list.pop()
Now we can finish the work item, by calling its finish method:
>>> item.finish()
WorkItemFinished('author')
ActivityFinished(Activity('sample.author'))
Transition(Activity('sample.author'), Activity('sample.review'))
ActivityStarted(Activity('sample.review'))
WorkItemStarting('review')
WorkItemStarted('review')
We see that we transitioned to the review activity. Note that the
`finish` method isn't a part of the workflow APIs. It was defined by
our sample classes. Other applications could use different mechanisms.
Now, we'll finish the review process by calling the review work item's
`finish`. We'll pass `False`, indicating that the content should not
be published:
>>> work_list.pop().finish(False)
WorkItemFinished('review')
ActivityFinished(Activity('sample.review'))
Transition(Activity('sample.review'), Activity('sample.reject'))
ActivityStarted(Activity('sample.reject'))
WorkItemStarting('reject')
Rejected
WorkItemFinished('reject')
ActivityFinished(Activity('sample.reject'))
ProcessFinished(Process('sample'))
WorkItemStarted('reject')
Ordering output transitions
---------------------------
Normally, outgoing transitions are ordered in the order of transition
definition and all transitions from a given activity are used.
If transitions are defined in an inconvenient order, then the workflow
might not work as expected. For example, let's modify the above
process by switching the order of definition of some of the
transitions. We'll reuse our integration object from the previous
example by passing it to the definition constructor:
>>> pd = process.ProcessDefinition('sample', integration)
>>> pdfactory.register(pd)
>>> pd.defineActivities(
... author = process.ActivityDefinition(),
... review = process.ActivityDefinition(),
... publish = process.ActivityDefinition(),
... reject = process.ActivityDefinition(),
... )
>>> pd.defineTransitions(
... process.TransitionDefinition('author', 'review'),
... process.TransitionDefinition('review', 'reject'),
... process.TransitionDefinition(
... 'review', 'publish',
... condition=lambda proc: proc.workflowRelevantData.publish),
... )
>>> pd.defineApplications(
... author = process.Application(),
... review = process.Application(
... process.OutputParameter('publish')),
... publish = process.Application(),
... reject = process.Application(),
... )
>>> pd.activities['author'].addApplication('author')
>>> pd.activities['review'].addApplication('review', ['publish'])
>>> pd.activities['publish'].addApplication('publish')
>>> pd.activities['reject'].addApplication('reject')
>>> pd.defineParticipants(
... author = process.Participant(),
... reviewer = process.Participant(),
... )
>>> pd.activities['author'].definePerformer('author')
>>> pd.activities['review'].definePerformer('reviewer')
and run our process:
>>> proc = pd()
>>> proc.start()
... # doctest: +NORMALIZE_WHITESPACE
ProcessStarted(Process('sample'))
Transition(None, Activity('sample.author'))
ActivityStarted(Activity('sample.author'))
WorkItemStarting('author')
WorkItemStarted('author')
>>> work_list.pop().finish()
WorkItemFinished('author')
ActivityFinished(Activity('sample.author'))
Transition(Activity('sample.author'), Activity('sample.review'))
ActivityStarted(Activity('sample.review'))
WorkItemStarting('review')
WorkItemStarted('review')
This time, we'll say that we should publish:
>>> work_list.pop().finish(True)
WorkItemFinished('review')
ActivityFinished(Activity('sample.review'))
Transition(Activity('sample.review'), Activity('sample.reject'))
ActivityStarted(Activity('sample.reject'))
WorkItemStarting('reject')
Rejected
WorkItemFinished('reject')
ActivityFinished(Activity('sample.reject'))
ProcessFinished(Process('sample'))
WorkItemStarted('reject')
But we went to the reject activity anyway. Why? Because transitions
are tested in order. Because the transition to the reject activity was
tested first and had no condition, we followed it without checking the
condition for the transition to the publish activity. We can fix this
by specifying outgoing transitions on the reviewer activity directly.
To do this, we'll also need to specify ids in our transitions. Let's
redefine the process:
>>> pd = process.ProcessDefinition('sample', integration)
>>> pdfactory.register(pd)
>>> pd.defineActivities(
... author = process.ActivityDefinition(),
... review = process.ActivityDefinition(),
... publish = process.ActivityDefinition(),
... reject = process.ActivityDefinition(),
... )
>>> pd.defineTransitions(
... process.TransitionDefinition('author', 'review'),
... process.TransitionDefinition('review', 'reject', id='reject'),
... process.TransitionDefinition(
... 'review', 'publish', id='publish',
... condition=lambda proc: proc.workflowRelevantData.publish),
... )
>>> pd.defineApplications(
... author = process.Application(),
... review = process.Application(
... process.OutputParameter('publish')),
... publish = process.Application(),
... reject = process.Application(),
... )
>>> pd.activities['author'].addApplication('author')
>>> pd.activities['review'].addApplication('review', ['publish'])
>>> pd.activities['publish'].addApplication('publish')
>>> pd.activities['reject'].addApplication('reject')
>>> pd.defineParticipants(
... author = process.Participant(),
... reviewer = process.Participant(),
... )
>>> pd.activities['author'].definePerformer('author')
>>> pd.activities['review'].definePerformer('reviewer')
>>> pd.activities['review'].addOutgoing('publish')
>>> pd.activities['review'].addOutgoing('reject')
Now, when we run the process, we'll go to the publish activity as
expected:
>>> proc = pd()
>>> proc.start()
... # doctest: +NORMALIZE_WHITESPACE
ProcessStarted(Process('sample'))
Transition(None, Activity('sample.author'))
ActivityStarted(Activity('sample.author'))
WorkItemStarting('author')
WorkItemStarted('author')
>>> work_list.pop().finish()
WorkItemFinished('author')
ActivityFinished(Activity('sample.author'))
Transition(Activity('sample.author'), Activity('sample.review'))
ActivityStarted(Activity('sample.review'))
WorkItemStarting('review')
WorkItemStarted('review')
>>> work_list.pop().finish(True)
WorkItemFinished('review')
ActivityFinished(Activity('sample.review'))
Transition(Activity('sample.review'), Activity('sample.publish'))
ActivityStarted(Activity('sample.publish'))
WorkItemStarting('publish')
Published
WorkItemFinished('publish')
ActivityFinished(Activity('sample.publish'))
ProcessFinished(Process('sample'))
WorkItemStarted('publish')
Let's see the other way also, where we should transition to reject:
>>> proc = pd()
>>> proc.start()
... # doctest: +NORMALIZE_WHITESPACE
ProcessStarted(Process('sample'))
Transition(None, Activity('sample.author'))
ActivityStarted(Activity('sample.author'))
WorkItemStarting('author')
WorkItemStarted('author')
>>> work_list.pop().finish()
WorkItemFinished('author')
ActivityFinished(Activity('sample.author'))
Transition(Activity('sample.author'), Activity('sample.review'))
ActivityStarted(Activity('sample.review'))
WorkItemStarting('review')
WorkItemStarted('review')
>>> work_list.pop().finish(False)
WorkItemFinished('review')
ActivityFinished(Activity('sample.review'))
Transition(Activity('sample.review'), Activity('sample.reject'))
ActivityStarted(Activity('sample.reject'))
WorkItemStarting('reject')
Rejected
WorkItemFinished('reject')
ActivityFinished(Activity('sample.reject'))
ProcessFinished(Process('sample'))
WorkItemStarted('reject')
Complex Flows
-------------
Lets look at a more complex example. In this example, we'll extend
the process to work with multiple reviewers. We'll also make the
work-list handling a bit more sophisticated. We'll also introduce
some new concepts:
- splits and joins
- process arguments
Consider the publication
process shown below::
Author: Tech Tech Editorial
Reviewer 1: Reviewer 2: Reviewer:
=========== =========== =========== ==============
---------
----------------------------------------------------| Start |
/ ---------
|
V
-----------
| Prepare |<------------------------------\
----------- \
| ------------ \
| | Tech |--------------- \ \
|------->| Review 1 | V |
| ------------ ---------- -------------
\ | Tech | | Editorial | ----------
------------------->| Review |--->| Review |-->| Reject |
| 2 | ------------- ----------
---------- | |
----------- / \
| Prepare | / \--------\
| Final |<----------------------------/ |
----------- |
^ | ---------- V
| \------------------------------->| Review | -----------
\ | Final |----->| Publish |
------------------------------------| | -----------
----------
Here we've arranged the process diagram into columns, with the
activities for each participant. We have four participants, the
author, two technical reviewers, and an editorial reviewer. The
author prepares a draft. The author sends the draft to *both*
technical reviewers for review. When the technical reviews have
completed, the editorial review does an initial editorial
review. Based on the technical reviews, the editor may choose to:
- Reject the document
- Publish the document as is
- Request technical changes (based on the technical reviewers'
comments), or
- Request editorial changes.
If technical changes are required, the work flows back to the
"Prepare" activity. If editorial changes are necessary, then work
flows to the "Prepare Final" activity. When the author has made the
editorial changes, work flows to "Review Final". The editor may
request additional changes, in which case, work flows back to "Prepare
Final", otherwise, the work flows to "Publish".
This example illustrates different kinds of "joins" and "splits". The
term "join" refers to the way incoming transitions to an activity are
handled. There are two kinds of joins: "and" and "xor". With an "and"
join, the activity waits for each of the incoming transitions. In
this example, the inputs to the "Editorial Review" activity form an
"and" join. Editorial review waits until each of the technical
reviews are completed. The rest of the joins in this example are
"xor" joins. The activity starts on any transition into the activity.
The term "split" refers to way outgoing transitions from an activity
are handled. Normally, exactly one transition out of an activity is
used. This is called an "xor" split. With an "and" split, all
transitions with boolean conditions that evaluate to `True` are used.
In this example, the "Prepare" activity has an "and" split. Work
flows simultaneously to the two technical review activities. The rest
of the splits in this example are "xor" splits.
Lets create our new workflow process. We'll reuse our existing
integration object:
>>> Publication = process.ProcessDefinition('Publication')
>>> Publication.integration = integration
>>> pdfactory.register(Publication)
>>> Publication.defineActivities(
... start = process.ActivityDefinition("Start"),
... prepare = process.ActivityDefinition("Prepare"),
... tech1 = process.ActivityDefinition("Technical Review 1"),
... tech2 = process.ActivityDefinition("Technical Review 2"),
... review = process.ActivityDefinition("Editorial Review"),
... final = process.ActivityDefinition("Final Preparation"),
... rfinal = process.ActivityDefinition("Review Final"),
... publish = process.ActivityDefinition("Publish"),
... reject = process.ActivityDefinition("Reject"),
... )
Here, we've passed strings to the activity definitions providing
names. Names must be either unicode or ASCII strings.
We define our transitions:
>>> Publication.defineTransitions(
... process.TransitionDefinition('start', 'prepare'),
... process.TransitionDefinition('prepare', 'tech1'),
... process.TransitionDefinition('prepare', 'tech2'),
... process.TransitionDefinition('tech1', 'review'),
... process.TransitionDefinition('tech2', 'review'),
...
... process.TransitionDefinition(
... 'review', 'reject',
... condition=lambda proc: not proc.workflowRelevantData.publish
... ),
... process.TransitionDefinition(
... 'review', 'prepare',
... condition=lambda proc: proc.workflowRelevantData.tech_changes
... ),
... process.TransitionDefinition(
... 'review', 'final',
... condition=lambda proc: proc.workflowRelevantData.ed_changes
... ),
... process.TransitionDefinition('review', 'publish'),
...
... process.TransitionDefinition('final', 'rfinal'),
... process.TransitionDefinition(
... 'rfinal', 'final',
... condition=lambda proc: proc.workflowRelevantData.ed_changes
... ),
... process.TransitionDefinition('rfinal', 'publish'),
... )
We specify our "and" split and join:
>>> Publication.activities['prepare'].andSplit(True)
>>> Publication.activities['review'].andJoin(True)
We define our participants and applications:
>>> Publication.defineParticipants(
... author = process.Participant("Author"),
... tech1 = process.Participant("Technical Reviewer 1"),
... tech2 = process.Participant("Technical Reviewer 2"),
... reviewer = process.Participant("Editorial Reviewer"),
... )
>>> Publication.defineApplications(
... prepare = process.Application(),
... tech_review = process.Application(
... process.OutputParameter('publish'),
... process.OutputParameter('tech_changes'),
... ),
... ed_review = process.Application(
... process.InputParameter('publish1'),
... process.InputParameter('tech_changes1'),
... process.InputParameter('publish2'),
... process.InputParameter('tech_changes2'),
... process.OutputParameter('publish'),
... process.OutputParameter('tech_changes'),
... process.OutputParameter('ed_changes'),
... ),
... publish = process.Application(),
... reject = process.Application(),
... final = process.Application(),
... rfinal = process.Application(
... process.OutputParameter('ed_changes'),
... ),
... )
>>> Publication.activities['prepare'].definePerformer('author')
>>> Publication.activities['prepare'].addApplication('prepare')
>>> Publication.activities['tech1'].definePerformer('tech1')
>>> Publication.activities['tech1'].addApplication(
... 'tech_review', ['publish1', 'tech_changes1'])
>>> Publication.activities['tech2'].definePerformer('tech2')
>>> Publication.activities['tech2'].addApplication(
... 'tech_review', ['publish2', 'tech_changes2'])
>>> Publication.activities['review'].definePerformer('reviewer')
>>> Publication.activities['review'].addApplication(
... 'ed_review',
... ['publish1', 'tech_changes1', 'publish2', 'tech_changes2',
... 'publish', 'tech_changes', 'ed_changes'],
... )
>>> Publication.activities['final'].definePerformer('author')
>>> Publication.activities['final'].addApplication('final')
>>> Publication.activities['rfinal'].definePerformer('reviewer')
>>> Publication.activities['rfinal'].addApplication(
... 'rfinal', ['ed_changes'],
... )
>>> Publication.activities['publish'].addApplication('publish')
>>> Publication.activities['reject'].addApplication('reject')
We want to be able to specify an author when we start the process.
We'd also like to be told the final disposition of the process. To
accomplish this, we'll define parameters for our process:
>>> Publication.defineParameters(
... process.InputParameter('author'),
... process.OutputParameter('publish'),
... )
Now that we've defined the process, we need to provide participant and
application components. Let's start with our participants. Rather
than sharing a single work list, we'll give each user their own
work list. We'll also create preexisting participants and return
them. Finally, we'll create multiple authors and use the selected one:
>>> class User:
... def __init__(self):
... self.work_list = []
>>> authors = {'bob': User(), 'ted': User(), 'sally': User()}
>>> reviewer = User()
>>> tech1 = User()
>>> tech2 = User()
>>> class Author(Participant):
... def __init__(self, activity, process):
... Participant.__init__(self, activity, process)
... author_name = activity.process.workflowRelevantData.author
... print(("Author `%s` selected" % author_name))
... self.user = authors[author_name]
In this example, we need to define a separate attribute for each participant:
>>> integration.authorParticipant = Author
When the process is created, the author name will be passed in and
assigned to the workflow-relevant data. Our author class uses this
information to select the named user.
>>> class Reviewer(Participant):
... user = reviewer
>>> integration.reviewerParticipant = Reviewer
>>> class Tech1(Participant):
... user = tech1
>>> integration.tech1Participant = Tech1
>>> class Tech2(Participant):
... user = tech2
>>> integration.tech2Participant = Tech2
We'll use our orginal participation class for activities without
performers:
>>> integration.Participant = Participant
Now we'll create our applications. Let's start with our author:
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class ApplicationBase(object):
... zope.component.adapts(interfaces.IParticipant)
...
... def __init__(self, participant, process, activity):
... self.participant = participant
... self.activity = participant.activity
... participant.user.work_list.append(self)
...
... def start(self, args):
... pass
...
... def finish(self):
... self.participant.activity.workItemFinished(self)
>>> class Prepare(ApplicationBase):
...
... def summary(self):
... process = self.activity.process
... doc = getattr(process.applicationRelevantData, 'doc', '')
... if doc:
... print ('Previous draft:')
... print (doc)
... print ('Changes we need to make:')
... for change in process.workflowRelevantData.tech_changes:
... print (change)
... else:
... print ('Please write the initial draft')
...
... def finish(self, doc):
... self.activity.process.applicationRelevantData.doc = doc
... super(Prepare, self).finish()
>>> integration.prepareWorkItem = Prepare
Since we used the prepare application for revisions as well as initial
preparation, we provide a summary method to show us what we have to do.
Here we get the document created by the author passed in as an
argument to the finish method. In a more realistic implementation,
the author task would create the document at the start of the task and
provide a user interface for the user to edit it. We store the
document as application-relevant data, since we'll want reviewers to
be able to access it, but we don't need it directly for workflow
control.
>>> class TechReview(ApplicationBase):
...
... def getDoc(self):
... return self.activity.process.applicationRelevantData.doc
...
... def finish(self, decision, changes):
... output = {'publish': decision, 'tech_changes': changes}
... self.activity.workItemFinished(self, output)
>>> integration.tech_reviewWorkItem = TechReview
Here, we provided a method to access the original document.
>>> class Review(TechReview):
...
... def start(self, args):
... publish1 = args['publish1']
... publish2 = args['publish2']
... changes1 = args['tech_changes1']
... changes2 = args['tech_changes2']
... if not (publish1 and publish2):
... output = {'publish': False,
... 'tech_changes': changes1 + changes2,
... 'ed_changes': ()}
... # Reject if either tech reviewer rejects
... self.activity.workItemFinished(
... self, output)
...
... if changes1 or changes2:
... output = {'publish': True,
... 'tech_changes': changes1 + changes2,
... 'ed_changes': ()}
... # we won't do anything if there are tech changes
... self.activity.workItemFinished(
... self, output)
...
... def finish(self, ed_changes):
... output = {'publish': True, 'tech_changes': (), 'ed_changes': ed_changes}
... self.activity.workItemFinished(self, output)
>>> integration.ed_reviewWorkItem = Review
In this implementation, we decided to reject outright if either
technical editor recommended rejection and to send work back to
preparation if there are any technical changes. We also subclassed
`TechReview` to get the `getDoc` method.
We'll reuse the `publish` and `reject` application from the previous
example.
>>> class Final(ApplicationBase):
...
... def summary(self):
... process = self.activity.process
... doc = getattr(process.applicationRelevantData, 'doc', '')
... print ('Previous draft:')
... print((self.activity.process.applicationRelevantData.doc))
... print ('Changes we need to make:')
... for change in process.workflowRelevantData.ed_changes:
... print (change)
...
... def finish(self, doc):
... self.activity.process.applicationRelevantData.doc = doc
... super(Final, self).finish()
>>> integration.finalWorkItem = Final
In our this application, we simply update the document to reflect
changes.
>>> class ReviewFinal(TechReview):
...
... def finish(self, ed_changes):
... output = {'ed_changes': ed_changes}
... self.activity.workItemFinished(self, output)
>>> integration.rfinalWorkItem = ReviewFinal
Our process now returns data. When we create a process, we need to
supply an object that it can call back to:
>>> @zope.interface.implementer(interfaces.IProcessContext)
... class PublicationContext:
...
... def processFinished(self, process, decision):
... self.decision = decision
Now, let's try out our process:
>>> context = PublicationContext()
>>> proc = Publication(context)
>>> proc.start('bob')
ProcessStarted(Process('Publication'))
Transition(None, Activity('Publication.start'))
ActivityStarted(Activity('Publication.start'))
ActivityFinished(Activity('Publication.start'))
Author `bob` selected
Transition(Activity('Publication.start'), Activity('Publication.prepare'))
ActivityStarted(Activity('Publication.prepare'))
WorkItemStarting('prepare')
WorkItemStarted('prepare')
We should have added an item to bob's work list. Let's get it and
finish it, submitting a document:
>>> item = authors['bob'].work_list.pop()
>>> item.finish("I give my pledge, as an American\n"
... "to save, and faithfully to defend from waste\n"
... "the natural resources of my Country.")
WorkItemFinished('prepare')
ActivityFinished(Activity('Publication.prepare'))
Transition(Activity('Publication.prepare'), Activity('Publication.tech1'))
ActivityStarted(Activity('Publication.tech1'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
Transition(Activity('Publication.prepare'), Activity('Publication.tech2'))
ActivityStarted(Activity('Publication.tech2'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
Notice that we transitioned to *two* activities, `tech1` and
`tech2`. This is because the prepare activity has an "and" split.
Now we'll do a tech review. Let's see what tech1 has:
>>> item = tech1.work_list.pop()
>>> print((item.getDoc()))
I give my pledge, as an American
to save, and faithfully to defend from waste
the natural resources of my Country.
Let's tell the author to change "American" to "Earthling":
>>> item.finish(True, ['Change "American" to "Earthling"'])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech1'))
Transition(Activity('Publication.tech1'), Activity('Publication.review'))
Here we transitioned to the editorial review activity, but we didn't
start it. This is because the editorial review activity has an "and"
join, meaning that it won't start until both transitions have
occurred.
Now we'll do the other technical review:
>>> item = tech2.work_list.pop()
>>> item.finish(True, ['Change "Country" to "planet"'])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech2'))
Transition(Activity('Publication.tech2'), Activity('Publication.review'))
ActivityStarted(Activity('Publication.review'))
WorkItemStarting('ed_review')
WorkItemFinished('ed_review')
ActivityFinished(Activity('Publication.review'))
Author `bob` selected
Transition(Activity('Publication.review'), Activity('Publication.prepare'))
ActivityStarted(Activity('Publication.prepare'))
WorkItemStarting('prepare')
WorkItemStarted('prepare')
WorkItemStarted('ed_review')
Now when we transitioned to the editorial review activity, we started
it, because each of the input transitions had happened. Our editorial
review application automatically sent the work back to preparation,
because there were technical comments. Of course the author is still `bob`.
Let's address the comments:
>>> item = authors['bob'].work_list.pop()
>>> item.summary()
Previous draft:
I give my pledge, as an American
to save, and faithfully to defend from waste
the natural resources of my Country.
Changes we need to make:
Change "American" to "Earthling"
Change "Country" to "planet"
>>> item.finish("I give my pledge, as an Earthling\n"
... "to save, and faithfully to defend from waste\n"
... "the natural resources of my planet.")
WorkItemFinished('prepare')
ActivityFinished(Activity('Publication.prepare'))
Transition(Activity('Publication.prepare'), Activity('Publication.tech1'))
ActivityStarted(Activity('Publication.tech1'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
Transition(Activity('Publication.prepare'), Activity('Publication.tech2'))
ActivityStarted(Activity('Publication.tech2'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
As before, after completing the initial edits, we start the technical
review activities again. We'll review it again. This time, we have no
comments, because the author applied our requested changes:
>>> item = tech1.work_list.pop()
>>> item.finish(True, [])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech1'))
Transition(Activity('Publication.tech1'), Activity('Publication.review'))
>>> item = tech2.work_list.pop()
>>> item.finish(True, [])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech2'))
Transition(Activity('Publication.tech2'), Activity('Publication.review'))
ActivityStarted(Activity('Publication.review'))
WorkItemStarting('ed_review')
WorkItemStarted('ed_review')
This time, we are left in the technical review activity because there
weren't any technical changes. We're ready to do our editorial review.
We'll request an editorial change:
>>> item = reviewer.work_list.pop()
>>> print((item.getDoc()))
I give my pledge, as an Earthling
to save, and faithfully to defend from waste
the natural resources of my planet.
>>> item.finish(['change "an" to "a"'])
WorkItemFinished('ed_review')
ActivityFinished(Activity('Publication.review'))
Author `bob` selected
Transition(Activity('Publication.review'), Activity('Publication.final'))
ActivityStarted(Activity('Publication.final'))
WorkItemStarting('final')
WorkItemStarted('final')
Because we requested editorial changes, we transitioned to the final
editing activity, so that the author (still bob) can make the changes:
>>> item = authors['bob'].work_list.pop()
>>> item.summary()
Previous draft:
I give my pledge, as an Earthling
to save, and faithfully to defend from waste
the natural resources of my planet.
Changes we need to make:
change "an" to "a"
>>> item.finish("I give my pledge, as a Earthling\n"
... "to save, and faithfully to defend from waste\n"
... "the natural resources of my planet.")
WorkItemFinished('final')
ActivityFinished(Activity('Publication.final'))
Transition(Activity('Publication.final'), Activity('Publication.rfinal'))
ActivityStarted(Activity('Publication.rfinal'))
WorkItemStarting('rfinal')
WorkItemStarted('rfinal')
We transition to the activity for reviewing the final edits. We
review the document and approve it for publication:
>>> item = reviewer.work_list.pop()
>>> print((item.getDoc()))
I give my pledge, as a Earthling
to save, and faithfully to defend from waste
the natural resources of my planet.
>>> item.finish([])
WorkItemFinished('rfinal')
ActivityFinished(Activity('Publication.rfinal'))
Transition(Activity('Publication.rfinal'), Activity('Publication.publish'))
ActivityStarted(Activity('Publication.publish'))
WorkItemStarting('publish')
Published
WorkItemFinished('publish')
ActivityFinished(Activity('Publication.publish'))
ProcessFinished(Process('Publication'))
WorkItemStarted('publish')
At this point, the rest of the process finished automatically. In
addition, the decision was recorded in the process context object:
>>> proc.workflowRelevantData.publish
True
Coming Soon
------------
- Timeouts/exceptions
See also
---------
http://www.wfmc.org
http://www.wfmc.org/standards/standards.htm
===========
XPDL Import
===========
We can import process definitions from files in the XML Process
Definition Language (XPDL) format. An XPDL file contains multiple
process definitions arranged in a package. When we load the file, we
get a package containing some number of process definitions.
Let's look at an example. The file `publication.xpdl`
contains a definition for the publication example developed in the
"README.txt" file. We can read it using the xpdl module:
>>> from shoobx.wfmc import xpdl
>>> import os
>>> package = xpdl.read(open(os.path.join(this_directory,
... 'publication-1.0.xpdl')))
This package contains a single definition:
>>> package
{'Publication': ProcessDefinition('Publication')}
>>> pd = package['Publication']
>>> from shoobx.wfmc.attributeintegration import AttributeIntegration
>>> integration = AttributeIntegration()
>>> pd.integration = integration
Now, having read the process definition, we can use it as we did
before (in "README.txt"). As before, we'll create an event subscriber
so that we can see what's going on:
>>> def log_workflow(event):
... print(event)
>>> import zope.event
>>> zope.event.subscribers.append(log_workflow)
and we'll register the process definition as a utility:
>>> import zope.component
>>> from shoobx.wfmc.process import StaticProcessDefinitionFactory
>>> pdfactory = StaticProcessDefinitionFactory()
>>> zope.component.provideUtility(pdfactory)
>>> pdfactory.register(pd)
and we'll define and register participant and application adapters:
>>> import zope.interface
>>> from shoobx.wfmc import interfaces
>>> @zope.interface.implementer(interfaces.IParticipant)
... class Participant(object):
... zope.component.adapts(interfaces.IActivity)
...
... def __init__(self, activity, process):
... self.activity = activity
>>> class User:
... def __init__(self):
... self.work_list = []
>>> authors = {'bob': User(), 'ted': User(), 'sally': User()}
>>> reviewer = User()
>>> tech1 = User()
>>> tech2 = User()
>>> class Author(Participant):
... def __init__(self, activity, process):
... Participant.__init__(self, activity, process)
... author_name = activity.process.workflowRelevantData.author
... print("Author `%s` selected" % author_name)
... self.user = authors[author_name]
>>> integration.authorParticipant = Author
>>> class Reviewer(Participant):
... user = reviewer
>>> integration.reviewerParticipant = Reviewer
>>> class Tech1(Participant):
... user = tech1
>>> integration.tech1Participant = Tech1
>>> class Tech2(Participant):
... user = tech2
>>> integration.tech2Participant = Tech2
>>> integration.SystemParticipant = Participant
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class ApplicationBase(object):
... zope.component.adapts(interfaces.IParticipant)
...
... def __init__(self, participant, process, activity):
... self.participant = participant
... self.activity = participant.activity
... participant.user.work_list.append(self)
...
... def start(self, args):
... pass
...
... def finish(self):
... self.participant.activity.workItemFinished(self)
>>> class Prepare(ApplicationBase):
...
... def summary(self):
... process = self.activity.process
... doc = getattr(process.applicationRelevantData, 'doc', '')
... if doc:
... print('Previous draft:')
... print(doc)
... print('Changes we need to make:')
... for change in process.workflowRelevantData.tech_changes:
... print(change)
... else:
... print('Please write the initial draft')
...
... def finish(self, doc):
... self.activity.process.applicationRelevantData.doc = doc
... super(Prepare, self).finish()
>>> integration.prepareWorkItem = Prepare
>>> class TechReview(ApplicationBase):
...
... def getDoc(self):
... return self.activity.process.applicationRelevantData.doc
...
... def finish(self, decision, changes):
... output = {'publish': decision, 'tech_changes': changes}
... self.activity.workItemFinished(self, output)
>>> integration.tech_reviewWorkItem = TechReview
>>> class Review(TechReview):
...
... def start(self, args):
... publish1 = args['publish1']
... publish2 = args['publish2']
... changes1 = args['tech_changes1']
... changes2 = args['tech_changes2']
... if not (publish1 and publish2):
... output = {'publish': False,
... 'tech_changes': changes1 + changes2,
... 'ed_changes': ()}
... # Reject if either tech reviewer rejects
... self.activity.workItemFinished(
... self, output)
...
... if changes1 or changes2:
... output = {'publish': True,
... 'tech_changes': changes1 + changes2,
... 'ed_changes': ()}
... # we won't do anyting if there are tech changes
... self.activity.workItemFinished(
... self, output)
...
... def finish(self, ed_changes):
... output = {'publish': True, 'tech_changes': (), 'ed_changes': ed_changes}
... self.activity.workItemFinished(self, output)
>>> integration.ed_reviewWorkItem = Review
>>> class Final(ApplicationBase):
...
... def summary(self):
... process = self.activity.process
... doc = getattr(process.applicationRelevantData, 'doc', '')
... print('Previous draft:')
... print(self.activity.process.applicationRelevantData.doc)
... print('Changes we need to make:')
... for change in process.workflowRelevantData.ed_changes:
... print(change)
...
... def finish(self, doc):
... self.activity.process.applicationRelevantData.doc = doc
... super(Final, self).finish()
>>> integration.finalWorkItem = Final
>>> class ReviewFinal(TechReview):
...
... def finish(self, ed_changes):
... output = {'publish': True, 'tech_changes': (), 'ed_changes': ed_changes}
... self.activity.workItemFinished(self, output)
>>> integration.rfinalWorkItem = ReviewFinal
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class Publish:
... zope.component.adapts(interfaces.IParticipant)
...
... def __init__(self, participant, process, activity):
... self.participant = participant
...
... def start(self, args):
... print("Published")
... self.finish()
...
... def finish(self):
... self.participant.activity.workItemFinished(self)
>>> integration.publishWorkItem = Publish
>>> class Reject(Publish):
... def start(self, args):
... print("Rejected")
... self.finish()
>>> integration.rejectWorkItem = Reject
and a process context, so we can pass parameters:
>>> @zope.interface.implementer(interfaces.IProcessContext)
... class PublicationContext:
...
... def processFinished(self, process, decision):
... self.decision = decision
Now, let's try out our process. We'll follow the same steps we did in
"README.txt", getting the same results:
>>> context = PublicationContext()
>>> proc = pd(context)
>>> proc.start('bob')
ProcessStarted(Process('Publication'))
Transition(None, Activity('Publication.start'))
ActivityStarted(Activity('Publication.start'))
ActivityFinished(Activity('Publication.start'))
Author `bob` selected
Transition(Activity('Publication.start'),
Activity('Publication.prepare'))
ActivityStarted(Activity('Publication.prepare'))
WorkItemStarting('prepare')
WorkItemStarted('prepare')
>>> item = authors['bob'].work_list.pop()
>>> item.finish("I give my pledge, as an American\n"
... "to save, and faithfully to defend from waste\n"
... "the natural resources of my Country.")
WorkItemFinished('prepare')
ActivityFinished(Activity('Publication.prepare'))
Transition(Activity('Publication.prepare'),
Activity('Publication.tech1'))
ActivityStarted(Activity('Publication.tech1'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
Transition(Activity('Publication.prepare'),
Activity('Publication.tech2'))
ActivityStarted(Activity('Publication.tech2'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
>>> item = tech1.work_list.pop()
>>> print(item.getDoc())
I give my pledge, as an American
to save, and faithfully to defend from waste
the natural resources of my Country.
>>> item.finish(True, ['Change "American" to "human"'])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech1'))
Transition(Activity('Publication.tech1'),
Activity('Publication.review'))
>>> item = tech2.work_list.pop()
>>> item.finish(True, ['Change "Country" to "planet"'])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech2'))
Transition(Activity('Publication.tech2'),
Activity('Publication.review'))
ActivityStarted(Activity('Publication.review'))
WorkItemStarting('ed_review')
WorkItemFinished('ed_review')
ActivityFinished(Activity('Publication.review'))
Author `bob` selected
Transition(Activity('Publication.review'),
Activity('Publication.prepare'))
ActivityStarted(Activity('Publication.prepare'))
WorkItemStarting('prepare')
WorkItemStarted('prepare')
WorkItemStarted('ed_review')
>>> item = authors['bob'].work_list.pop()
>>> item.summary()
Previous draft:
I give my pledge, as an American
to save, and faithfully to defend from waste
the natural resources of my Country.
Changes we need to make:
Change "American" to "human"
Change "Country" to "planet"
>>> item.finish("I give my pledge, as an human\n"
... "to save, and faithfully to defend from waste\n"
... "the natural resources of my planet.")
WorkItemFinished('prepare')
ActivityFinished(Activity('Publication.prepare'))
Transition(Activity('Publication.prepare'),
Activity('Publication.tech1'))
ActivityStarted(Activity('Publication.tech1'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
Transition(Activity('Publication.prepare'),
Activity('Publication.tech2'))
ActivityStarted(Activity('Publication.tech2'))
WorkItemStarting('tech_review')
WorkItemStarted('tech_review')
>>> item = tech1.work_list.pop()
>>> item.finish(True, [])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech1'))
Transition(Activity('Publication.tech1'),
Activity('Publication.review'))
>>> item = tech2.work_list.pop()
>>> item.finish(True, [])
WorkItemFinished('tech_review')
ActivityFinished(Activity('Publication.tech2'))
Transition(Activity('Publication.tech2'),
Activity('Publication.review'))
ActivityStarted(Activity('Publication.review'))
WorkItemStarting('ed_review')
WorkItemStarted('ed_review')
>>> item = reviewer.work_list.pop()
>>> print(item.getDoc())
I give my pledge, as an human
to save, and faithfully to defend from waste
the natural resources of my planet.
>>> item.finish(['change "an" to "a"'])
WorkItemFinished('ed_review')
ActivityFinished(Activity('Publication.review'))
Author `bob` selected
Transition(Activity('Publication.review'),
Activity('Publication.final'))
ActivityStarted(Activity('Publication.final'))
WorkItemStarting('final')
WorkItemStarted('final')
>>> item = authors['bob'].work_list.pop()
>>> item.summary()
Previous draft:
I give my pledge, as an human
to save, and faithfully to defend from waste
the natural resources of my planet.
Changes we need to make:
change "an" to "a"
>>> item.finish("I give my pledge, as a human\n"
... "to save, and faithfully to defend from waste\n"
... "the natural resources of my planet.")
WorkItemFinished('final')
ActivityFinished(Activity('Publication.final'))
Transition(Activity('Publication.final'),
Activity('Publication.rfinal'))
ActivityStarted(Activity('Publication.rfinal'))
WorkItemStarting('rfinal')
WorkItemStarted('rfinal')
>>> item = reviewer.work_list.pop()
>>> print(item.getDoc())
I give my pledge, as a human
to save, and faithfully to defend from waste
the natural resources of my planet.
>>> item.finish([])
WorkItemFinished('rfinal')
ActivityFinished(Activity('Publication.rfinal'))
Transition(Activity('Publication.rfinal'),
Activity('Publication.publish'))
ActivityStarted(Activity('Publication.publish'))
WorkItemStarting('publish')
Published
WorkItemFinished('publish')
ActivityFinished(Activity('Publication.publish'))
ProcessFinished(Process('Publication'))
WorkItemStarted('publish')
>>> proc.workflowRelevantData.publish
True
Descriptions
------------
Most process elements can have names and descriptions.
>>> pd.__name__
'Publication'
>>> pd.description
'This is the sample process'
>>> pd.applications['prepare'].__name__
'Prepare'
>>> pd.applications['prepare'].description
'Prepare the initial draft'
>>> pd.activities['tech1'].__name__
'Technical Review 1'
>>> pd.activities['tech1'].description
'This is the first Technical Review.'
>>> pd.participants['tech1'].__name__
'Technical Reviewer 1'
>>> pd.participants['tech1'].description
'He is a smart guy.'
>>> sorted([item.__name__ for item in pd.transitions])
['Transition', 'Transition', 'Transition', 'Transition',
'Transition', 'Transition', 'Transition', 'Transition',
'Transition', 'Transition', 'Transition to Tech Review 1',
'Transition to Tech Review 2']
>>> descriptions = [item.description for item in pd.transitions if item.description]
>>> 'Use this transition if there are editorial changes required.' in descriptions
True
=======
CHANGES
=======
4.3.2 (2024-10-17)
------------------
- Added support for LiteralParameters
4.3.1 (2023-04-04)
------------------
- Moving CI to github actions
- Removed buildout support
- Added Python 3.10 and 3.11 support.
- Removed Python 2 support.
- Fixed Deadline / ExceptionName parsing.
4.3.0 (2022-04-07)
------------------
- `evaluateInputs`: refactored to handle most common exceptions.
- `getInitialDataFieldsValues`: new function to parse datafields initial values.
- drop Python 2 support.
4.2.2 (2019-09-06)
------------------
- Exposed deadline parsing as `Activity.digestDeadlineDefinition`
4.2.0 (2018-11-12)
------------------
- Add Python 3.7 support.
- Remove Python 3.5 support.
- Remvoe all deprecation and resource warnings.
4.1.1 (2018-02-08)
------------------
- More Python 3 compatibility.
4.1.0 (2018-02-06)
------------------
- Python 3 support.
4.0.4 (2017-11-01)
------------------
- Make the `now` function pluggable.
4.0.3 (2017-06-20)
------------------
- Nothing changed yet.
4.0.2 (2017-05-25)
------------------
- Update and improve Trove classifiers.
4.0.1 (2017-05-25)
------------------
- Fix small ReST issues, so that PyPI description will render.
4.0.0 (2017-05-25)
------------------
- Renamed from `zope.wfmc` to `shoobx.wfmc`.
- Added support for community CI and coverage tools.
- Raise an exception on duplicate `ExtendedAttribute` `Name` in a single
`ExtendedAttributes` container
- Use IProcessDefinitionFactory to retrieve process definitions instead of
named utilities. This additional layer of indirection allows to generate
definitions dynamically.
- Support for synchronious and asynchronous execution of WFMC subflows.
Subflows are executed as part of main process, however have their separate
state (workflow variables).
- The simplistic Python ``evaluate(expr, locals)`` function has been replaced
by the `PythonExpressionEvaluator` component, which is an adapter from
`IProcess` to `IPythonExpressionEvaluator`. The evaluation locals namespace
is automatically filled with workflow- and application-relevant data
attributes, the context of the process and the passed in locals variable.
All calls of `evaluate()` have been updated to use the adapter.
This change allows for easy replacement of the evaluation engine to hook up
a safe Python engine (i.e. RestrictedPython) and to provide more namespace
entries.
- Transition conditions can now be evaluated in the larger context of a
process, instead of just the workflow-relevant data. Thus their calling
signature changed from `condition(data)` to `condition(process, data)`.
- `TextCondition` has been changed to use the `PythonExpressionEvaluator`
component. Also, the compile optimization has been removed, since the
expression evalautor can do this more effectively.
- Support for aborting processes and activities.
* Work items can be abortable by implementing ``IAbortWorkItem``.
* Work items can be cleaned up, if they implement ``ICleanupWorkItem``.
* Activities keep track of finished work items.
* Activities can clean themselves up by cleaning up work items.
* Processes keep track of finished activities.
* When processes are aborted, the following is done:
+ All activities are aborted.
+ All finished activities are cleaned up.
+ isAborted flag is set on a process.
- Support for reading XPDL-2.1 added
- Added reading Pools and Lanes from XPDL
3.5.0 (2009-07-24)
------------------
- Update tests to latest package versions.
3.4.0 (2007-11-02)
------------------
- Initial release independent of the main Zope tree.
Raw data
{
"_id": null,
"home_page": "http://pypi.python.org/pypi/shoobx.wfmc",
"name": "shoobx.wfmc",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "bpmn wfmc xpdl workflow engine",
"author": "Zope Corporation and Contributors",
"author_email": "zope3-dev@zope.org",
"download_url": "https://files.pythonhosted.org/packages/6a/5d/ca63fbd181e1bec641891f0bc5711a2ef28d857dc9f15b3caeec28bc2a32/shoobx.wfmc-4.3.2.tar.gz",
"platform": null,
"description": "--------------------------------\nShoobx WfMC-based Process Engine\n--------------------------------\n\n.. image:: https://github.com/Shoobx/shoobx.wfmc/actions/workflows/test.yml/badge.svg\n :target: https://github.com/Shoobx/shoobx.wfmc/actions\n\n.. image:: https://coveralls.io/repos/github/Shoobx/shoobx.wfmc/badge.svg?branch=master\n :target: https://coveralls.io/github/Shoobx/shoobx.wfmc?branch=master\n\n.. image:: https://img.shields.io/pypi/v/shoobx.wfmc.svg\n :target: https://pypi.python.org/pypi/shoobx.wfmc\n\n.. image:: https://img.shields.io/pypi/pyversions/shoobx.wfmc.svg\n :target: https://pypi.python.org/pypi/shoobx.wfmc/\n\n.. image:: https://api.codeclimate.com/v1/badges/f3c23e8e1b19a03a37e1/maintainability\n :target: https://codeclimate.com/github/Shoobx/shoobx.wfmc/maintainability\n :alt: Maintainability\n \nThis package provides an implementation of a Workflow-Management\nCoalition (WFMC) workflow engine. The engine is provided as a\ncollection of workflow process components. Workflow processes can be\ndefined in Python or via the XML Process-Definition Language, XPDL.\n\n\nDetailed Documentation\n++++++++++++++++++++++\n\n\n\nWorkflow-Management Coalition Workflow Engine\n=============================================\n\nThis package provides an implementation of a Workflow-Management\nCoalition (WFMC) workflow engine. The engine is provided as a\ncollection of workflow process components. Workflow processes can be\ndefined in Python or via the XML Process-Definition Language, XPDL.\n\nIn this document, we'll look at Python-defined process definitions:\n\n >>> from shoobx.wfmc import process\n >>> pd = process.ProcessDefinition('sample')\n\nThe argument to the process is a process id.\n\nA process has a number of parts. Let's look at a sample review\nprocess::\n\n -----------\n -->| Publish |\n ---------- ---------- / -----------\n | Author |-->| Review |- ----------\n ---------- ---------- \\-->| Reject |\n ----------\n\nHere we have a single start activity and 2 end activities. We could\nhave modeled this with a single end activity, but that is not\nrequired. A single start activity *is* required. A process definition\nhas a set of activities, with transitions between them. Let's define\nthe activities for our process definition:\n\n >>> pd.defineActivities(\n ... author = process.ActivityDefinition(),\n ... review = process.ActivityDefinition(),\n ... publish = process.ActivityDefinition(),\n ... reject = process.ActivityDefinition(),\n ... )\n\nWe supply activities as keyword arguments. The argument names provide\nactivity ids that we'll use when defining transitions:\n\n >>> pd.defineTransitions(\n ... process.TransitionDefinition('author', 'review'),\n ... process.TransitionDefinition('review', 'publish'),\n ... process.TransitionDefinition('review', 'reject'),\n ... )\n\nEach transition is constructed with an identifier for a starting\nactivity, and an identifier for an ending activity.\n\nBefore we can use a workflow definition, we have to register it as a\nutility. This is necessary so that process instances can find their\ndefinitions. In addition, the utility name must match the process id:\n\n >>> import zope.component\n >>> from shoobx.wfmc.process import StaticProcessDefinitionFactory\n >>> pdfactory = StaticProcessDefinitionFactory()\n >>> zope.component.provideUtility(pdfactory)\n >>> pdfactory.register(pd)\n\nNow, with this definition, we can execute our workflow. We haven't\ndefined any work yet, but we can see the workflow execute. We'll see\nthe workflow executing by registering a subscriber that logs workflow\nevents:\n\n >>> def log_workflow(event):\n ... print (event)\n\n >>> import zope.event\n >>> zope.event.subscribers.append(log_workflow)\n\nTo use the workflow definition, we need to create an instance:\n\n >>> proc = pd()\n\nNow, if we start the workflow:\n\n >>> proc.start()\n ProcessStarted(Process('sample'))\n Transition(None, Activity('sample.author'))\n ActivityStarted(Activity('sample.author'))\n ActivityFinished(Activity('sample.author'))\n Transition(Activity('sample.author'), Activity('sample.review'))\n ActivityStarted(Activity('sample.review'))\n ActivityFinished(Activity('sample.review'))\n Transition(Activity('sample.review'), Activity('sample.publish'))\n ActivityStarted(Activity('sample.publish'))\n ActivityFinished(Activity('sample.publish'))\n ProcessFinished(Process('sample'))\n\nwe see that we transition immediately into the author activity, then\ninto review and publish. Normally, we'd need to do some work in each\nactivity, and transitions would continue only after work had been\ndone, however, in this case, we didn't define any work, so each\nactivity completed immediately.\n\nNote that we didn't transition into the rejected activity. By\ndefault, when an activity is completed, the first transition for which\nits condition evaluates to `True` is used. By default, transitions\nhave boolean conditions that evaluate to `True`, so the transition\nto `publish` is used because it was defined before the transition to\n`reject`. What we want is to transition to `publish` if a reviewer\napproves the content for publication, but to `reject` if the reviewer\nrejects the content for publication. We can use a condition for this:\n\n >>> pd = process.ProcessDefinition('sample')\n >>> pdfactory.register(pd)\n\n >>> pd.defineActivities(\n ... author = process.ActivityDefinition(),\n ... review = process.ActivityDefinition(),\n ... publish = process.ActivityDefinition(),\n ... reject = process.ActivityDefinition(),\n ... )\n >>> pd.defineTransitions(\n ... process.TransitionDefinition('author', 'review'),\n ... process.TransitionDefinition(\n ... 'review', 'publish',\n ... condition=lambda proc: proc.workflowRelevantData.publish),\n ... process.TransitionDefinition('review', 'reject'),\n ... )\n\nWe redefined the workflow process, specifying a condition for the\ntransition to `publish`. Boolean conditions are just callable objects that\ntake a data object and return a boolean value. The data object is\ncalled \"workflow-relevant data\". A process instance has a data object\ncontaining this data. In the example, above, the condition simply\nreturned the value of the `publish` attribute. How does this attribute\nget set? It needs to be set by the review activity. To do that, we\nneed to arrange for the activity to set the data. This brings us to\napplications.\n\nProcess definitions are meant to be used with different\napplications. For this reason, process definitions don't include\napplication logic. What they do include is a specifications of the\napplications to be invoked and the flow of work-flow-relevant data to\nand from the application. Now, we can define our applications:\n\n >>> pd.defineApplications(\n ... author = process.Application(),\n ... review = process.Application(\n ... process.OutputParameter('publish')),\n ... publish = process.Application(),\n ... reject = process.Application(),\n ... )\n\nWe used the same names for the applications that we used for our\nactivities. This isn't required, but is a common practice. Note that\nthe `review` application includes a specification of an output\nparameter. Now that we've defined our applications, we need to modify\nour activities to use them:\n\n >>> pd.activities['author'].addApplication('author')\n >>> pd.activities['review'].addApplication('review', ['publish'])\n >>> pd.activities['publish'].addApplication('publish')\n >>> pd.activities['reject'].addApplication('reject')\n\nAn activity can use many applications, so we call `addApplication`.\nIn the application definition for the 'review' application, we\nprovided the name of a workflow-relevent data variable corresponding\nto the output parameter defined for the application. When using an\napplication in an activity, a workflow-relevent data variable name\nmust be provided for each of the parameters in the identified\napplications's signature. When an application is used in an activity,\nworkflow-relevent data are passed for each of the input parameters and\nare set by each of the output parameters. In this example, the output\nparameter, will be used to add a `publish` attribute to the workflow\nrelevant data.\n\nParticipants\n------------\n\nWe've declared some applications, and we've wired them up to\nactivities, but we still haven't specified any application code. Before\nwe can specify application code, we need to consider who will be\nperforming the application. Workflow applications are normally\nexecuted by people, or other external actors. As with applications,\nprocess definitions allow participants in the workflow to be declared\nand identified with activities. We declare participants much as we\ndeclare applications, except without parameters:\n\n >>> pd.defineParticipants(\n ... author = process.Participant(),\n ... reviewer = process.Participant(),\n ... )\n\nIn this case, we happened to reuse an activity name for one, but\nnot both of the participants. Having defined these participants, we\ncan associate them with activities:\n\n >>> pd.activities['author'].definePerformer('author')\n >>> pd.activities['review'].definePerformer('reviewer')\n\nApplication Integration\n-----------------------\n\nTo use a process definition to control application logic, we need to\nassociate it with an \"integration\" object.\n\nWhen a process needs to get a participant, it calls createParticipant\non its integration attribute, passing the process id and the\nperformer id. If an activity doesn't have a\nperformer, then the procedure above is used with an empty performer id.\n\nSimilarly, when a process needs a work item, it calls createWorkItem\non its integration attribute, passing the process id and the\napplication id.\n\nWork items provide a `start` method, which is used to start the work\nand pass input arguments. It is the responsibility of the work item,\nat some later time, to call the `workItemFinished` method on the\nactivity, to notify the activity that the work item was\ncompleted. Output parameters are passed to the `workItemFinished`\nmethod.\n\nA simple way to create integration objects is with\n`shoobx.wfmc.attributeintegration.AttributeIntegration`.\n\n >>> from shoobx.wfmc.attributeintegration import AttributeIntegration\n >>> integration = AttributeIntegration()\n >>> pd.integration = integration\n\nWe'll start by defining a simple Participant class:\n\n >>> import zope.interface\n >>> from shoobx.wfmc import interfaces\n\n >>> @zope.interface.implementer(interfaces.IParticipant)\n ... class Participant(object):\n ... zope.component.adapts(interfaces.IActivity)\n ... \n ... def __init__(self, activity, process):\n ... self.activity = activity\n\nWe set attributes on the integration for each participant:\n\n >>> integration.authorParticipant = Participant\n >>> integration.reviewerParticipant = Participant\n\nWe also define an attribute for participants for activities that don't\nhave performers:\n\n >>> integration.Participant = Participant\n\nNow we'll define our work-items. First we'll define some classes:\n\n >>> work_list = []\n\n >>> @zope.interface.implementer(interfaces.IWorkItem)\n ... class ApplicationBase:\n ... zope.component.adapts(interfaces.IParticipant)\n ... \n ... def __init__(self, participant, process, activity):\n ... self.participant = participant\n ... work_list.append(self)\n ... \n ... def start(self, args):\n ... pass\n ... \n ... def finish(self):\n ... self.participant.activity.workItemFinished(self)\n\n >>> class Review(ApplicationBase):\n ... def finish(self, publish):\n ... output = {'publish': publish}\n ... self.participant.activity.workItemFinished(self, output)\n\n >>> class Publish(ApplicationBase):\n ... def start(self, args):\n ... print (\"Published\")\n ... self.finish()\n\n >>> class Reject(ApplicationBase):\n ... def start(self, args):\n ... print (\"Rejected\")\n ... self.finish()\n\nand then we'll hook them up with the integration object:\n\n >>> integration.authorWorkItem = ApplicationBase\n >>> integration.reviewWorkItem = Review\n >>> integration.publishWorkItem = Publish\n >>> integration.rejectWorkItem = Reject\n\nUsing workflow processes\n------------------------\n\nTo use a process definition, instantiate it and call its start method\nto start execution:\n\n >>> proc = pd()\n >>> proc.start()\n ... # doctest: +NORMALIZE_WHITESPACE\n ProcessStarted(Process('sample'))\n Transition(None, Activity('sample.author'))\n ActivityStarted(Activity('sample.author'))\n WorkItemStarting('author')\n WorkItemStarted('author')\n\nWe transition into the author activity and wait for work to get done.\nTo move forward, we need to get at the authoring work item, so we can\nfinish it. Our work items add themselves to a work list, so we can\nget the item from the list.\n\n >>> item = work_list.pop()\n\nNow we can finish the work item, by calling its finish method:\n\n >>> item.finish()\n WorkItemFinished('author')\n ActivityFinished(Activity('sample.author'))\n Transition(Activity('sample.author'), Activity('sample.review'))\n ActivityStarted(Activity('sample.review'))\n WorkItemStarting('review')\n WorkItemStarted('review')\n\nWe see that we transitioned to the review activity. Note that the\n`finish` method isn't a part of the workflow APIs. It was defined by\nour sample classes. Other applications could use different mechanisms.\n\nNow, we'll finish the review process by calling the review work item's\n`finish`. We'll pass `False`, indicating that the content should not\nbe published:\n\n >>> work_list.pop().finish(False)\n WorkItemFinished('review')\n ActivityFinished(Activity('sample.review'))\n Transition(Activity('sample.review'), Activity('sample.reject'))\n ActivityStarted(Activity('sample.reject'))\n WorkItemStarting('reject')\n Rejected\n WorkItemFinished('reject')\n ActivityFinished(Activity('sample.reject'))\n ProcessFinished(Process('sample'))\n WorkItemStarted('reject')\n\nOrdering output transitions\n---------------------------\n\nNormally, outgoing transitions are ordered in the order of transition\ndefinition and all transitions from a given activity are used.\n\nIf transitions are defined in an inconvenient order, then the workflow\nmight not work as expected. For example, let's modify the above\nprocess by switching the order of definition of some of the\ntransitions. We'll reuse our integration object from the previous\nexample by passing it to the definition constructor:\n\n >>> pd = process.ProcessDefinition('sample', integration)\n >>> pdfactory.register(pd)\n\n >>> pd.defineActivities(\n ... author = process.ActivityDefinition(),\n ... review = process.ActivityDefinition(),\n ... publish = process.ActivityDefinition(),\n ... reject = process.ActivityDefinition(),\n ... )\n >>> pd.defineTransitions(\n ... process.TransitionDefinition('author', 'review'),\n ... process.TransitionDefinition('review', 'reject'),\n ... process.TransitionDefinition(\n ... 'review', 'publish',\n ... condition=lambda proc: proc.workflowRelevantData.publish),\n ... )\n\n >>> pd.defineApplications(\n ... author = process.Application(),\n ... review = process.Application(\n ... process.OutputParameter('publish')),\n ... publish = process.Application(),\n ... reject = process.Application(),\n ... )\n\n >>> pd.activities['author'].addApplication('author')\n >>> pd.activities['review'].addApplication('review', ['publish'])\n >>> pd.activities['publish'].addApplication('publish')\n >>> pd.activities['reject'].addApplication('reject')\n\n >>> pd.defineParticipants(\n ... author = process.Participant(),\n ... reviewer = process.Participant(),\n ... )\n\n >>> pd.activities['author'].definePerformer('author')\n >>> pd.activities['review'].definePerformer('reviewer')\n\nand run our process:\n\n >>> proc = pd()\n >>> proc.start()\n ... # doctest: +NORMALIZE_WHITESPACE\n ProcessStarted(Process('sample'))\n Transition(None, Activity('sample.author'))\n ActivityStarted(Activity('sample.author'))\n WorkItemStarting('author')\n WorkItemStarted('author')\n\n >>> work_list.pop().finish()\n WorkItemFinished('author')\n ActivityFinished(Activity('sample.author'))\n Transition(Activity('sample.author'), Activity('sample.review'))\n ActivityStarted(Activity('sample.review'))\n WorkItemStarting('review')\n WorkItemStarted('review')\n\nThis time, we'll say that we should publish:\n\n >>> work_list.pop().finish(True)\n WorkItemFinished('review')\n ActivityFinished(Activity('sample.review'))\n Transition(Activity('sample.review'), Activity('sample.reject'))\n ActivityStarted(Activity('sample.reject'))\n WorkItemStarting('reject')\n Rejected\n WorkItemFinished('reject')\n ActivityFinished(Activity('sample.reject'))\n ProcessFinished(Process('sample'))\n WorkItemStarted('reject')\n\nBut we went to the reject activity anyway. Why? Because transitions\nare tested in order. Because the transition to the reject activity was\ntested first and had no condition, we followed it without checking the\ncondition for the transition to the publish activity. We can fix this\nby specifying outgoing transitions on the reviewer activity directly.\nTo do this, we'll also need to specify ids in our transitions. Let's\nredefine the process:\n\n\n >>> pd = process.ProcessDefinition('sample', integration)\n >>> pdfactory.register(pd)\n\n >>> pd.defineActivities(\n ... author = process.ActivityDefinition(),\n ... review = process.ActivityDefinition(),\n ... publish = process.ActivityDefinition(),\n ... reject = process.ActivityDefinition(),\n ... )\n >>> pd.defineTransitions(\n ... process.TransitionDefinition('author', 'review'),\n ... process.TransitionDefinition('review', 'reject', id='reject'),\n ... process.TransitionDefinition(\n ... 'review', 'publish', id='publish',\n ... condition=lambda proc: proc.workflowRelevantData.publish),\n ... )\n\n >>> pd.defineApplications(\n ... author = process.Application(),\n ... review = process.Application(\n ... process.OutputParameter('publish')),\n ... publish = process.Application(),\n ... reject = process.Application(),\n ... )\n\n >>> pd.activities['author'].addApplication('author')\n >>> pd.activities['review'].addApplication('review', ['publish'])\n >>> pd.activities['publish'].addApplication('publish')\n >>> pd.activities['reject'].addApplication('reject')\n\n >>> pd.defineParticipants(\n ... author = process.Participant(),\n ... reviewer = process.Participant(),\n ... )\n\n >>> pd.activities['author'].definePerformer('author')\n >>> pd.activities['review'].definePerformer('reviewer')\n\n >>> pd.activities['review'].addOutgoing('publish')\n >>> pd.activities['review'].addOutgoing('reject')\n\nNow, when we run the process, we'll go to the publish activity as\nexpected:\n\n\n >>> proc = pd()\n >>> proc.start()\n ... # doctest: +NORMALIZE_WHITESPACE\n ProcessStarted(Process('sample'))\n Transition(None, Activity('sample.author'))\n ActivityStarted(Activity('sample.author'))\n WorkItemStarting('author')\n WorkItemStarted('author')\n\n >>> work_list.pop().finish()\n WorkItemFinished('author')\n ActivityFinished(Activity('sample.author'))\n Transition(Activity('sample.author'), Activity('sample.review'))\n ActivityStarted(Activity('sample.review'))\n WorkItemStarting('review')\n WorkItemStarted('review')\n\n >>> work_list.pop().finish(True)\n WorkItemFinished('review')\n ActivityFinished(Activity('sample.review'))\n Transition(Activity('sample.review'), Activity('sample.publish'))\n ActivityStarted(Activity('sample.publish'))\n WorkItemStarting('publish')\n Published\n WorkItemFinished('publish')\n ActivityFinished(Activity('sample.publish'))\n ProcessFinished(Process('sample'))\n WorkItemStarted('publish')\n\n\nLet's see the other way also, where we should transition to reject:\n\n\n >>> proc = pd()\n >>> proc.start()\n ... # doctest: +NORMALIZE_WHITESPACE\n ProcessStarted(Process('sample'))\n Transition(None, Activity('sample.author'))\n ActivityStarted(Activity('sample.author'))\n WorkItemStarting('author')\n WorkItemStarted('author')\n\n >>> work_list.pop().finish()\n WorkItemFinished('author')\n ActivityFinished(Activity('sample.author'))\n Transition(Activity('sample.author'), Activity('sample.review'))\n ActivityStarted(Activity('sample.review'))\n WorkItemStarting('review')\n WorkItemStarted('review')\n\n >>> work_list.pop().finish(False)\n WorkItemFinished('review')\n ActivityFinished(Activity('sample.review'))\n Transition(Activity('sample.review'), Activity('sample.reject'))\n ActivityStarted(Activity('sample.reject'))\n WorkItemStarting('reject')\n Rejected\n WorkItemFinished('reject')\n ActivityFinished(Activity('sample.reject'))\n ProcessFinished(Process('sample'))\n WorkItemStarted('reject')\n\n\nComplex Flows\n-------------\n\nLets look at a more complex example. In this example, we'll extend\nthe process to work with multiple reviewers. We'll also make the\nwork-list handling a bit more sophisticated. We'll also introduce\nsome new concepts:\n\n- splits and joins\n\n- process arguments\n\nConsider the publication\nprocess shown below::\n\n\n Author: Tech Tech Editorial\n Reviewer 1: Reviewer 2: Reviewer:\n =========== =========== =========== ==============\n ---------\n ----------------------------------------------------| Start |\n / ---------\n |\n V\n -----------\n | Prepare |<------------------------------\\\n ----------- \\\n | ------------ \\\n | | Tech |--------------- \\ \\\n |------->| Review 1 | V |\n | ------------ ---------- -------------\n \\ | Tech | | Editorial | ----------\n ------------------->| Review |--->| Review |-->| Reject |\n | 2 | ------------- ----------\n ---------- | |\n ----------- / \\\n | Prepare | / \\--------\\\n | Final |<----------------------------/ |\n ----------- |\n ^ | ---------- V\n | \\------------------------------->| Review | -----------\n \\ | Final |----->| Publish |\n ------------------------------------| | -----------\n ----------\n\nHere we've arranged the process diagram into columns, with the\nactivities for each participant. We have four participants, the\nauthor, two technical reviewers, and an editorial reviewer. The\nauthor prepares a draft. The author sends the draft to *both*\ntechnical reviewers for review. When the technical reviews have\ncompleted, the editorial review does an initial editorial\nreview. Based on the technical reviews, the editor may choose to:\n\n- Reject the document\n\n- Publish the document as is\n\n- Request technical changes (based on the technical reviewers'\n comments), or\n\n- Request editorial changes.\n\nIf technical changes are required, the work flows back to the\n\"Prepare\" activity. If editorial changes are necessary, then work\nflows to the \"Prepare Final\" activity. When the author has made the\neditorial changes, work flows to \"Review Final\". The editor may\nrequest additional changes, in which case, work flows back to \"Prepare\nFinal\", otherwise, the work flows to \"Publish\".\n\nThis example illustrates different kinds of \"joins\" and \"splits\". The\nterm \"join\" refers to the way incoming transitions to an activity are\nhandled. There are two kinds of joins: \"and\" and \"xor\". With an \"and\"\njoin, the activity waits for each of the incoming transitions. In\nthis example, the inputs to the \"Editorial Review\" activity form an\n\"and\" join. Editorial review waits until each of the technical\nreviews are completed. The rest of the joins in this example are\n\"xor\" joins. The activity starts on any transition into the activity.\n\nThe term \"split\" refers to way outgoing transitions from an activity\nare handled. Normally, exactly one transition out of an activity is\nused. This is called an \"xor\" split. With an \"and\" split, all\ntransitions with boolean conditions that evaluate to `True` are used.\nIn this example, the \"Prepare\" activity has an \"and\" split. Work\nflows simultaneously to the two technical review activities. The rest\nof the splits in this example are \"xor\" splits.\n\nLets create our new workflow process. We'll reuse our existing\nintegration object:\n\n >>> Publication = process.ProcessDefinition('Publication')\n >>> Publication.integration = integration\n >>> pdfactory.register(Publication)\n\n >>> Publication.defineActivities(\n ... start = process.ActivityDefinition(\"Start\"),\n ... prepare = process.ActivityDefinition(\"Prepare\"),\n ... tech1 = process.ActivityDefinition(\"Technical Review 1\"),\n ... tech2 = process.ActivityDefinition(\"Technical Review 2\"),\n ... review = process.ActivityDefinition(\"Editorial Review\"),\n ... final = process.ActivityDefinition(\"Final Preparation\"),\n ... rfinal = process.ActivityDefinition(\"Review Final\"),\n ... publish = process.ActivityDefinition(\"Publish\"),\n ... reject = process.ActivityDefinition(\"Reject\"),\n ... )\n\nHere, we've passed strings to the activity definitions providing\nnames. Names must be either unicode or ASCII strings.\n\nWe define our transitions:\n\n >>> Publication.defineTransitions(\n ... process.TransitionDefinition('start', 'prepare'),\n ... process.TransitionDefinition('prepare', 'tech1'),\n ... process.TransitionDefinition('prepare', 'tech2'),\n ... process.TransitionDefinition('tech1', 'review'),\n ... process.TransitionDefinition('tech2', 'review'),\n ...\n ... process.TransitionDefinition(\n ... 'review', 'reject',\n ... condition=lambda proc: not proc.workflowRelevantData.publish\n ... ),\n ... process.TransitionDefinition(\n ... 'review', 'prepare',\n ... condition=lambda proc: proc.workflowRelevantData.tech_changes\n ... ),\n ... process.TransitionDefinition(\n ... 'review', 'final',\n ... condition=lambda proc: proc.workflowRelevantData.ed_changes\n ... ),\n ... process.TransitionDefinition('review', 'publish'),\n ...\n ... process.TransitionDefinition('final', 'rfinal'),\n ... process.TransitionDefinition(\n ... 'rfinal', 'final',\n ... condition=lambda proc: proc.workflowRelevantData.ed_changes\n ... ),\n ... process.TransitionDefinition('rfinal', 'publish'),\n ... )\n\nWe specify our \"and\" split and join:\n\n >>> Publication.activities['prepare'].andSplit(True)\n >>> Publication.activities['review'].andJoin(True)\n\nWe define our participants and applications:\n\n >>> Publication.defineParticipants(\n ... author = process.Participant(\"Author\"),\n ... tech1 = process.Participant(\"Technical Reviewer 1\"),\n ... tech2 = process.Participant(\"Technical Reviewer 2\"),\n ... reviewer = process.Participant(\"Editorial Reviewer\"),\n ... )\n\n >>> Publication.defineApplications(\n ... prepare = process.Application(),\n ... tech_review = process.Application(\n ... process.OutputParameter('publish'),\n ... process.OutputParameter('tech_changes'),\n ... ),\n ... ed_review = process.Application(\n ... process.InputParameter('publish1'),\n ... process.InputParameter('tech_changes1'),\n ... process.InputParameter('publish2'),\n ... process.InputParameter('tech_changes2'),\n ... process.OutputParameter('publish'),\n ... process.OutputParameter('tech_changes'),\n ... process.OutputParameter('ed_changes'),\n ... ),\n ... publish = process.Application(),\n ... reject = process.Application(),\n ... final = process.Application(),\n ... rfinal = process.Application(\n ... process.OutputParameter('ed_changes'),\n ... ),\n ... )\n\n >>> Publication.activities['prepare'].definePerformer('author')\n >>> Publication.activities['prepare'].addApplication('prepare')\n\n >>> Publication.activities['tech1'].definePerformer('tech1')\n >>> Publication.activities['tech1'].addApplication(\n ... 'tech_review', ['publish1', 'tech_changes1'])\n\n >>> Publication.activities['tech2'].definePerformer('tech2')\n >>> Publication.activities['tech2'].addApplication(\n ... 'tech_review', ['publish2', 'tech_changes2'])\n\n >>> Publication.activities['review'].definePerformer('reviewer')\n >>> Publication.activities['review'].addApplication(\n ... 'ed_review',\n ... ['publish1', 'tech_changes1', 'publish2', 'tech_changes2',\n ... 'publish', 'tech_changes', 'ed_changes'],\n ... )\n\n >>> Publication.activities['final'].definePerformer('author')\n >>> Publication.activities['final'].addApplication('final')\n\n >>> Publication.activities['rfinal'].definePerformer('reviewer')\n >>> Publication.activities['rfinal'].addApplication(\n ... 'rfinal', ['ed_changes'],\n ... )\n\n >>> Publication.activities['publish'].addApplication('publish')\n >>> Publication.activities['reject'].addApplication('reject')\n\nWe want to be able to specify an author when we start the process.\nWe'd also like to be told the final disposition of the process. To\naccomplish this, we'll define parameters for our process:\n\n >>> Publication.defineParameters(\n ... process.InputParameter('author'),\n ... process.OutputParameter('publish'),\n ... )\n\nNow that we've defined the process, we need to provide participant and\napplication components. Let's start with our participants. Rather\nthan sharing a single work list, we'll give each user their own\nwork list. We'll also create preexisting participants and return\nthem. Finally, we'll create multiple authors and use the selected one:\n\n\n >>> class User:\n ... def __init__(self):\n ... self.work_list = []\n\n >>> authors = {'bob': User(), 'ted': User(), 'sally': User()}\n\n >>> reviewer = User()\n >>> tech1 = User()\n >>> tech2 = User()\n\n >>> class Author(Participant):\n ... def __init__(self, activity, process):\n ... Participant.__init__(self, activity, process)\n ... author_name = activity.process.workflowRelevantData.author\n ... print((\"Author `%s` selected\" % author_name))\n ... self.user = authors[author_name]\n\nIn this example, we need to define a separate attribute for each participant:\n\n >>> integration.authorParticipant = Author\n\nWhen the process is created, the author name will be passed in and\nassigned to the workflow-relevant data. Our author class uses this\ninformation to select the named user.\n\n >>> class Reviewer(Participant):\n ... user = reviewer\n >>> integration.reviewerParticipant = Reviewer\n\n >>> class Tech1(Participant):\n ... user = tech1\n >>> integration.tech1Participant = Tech1\n\n >>> class Tech2(Participant):\n ... user = tech2\n >>> integration.tech2Participant = Tech2\n\nWe'll use our orginal participation class for activities without\nperformers:\n\n >>> integration.Participant = Participant\n\nNow we'll create our applications. Let's start with our author:\n\n >>> @zope.interface.implementer(interfaces.IWorkItem)\n ... class ApplicationBase(object):\n ... zope.component.adapts(interfaces.IParticipant)\n ... \n ... def __init__(self, participant, process, activity):\n ... self.participant = participant\n ... self.activity = participant.activity\n ... participant.user.work_list.append(self)\n ... \n ... def start(self, args):\n ... pass\n ... \n ... def finish(self):\n ... self.participant.activity.workItemFinished(self)\n\n >>> class Prepare(ApplicationBase):\n ...\n ... def summary(self):\n ... process = self.activity.process\n ... doc = getattr(process.applicationRelevantData, 'doc', '')\n ... if doc:\n ... print ('Previous draft:')\n ... print (doc)\n ... print ('Changes we need to make:')\n ... for change in process.workflowRelevantData.tech_changes:\n ... print (change)\n ... else:\n ... print ('Please write the initial draft')\n ...\n ... def finish(self, doc):\n ... self.activity.process.applicationRelevantData.doc = doc\n ... super(Prepare, self).finish()\n\n >>> integration.prepareWorkItem = Prepare\n\nSince we used the prepare application for revisions as well as initial\npreparation, we provide a summary method to show us what we have to do.\n\nHere we get the document created by the author passed in as an\nargument to the finish method. In a more realistic implementation,\nthe author task would create the document at the start of the task and\nprovide a user interface for the user to edit it. We store the\ndocument as application-relevant data, since we'll want reviewers to\nbe able to access it, but we don't need it directly for workflow\ncontrol.\n\n >>> class TechReview(ApplicationBase):\n ...\n ... def getDoc(self):\n ... return self.activity.process.applicationRelevantData.doc\n ...\n ... def finish(self, decision, changes):\n ... output = {'publish': decision, 'tech_changes': changes}\n ... self.activity.workItemFinished(self, output)\n\n >>> integration.tech_reviewWorkItem = TechReview\n\nHere, we provided a method to access the original document.\n\n >>> class Review(TechReview):\n ...\n ... def start(self, args):\n ... publish1 = args['publish1']\n ... publish2 = args['publish2']\n ... changes1 = args['tech_changes1']\n ... changes2 = args['tech_changes2']\n ... if not (publish1 and publish2):\n ... output = {'publish': False, \n ... 'tech_changes': changes1 + changes2, \n ... 'ed_changes': ()}\n ... # Reject if either tech reviewer rejects\n ... self.activity.workItemFinished(\n ... self, output)\n ...\n ... if changes1 or changes2:\n ... output = {'publish': True, \n ... 'tech_changes': changes1 + changes2, \n ... 'ed_changes': ()}\n ... # we won't do anything if there are tech changes\n ... self.activity.workItemFinished(\n ... self, output)\n ...\n ... def finish(self, ed_changes):\n ... output = {'publish': True, 'tech_changes': (), 'ed_changes': ed_changes}\n ... self.activity.workItemFinished(self, output)\n\n >>> integration.ed_reviewWorkItem = Review\n\nIn this implementation, we decided to reject outright if either\ntechnical editor recommended rejection and to send work back to\npreparation if there are any technical changes. We also subclassed\n`TechReview` to get the `getDoc` method.\n\nWe'll reuse the `publish` and `reject` application from the previous\nexample.\n\n >>> class Final(ApplicationBase):\n ... \n ... def summary(self):\n ... process = self.activity.process\n ... doc = getattr(process.applicationRelevantData, 'doc', '')\n ... print ('Previous draft:')\n ... print((self.activity.process.applicationRelevantData.doc))\n ... print ('Changes we need to make:')\n ... for change in process.workflowRelevantData.ed_changes:\n ... print (change)\n ... \n ... def finish(self, doc):\n ... self.activity.process.applicationRelevantData.doc = doc\n ... super(Final, self).finish()\n\n >>> integration.finalWorkItem = Final\n\nIn our this application, we simply update the document to reflect\nchanges.\n\n >>> class ReviewFinal(TechReview):\n ...\n ... def finish(self, ed_changes):\n ... output = {'ed_changes': ed_changes}\n ... self.activity.workItemFinished(self, output)\n\n >>> integration.rfinalWorkItem = ReviewFinal\n\nOur process now returns data. When we create a process, we need to\nsupply an object that it can call back to:\n\n >>> @zope.interface.implementer(interfaces.IProcessContext)\n ... class PublicationContext:\n ... \n ... def processFinished(self, process, decision):\n ... self.decision = decision\n\nNow, let's try out our process:\n\n >>> context = PublicationContext()\n >>> proc = Publication(context)\n >>> proc.start('bob')\n ProcessStarted(Process('Publication'))\n Transition(None, Activity('Publication.start'))\n ActivityStarted(Activity('Publication.start'))\n ActivityFinished(Activity('Publication.start'))\n Author `bob` selected\n Transition(Activity('Publication.start'), Activity('Publication.prepare'))\n ActivityStarted(Activity('Publication.prepare'))\n WorkItemStarting('prepare')\n WorkItemStarted('prepare')\n\nWe should have added an item to bob's work list. Let's get it and\nfinish it, submitting a document:\n\n >>> item = authors['bob'].work_list.pop()\n >>> item.finish(\"I give my pledge, as an American\\n\"\n ... \"to save, and faithfully to defend from waste\\n\"\n ... \"the natural resources of my Country.\")\n WorkItemFinished('prepare')\n ActivityFinished(Activity('Publication.prepare'))\n Transition(Activity('Publication.prepare'), Activity('Publication.tech1'))\n ActivityStarted(Activity('Publication.tech1'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n Transition(Activity('Publication.prepare'), Activity('Publication.tech2'))\n ActivityStarted(Activity('Publication.tech2'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n\nNotice that we transitioned to *two* activities, `tech1` and\n`tech2`. This is because the prepare activity has an \"and\" split.\nNow we'll do a tech review. Let's see what tech1 has:\n\n >>> item = tech1.work_list.pop()\n >>> print((item.getDoc()))\n I give my pledge, as an American\n to save, and faithfully to defend from waste\n the natural resources of my Country.\n\nLet's tell the author to change \"American\" to \"Earthling\":\n\n >>> item.finish(True, ['Change \"American\" to \"Earthling\"'])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech1'))\n Transition(Activity('Publication.tech1'), Activity('Publication.review'))\n\nHere we transitioned to the editorial review activity, but we didn't\nstart it. This is because the editorial review activity has an \"and\"\njoin, meaning that it won't start until both transitions have\noccurred.\n\nNow we'll do the other technical review:\n\n >>> item = tech2.work_list.pop()\n >>> item.finish(True, ['Change \"Country\" to \"planet\"'])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech2'))\n Transition(Activity('Publication.tech2'), Activity('Publication.review'))\n ActivityStarted(Activity('Publication.review'))\n WorkItemStarting('ed_review')\n WorkItemFinished('ed_review')\n ActivityFinished(Activity('Publication.review'))\n Author `bob` selected\n Transition(Activity('Publication.review'), Activity('Publication.prepare'))\n ActivityStarted(Activity('Publication.prepare'))\n WorkItemStarting('prepare')\n WorkItemStarted('prepare')\n WorkItemStarted('ed_review')\n\nNow when we transitioned to the editorial review activity, we started\nit, because each of the input transitions had happened. Our editorial\nreview application automatically sent the work back to preparation,\nbecause there were technical comments. Of course the author is still `bob`.\nLet's address the comments:\n\n >>> item = authors['bob'].work_list.pop()\n >>> item.summary()\n Previous draft:\n I give my pledge, as an American\n to save, and faithfully to defend from waste\n the natural resources of my Country.\n Changes we need to make:\n Change \"American\" to \"Earthling\"\n Change \"Country\" to \"planet\"\n\n >>> item.finish(\"I give my pledge, as an Earthling\\n\"\n ... \"to save, and faithfully to defend from waste\\n\"\n ... \"the natural resources of my planet.\")\n WorkItemFinished('prepare')\n ActivityFinished(Activity('Publication.prepare'))\n Transition(Activity('Publication.prepare'), Activity('Publication.tech1'))\n ActivityStarted(Activity('Publication.tech1'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n Transition(Activity('Publication.prepare'), Activity('Publication.tech2'))\n ActivityStarted(Activity('Publication.tech2'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n\nAs before, after completing the initial edits, we start the technical\nreview activities again. We'll review it again. This time, we have no\ncomments, because the author applied our requested changes:\n\n >>> item = tech1.work_list.pop()\n >>> item.finish(True, [])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech1'))\n Transition(Activity('Publication.tech1'), Activity('Publication.review'))\n\n >>> item = tech2.work_list.pop()\n >>> item.finish(True, [])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech2'))\n Transition(Activity('Publication.tech2'), Activity('Publication.review'))\n ActivityStarted(Activity('Publication.review'))\n WorkItemStarting('ed_review')\n WorkItemStarted('ed_review')\n\nThis time, we are left in the technical review activity because there\nweren't any technical changes. We're ready to do our editorial review.\nWe'll request an editorial change:\n\n >>> item = reviewer.work_list.pop()\n >>> print((item.getDoc()))\n I give my pledge, as an Earthling\n to save, and faithfully to defend from waste\n the natural resources of my planet.\n\n >>> item.finish(['change \"an\" to \"a\"'])\n WorkItemFinished('ed_review')\n ActivityFinished(Activity('Publication.review'))\n Author `bob` selected\n Transition(Activity('Publication.review'), Activity('Publication.final'))\n ActivityStarted(Activity('Publication.final'))\n WorkItemStarting('final')\n WorkItemStarted('final')\n\nBecause we requested editorial changes, we transitioned to the final\nediting activity, so that the author (still bob) can make the changes:\n\n >>> item = authors['bob'].work_list.pop()\n >>> item.summary()\n Previous draft:\n I give my pledge, as an Earthling\n to save, and faithfully to defend from waste\n the natural resources of my planet.\n Changes we need to make:\n change \"an\" to \"a\"\n\n >>> item.finish(\"I give my pledge, as a Earthling\\n\"\n ... \"to save, and faithfully to defend from waste\\n\"\n ... \"the natural resources of my planet.\")\n WorkItemFinished('final')\n ActivityFinished(Activity('Publication.final'))\n Transition(Activity('Publication.final'), Activity('Publication.rfinal'))\n ActivityStarted(Activity('Publication.rfinal'))\n WorkItemStarting('rfinal')\n WorkItemStarted('rfinal')\n\nWe transition to the activity for reviewing the final edits. We\nreview the document and approve it for publication:\n\n >>> item = reviewer.work_list.pop()\n >>> print((item.getDoc()))\n I give my pledge, as a Earthling\n to save, and faithfully to defend from waste\n the natural resources of my planet.\n\n >>> item.finish([])\n WorkItemFinished('rfinal')\n ActivityFinished(Activity('Publication.rfinal'))\n Transition(Activity('Publication.rfinal'), Activity('Publication.publish'))\n ActivityStarted(Activity('Publication.publish'))\n WorkItemStarting('publish')\n Published\n WorkItemFinished('publish')\n ActivityFinished(Activity('Publication.publish'))\n ProcessFinished(Process('Publication'))\n WorkItemStarted('publish')\n\nAt this point, the rest of the process finished automatically. In\naddition, the decision was recorded in the process context object:\n\n >>> proc.workflowRelevantData.publish\n True\n\nComing Soon\n------------\n\n- Timeouts/exceptions\n\n\nSee also\n---------\nhttp://www.wfmc.org\nhttp://www.wfmc.org/standards/standards.htm\n\n\n\n\n===========\nXPDL Import\n===========\n\nWe can import process definitions from files in the XML Process\nDefinition Language (XPDL) format. An XPDL file contains multiple\nprocess definitions arranged in a package. When we load the file, we\nget a package containing some number of process definitions.\n\nLet's look at an example. The file `publication.xpdl`\ncontains a definition for the publication example developed in the\n\"README.txt\" file. We can read it using the xpdl module:\n\n >>> from shoobx.wfmc import xpdl\n >>> import os\n >>> package = xpdl.read(open(os.path.join(this_directory,\n ... 'publication-1.0.xpdl')))\n\nThis package contains a single definition:\n\n >>> package\n {'Publication': ProcessDefinition('Publication')}\n\n >>> pd = package['Publication']\n >>> from shoobx.wfmc.attributeintegration import AttributeIntegration\n >>> integration = AttributeIntegration()\n >>> pd.integration = integration\n\nNow, having read the process definition, we can use it as we did\nbefore (in \"README.txt\"). As before, we'll create an event subscriber\nso that we can see what's going on:\n\n >>> def log_workflow(event):\n ... print(event)\n\n >>> import zope.event\n >>> zope.event.subscribers.append(log_workflow)\n\nand we'll register the process definition as a utility:\n\n >>> import zope.component\n >>> from shoobx.wfmc.process import StaticProcessDefinitionFactory\n >>> pdfactory = StaticProcessDefinitionFactory()\n >>> zope.component.provideUtility(pdfactory)\n >>> pdfactory.register(pd)\n\nand we'll define and register participant and application adapters:\n\n >>> import zope.interface\n >>> from shoobx.wfmc import interfaces\n\n >>> @zope.interface.implementer(interfaces.IParticipant)\n ... class Participant(object):\n ... zope.component.adapts(interfaces.IActivity)\n ...\n ... def __init__(self, activity, process):\n ... self.activity = activity\n\n >>> class User:\n ... def __init__(self):\n ... self.work_list = []\n\n >>> authors = {'bob': User(), 'ted': User(), 'sally': User()}\n\n >>> reviewer = User()\n >>> tech1 = User()\n >>> tech2 = User()\n\n >>> class Author(Participant):\n ... def __init__(self, activity, process):\n ... Participant.__init__(self, activity, process)\n ... author_name = activity.process.workflowRelevantData.author\n ... print(\"Author `%s` selected\" % author_name)\n ... self.user = authors[author_name]\n\n >>> integration.authorParticipant = Author\n\n >>> class Reviewer(Participant):\n ... user = reviewer\n >>> integration.reviewerParticipant = Reviewer\n\n >>> class Tech1(Participant):\n ... user = tech1\n >>> integration.tech1Participant = Tech1\n\n >>> class Tech2(Participant):\n ... user = tech2\n >>> integration.tech2Participant = Tech2\n\n >>> integration.SystemParticipant = Participant\n\n >>> @zope.interface.implementer(interfaces.IWorkItem)\n ... class ApplicationBase(object):\n ... zope.component.adapts(interfaces.IParticipant)\n ...\n ... def __init__(self, participant, process, activity):\n ... self.participant = participant\n ... self.activity = participant.activity\n ... participant.user.work_list.append(self)\n ...\n ... def start(self, args):\n ... pass\n ...\n ... def finish(self):\n ... self.participant.activity.workItemFinished(self)\n\n >>> class Prepare(ApplicationBase):\n ...\n ... def summary(self):\n ... process = self.activity.process\n ... doc = getattr(process.applicationRelevantData, 'doc', '')\n ... if doc:\n ... print('Previous draft:')\n ... print(doc)\n ... print('Changes we need to make:')\n ... for change in process.workflowRelevantData.tech_changes:\n ... print(change)\n ... else:\n ... print('Please write the initial draft')\n ...\n ... def finish(self, doc):\n ... self.activity.process.applicationRelevantData.doc = doc\n ... super(Prepare, self).finish()\n\n >>> integration.prepareWorkItem = Prepare\n\n >>> class TechReview(ApplicationBase):\n ...\n ... def getDoc(self):\n ... return self.activity.process.applicationRelevantData.doc\n ...\n ... def finish(self, decision, changes):\n ... output = {'publish': decision, 'tech_changes': changes}\n ... self.activity.workItemFinished(self, output)\n\n >>> integration.tech_reviewWorkItem = TechReview\n\n >>> class Review(TechReview):\n ...\n ... def start(self, args):\n ... publish1 = args['publish1']\n ... publish2 = args['publish2']\n ... changes1 = args['tech_changes1']\n ... changes2 = args['tech_changes2']\n ... if not (publish1 and publish2):\n ... output = {'publish': False,\n ... 'tech_changes': changes1 + changes2,\n ... 'ed_changes': ()}\n ... # Reject if either tech reviewer rejects\n ... self.activity.workItemFinished(\n ... self, output)\n ...\n ... if changes1 or changes2:\n ... output = {'publish': True,\n ... 'tech_changes': changes1 + changes2,\n ... 'ed_changes': ()}\n ... # we won't do anyting if there are tech changes\n ... self.activity.workItemFinished(\n ... self, output)\n ...\n ... def finish(self, ed_changes):\n ... output = {'publish': True, 'tech_changes': (), 'ed_changes': ed_changes}\n ... self.activity.workItemFinished(self, output)\n\n >>> integration.ed_reviewWorkItem = Review\n\n >>> class Final(ApplicationBase):\n ...\n ... def summary(self):\n ... process = self.activity.process\n ... doc = getattr(process.applicationRelevantData, 'doc', '')\n ... print('Previous draft:')\n ... print(self.activity.process.applicationRelevantData.doc)\n ... print('Changes we need to make:')\n ... for change in process.workflowRelevantData.ed_changes:\n ... print(change)\n ...\n ... def finish(self, doc):\n ... self.activity.process.applicationRelevantData.doc = doc\n ... super(Final, self).finish()\n\n >>> integration.finalWorkItem = Final\n\n >>> class ReviewFinal(TechReview):\n ...\n ... def finish(self, ed_changes):\n ... output = {'publish': True, 'tech_changes': (), 'ed_changes': ed_changes}\n ... self.activity.workItemFinished(self, output)\n\n >>> integration.rfinalWorkItem = ReviewFinal\n\n\n >>> @zope.interface.implementer(interfaces.IWorkItem)\n ... class Publish:\n ... zope.component.adapts(interfaces.IParticipant)\n ...\n ... def __init__(self, participant, process, activity):\n ... self.participant = participant\n ...\n ... def start(self, args):\n ... print(\"Published\")\n ... self.finish()\n ...\n ... def finish(self):\n ... self.participant.activity.workItemFinished(self)\n\n\n >>> integration.publishWorkItem = Publish\n\n >>> class Reject(Publish):\n ... def start(self, args):\n ... print(\"Rejected\")\n ... self.finish()\n\n >>> integration.rejectWorkItem = Reject\n\nand a process context, so we can pass parameters:\n\n >>> @zope.interface.implementer(interfaces.IProcessContext)\n ... class PublicationContext:\n ...\n ... def processFinished(self, process, decision):\n ... self.decision = decision\n\nNow, let's try out our process. We'll follow the same steps we did in\n\"README.txt\", getting the same results:\n\n >>> context = PublicationContext()\n >>> proc = pd(context)\n >>> proc.start('bob')\n ProcessStarted(Process('Publication'))\n Transition(None, Activity('Publication.start'))\n ActivityStarted(Activity('Publication.start'))\n ActivityFinished(Activity('Publication.start'))\n Author `bob` selected\n Transition(Activity('Publication.start'),\n Activity('Publication.prepare'))\n ActivityStarted(Activity('Publication.prepare'))\n WorkItemStarting('prepare')\n WorkItemStarted('prepare')\n\n >>> item = authors['bob'].work_list.pop()\n >>> item.finish(\"I give my pledge, as an American\\n\"\n ... \"to save, and faithfully to defend from waste\\n\"\n ... \"the natural resources of my Country.\")\n WorkItemFinished('prepare')\n ActivityFinished(Activity('Publication.prepare'))\n Transition(Activity('Publication.prepare'),\n Activity('Publication.tech1'))\n ActivityStarted(Activity('Publication.tech1'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n Transition(Activity('Publication.prepare'),\n Activity('Publication.tech2'))\n ActivityStarted(Activity('Publication.tech2'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n\n >>> item = tech1.work_list.pop()\n >>> print(item.getDoc())\n I give my pledge, as an American\n to save, and faithfully to defend from waste\n the natural resources of my Country.\n\n >>> item.finish(True, ['Change \"American\" to \"human\"'])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech1'))\n Transition(Activity('Publication.tech1'),\n Activity('Publication.review'))\n\n >>> item = tech2.work_list.pop()\n >>> item.finish(True, ['Change \"Country\" to \"planet\"'])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech2'))\n Transition(Activity('Publication.tech2'),\n Activity('Publication.review'))\n ActivityStarted(Activity('Publication.review'))\n WorkItemStarting('ed_review')\n WorkItemFinished('ed_review')\n ActivityFinished(Activity('Publication.review'))\n Author `bob` selected\n Transition(Activity('Publication.review'),\n Activity('Publication.prepare'))\n ActivityStarted(Activity('Publication.prepare'))\n WorkItemStarting('prepare')\n WorkItemStarted('prepare')\n WorkItemStarted('ed_review')\n\n >>> item = authors['bob'].work_list.pop()\n >>> item.summary()\n Previous draft:\n I give my pledge, as an American\n to save, and faithfully to defend from waste\n the natural resources of my Country.\n Changes we need to make:\n Change \"American\" to \"human\"\n Change \"Country\" to \"planet\"\n\n >>> item.finish(\"I give my pledge, as an human\\n\"\n ... \"to save, and faithfully to defend from waste\\n\"\n ... \"the natural resources of my planet.\")\n WorkItemFinished('prepare')\n ActivityFinished(Activity('Publication.prepare'))\n Transition(Activity('Publication.prepare'),\n Activity('Publication.tech1'))\n ActivityStarted(Activity('Publication.tech1'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n Transition(Activity('Publication.prepare'),\n Activity('Publication.tech2'))\n ActivityStarted(Activity('Publication.tech2'))\n WorkItemStarting('tech_review')\n WorkItemStarted('tech_review')\n\n >>> item = tech1.work_list.pop()\n >>> item.finish(True, [])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech1'))\n Transition(Activity('Publication.tech1'),\n Activity('Publication.review'))\n\n >>> item = tech2.work_list.pop()\n >>> item.finish(True, [])\n WorkItemFinished('tech_review')\n ActivityFinished(Activity('Publication.tech2'))\n Transition(Activity('Publication.tech2'),\n Activity('Publication.review'))\n ActivityStarted(Activity('Publication.review'))\n WorkItemStarting('ed_review')\n WorkItemStarted('ed_review')\n\n >>> item = reviewer.work_list.pop()\n >>> print(item.getDoc())\n I give my pledge, as an human\n to save, and faithfully to defend from waste\n the natural resources of my planet.\n\n >>> item.finish(['change \"an\" to \"a\"'])\n WorkItemFinished('ed_review')\n ActivityFinished(Activity('Publication.review'))\n Author `bob` selected\n Transition(Activity('Publication.review'),\n Activity('Publication.final'))\n ActivityStarted(Activity('Publication.final'))\n WorkItemStarting('final')\n WorkItemStarted('final')\n\n >>> item = authors['bob'].work_list.pop()\n >>> item.summary()\n Previous draft:\n I give my pledge, as an human\n to save, and faithfully to defend from waste\n the natural resources of my planet.\n Changes we need to make:\n change \"an\" to \"a\"\n\n >>> item.finish(\"I give my pledge, as a human\\n\"\n ... \"to save, and faithfully to defend from waste\\n\"\n ... \"the natural resources of my planet.\")\n WorkItemFinished('final')\n ActivityFinished(Activity('Publication.final'))\n Transition(Activity('Publication.final'),\n Activity('Publication.rfinal'))\n ActivityStarted(Activity('Publication.rfinal'))\n WorkItemStarting('rfinal')\n WorkItemStarted('rfinal')\n\n >>> item = reviewer.work_list.pop()\n >>> print(item.getDoc())\n I give my pledge, as a human\n to save, and faithfully to defend from waste\n the natural resources of my planet.\n\n >>> item.finish([])\n WorkItemFinished('rfinal')\n ActivityFinished(Activity('Publication.rfinal'))\n Transition(Activity('Publication.rfinal'),\n Activity('Publication.publish'))\n ActivityStarted(Activity('Publication.publish'))\n WorkItemStarting('publish')\n Published\n WorkItemFinished('publish')\n ActivityFinished(Activity('Publication.publish'))\n ProcessFinished(Process('Publication'))\n WorkItemStarted('publish')\n\n >>> proc.workflowRelevantData.publish\n True\n\n\nDescriptions\n------------\n\nMost process elements can have names and descriptions.\n\n >>> pd.__name__\n 'Publication'\n\n >>> pd.description\n 'This is the sample process'\n\n >>> pd.applications['prepare'].__name__\n 'Prepare'\n\n >>> pd.applications['prepare'].description\n 'Prepare the initial draft'\n\n >>> pd.activities['tech1'].__name__\n 'Technical Review 1'\n\n >>> pd.activities['tech1'].description\n 'This is the first Technical Review.'\n\n >>> pd.participants['tech1'].__name__\n 'Technical Reviewer 1'\n\n >>> pd.participants['tech1'].description\n 'He is a smart guy.'\n\n >>> sorted([item.__name__ for item in pd.transitions])\n ['Transition', 'Transition', 'Transition', 'Transition',\n 'Transition', 'Transition', 'Transition', 'Transition',\n 'Transition', 'Transition', 'Transition to Tech Review 1',\n 'Transition to Tech Review 2']\n\n >>> descriptions = [item.description for item in pd.transitions if item.description]\n >>> 'Use this transition if there are editorial changes required.' in descriptions\n True\n\n\n\n\n=======\nCHANGES\n=======\n\n4.3.2 (2024-10-17)\n------------------\n\n- Added support for LiteralParameters\n\n\n4.3.1 (2023-04-04)\n------------------\n\n- Moving CI to github actions\n\n- Removed buildout support\n\n- Added Python 3.10 and 3.11 support.\n\n- Removed Python 2 support.\n\n- Fixed Deadline / ExceptionName parsing.\n\n\n4.3.0 (2022-04-07)\n------------------\n\n- `evaluateInputs`: refactored to handle most common exceptions.\n\n- `getInitialDataFieldsValues`: new function to parse datafields initial values.\n\n- drop Python 2 support.\n\n4.2.2 (2019-09-06)\n------------------\n\n- Exposed deadline parsing as `Activity.digestDeadlineDefinition`\n\n\n4.2.0 (2018-11-12)\n------------------\n\n- Add Python 3.7 support.\n\n- Remove Python 3.5 support.\n\n- Remvoe all deprecation and resource warnings.\n\n\n4.1.1 (2018-02-08)\n------------------\n\n- More Python 3 compatibility.\n\n\n4.1.0 (2018-02-06)\n------------------\n\n- Python 3 support.\n\n\n4.0.4 (2017-11-01)\n------------------\n\n- Make the `now` function pluggable.\n\n\n4.0.3 (2017-06-20)\n------------------\n\n- Nothing changed yet.\n\n\n4.0.2 (2017-05-25)\n------------------\n\n- Update and improve Trove classifiers.\n\n\n4.0.1 (2017-05-25)\n------------------\n\n- Fix small ReST issues, so that PyPI description will render.\n\n\n4.0.0 (2017-05-25)\n------------------\n\n- Renamed from `zope.wfmc` to `shoobx.wfmc`.\n\n- Added support for community CI and coverage tools.\n\n- Raise an exception on duplicate `ExtendedAttribute` `Name` in a single\n `ExtendedAttributes` container\n\n- Use IProcessDefinitionFactory to retrieve process definitions instead of\n named utilities. This additional layer of indirection allows to generate\n definitions dynamically.\n\n- Support for synchronious and asynchronous execution of WFMC subflows.\n Subflows are executed as part of main process, however have their separate\n state (workflow variables).\n\n- The simplistic Python ``evaluate(expr, locals)`` function has been replaced\n by the `PythonExpressionEvaluator` component, which is an adapter from\n `IProcess` to `IPythonExpressionEvaluator`. The evaluation locals namespace\n is automatically filled with workflow- and application-relevant data\n attributes, the context of the process and the passed in locals variable.\n\n All calls of `evaluate()` have been updated to use the adapter.\n\n This change allows for easy replacement of the evaluation engine to hook up\n a safe Python engine (i.e. RestrictedPython) and to provide more namespace\n entries.\n\n- Transition conditions can now be evaluated in the larger context of a\n process, instead of just the workflow-relevant data. Thus their calling\n signature changed from `condition(data)` to `condition(process, data)`.\n\n- `TextCondition` has been changed to use the `PythonExpressionEvaluator`\n component. Also, the compile optimization has been removed, since the\n expression evalautor can do this more effectively.\n\n- Support for aborting processes and activities.\n\n * Work items can be abortable by implementing ``IAbortWorkItem``.\n\n * Work items can be cleaned up, if they implement ``ICleanupWorkItem``.\n\n * Activities keep track of finished work items.\n\n * Activities can clean themselves up by cleaning up work items.\n\n * Processes keep track of finished activities.\n\n * When processes are aborted, the following is done:\n\n + All activities are aborted.\n\n + All finished activities are cleaned up.\n\n\t+ isAborted flag is set on a process.\n\n- Support for reading XPDL-2.1 added\n\n- Added reading Pools and Lanes from XPDL\n\n\n3.5.0 (2009-07-24)\n------------------\n\n- Update tests to latest package versions.\n\n\n3.4.0 (2007-11-02)\n------------------\n\n- Initial release independent of the main Zope tree.\n",
"bugtrack_url": null,
"license": "ZPL 2.1",
"summary": "Workflow-Management Coalition Workflow Engine",
"version": "4.3.2",
"project_urls": {
"Homepage": "http://pypi.python.org/pypi/shoobx.wfmc"
},
"split_keywords": [
"bpmn",
"wfmc",
"xpdl",
"workflow",
"engine"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "98767ef01d8458266389b6a4fdd710de4172815696df93c6bf0530d4225b94b9",
"md5": "f59652aa62c5b781800d6c6a1aded7b9",
"sha256": "013a22b7c6c5da574f5e3d0fe122758d03de60eecc544175e18be10d5e1874f0"
},
"downloads": -1,
"filename": "shoobx.wfmc-4.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f59652aa62c5b781800d6c6a1aded7b9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 77811,
"upload_time": "2024-10-17T07:40:37",
"upload_time_iso_8601": "2024-10-17T07:40:37.512705Z",
"url": "https://files.pythonhosted.org/packages/98/76/7ef01d8458266389b6a4fdd710de4172815696df93c6bf0530d4225b94b9/shoobx.wfmc-4.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6a5dca63fbd181e1bec641891f0bc5711a2ef28d857dc9f15b3caeec28bc2a32",
"md5": "8c828de7784e1115fc71dcb0ff6dc9bc",
"sha256": "3fa646f1f4260c5deb4333752c222f9ab3d970fc1fcf26250ecdbb2fd4ffa331"
},
"downloads": -1,
"filename": "shoobx.wfmc-4.3.2.tar.gz",
"has_sig": false,
"md5_digest": "8c828de7784e1115fc71dcb0ff6dc9bc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 82208,
"upload_time": "2024-10-17T07:40:39",
"upload_time_iso_8601": "2024-10-17T07:40:39.599919Z",
"url": "https://files.pythonhosted.org/packages/6a/5d/ca63fbd181e1bec641891f0bc5711a2ef28d857dc9f15b3caeec28bc2a32/shoobx.wfmc-4.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-17 07:40:39",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "shoobx.wfmc"
}