[quote]前篇我引入了互联网上找来的一篇文章,接着上篇讲:osworkflow 工作流是非常轻量级的,虽然2006就停止活动了,互联网上的资料也不是很多,官网也没过多的说明,比起jbpm 和activiti来说资料是相当少,但是不妨碍我们学习这个轻量级的工作流引擎。闲话少说[/quote]

[quote]demo1 入门
需要导入依赖:
lib/commons-logging.jar
oscore-2.2.5.jar
osworkflow-2.8.0.jar
propertyset-1.4.jar
[/quote]


  1. /*
    * Copyright 1999-29 Nov 2015 Alibaba.com All right reserved. This software is the
    * confidential and proprietary information of Alibaba.com ("Confidential
    * Information"). You shall not disclose such Confidential Information and shall
    * use it only in accordance with the terms of the license agreement you entered
    * into with Alibaba.com.
    */
    package com.osworkflow;

    import com.opensymphony.workflow.*;
    import com.opensymphony.workflow.basic.BasicWorkflow;
    import com.opensymphony.workflow.loader.WorkflowDescriptor;

    import java.util.HashMap;
    import java.util.List;

    /**
    * @author liuy 29 Nov 2015 4:17:44 pm
    */
    public class OsWorkflow {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws InvalidActionException, InvalidRoleException, InvalidInputException, InvalidEntryStateException, WorkflowException {
    String caller = "testUser";
    String params1 = "params1";
    String docTitle = "docTitle";
    long workflowId = 1;
    HashMap inputs = new HashMap();

    Workflow workflow = new BasicWorkflow(caller);
    inputs.put("params1", params1);
    inputs.put("docTitle", docTitle);
    workflowId = workflow.initialize("mytest", 100, inputs);

    //执行第1步动作
    workflow.doAction(workflowId, 1, inputs);
    WorkflowDescriptor wd = workflow.getWorkflowDescriptor(workflow.getWorkflowName(1));
    System.out.println(wd);
    List list= workflow.getCurrentSteps(1);
    System.out.println(list);
    System.out.println("finished");
    }
    }

要执行的业务函数:这里我用simulate 模拟打开一个浏览器的操作


  1. /*
    * Copyright 1999-29 Nov 2015 Alibaba.com All right reserved. This software is the
    * confidential and proprietary information of Alibaba.com ("Confidential
    * Information"). You shall not disclose such Confidential Information and shall
    * use it only in accordance with the terms of the license agreement you entered
    * into with Alibaba.com.
    */
    package com.osworkflow;

    import com.nnk.selenium.win.PayEditInputTyper;
    import com.opensymphony.module.propertyset.PropertySet;
    import com.opensymphony.workflow.FunctionProvider;
    import com.opensymphony.workflow.WorkflowException;
    import org.apache.commons.logging.impl.Log4JCategoryLog;
    import org.apache.log4j.Logger;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.ExpectedCondition;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.Assert;

    import java.util.List;
    import java.util.Map;

    /**
    * 类TestFunction.java的实现描述:TODO 类实现描述
    * @author liuy 29 Nov 2015 5:19:17 pm
    */
    public class TestFunction implements FunctionProvider {
    private Logger logger = Logger.getLogger(TestFunction.class);
    @Override
    public void execute(Map arg0, Map arg1, PropertySet arg2) throws WorkflowException {
    // 改状态
    System.out.println("change status...");
    System.out.println(arg0);
    System.out.println(arg1);
    System.out.println(arg2);
    System.out.println(arg1.get("context"));
    System.setProperty("webdriver.firefox.bin", "E:/Program Files (x86)/Mozilla Firefox/firefox.exe");
    Log4JCategoryLog log = (Log4JCategoryLog) arg0.get("log");
    log.info("hello");
    //声明一个火狐浏览器driver对象
    WebDriver driver= new FirefoxDriver();
    //设置窗口最大化
    driver.manage().window().maximize();

    //打开360搜索
    driver.get("http://www.007ka.cn/007kaWeb/");
    //找到搜索框元素
    WebElement searchInput= driver.findElement(By.id("mobno"));
    //向搜索框输入“selenium”
    searchInput.sendKeys("13267191379");

    WebElement searchInput2= driver.findElement(By.name("czval"));
    // Select value = new Select(searchInput2);
    // value.selectByVisibleText("200元");
    //向搜索框输入“selenium”
    searchInput2.sendKeys("400");
    //找到搜索按钮
    WebElement searchButton= driver.findElement(By.id("commit"));
    //点击搜索按钮
    searchButton.click();
    waitForElementToLoad(driver,2000,By.name("mob"));
    driver.findElement(By.name("mob")).sendKeys("13267191379");

    WebElement submit = driver.findElement(By.name("Submit"));

    submit.click();
    driver.findElement(By.className("button")).click();
    List<WebElement> interface1 = driver.findElements(By.name("card_type"));
    for(WebElement e:interface1){
    String value = e.getAttribute("value");
    if(value.equals("5")){
    e.click(); break;
    }
    }
    driver.findElement(By.className("button")).click();
    boolean ret = waitForElementToLoad(driver,2000,By.xpath(".//*[@id='divWP']/div[2]/div[2]/div/div/span[2]"));
    // Assert.assertEquals(ret, true);
    driver.findElement(By.xpath(".//*[@id='divWP']/div[2]/div[2]/div/div/span[2]")).click();

    try {
    PayEditInputTyper.setPassword("MozillaWindowClass", "招商银行网上支付[SZG] - Mozilla Firefox", "42342234253434323433");
    } catch (InterruptedException e) {
    e.printStackTrace();
    }

    try{
    //这里我们暂时用sleep方式等待页面条状,后续会讲到如何智能等待
    Thread.sleep(2000);
    } catch(InterruptedException e) {
    e.printStackTrace();
    }
    //跳转之后的页面关键字输入框元素
    // WebElement keywordInput= driver.findElement(By.id("keyword"));
    //验证输入框的内容是不是selenium
    // Assert.assertEquals(keywordInput.getAttribute("value"), "selenium");
    //关闭浏览器
    // driver.quit();
    }
    public static boolean waitForElementToLoad(WebDriver driver,int timeOut,final By by){
    try {
    new WebDriverWait(driver, timeOut).until(new ExpectedCondition<Boolean>() {

    @Override
    public Boolean apply(WebDriver driver) {
    // TODO Auto-generated method stub
    WebElement element = driver.findElement(by);
    System.out.println("find zhe element");
    return element.isDisplayed();
    }
    });
    } catch (Exception e) {
    // TODO: handle exception
    Assert.fail("超时!! " + timeOut + " 秒之后还没找到元素 [" + by + "]", e);
    }
    return false;
    }
    }

查看下osworkflow 的工作流配置:
workflows:


  1. <workflows>
    <workflow name="mytest" type="resource" location="myworkflow.xml" />
    </workflows>

osworkflow.xml:

  1. <osworkflow>
    <persistence
    class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore" />
    <factory
    class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
    <property key="resource" value="workflows.xml" />
    </factory>
    </osworkflow>

myworkflow.xml


  1. <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE workflow PUBLIC
    "-//OpenSymphony Group//DTD OSWorkflow 2.7//EN"
    "http://www.opensymphony.com/osworkflow/workflow_2_7.dtd">
    <workflow>
    <registers>
    <register type="class" variable-name="log">
    <arg name="class.name">com.opensymphony.workflow.util.LogRegister</arg>
    <arg name="addInstanceId">true</arg>
    <arg name="Category">workflow</arg>
    </register>
    </registers>
    <initial-actions>
    <action id="100" 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="1" name="Start First Draft">
    <restrict-to>
    <conditions>
    <condition type="class">
    <arg name="class.name">
    com.opensymphony.workflow.util.StatusCondition
    </arg>
    <arg name="status">Queued</arg>
    </condition>
    </conditions>
    </restrict-to>
    <pre-functions>
    <function type="class">
    <arg name="class.name">
    com.osworkflow.TestFunction
    </arg>
    <arg name="context">
    aaaaaa
    </arg>
    </function>
    </pre-functions>
    <results>
    <unconditional-result old-status="Finished"
    status="queue" step="2" owner="${caller}" />
    </results>
    </action>
    <action id="2" name="Finish First Draft">
    <restrict-to>
    <conditions type="AND">
    <condition type="class">
    <arg name="class.name">
    com.opensymphony.workflow.util.StatusCondition
    </arg>
    <arg name="status">Underway</arg>
    </condition>
    <condition type="class">
    <arg name="class.name">
    com.opensymphony.workflow.util.AllowOwnerOnlyCondition
    </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>

运行结果:[quote]change status...
{params1=params1, store=com.opensymphony.workflow.spi.memory.MemoryWorkflowStore@7c9139fc, descriptor=com.opensymphony.workflow.loader.WorkflowDescriptor@22760f48, entry=com.opensymphony.workflow.spi.SimpleWorkflowEntry@74e551a4, docTitle=docTitle, context=com.opensymphony.workflow.basic.BasicWorkflowContext@7b5321f0, actionId=1, configuration=com.opensymphony.workflow.config.DefaultConfiguration@ed952d1, log=org.apache.commons.logging.impl.Log4JCategoryLog@5dcc1ef4, currentSteps=[SimpleStep@1[owner=, actionId=0, status=Queued]]}
{class.name=
com.osworkflow.TestFunction
, context=
aaaaaa
}
com.opensymphony.module.propertyset.memory.MemoryPropertySet {
}

aaaaaa
[/quote]

osworkflow 入门基础2的更多相关文章

  1. osworkflow 入门基础

    OSWorkFlow入门指南目的 这篇指导资料的目的是介绍OSWorkflow的所有概念,指导你如何使用它,并且保证你逐步理解OSWorkflow的关键内容. 本指导资料假定你已经部署OSWorkfl ...

  2. mybatis入门基础(二)----原始dao的开发和mapper代理开发

    承接上一篇 mybatis入门基础(一) 看过上一篇的朋友,肯定可以看出,里面的MybatisService中存在大量的重复代码,看起来不是很清楚,但第一次那样写,是为了解mybatis的执行步骤,先 ...

  3. 01shell入门基础

    01shell入门基础 为什么学习和使用shell编程 shell是一种脚本语言,脚本语言是相对于编译语言而言的.脚本语言不需要编译,由解释器读取程序并且执行其中的语句,而编译语言需要编译成可执行代码 ...

  4. Markdown入门基础

    // Markdown入门基础 最近准备开始强迫自己写博文,以治疗严重的拖延症,再不治疗就“病入骨髓,司命之所属,无奈何”了啊.正所谓“工欲善其事,必先利其器”,于是乎在写博文前,博主特地研究了下博文 ...

  5. JavaScript入门基础

    JavaScript基本语法 1.运算符 运算符就是完成操作的一系列符号,它有七类: 赋值运算符(=,+=,-=,*=,/=,%=,<<=,>>=,|=,&=).算术运 ...

  6. C++ STL编程轻松入门基础

    C++ STL编程轻松入门基础 1 初识STL:解答一些疑问 1.1 一个最关心的问题:什么是STL 1.2 追根溯源:STL的历史 1.3 千丝万缕的联系 1.4 STL的不同实现版本 2 牛刀小试 ...

  7. HTML入门基础教程相关知识

    HTML入门基础教程 html是什么,什么是html通俗解答: html是hypertext markup language的缩写,即超文本标记语言.html是用于创建可从一个平台移植到另一平台的超文 ...

  8. Linux shell入门基础(六)

    六.Shell脚本编程详解 将上述五部分的内容,串联起来,增加对Shell的了解 01.shell脚本 shell: # #perl #python #php #jsp 不同的脚本执行不同的文本,执行 ...

  9. Linux shell入门基础(一)

    Linux shell入门基础(一): 01.增加删除用户: #useradd byf   userdel byf(主目录未删除)  userdel -r byf   该用户的属性:usermod 用 ...

随机推荐

  1. MySQL数据表列转行

    简单例子 数据结构如下 use dataTest create table t_score ( name ) , subject ), grade ,) ) INSERT INTO `t_score` ...

  2. Python内置函数reversed()用法分析

    Python内置函数reversed()用法分析 这篇文章主要介绍了Python内置函数reversed()用法,结合实例形式分析了reversed()函数的功能及针对序列元素相关操作技巧与使用注意事 ...

  3. laravel 5.8 实现消息推送

    以下教程是基于5.6 的,在使用5.8实现时遇到一些问题,做一下记录 在我看来,实时通信才是 APP 应用的将来. Socket 服务通常不是那么容易实现,但是 Laravel Echo 服务改变了这 ...

  4. 【AMAD】jsonschema -- (又)一个JSON Schema的Python实现

    动机 简介 用法 个人评分 动机 JSON Schema1是一个专业词汇,可以让你注解和验证JSON文档. 使用JSON Schema的好处有: 描述你的数据格式 提供清晰的易读的文档 验证数据: 用 ...

  5. KVM虚拟化原理

    CPU虚拟化 KVM虚拟化是需要硬件支持的.我们可以用 egrep -o '(vmx|svm)' /proc/cpuinfo 来查看是否支持CPU虚拟化. 虚拟机中每一个vCPU对应qemu-kvm中 ...

  6. classmethod自己定制

    # # 利用描述符原理定义一个@classmethod # class ClassMethod: # def __init__(self,func): # self.func = func # def ...

  7. VMware Workstation 15 Pro简化安装Kali Linux 2019.2

    记录下简单安装的步骤

  8. 【Linux开发】linux设备驱动归纳总结(九):1.platform总线的设备和驱动

    linux设备驱动归纳总结(九):1.platform总线的设备和驱动 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  9. SolidWorks学习笔记7 镜像,阵列

    镜像 将特征,面,实体相对于一个平面来复制.修改原来的特征,镜像特征随之改变 阵列 线性阵列 , 在左侧,先激活要阵列的特征,然后点击小柱 然后选择方向1和方向2,该方向的阵列距离和数量(一般使用边线 ...

  10. PTA(Basic Level)1037.在霍格沃茨找零钱

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.& ...