Skip to content
This repository has been archived by the owner on Dec 21, 2020. It is now read-only.

Commit

Permalink
Fixed a bug in handling multiple process-input parameters.
Browse files Browse the repository at this point in the history
Created some interfaces for some of the events.  Need to do more
later.
  • Loading branch information
Jim Fulton committed Feb 23, 2005
1 parent 62aefb7 commit 004834b
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 53 deletions.
69 changes: 45 additions & 24 deletions interfaces.py
Expand Up @@ -16,13 +16,13 @@
$Id$
"""

import zope.interface
from zope import interface

class IProcessDefinition(zope.interface.Interface):
class IProcessDefinition(interface.Interface):
"""Process definition
"""

id = zope.interface.Attribute("Process-definition identifier")
id = interface.Attribute("Process-definition identifier")

def defineActivities(**activities):
"""Add activity definitions to the collection of defined activities
Expand Down Expand Up @@ -66,11 +66,11 @@ def defineParameters(*parameters):
"""

class IActivityDefinition(zope.interface.Interface):
class IActivityDefinition(interface.Interface):
"""Activity definition
"""

id = zope.interface.Attribute("Activity identifier")
id = interface.Attribute("Activity identifier")

def addApplication(id, *parameters):
"""Declare that the activity uses the identified activity
Expand Down Expand Up @@ -102,25 +102,25 @@ def setAndJoin(setting):
If the setting is true, then the activity will use an "and" join.
"""

class ITransitionDefinition(zope.interface.Interface):
class ITransitionDefinition(interface.Interface):
"""Activity definition
"""

class IProcess(zope.interface.Interface):
class IProcess(interface.Interface):
"""Process instance
"""

definition = zope.interface.Attribute("Process definition")
definition = interface.Attribute("Process definition")

workflowRelevantData = zope.interface.Attribute(
workflowRelevantData = interface.Attribute(
"""Workflow-relevant data
Object with attributes containing data used in conditions and
to pass data as parameters between applications
"""
)

applicationRelevantData = zope.interface.Attribute(
applicationRelevantData = interface.Attribute(
"""Application-relevant data
Object with attributes containing data used to pass data as
Expand All @@ -129,61 +129,61 @@ class IProcess(zope.interface.Interface):
"""
)

class IProcessContext(zope.interface.Interface):
class IProcessContext(interface.Interface):
"""Object that can recieve process results.
"""

def processFinished(process, *results):
"""Recieve notification of process completion, with results
"""

class IActivity(zope.interface.Interface):
class IActivity(interface.Interface):
"""Activity instance
"""

id = zope.interface.Attribute(
id = interface.Attribute(
"""Activity identifier
This identifier is set by the process instance
""")

definition = zope.interface.Attribute("Activity definition")
definition = interface.Attribute("Activity definition")

def workItemFinished(work_item, *results):
"""Notify the activity that the work item has been completed.
"""

class IApplicationDefinition(zope.interface.Interface):
class IApplicationDefinition(interface.Interface):
"""Application definition
"""

parameters = zope.interface.Attribute(
parameters = interface.Attribute(
"A sequence of parameter definitions")

class IParameterDefinition(zope.interface.Interface):
class IParameterDefinition(interface.Interface):
"""Parameter definition
"""

name = zope.interface.Attribute("Parameter name")
name = interface.Attribute("Parameter name")

input = zope.interface.Attribute("Is this an input parameter?")
input = interface.Attribute("Is this an input parameter?")

output = zope.interface.Attribute("Is this an output parameter?")
output = interface.Attribute("Is this an output parameter?")

class IParticipantDefinition(zope.interface.Interface):
class IParticipantDefinition(interface.Interface):
"""Participant definition
"""

class IParticipant(zope.interface.Interface):
class IParticipant(interface.Interface):
"""Workflow participant
"""

class IWorkItem(zope.interface.Interface):
class IWorkItem(interface.Interface):
"""Work items
"""

id = zope.interface.Attribute(
id = interface.Attribute(
"""Item identifier
This identifier is set by the activity instance
Expand All @@ -193,3 +193,24 @@ class IWorkItem(zope.interface.Interface):
def start(*arguments):
"""Start the work
"""


class InvalidProcessDefinition(Exception):
"""A process definition isn't valid in some way.
"""

class ProcessError(Exception):
"""An error occured in execution of a process
"""

class IProcessStarted(interface.Interface):
"""A process has begun executing
"""

process = interface.Attribute("The process")

class IProcessFinished(interface.Interface):
"""A process has finished executing
"""

process = interface.Attribute("The process")
57 changes: 28 additions & 29 deletions process.py
Expand Up @@ -19,24 +19,18 @@
import sets

import persistent

import zope.cachedescriptors.property
import zope.component
import zope.event
import zope.interface

from zope.wfmc import interfaces
from zope import component, interface

class InvalidProcessDefinition(Exception):
"""A process definition isn't valid in some way.
"""
import zope.event

class ProcessError(Exception):
"""An error occured in execution of a process
"""
from zope.wfmc import interfaces

class ProcessDefinition:

zope.interface.implements(interfaces.IProcessDefinition)
interface.implements(interfaces.IProcessDefinition)

def __init__(self, id):
self.id = id
Expand Down Expand Up @@ -97,16 +91,19 @@ def _start(self):
if not activity.incoming:
start += ((aid, activity), )
if not activity.outgoing:
raise InvalidProcessDefinition(
raise interfaces.InvalidProcessDefinition(
"Activity %s has no transitions",
aid)

if len(start) != 1:
if start:
raise InvalidProcessDefinition("Multiple start activities",
[id for (id, a) in start])
raise interfaces.InvalidProcessDefinition(
"Multiple start activities",
[id for (id, a) in start]
)
else:
raise InvalidProcessDefinition("No start activities")
raise interfaces.InvalidProcessDefinition(
"No start activities")

return TransitionDefinition(None, start[0][0])

Expand All @@ -123,7 +120,7 @@ def _dirty(self):

class ActivityDefinition:

zope.interface.implements(interfaces.IActivityDefinition)
interface.implements(interfaces.IActivityDefinition)

performer = ''
process = None
Expand Down Expand Up @@ -152,7 +149,7 @@ def definePerformer(self, performer):

class TransitionDefinition:

zope.interface.implements(interfaces.ITransitionDefinition)
interface.implements(interfaces.ITransitionDefinition)

def __init__(self, from_, to, condition=lambda data: True):
self.from_ = from_
Expand All @@ -162,7 +159,7 @@ def __init__(self, from_, to, condition=lambda data: True):

class Process(persistent.Persistent):

zope.interface.implements(interfaces.IProcess)
interface.implements(interfaces.IProcess)

def __init__(self, definition, start, context=None):
self.process_definition_identifier = definition.id
Expand All @@ -174,7 +171,7 @@ def __init__(self, definition, start, context=None):
self.applicationRelevantData = WorkflowData()

def definition(self):
return zope.component.getUtility(
return component.getUtility(
interfaces.IProcessDefinition,
self.process_definition_identifier,
)
Expand All @@ -189,7 +186,7 @@ def start(self, *arguments):
args = arguments
for parameter in definition.parameters:
if parameter.input:
arg, args = arguments[0], args[1:]
arg, args = args[0], args[1:]
setattr(data, parameter.__name__, arg)
if args:
raise TypeError("Too many arguments. Expected %s. got %s",
Expand Down Expand Up @@ -250,6 +247,7 @@ class WorkflowData(persistent.Persistent):
"""

class ProcessStarted:
interface.implements(interfaces.IProcessStarted)

def __init__(self, process):
self.process = process
Expand All @@ -258,6 +256,7 @@ def __repr__(self):
return "ProcessStarted(%r)" % self.process

class ProcessFinished:
interface.implements(interfaces.IProcessFinished)

def __init__(self, process):
self.process = process
Expand All @@ -268,7 +267,7 @@ def __repr__(self):

class Activity(persistent.Persistent):

zope.interface.implements(interfaces.IActivity)
interface.implements(interfaces.IActivity)

def __init__(self, process, definition):
self.process = process
Expand All @@ -277,23 +276,23 @@ def __init__(self, process, definition):
workitems = {}
if definition.applications:

performer = zope.component.queryAdapter(
performer = component.queryAdapter(
self, interfaces.IParticipant,
process.process_definition_identifier
+ '.' + definition.performer)

if performer is None:
performer = zope.component.getAdapter(
performer = component.getAdapter(
self, interfaces.IParticipant,
'.' + definition.performer)

i = 0
for application, formal, actual in definition.applications:
workitem = zope.component.queryAdapter(
workitem = component.queryAdapter(
performer, interfaces.IWorkItem,
process.process_definition_identifier + '.' + application)
if workitem is None:
workitem = zope.component.getAdapter(
workitem = component.getAdapter(
performer, interfaces.IWorkItem,
'.' + application)
i += 1
Expand All @@ -315,7 +314,7 @@ def start(self, transition):

if definition.andJoinSetting:
if transition in self.incoming:
raise ProcessError(
raise interfaces.ProcessError(
"Repeated incoming transition while waiting for and "
"completion")
self.incoming += (transition, )
Expand Down Expand Up @@ -414,7 +413,7 @@ def __repr__(self):

class Parameter:

zope.interface.implements(interfaces.IParameterDefinition)
interface.implements(interfaces.IParameterDefinition)

input = output = False

Expand All @@ -435,7 +434,7 @@ class InputOutputParameter(InputParameter, OutputParameter):

class Application:

zope.interface.implements(interfaces.IApplicationDefinition)
interface.implements(interfaces.IApplicationDefinition)

def __init__(self, *parameters):
self.parameters = parameters
Expand All @@ -445,7 +444,7 @@ def defineParameters(self, *parameters):

class Participant:

zope.interface.implements(interfaces.IParticipantDefinition)
interface.implements(interfaces.IParticipantDefinition)

def __init__(self, name=None):
self.__name__ = name

0 comments on commit 004834b

Please sign in to comment.