Changes between Version 11 and Version 12 of TestManagerForTracPluginWorkflow


Ignore:
Timestamp:
Jan 4, 2011 1:16:19 PM (4 years ago)
Author:
seccanj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TestManagerForTracPluginWorkflow

    v11 v12  
    33The Test Manager plugin is comprised of four plugins, one of which is a Generic Workflow Engine plugin for any Trac resource. 
    44 
    5 The following figure shows a sample workflow added to Test Cases with custom sample operations. No built-in operation is currently implemented but the sample one shown here, named 'sample_operation', which logs a debug message with the text input by the User. 
     5The following figure shows a sample workflow added to Test Cases with custom sample operations. A small [wiki:TestManagerPluginWorkflowOperations set of built-in operations] is currently implemented, plus the sample one shown here, named 'sample_operation', which logs a debug message with the text input by the User. 
    66 
    77Every object which has a workflow defined is created in a "new" state, so every transition should consider this as the first state in the state machine. 
     
    238238all this is automatically performed by the plugin. 
    239239 
    240 So, let's take a look at how the [wiki:TestManagerForTracPlugin TestManager] plugin incorporates this web interface support. 
     240So, let's take a look at (a simplified version of) how the [wiki:TestManagerForTracPlugin TestManager] plugin incorporates this web interface support. 
    241241 
    242242{{{ 
     
    252252    def filter_stream(self, req, method, filename, stream, data): 
    253253        page_name = req.args.get('page', 'WikiStart') 
    254         planid = req.args.get('planid', '-1') 
    255  
    256         if page_name == 'TC': 
    257             # The root catalog does not have workflows 
    258             return stream 
    259  
    260         if page_name.startswith('TC') and filename == 'wiki_view.html': 
    261             req.perm.require('TEST_VIEW') 
     254        req.perm.require('TEST_VIEW') 
    262255             
    263             # Determine which object is being displayed (i.e. realm),  
    264             # based on Wiki page name and the presence of the planid  
    265             # request parameter. 
    266             realm = None 
    267             if page_name.find('_TC') >= 0: 
    268                 if not planid or planid == '-1': 
    269                     realm = 'testcase' 
    270                     key = {'id': page_name.rpartition('_TC')[2]} 
    271                 else: 
    272                     realm = 'testcaseinplan' 
    273                     key = {'id': page_name.rpartition('_TC')[2], 'planid': planid} 
    274             else: 
    275                 if not planid or planid == '-1': 
    276                     realm = 'testcatalog' 
    277                     key = {'id': page_name.rpartition('_TT')[2]} 
    278                 else: 
    279                     realm = 'testplan' 
    280                     key = {'id': planid} 
    281  
    282             id = get_string_from_dictionary(key) 
    283             res = Resource(realm, id) 
    284  
    285             workflow_markup = ResourceWorkflowSystem(self.env).get_workflow_markup(req, '..', realm, res) 
     256        realm = 'testcase' 
     257        key = {'id': page_name.rpartition('_TC')[2]} 
     258 
     259        id = get_string_from_dictionary(key) 
     260        res = Resource(realm, id) 
     261 
     262        # This is where we ask the workflow engine to generate the HTML markup 
     263        # to be displayed in the web page to let the User change a resource workflow state 
     264        workflow_markup = ResourceWorkflowSystem(self.env).get_workflow_markup(req, '..', realm, res) 
    286265             
    287             return stream | Transformer('//div[contains(@class,"wikipage")]').after(workflow_markup)  
    288  
    289         return stream 
     266        return stream | Transformer('//div[contains(@class,"wikipage")]').after(workflow_markup)  
    290267}}} 
    291268 
     
    310287  res = Resource(realm, id) 
    311288}}} 
     289 
     290== Programmatic Interface == 
     291 
     292The workflow engine comes with a programmatic interface, letting other plugins interact with the workflow lifecycle. 
     293 
     294There are two interfaces that let you interact with the workflow transitions: 
     295 
     296 1. You can give or deny permission to actually perform the transition => IWorkflowTransitionAuthorization 
     297 2. Being notified of state transitions => IWorkflowTransitionListener 
     298 
     299 
     300=== IWorkflowTransitionAuthorization === 
     301 
     302{{{ 
     303class IWorkflowTransitionAuthorization(Interface): 
     304    """ 
     305    Extension point interface for components that wish to augment the 
     306    state machine at runtime, by allowing or denying each transition 
     307    based on the object and the current and new states. 
     308    """ 
     309 
     310    def is_authorized(res_wf_state, resource, action, old_state, new_state): 
     311        """ 
     312        Called before allowing the transition. 
     313        Return True to allow for the transition, False to deny it. 
     314         
     315        :param res_wf_state: the ResourceWorkflowState being  
     316                             transitioned from old_state to new_state 
     317        :param resource: the Resource object being transitioned. 
     318        :param action: the action being performed. 
     319        """ 
     320}}} 
     321 
     322=== IWorkflowTransitionListener === 
     323 
     324{{{ 
     325class IWorkflowTransitionListener(Interface): 
     326    """ 
     327    Extension point interface for components that require notification 
     328    when objects transition between states. 
     329    """ 
     330 
     331    def object_transition(res_wf_state, resource, action, old_state, new_state): 
     332        """ 
     333        Called when an object has transitioned to a new state. 
     334 
     335        :param res_wf_state: the ResourceWorkflowState   
     336                             transitioned from old_state to new_state 
     337        :param resource: the Resource object transitioned. 
     338        :param action: the action been performed. 
     339        """ 
     340}}} 
     341