[Zope3-checkins] CVS: Zope3/src/zope/app/workflow/interfaces - __init__.py:1.1 stateful.py:1.1 wfmc.py:1.1

Philipp von Weitershausen philikon at philikon.de
Fri Feb 27 11:50:40 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/workflow/interfaces
In directory cvs.zope.org:/tmp/cvs-serv22977/workflow/interfaces

Added Files:
	__init__.py stateful.py wfmc.py 
Log Message:
Centralized the workflow interfaces and browser views in
zope.app.workflow.


=== Added File Zope3/src/zope/app/workflow/interfaces/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 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, definition and instance.

$Id: __init__.py,v 1.1 2004/02/27 16:50:39 philikon Exp $
"""
from zope.interface import Interface
from zope.interface import Attribute
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.container import IContainer
from zope.app.interfaces.event import IEvent
from zope.app.interfaces.services.registration \
     import INamedComponentRegistration
from zope.app.interfaces.services.registration import ComponentPath


class IWorkflowEvent(IEvent):
    """This event describes a generic event that is triggered by the workflow
    mechanism."""


class IWorkflowService(Interface):
    """Workflow service.

    A workflow service manages the process definitions."""

    def getProcessDefinitionNames():
        """Return the definition names.

        Returns a sequence of names."""

    def getProcessDefinition(name):
        """Return the IProcessDefinition for the name."""

    def queryProcessDefinition(name, default=None):
        """Return the IProcessDefinition for the name or default."""

    def createProcessInstance(definition_name):
        """Create a process instance from a process definition."""


class IProcessDefinitionRegistration(INamedComponentRegistration):
    """Registration for a workflow process definition."""

    componentPath = ComponentPath(
        title=_("Component path"),
        description=_("The physical path to the component"),
        required=True,
        readonly=True,
        )


class IProcessDefinition(Interface):
    """Interface for workflow process definition."""

    name = Attribute("""The name of the ProcessDefinition""")

    def createProcessInstance(definition_name):
        """Create a new process instance for this process definition.

        Returns an IProcessInstance."""


class IProcessDefinitionElementContainer(IContainer):
    """Abstract Interface for ProcessDefinitionElementContainers."""


    def getProcessDefinition():
        """Return the ProcessDefinition Object."""


class IProcessInstance(Interface):
    """Workflow process instance.

    Represents the instance of a process defined by a ProcessDefinition."""

    status = Attribute("The status in which the workitem is.")

    processDefinitionName = Attribute("The process definition Name.")



class IProcessInstanceContainer(IContainer):
    """Workflow process instance container."""


class IProcessInstanceContainerAdaptable(Interface):
    """Marker interface for components that can be adapted to a process
    instance container."""


class IProcessInstanceControl(Interface):
    """Interface to interact with a process instance."""

    def start():
        """Start a process instance."""

    def finish():
        """Finish a process instance."""


class IWorklistHandler(Interface):
    """Base interface for Workflow Worklist Handler."""

    def getWorkitems():
        """Return a sequence of workitem."""


class IProcessDefinitionImportExport(Interface):
    """ProcessDefinition Import/Export."""

    def importProcessDefinition(context, data):
        """Import a Process Definition"""

    def exportProcessDefinition(context, process_definition):
        """Export a Process Definition"""


class IGlobalProcessDefinitionImportExport(IProcessDefinitionImportExport):
    """Global ImportExport with additional method to register import/export
    handlers."""

    def addImportHandler(interface, factory):
        """Add a factory for an import handler for a certain interface."""

    def addExportHandler(interface, factory):
        """Add a factory for an export handler for a certain interface."""


class IProcessDefinitionImportHandler(Interface):
    """Handler for Import of ProcessDefinitions."""

    def canImport(context, data):
        """Check if handler can import a processdefinition
           based on the data given."""

    def doImport(context, data):
        """Create a ProcessDefinition from the data given.

        Returns a ProcessDefinition Instance."""

class IProcessDefinitionExportHandler(Interface):
    """Handler for Export of ProcessDefinitions."""

    def doExport(context, process_definition):
        """Export a ProcessDefinition into a specific format.

        Returns the serialized value of the given ProcessDefintion."""


=== Added File Zope3/src/zope/app/workflow/interfaces/stateful.py ===
##############################################################################
#
# Copyright (c) 2001, 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 stateful workflow process definition.

$Id: stateful.py,v 1.1 2004/02/27 16:50:39 philikon Exp $
"""
import zope.schema
from zope.app.security.permission import PermissionField

from zope.interface import Interface, Attribute
from zope.app.component.interfacefield import InterfaceField
from zope.app.workflow.interfaces import IWorkflowEvent
from zope.app.workflow.interfaces import IProcessDefinition
from zope.app.workflow.interfaces import IProcessInstance
from zope.app.workflow.interfaces import IProcessDefinitionElementContainer

AUTOMATIC = u'Automatic'
MANUAL = u'Manual'
INITIAL = u'INITIAL'


class ITransitionEvent(IWorkflowEvent):
    """An event that signalizes a transition from one state to another."""

    object = Attribute("""The content object whose status will be changed.""")

    process = Attribute("""The process instance that is doing the
                           transition. Note that this object really represents
                           the workflow.""")

    transition = Attribute("""The transition that is being fired/executed. It
                              contains all the specific information, such as
                              source and destination state.""")


class IBeforeTransitionEvent(ITransitionEvent):
    """This event is published before a the specified transition occurs. This
    allows other objects to veto the transition."""


class IAfterTransitionEvent(ITransitionEvent):
    """This event is published after the transition. This is important for
    objects that might change permissions when changing the status."""


class IRelevantDataChangeEvent(IWorkflowEvent):
    """This event is fired, when the object's data changes and the data is
    considered 'relevant' to the workflow. The attributes of interest are
    usually defined by a so called Relevant Data Schema."""

    process = Attribute("""The process instance that is doing the
                           transition. Note that this object really represents
                           the workflow.""")

    schema = Attribute("""The schema that defines the relevant data
                          attributes.""")

    attributeName = Attribute("""Name of the attribute that is changed.""")

    oldValue = Attribute("""The old value of the attribute.""")

    newValue = Attribute("""The new value of the attribute.""")


class IBeforeRelevantDataChangeEvent(IRelevantDataChangeEvent):
    """This event is triggered before some of the workflow-relevant data is
    being changed."""


class IAfterRelevantDataChangeEvent(IRelevantDataChangeEvent):
    """This event is triggered after some of the workflow-relevant data has
    been changed."""


class IState(Interface):
    """Interface for state of a stateful workflow process definition."""
    # XXX Should at least have a title, if not a value as well

class IStatefulStatesContainer(IProcessDefinitionElementContainer):
    """Container that stores States."""



class AvailableStatesField(zope.schema.TextLine):
    """Available States."""

    def __allowed(self):
        pd = self.context.getProcessDefinition()
        return pd.getStateNames()

    allowed_values = property(__allowed)


class TriggerModeField(zope.schema.TextLine):
    """Trigger Mode."""

    def __allowed(self):
        return [MANUAL, AUTOMATIC]

    allowed_values = property(__allowed)


class ITransition(Interface):
    """Stateful workflow transition."""

    sourceState = AvailableStatesField(
        title=u"Source State",
        description=u"Name of the source state.",
        required=True)

    destinationState = AvailableStatesField(
        title=u"Destination State",
        description=u"Name of the destination state.",
        required=True)

    condition = zope.schema.TextLine(
        title=u"Condition",
        description=u"""The condition that is evaluated to decide if the
                        transition can be fired or not.""",
        required=False)

    script = zope.schema.TextLine(
        title=u"Script",
        description=u"""The script that is evaluated to decide if the
                        transition can be fired or not.""",
        required=False)

    # XXX cannot add a default value -> raises
    # ComponentLookupError: Permissions
    # required=False does not help as well
    # so for now the permission needs to be set ttw
    # till we find another solution
    permission = PermissionField(
        title=u"The permission needed to fire the Transition.",
        required=True)


    triggerMode = TriggerModeField(
        title=u"Trigger Mode",
        description=u"How the Transition is triggered (Automatic/Manual)",
        default=u"Manual")


    def getSourceState():
        """Get Source State."""

    def setSourceState(source):
        """Set Source State."""

    def getDestinationState():
        """Get Destination State."""

    def setDestinationState(destination):
        """Set Destination State."""

    def getCondition():
        """Get Condition."""

    def setCondition(condition):
        """Set Condition."""

    def getScript():
        """Get Script."""

    def setScript(script):
        """Set Script."""

    def getPermission():
        """Get Permission."""

    def setPermission(permission):
        """Set Permission."""

    def getTriggerMode():
        """Return the TriggerMode."""

    def setTriggerMode():
        """Set TriggerMode."""

    def getProcessDefinition():
        """Return the ProcessDefinition Object."""


class IStatefulTransitionsContainer(IProcessDefinitionElementContainer):
    """Container that stores Transitions."""


class IStatefulProcessDefinition(IProcessDefinition):
    """Interface for stateful workflow process definition."""

    relevantDataSchema = InterfaceField(
        title=u"Workflow-Relevant Data Schema",
        description=u"Specifies the schema that characterizes the workflow "
                    u"relevant data of a process instance, found in pd.data.",
        default=None,
        required=False)

    schemaPermissions = Attribute(u"A dictionary that maps set/get permissions"
                                  u"on the schema's fields. Entries looks as"
                                  u"follows: {fieldname:(set_perm, get_perm)}")

    states = Attribute("State objects container.")

    transitions = Attribute("Transition objects container.")

    def addState(name, state):
        """Add a IState to the process definition."""

    def getState(name):
        """Get the named state."""

    def removeState(name):
        """Remove a state from the process definition

        Raises ValueError exception if trying to delete the initial state.
        """

    def getStateNames():
        """Get the state names."""

    def getInitialStateName():
        """Get the name of the initial state."""

    def addTransition(name, transition):
        """Add a ITransition to the process definition."""

    def getTransition(name):
        """Get the named transition."""

    def removeTransition(name):
        """Remove a transition from the process definition."""

    def getTransitionNames():
        """Get the transition names."""

    # XXX Temporarily till we find a better solution
    def clear():
        """Clear the whole ProcessDefinition."""



class IStatefulProcessInstance(IProcessInstance):
    """Workflow process instance.

    Represents the instance of a process defined by a
    StatefulProcessDefinition.
    """

    data = Attribute("Relevant Data object.")

    def initialize():
        """Initialize the ProcessInstance.

        set Initial State and create relevant Data.
        """

    def getOutgoingTransitions():
        """Get the outgoing transitions."""

    def fireTransition(id):
        """Fire a outgoing transitions."""

    def getProcessDefinition():
        """Get the process definition for this instance."""


class IContentProcessRegistry(Interface):
    """Content Type <-> Process Definitions Registry

    This is a registry for mapping content types (interface) to workflow
    process definitions (by name).
    """

    def register(iface, name):
        """Register a new process definition (name) for the interface iface."""

    def unregister(iface, name):
        """Unregister a process (name) for a particular interface."""

    def getProcessNamesForInterface(iface):
        """Return a list of process defintion names for the particular
        interface."""

    def getInterfacesForProcessName(name):
        """Return a list of interfaces for the particular process name."""


class IContentWorkflowsManager(IContentProcessRegistry):
    """A Content Workflows Manager.

    It associates content objects with some workflow process definitions.
    """

    def subscribe():
        """Subscribe to the prevailing object hub service."""

    def unsubscribe():
        """Unsubscribe from the object hub service."""

    def isSubscribed():
        """Return whether we are currently subscribed."""

    def getProcessDefinitionNamesForObject(object):
        """Get the process definition names for a particular object.

        This method reads in all the interfaces this object implements and
        finds then the corresponding process names using the
        IContentProcessRegistry."""


=== Added File Zope3/src/zope/app/workflow/interfaces/wfmc.py ===
##############################################################################
#
# Copyright (c) 2001, 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 WfMC workflow process definition.

Status: Draft

$Id: wfmc.py,v 1.1 2004/02/27 16:50:39 philikon Exp $
"""
from zope.interface import Interface, Attribute

from zope.app.workflow.interfaces import IProcessDefinition
from zope.app.workflow.interfaces import IProcessInstance

from zope.app.interfaces.container import IContainer


# ToDo:
# - Specify all Attributes as SchemaFields where possible
# - Define necessary methods for Interfaces


class IWfMCProcessDefinition(IProcessDefinition):
    """WfMC Workflow process definition.
    """

    # will we have packages ??
    # package = Attribute("ref to package")

    processDefinitionHeader = Attribute("ref to pd header")

    redefinableHeader = Attribute("ref to refinable header")

    formalParameters = Attribute("parameters that are interchanged e.g. subflow")

    relevantData = Attribute("wfr data definition")

    participants = Attribute("colletion of participants")

    applications = Attribute("collection of applictations")

    startActivity = Attribute("ref to start activity")

    endActivity = Attribute("ref to end activity")

    activities = Attribute("list activities contained by PD")

    transitions = Attribute("list transitions contained by PD")



class IWfMCProcessDefinitionHeader(Interface):
    """WfMC Workflow process definition header.
    """

    created = Attribute("date of creation")

    description = Attribute("description of package")

    validFrom = Attribute("date the PD is valid from")

    validTo = Attribute("date the PD is valid to")

    limit = Attribute("limit for timemanagement in units of DurationUnit")

    priority = Attribute("priority of PD")

    durationUnit = Attribute("Duration Unit")

    workingTime = Attribute("amount of time, performer of activity needs to perform task")

    waitingTime = Attribute("amount of time, needed to prepare performance of task")

    duration = Attribute("duration in units")

    timeEstimation = Attribute("estimated time for the process")



class IWfMCProcessDefinitionElement(Interface):
    """WfMC process definition Element."""

    # components usually don't know their id within a container
    # id = Attribute("id of ProcessDefinitionElement")

    # we have to decide how to handle the Extended Attributes
    extendedAttributes = Attribute("list of extended Attributes")




## FormalParameter Declaration

class IWfMCFormalParameter(IContainer):
    """WfMC Formal Parameters Container.
    """

class IWfMCFormalParameter(IWfMCProcessDefinitionElement):
    """WfMC Formal Parameter.
    """

    mode = Attribute("mode: in/out/inout")

    index = Attribute("index of par")

    dataType = Attribute("data type of Parameter")

    description = Attribute("the Parameter Description")


## RelevantData Declaration

class IWfMCRelevantDataContainer(IContainer):
    """WfMC Relevant Data Container.
    """

class IWfMCRelevantData(IWfMCProcessDefinitionElement):
    """WfMC Relevant Data.
    """

    name = Attribute("name of DataField")

    isArray = Attribute("is array ?")

    dataType = Attribute("type of data")

    initialValue = Attribute("initial Value")

    description = Attribute("description of WFRD")


## Application Declaration

class IWfMCApplicationContainer(IContainer):
    """WfMC Application Definition Container.
    """

class IWfMCApplication(IWfMCProcessDefinitionElement):
    """WfMC Application Definition.
    """

    name = Attribute("Name of Application.")

    description = Attribute("Description of Application.")

    formalParameterList = Attribute("Sequence of Formal Parameters.")


## Participant Declaration

class IWfMCParticipantContainer(IContainer):
    """WfMC Participant Definition Container.
    """

class IWfMCParticipant(IWfMCProcessDefinitionElement):
    """WfMC Participant Definition.
    """

    name = Attribute("Name of Participant.")

    type = Attribute("""Type of Participant: RESOURCE_SET/RESOURCE/ROLE/
                        ORGANIZATIONAL_UNIT/HUMAN/SYSTEM""")

    description = Attribute("Description of Participant.")



## Activity

class IWfMCActivityContainer(IContainer):
    """WfMC Activity Container.
    """

class IWfMCActivity(IWfMCProcessDefinitionElement):
    """WfMC Activity.
    """

    # we get get this via acquisition
    # processDefinition = Attribute("ref to PD the activity belongs to")

    name = Attribute("a Activity Name")

    description = Attribute("a description")

    isRoute = Attribute("is this a route Activity")

    startMode = Attribute("how Activity is started (0-Manual/1-Automatic)")

    finishMode = Attribute("how Activity is finished (0-Manual/1-Automatic)")

    performer = Attribute("link to workflow participant (may be expression)")

    implementation = Attribute("if not Route-Activity: mandatory (no/tool+/subflow/loop)")

    instantiation = Attribute("capability: once/multiple times")

    priority = Attribute("priority of Activity")

    cost = Attribute("average cost")

    workingTime = Attribute("amount of time, performer of activity needs to perform task")

    waitingTime = Attribute("amount of time, needed to prepare performance of task")

    duration = Attribute("duration of activity")

    limit = Attribute("limit in costUnits")

    icon = Attribute("icon of activity")

    documentation = Attribute("documentation")

    splitMode = Attribute("split Mode (and/xor)")

    joinMode = Attribute("join Mode (and/xor)")

    inlineBlock = Attribute("inline Block definition")



class IWfMCImplementation(IWfMCProcessDefinitionElement):
    """WfMC Implementation Definition.

    is referenced by Activity Attribute: implementation.
    """

    type = Attribute("Type of Implementation: NO/SUBFLOW/TOOL")


class IWfMCSubflow(IWfMCImplementation):
    """WfMC Implementation Subflow.
    """

    name = Attribute("Name of Subflow to start.")

    execution = Attribute("Type of Execution: Asynchr/synchr.")

    actualParameterList = Attribute("""Sequence of ActualParameters with those the
                                     new Instance is initialized and whose are
                                     returned.""")


class IWfMCTool(IWfMCImplementation):
    """WfMC Implementation Subflow.
    """

    name = Attribute("Name of Application/Procedure to invoke (Application Declaration).")

    type = Attribute("Type of Tool: APPLICATION/PROCEDURE.")

    description = Attribute("Description of Tool.")

    actualParameterList = Attribute("""Sequence of ActualParameters with those the
                                     new Instance is initialized and whose are
                                     returned.""")



## Transition

class IWfMCCondition(Interface):
    """WfMC Condition.
    """

    type = Attribute("Type of Condition: CONDITION/OTHERWISE")

    expression = Attribute("Expression to evaluate.")


class IWfMCTransitionContainer(IContainer):
    """WfMC Transition Container.
    """

class IWfMCTransition(IWfMCProcessDefinitionElement):
    """WfMC Transition.
    """

    name = Attribute("Name of Transition.")

    condition = Attribute("ref to Condition.")

    fromActivityId = Attribute("Id of FromActivity.")

    toActivityId = Attribute("Id of ToActivity.")







## ProcessInstance

class IWfMCProcessInstanceData(Interface):
    """WfMC ProcessInstance Data.

    this is a base interfaces that gets extended dynamically
    when creating a ProcessInstance from the relevantData Spec.
    """

    # XXX Not shure how to implement this.
    # probably using schemagen


class IWfMCProcessInstance(IProcessInstance):
    """WfMC Workflow process instance.
    """

    processDefinitionId = Attribute("Id of ProcessDefinition.")

    name = Attribute("Name of ProcessInstance.")

    creationTime = Attribute("Creation Time of ProcessInstance.")

    activityInstances = Attribute("ref to ActivityInstanceContainer.")

    data = Attribute("WorkflowRelevant Data (instance, not definition.)")

    # XXX Do we need an actual Participantlist for implementation ??




## ActivityInstance

class IWfMCActivityInstanceContainer(IContainer):
    """WfMC ActivityInstance Container.
    """

class IWfMCActivityInstance(Interface):
    """WfMC Workflow activity instance.
    """

    activityId = Attribute("Id of Activity.")

    name = Attribute("Name of ActivityInstance.")

    creationTime = Attribute("Creation Time of ActivityInstance.")

    status = Attribute("Status of ActivityInstance.")

    priority = Attribute("Priority of ActivityInstance (initialized from Activity).")

    workitems = Attribute("ref to WorkitemContainer.")

    # XXX
    # participants = Attribute("Sequence of assigned Participants.")


## WorkItem

class IWfMCWorkitemContainer(IContainer):
    """WfMC Workitem Container.
    """

class IWfMCWorkitem(Interface):
    """WfMC Workflow  instance.
    """

    status = Attribute("Status of Workitem.")

    priority = Attribute("Priority of Workitem.")

    participant = Attribute("Participant that is assigned to do this item of Work.")





More information about the Zope3-Checkins mailing list