Personal tools
You are here: Home Products Plone Roadmap #217: Use Adaptation for Workflow Assignment
Document Actions

#217: Use Adaptation for Workflow Assignment

Contents
  1. Motivation
  2. Proposal
  3. Deliverables
  4. Risks
by Alec Mitchell last modified March 2, 2008 - 19:43
There is still one major area in which the workflow is difficult to customize: workflow assignment by a mechanism other than portal_type. This proposal attempts to address this issue by using adaptation to determine workflow assignment.
Proposed by
Alec Mitchell
Proposal type
Architecture
Assigned to release
State
completed

Motivation

Currently it is very difficult to use alternate mechanisms for assigning workflow. For example CMFPlacefulWorkflow needs to monkey patch the workflow tool in order to support assignment based on location. There is also no way to change the workflow assigned to an object based on "sub-type", i.e. a marker interface applied to content. Further, though the workflow engine is built to work with non-CMF content, the workflow assignment mechanism assumes the existence of a portal_type. This inflexibility can easily be addressed by using adaptation to determine which workflows apply to a particular object.

Proposal

Providing workflow assignment via adaptation is a pretty trivial task which can be made fully backward compatible. We simply need to replace the content of the WorkflowTool.getWorkflowsFor method with a lookup via adaptation. For simplicity we could use a single adaptation:

def getWorkflowsFor(self, ob)
    return IWorkflowChain(ob)

Where IWorkflowChain is a simple iterable of workflow objects. However, in order to support more complex usecases, which might need to change workflow policy portal wide, it makes sense to use a multi-adapter on the object and the workflow tool:

def getWorkflowsFor(self, ob):
    return getMultiAdapter((ob, self), IWorkflowChain)

This would allow for something like CMFPlacefulWorkflow to, on install, mark the workflow tool with an interface indicating a policy change, and then provide a specialized adapter for the marked tool. The default adapter itself would be simple:

class DefaultWorkflowLookup(object):
    implements(IWorkflowChain)
    adapts(IDynamicType, IWorkflowTool)

    def __init__(self, obj, tool):
        self.tool = tool
        self.obj = obj

    def __iter__(self):
        tool = self.tool
        for wf_id in tool.getChainFor(self.obj):
            wf = tool.getWorkflowById(wf_id)
            if wf is not None:
                yield wf

Alternatively, we could replace getChainFor instead of getWorkflowsFor, so that the task of looking up the workflow by id would be left up to the tool and wouldn't have to be implemented by every adapter. However, this would eliminate the potential to use workflows defined outside the tool (perhaps even non-persistent workflows).

Ideally this would be done in CMFCore. However, it's certainly feasible to do it inside of the CMFPlone workflow tool if no major release of CMF is imminent. The changes could easily be merged back into the core as needed.

Another, non-mandatory step would be to re-implement the CMFPlacefulWorkflow monkeypatch as an adapter using this pattern and have its Product install method apply an appropriate marker interface to the workflow tool (the uninstall would of course remove the marker).

Deliverables

  • The interface for IWorkflowChain would need to be created.
  • The getWorkflowsFor method would need to be rewritten/overridden, and a test would need to be written to demonstrate the adaptation based mechanism.
  • The default adapter would need to be created, and existing tests would need to be changed to test that adapter specifically.
  • Some documentation on how to provide a custom workflow assignment mechanism should be provided.

Risks

There should be no risks for this change. The only risk is that our workflow tool will deviate further from the CMF version, hopefully we can get this code applied in CMFCore sooner rather than later.

A CMFPlacefulWorkflow extension

Posted by Encolpe Degoute at December 14, 2007 - 09:01
#1 IWorkflowChain is a simple iterable of workflow objects => 'workflow objects' should be 'objects that implements IPloneWorkflow'

#2 This approach object by object is complementary to the CMFPlacefulWorkflow that make possible a CMF like workflow strategy (id est by type) for a part of the site. The next step should be to have a more open implementation of strategies to be able to run by language workflow for example.

Previously Existing Work

Posted by Sidnei da Silva at December 14, 2007 - 12:34
It is great that you've made this into a PLIP, it was on my TODO for about a year *wink*.

Kapil has proposed a similar solution on the CMF mailing list, but no-one paid attention:

http://article.gmane.org/gmane.comp.web.zope.cmf/12834/match=using+adapters+workflow+tool

His code is available on the CMFBlackBird product, at Object Realms SVN:

http://svn.objectrealms.net/view/public/browser/cmfblackbird/trunk/workflow.py

Hope that's useful to you...

updated code reference

Posted by Kapil Thangavelu at January 3, 2008 - 17:39
fwiw. i updated that code to be backwards compatible replacement it covers plip 217 and 221 (adaptation to find workflow, and adaptation to store workflow state/history)

http://svn.objectrealms.net/view/public/browser/ore.adaptedworkflow/trunk/src/ore/adaptedworkflow

+1 on the idea

Framework team vote

Posted by Andreas Zeidler at December 14, 2007 - 16:45
+1 (see http://lists.plone.org/pipermail/framework-team/2007-December/001547.html)

Framework team vote

Posted by Martijn Pieters at December 14, 2007 - 17:08
+1

Framework team vote

Posted by Raphael Ritz at December 17, 2007 - 12:30
+1

Framework team vote

Posted by Tom Lazar at December 20, 2007 - 13:26
+1

Framework team vote

Posted by Danny Bloemendaal at December 22, 2007 - 16:05
+1
Does this also mean that you theoretically could have a setting on an object which workflows it uses? That would be nice (with the proper UI of course ;-))

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by