Quick Tour of DaCE

Introduction to business processes

In a company, a product is usually the result of a sequence of actions, according to business rules, performed by professional actors. The sequence of these actions is called a business process. Some of these actions can be automated in order to simplify the interaction of the different actors with data.

Processes in DaCE

In DaCE, a process is a set of nodes interconnected by oriented transitions (see Fig 1). These nodes can be actions, events or gateways.

hello process

Fig 1: Hello process example

DaCE implement a set of concepts introduced in the BPMN standard. For more informtion about actions, events or gateways see BPMN Specification - Business Process Model and Notation.

DaCE enables the definition and execution of complex processes. It provide an API to manage processes and their nodes.

DaCE is an application built using the SubstanceD application server and the Pyramid web framework.

Installation

If you have already installed Substance D

  1. Add ecreall_dace and ‘mock’ in requires in the setup.py file.:

    ...
    requires = [
        ...
        'ecreall_dace',
        'mock',
        ]
    ...
    
  2. Include DaCE in the Pyramid configurator in the myproj/__init__.py file:

    ...
    def main(global_config, **settings):
        ...
        config.include('substanced')
        # include dace in the Pyramid configurator
        config.include('dace')
        ...
    

If you didn’t already installed SubstanceD

You can install DaCE by performing the following steps.

  1. Create a new directory somewhere and cd to it:

    $ virtualenv -p python3.4 hack-on-substanced
    $ cd hack-on-substanced
    $ . bin/activate
    
  2. Install Substance D either from PyPI or from a git checkout:

    $ pip install substanced
    

    OR:

    $ pip install git+https://github.com/Pylons/substanced#egg=substanced
    

    Alternatively create a writeable fork on GitHub and check that out.

  3. Check that the python-magic library has been installed:

    $ python -c "from substanced.file import magic; assert magic is not None, 'python-magic not installed'"
    

    If you then see “python-magic not installed” then you will need to take additional steps to install the python-magic library.

  4. Move back to the parent directory:

    $ cd ..
    
  5. Now you should be able to create new Substance D projects by using pcreate. The following pcreate command uses the scaffold substanced to create a new project named myproj:

    $ pcreate -s substanced myproj
    
  6. Add ecreall_dace in requires in the setup.py file.:

    ...
    requires = [
        ...
        'ecreall_dace',
        ]
    ...
    
  7. Include DaCE in the Pyramid configurator in the myproj/__init__.py file:

    ...
    def main(global_config, **settings):
        ...
        config.include('substanced')
        # include dace in the Pyramid configurator
        config.include('dace')
        ...
    
  8. Install that project using pip install -e into the virtualenv:

    $ pip install -e .
    
  9. Run the resulting project via pserve development.ini. The development server listens to requests sent to http://0.0.0.0:6543 by default. Open this URL in a web browser.

Hello World

Applications have shown that learning starts best from a very small first step. Here’s a tiny process definition in DaCE (see Fig 1):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from zope.interface import Interface

from pyramid.view import view_config

from dace.definition.processdef import ProcessDefinition
from dace.definition.activitydef import ActivityDefinition
from dace.definition.transitiondef import TransitionDefinition
from dace.definition.eventdef import (
    StartEventDefinition,
    EndEventDefinition)
from dace.model.services.processdef_container import (
    process_definition)
from dace.instance.activity import ElementaryAction
from dace.util import get_all_business_actions

# Step 1: Define a behavior to execute. This behavior is an
# 'ElementaryAction'. It means that the behavior is executed
# only one time in the process instance.
class MyBehavior(ElementaryAction):
    context = Interface

    def start(self, context, request, appstruct, **kw):
        # Your code here
        return {'message': 'Hello world!'}


# Step 2: Define the process with its nodes and transitions
@process_definition(
    id='myprocessid',
    title='My process')
class MyProcess(ProcessDefinition):

    def init_definition(self):
        # define process nodes
        self.define_nodes(
            # start node: the beginning of the process
            start=StartEventDefinition(),
            # hello node
            hello=ActivityDefinition(
                # MyBehavior is the behavior to execute
                # when the node is called
                behaviors=[MyBehavior],
                description='Hello behavior',
                title='Hello!'),
            # end node: the ending of the process
            end=EndEventDefinition(),
        )
        # define transitions between process nodes
        self.define_transitions(
            TransitionDefinition('start', 'hello'),
            TransitionDefinition('hello', 'end'),
        )


# Step 3: Define a simple view for find, execute and
# display the result of the execution of our behavior
# defined in our process.
@view_config(name='my_process', renderer='json')
def my_process_view(request):
    # 'get_all_business_actions' enable to retrieve all of
    # behaviors in all of process instances with the id
    # equal to 'myprocessid'
    process_actions = get_all_business_actions(
        context=request.root,
        request=request,
        process_id='myprocessid')
    if process_actions:
        # Get the first action
        action_to_execute = process_actions[0]
        # Get action title
        action_title = action_to_execute.node.title
        # Excute the first action
        result = action_to_execute.execute(
            request.root, request, {})
        # Get the execution result of the behavior.
        # See 'start' method of MyBehavior class
        excution = result.get('message', None)
        # Get the process instance id
        process_id = action_to_execute.process.__name__
        return {'action title': action_title,
                'message': excution,
                'process id': process_id}

    return {}

This simple example is easy to run. Save this as process_definition.py in your project (myproj) and run it.

Next open http://0.0.0.0:6543/my_process in a browser, and you will see the Hello World! message.

New to DaCE? If so, some lines in the module merit an explanation:

  1. Step 1 - Line 19. The ElementaryAction is one of multiple behavior type in DaCE. This type of behavior is executed only one time in the process instance. See Behaviors types for more information.
  2. Step 1 - Line 20. The behavior is executed only on objects that implement the context.
  3. Step 3 - Line 63. get_all_business_actions retrieves all of behaviors in all of process instances of myprocessid for a given object. For more information about the DaCE utilities see DaCE utilities