[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Workflow - IWorkflowProcessDefinitionConfiguration.py:1.1.2.1 WorkflowProcessDefinitionConfiguration.py:1.1.2.1 configure.zcml:1.1.2.1 IWorkflowService.py:1.2.24.1 WorkflowService.py:1.2.24.1

Florent Guillaume fg@nuxeo.com
Tue, 3 Dec 2002 10:32:14 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Workflow
In directory cvs.zope.org:/tmp/cvs-serv8003

Modified Files:
      Tag: sprintathon-wf-branch
	IWorkflowService.py WorkflowService.py 
Added Files:
      Tag: sprintathon-wf-branch
	IWorkflowProcessDefinitionConfiguration.py 
	WorkflowProcessDefinitionConfiguration.py configure.zcml 
Log Message:
Beginning of Sprintathon work on workflow.

Ulrich and Florent:
Empty workflow service, using the configuration framework.
No tests yet.


=== Added File Zope3/lib/python/Zope/App/Workflow/IWorkflowProcessDefinitionConfiguration.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

"""Interfaces for workflow process definition configuration.
"""

from Interface.Attribute import Attribute
from Zope.App.OFS.Services.ConfigurationInterfaces import IConfiguration


class IWorkflowProcessDefinitionConfiguration(IConfiguration):
    """Configuration for a workflow process definition.
    """

    definitionName = Attribute("The definition name")

    componentPath = Attribute("The physical path to the component")

    def getDefinition():
        """Return the definition."""


=== Added File Zope3/lib/python/Zope/App/Workflow/WorkflowProcessDefinitionConfiguration.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

"""Implementation of workflow process definition configuration.
"""

from Persistence import Persistent
from Zope.ComponentArchitecture import getServiceManager
from Zope.ContextWrapper import ContextMethod
from Zope.Security.Checker import CheckerPublic
from Zope.App.Traversing import traverse
from Zope.App.Traversing import getPhysicalPathString
from Zope.App.DependencyFramework.IDependable import IDependable
from Zope.App.DependencyFramework.Exceptions import DependencyError
from Zope.App.OFS.Container.IAddNotifiable import IAddNotifiable
from Zope.App.OFS.Container.IDeleteNotifiable import IDeleteNotifiable
from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty
from Zope.App.OFS.Services.ConfigurationInterfaces import Active
from Zope.App.OFS.Services.ConfigurationInterfaces import Registered
from Zope.App.OFS.Services.ConfigurationInterfaces import Unregistered


class WorkflowProcessDefinitionConfiguration(Persistent):
    """
    """

    __implements__ = (IWorkflowProcessDefinitionConfiguration,
                      IAddNotifiable, IDeleteNotifiable)

    def __init__(self, name, component_path, permission=None):
        self.definitionName = name
        self.componentPath = component_path
        if permission is None:
            permission = CheckerPublic
        self.permission = permission

    def __repr__(self):
        return "workflow process definition(%s, %s)" % (self.definitionName,
                                                        self.componentPath)

    ############################################################
    # Implementation methods for interface
    # Zope.App.Workflow.IWorkflowProcessDefinitionConfiguration

    def getDefinition(self):
        definition = getattr(self, '_v_definition', None)
        if definition is not None:
            return definition
        sm = getServiceManager(self)
        definition = traverse(sm, self.componentPath)
        self._v_definition = definition
        return definition

    getDefinition = ContextMethod(getDefinition)

    ############################################################
    # IConfigurationSummary

    title = u''

    status = ConfigurationStatusProperty('Workflows')

    ############################################################
    # IConfiguration

    description = u''

    def activated(self):
        pass
    #activated = ContextMethod(activated)

    def deactivated(self):
        pass
    #deactivated = ContextMethod(deactivated)

    ############################################################
    # IAddNotifiable

    def manage_afterAdd(self, configuration, container):
        "See Zope.App.OFS.Container.IAddNotifiable"
        sm = getServiceManager(configuration)
        definition = configuration.getDefinition()
        dependents = getAdapter(definition, IDependable)
        objectpath = getPhysicalPathString(configuration)
        dependents.addDependent(objectpath)

    ############################################################
    # IDeleteNotifiable

    def manage_beforeDelete(self, configuration, container):
        "See Zope.App.OFS.Container.IDeleteNotifiable"
        sm = getServiceManager(self)
        objectstatus = self.status
        dependents = getAdapter(definition, IDependable)
        objectpath = getPhysicalPathString(self)
        if objectstatus == Active:
            raise DependencyError("Can't delete active configurations")
        elif objectstatus == Registered:
            self.status = Unregistered
        dependents.removeDependent(objectpath)

    manage_beforeDelete = ContextMethod(manage_beforeDelete)

    #
    ############################################################


=== Added File Zope3/lib/python/Zope/App/Workflow/configure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
   xmlns:service='http://namespaces.zope.org/service'>

<content class=".WorkflowService.">
  <factory
      id="WorkflowService"
      permission="Zope.ManageServices"
      />
  <require
      permission="Zope.View"
      attributes="getDefinitionNames getDefinition" />
  <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
</content>

<serviceType id='Workflows'
             interface='.IWorkflowService.' />

<browser:menuItem
    menu="add_component"
    for="Zope.App.OFS.Container.IAdding."
    action="WorkflowService"
    title='Workflow Service'
    description="A Workflow Service" />


<!-- <include package=".Views" /> -->

</zopeConfigure>


=== Zope3/lib/python/Zope/App/Workflow/IWorkflowService.py 1.2 => 1.2.24.1 ===
--- Zope3/lib/python/Zope/App/Workflow/IWorkflowService.py:1.2	Mon Jun 10 19:28:18 2002
+++ Zope3/lib/python/Zope/App/Workflow/IWorkflowService.py	Tue Dec  3 10:32:13 2002
@@ -1,59 +1,44 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
 
-"""
-    Interfaces for Workflow Service.
+"""Interfaces for workflow service.
 """
 
 from Interface import Interface
+from Zope.App.OFS.Services.ConfigurationInterfaces import IConfigurable
 
 
-class IWorkflowService( Interface ):
-    """
-        Interface for workflow service.
-    """
+class IWorkflowService(IConfigurable):
+    """Workflow service.
 
-    def listEngine():
-        """
-           Return the list of engine and their interfaces
-        """
-        pass
+    A workflow service manages the process definitions.
+    """
 
+    def getDefinitionNames():
+        """Return the definition names.
 
-    def getEngine(IWorkflowEngine):
-        """
-           Return a workflow engine giving its interface
+        Returns a sequence of names.
         """
-        pass
 
+    def getDefinition(name):
+        """Return the definition for name."""
 
-    def addEngine(WorkflowEngine):
-        """
-           Add a workflow engine
-        """
+    # configuration
 
-    def removeEngine(WorkflowEngine):
-        """
-           Remove Workflow engine from the system
-        """
-        pass
+    def queryConfigurations(name):
+        """Return an IConfigurationRegistry for a process definition name."""
 
+    def createConfigurationsFor(configuration):
+        """Create and return an IConfigurationRegistry."""
 
-    def listWorkflowEngineActions():
-        """
-           Return an aggregation of the actions provided
-           by the present engines
-        """
-
-    


=== Zope3/lib/python/Zope/App/Workflow/WorkflowService.py 1.2 => 1.2.24.1 ===
--- Zope3/lib/python/Zope/App/Workflow/WorkflowService.py:1.2	Mon Jun 10 19:28:18 2002
+++ Zope3/lib/python/Zope/App/Workflow/WorkflowService.py	Tue Dec  3 10:32:13 2002
@@ -1,56 +1,66 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
+
+"""Workflow service implementation.
+"""
+
+
+from Persistence.Module import PersistentModuleRegistry
+
+from Zope.ContextWrapper import ContextMethod
+from Zope.ComponentArchitecture import getService
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
 from Zope.App.Workflow.IWorkflowService import IWorkflowService
 
-class WorkflowService:
 
-    __implements__ =  IWorkflowService
+class WorkflowService(PersistentModuleRegistry):
+
+    __implements__ = (IWorkflowService,
+                      PersistentModuleRegistry.__implements__)
+
+    def __init__(self):
+        super(WorkflowService, self).__init__()
+        self.__definitions = {}
 
     ############################################################
     # Implementation methods for interface
     # Zope.App.Workflow.IWorkflowService
 
-    engines = ()
+    def getDefinitionNames(self):
+        return self.__definitions.keys()
+
+    def getDefinition(self, name):
+        definition = self.getBoundDefinition(name)
+        if definition is not None:
+            return definition
+        service = getService(self, IWorkflowService)
+        if service is not None:
+            return service.getDefinition(name)
+        raise ComponentLookupError
+
+    getDefinition = ContextMethod(getDefinition)
 
-    def removeEngine(self, engine):
-        '''See interface IWorkflowService'''
-        self.engines = tuple(filter(lambda x: x != engine, self.engines))
-
-    def listWorkflowEngineActions(self):
-        '''See interface IWorkflowService'''
-        result = []
-        for engine in self.engines:
-            result.extend(engine.listActions())
-        return result
-    
-    def listEngine(self):
-        '''See interface IWorkflowService'''
-        return self.engines
-
-    def addEngine(self, engine):
-        '''See interface IWorkflowService'''
-
-        self.engines = self.engines + (engine,)
-
-    def getEngine(self, interface):
-        '''See interface IWorkflowService'''
-
-        result = []
-        for engine in self.engines:
-            if interface.isImplementedBy(engine):
-                result.append(engine)
-        return result
-    
     #
     ############################################################
+
+    def getBoundDefinition(self, name):
+        registry = self.queryConfigurations(name)
+        if registry is None:
+            return None
+        configuration = registry.active()
+        if configuration is None:
+            return None
+        return configuration.getDefinition()
+
+