DotNetTools Workflow tutorial (2)

Source: Internet
Author: User
Tags how to write test cases

Function

Next, we want to set a user as "owner" after a draft is written ". To achieve this goal, we need to do two things:

1) set the "caller" variable in the current environment through a function.
2) set the "owner" attribute based on the "caller" variable.
A function is a powerful feature of Workflow. A function is basically a work unit in a workflow and does not affect the process itself. For example, you may have a "SendEmail" function to send email reminders when a specific flow occurs.

The function can also be used to add variables to the current environment settings. A variable is an object with a specified name. It can be used by subsequent functions or scripts in a workflow.
Workflow provides some built-in common functions. One of them is called "Caller". This function will get the user who calls the workflow and put it into a variable named "caller.

Because we need to track which user started to write a draft, we can use this function to modify our action definition:

<Action id = "2" name = "Start First Draft">

<Pre-functions>

<Function type = "type">

<Arg name = "type. name"> DotNetTools. Workflow. Util. Caller, DotNetTools. Workflow </arg>

</Function>

</Pre-functions>

<Results>

<Unconditional-result old-status = "Finished" status = "Underway"

Step = "1" owner = "$ {caller}"/>

</Results>

</Action>

Combination

 

 

Combine these concepts so that we have action 2:

<Action id = "2" name = "Start First Draft">

<Restrict-to>

<Conditions>

<Condition type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. StatusCondition, DotNetTools. Workflow

</Arg>

<Arg name = "status"> Queued </arg>

</Condition>

</Conditions>

</Restrict-to>

<Pre-functions>

<Function type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. Caller, DotNetTools. Workflow

</Arg>

</Function>

</Pre-functions>

<Results>

<Unconditional-result old-status = "Finished" status = "Underway"

Step = "1" owner = "$ {caller}"/>

</Results>

</Action>


We use a similar idea to set Action 3:

<Action id = "3" name = "Finish First Draft">

<Restrict-to>

<Conditions type = "AND">

<Condition type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. StatusCondition, DotNetTools. Workflow

</Arg>

<Arg name = "status"> Underway </arg>

</Condition>

<Condition type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. AllowOwnerOnlyCondition, DotNetTools. Workflow

</Arg>

</Condition>

</Conditions>

</Restrict-to>

<Results>

<Unconditional-result old-status = "Finished" status = "Queued" step = "2"/>

</Results>

</Action>


Here we specify a new condition: "allow owner only ". This ensures that only the users who have started writing this draft can complete it. The status condition ensures that the "finish first draft" action can be called only for the process in the "Underway" state.

When they are combined, we have the first process definition:

<? Xml version = "1.0" encoding = "UTF-8"?>

<! DOCTYPE workflow PUBLIC "-// dotnettools.org//DTD Workflow 2.8 //" http://www.dotnettools.org/workflow/workflow_2_8.dtd ">

<Workflow>

<Initial-actions>

<Action id = "1" name = "Start Workflow">

<Results>

<Unconditional-result old-status = "Finished" status = "Queued" step = "1"/>

</Results>

</Action>

</Initial-actions>

<Steps>

<Step id = "1" name = "First Draft">

<Actions>

<Action id = "2" name = "Start First Draft">

<Restrict-to>

<Conditions>

<Condition type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. StatusCondition, DotNetTools. Workflow

</Arg>

<Arg name = "status"> Queued </arg>

</Condition>

</Conditions>

</Restrict-to>

<Pre-functions>

<Function type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. Caller, DotNetTools. Workflow

</Arg>

</Function>

</Pre-functions>

<Results>

<Unconditional-result old-status = "Finished" status = "Underway"

Step = "1" owner = "$ {caller}"/>

</Results>

</Action>

<Action id = "3" name = "Finish First Draft">

<Restrict-to>

<Conditions type = "AND">

<Condition type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. StatusCondition, DotNetTools. Workflow

</Arg>

<Arg name = "status"> Underway </arg>

</Condition>

<Condition type = "type">

<Arg name = "type. name">

DotNetTools. Workflow. Util. AllowOwnerOnlyCondition, DotNetTools. Workflow

</Arg>

</Condition>

</Conditions>

</Restrict-to>

<Results>

<Unconditional-result old-status = "Finished" status = "Queued" step = "2"/>

</Results>

</Action>

</Actions>

</Step>

<Step id = "2" name = "finished"/>

</Steps>

</Workflow>
Now that the definition of this workflow is complete, let's test and check its running.

Now we have completed a complete workflow definition. The next step is to verify whether the workflow is executed as expected.

In a quick development environment, the simplest way is to write a test case. Call the workflow through test cases, and capture Possible Errors Based on the verification results to ensure the correctness of the process definition.
Let's assume that you are familiar with Junit and know how to write test cases. If you are not familiar with this knowledge, you can go to the JUnit website to find and read relevant documents. Writing Test cases will become a very useful tool for you.

Before loading the process definition and calling actions, we need to configure the data storage mode and file location of Workflow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.