[Zope3-checkins] SVN: Zope3/trunk/src/zope/wfmc/ Changed activity application declarations to use just application

Jim Fulton jim at zope.com
Fri Jan 7 16:04:16 EST 2005


Log message for revision 28767:
  Changed activity application declarations to use just application
  names, as defined by xpdl.  I mistakingly overcomplicated this
  before.
  
  Added a repr for process definitions to aid a test.
  

Changed:
  U   Zope3/trunk/src/zope/wfmc/README.txt
  U   Zope3/trunk/src/zope/wfmc/process.py

-=-
Modified: Zope3/trunk/src/zope/wfmc/README.txt
===================================================================
--- Zope3/trunk/src/zope/wfmc/README.txt	2005-01-07 16:43:09 UTC (rev 28766)
+++ Zope3/trunk/src/zope/wfmc/README.txt	2005-01-07 21:04:16 UTC (rev 28767)
@@ -146,22 +146,21 @@
 our activities to use them:
 
     >>> pd.activities['author'].addApplication('author')
-    >>> pd.activities['review'].addApplication('review',
-    ...     process.OutputParameter('publish'))
+    >>> 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 again
-specified an output arguments definition. Why do we specify the output
-parameter for both the application definition and the application
-assignment?  The parameters in the application definition are "formal
-parameters".  The parameters in the application assignment are
-"actual parameters".  Parameters are positional. The names (but not
-the direction) are allowed to differ.  The names of the actual
-parameters are used to access or update workflow-relevant data.  In
-this example, the output parameter, will be used to add a `publish`
-attribute to the workflow relevant data.
+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.
 
 We've declared some applications, and we've wired them up to
 activities, but we still haven't specified any application code. Before
@@ -489,28 +488,17 @@
 
     >>> Publication.activities['tech1'].definePerformer('tech1')
     >>> Publication.activities['tech1'].addApplication(
-    ...     'tech_review',
-    ...     process.OutputParameter('publish1'),
-    ...     process.OutputParameter('tech_changes1'),
-    ...     )
+    ...     'tech_review', ['publish1', 'tech_changes1'])
 
     >>> Publication.activities['tech2'].definePerformer('tech2')
     >>> Publication.activities['tech2'].addApplication(
-    ...     'tech_review',
-    ...     process.OutputParameter('publish2'),
-    ...     process.OutputParameter('tech_changes2'),
-    ...     )
+    ...     'tech_review', ['publish2', 'tech_changes2'])
 
     >>> Publication.activities['review'].definePerformer('reviewer')
     >>> Publication.activities['review'].addApplication(
     ...     'ed_review',
-    ...     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'),
+    ...     ['publish1', 'tech_changes1', 'publish2', 'tech_changes2',
+    ...      'publish', 'tech_changes', 'ed_changes'],
     ...     )
 
     >>> Publication.activities['final'].definePerformer('author')
@@ -518,8 +506,7 @@
 
     >>> Publication.activities['rfinal'].definePerformer('reviewer')
     >>> Publication.activities['rfinal'].addApplication(
-    ...     'rfinal',
-    ...     process.OutputParameter('ed_changes'),
+    ...     'rfinal', ['ed_changes'],
     ...     )
 
     >>> Publication.activities['publish'].addApplication('publish')

Modified: Zope3/trunk/src/zope/wfmc/process.py
===================================================================
--- Zope3/trunk/src/zope/wfmc/process.py	2005-01-07 16:43:09 UTC (rev 28766)
+++ Zope3/trunk/src/zope/wfmc/process.py	2005-01-07 21:04:16 UTC (rev 28767)
@@ -46,6 +46,9 @@
         self.participants = {}
         self.parameters = ()
 
+    def __repr__(self):
+        return "ProcessDefinition(%r)" % self.id
+
     def defineActivities(self, **activities):
         self._dirty()
         for id, activity in activities.items():
@@ -137,18 +140,12 @@
     def andJoin(self, setting):
         self.andJoinSetting = setting
 
-    def addApplication(self, application, *parameters):
+    def addApplication(self, application, actual=()):
         formal = self.process.applications[application].parameters
-        if len(formal) != len(parameters):
+        if len(formal) != len(actual):
             raise TypeError("Wrong number of parameters")
-
-        for formal, parameter in zip(formal, parameters):
-            if (formal.input != parameter.input
-                or formal.output != parameter.output
-                ):
-                raise TypeError("Parameter type missmatch")
         
-        self.applications += ((application, parameters), )
+        self.applications += ((application, formal, tuple(actual)), )
 
     def definePerformer(self, performer):
         self.performer = performer
@@ -291,7 +288,7 @@
                     '.' + definition.performer)
 
             i = 0
-            for application, parameters in definition.applications:
+            for application, formal, actual in definition.applications:
                 workitem = zope.component.queryAdapter(
                     performer, interfaces.IWorkItem,
                     process.process_definition_identifier + '.' + application)
@@ -301,7 +298,7 @@
                         '.' + application)
                 i += 1
                 workitem.id = i
-                workitems[i] = workitem, application, parameters
+                workitems[i] = workitem, application, formal, actual
         
         self.workitems = workitems
 
@@ -329,34 +326,32 @@
         zope.event.notify(ActivityStarted(self))
         
         if self.workitems:
-            for workitem, application, parameters in self.workitems.values():
+            for workitem, app, formal, actual in self.workitems.values():
                 args = []
-                for parameter in parameters:
+                for parameter, name in zip(formal, actual):
                     if parameter.input:
                         args.append(
-                            getattr(self.process.workflowRelevantData,
-                                    parameter.__name__))
+                            getattr(self.process.workflowRelevantData, name))
                 workitem.start(*args)
         else:
             # Since we don't have any work items, we're done
             self.finish()
 
     def workItemFinished(self, work_item, *results):
-        unused, application, parameters = self.workitems.pop(work_item.id)
+        unused, app, formal, actual = self.workitems.pop(work_item.id)
         self._p_changed = True
         res = results
-        for parameter in parameters:
+        for parameter, name in zip(formal, actual):
             if parameter.output:
                 v = res[0]
                 res = res[1:]
-                setattr(self.process.workflowRelevantData,
-                        parameter.__name__, v)
+                setattr(self.process.workflowRelevantData, name, v)
 
         if res:
             raise TypeError("Too many results")
 
         zope.event.notify(WorkItemFinished(
-            work_item, application, parameters, results))
+            work_item, app, actual, results))
         
         if not self.workitems:
             self.finish()
@@ -445,6 +440,9 @@
     def __init__(self, *parameters):
         self.parameters = parameters
 
+    def defineParameters(self, *parameters):
+        self.parameters += parameters
+
 class Participant:
 
     zope.interface.implements(interfaces.IParticipantDefinition)



More information about the Zope3-Checkins mailing list