- 浏览: 2685 次
文章分类
最新评论
引用
前篇我引入了互联网上找来的一篇文章,接着上篇讲:osworkflow 工作流是非常轻量级的,虽然2006就停止活动了,互联网上的资料也不是很多,官网也没过多的说明,比起jbpm 和activiti来说资料是相当少,但是不妨碍我们学习这个轻量级的工作流引擎。闲话少说
引用
demo1 入门
需要导入依赖:
lib/commons-logging.jar
oscore-2.2.5.jar
osworkflow-2.8.0.jar
propertyset-1.4.jar
需要导入依赖:
lib/commons-logging.jar
oscore-2.2.5.jar
osworkflow-2.8.0.jar
propertyset-1.4.jar
/* * 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 模拟打开一个浏览器的操作
/* * 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:
<workflows> <workflow name="mytest" type="resource" location="myworkflow.xml" /> </workflows>
osworkflow.xml:
<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
<?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>
运行结果:
引用
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
{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
相关推荐
Osworkflow 是一个开源的工作流引擎,它为应用程序提供了一种灵活的方式来管理业务流程。这个入门级的例子将带你了解 ...一旦掌握了基础,你就可以根据具体需求扩展 Osworkflow,构建出复杂而高效的工作流管理系统。
这篇入门指南主要面向初学者,旨在帮助他们快速理解和使用 OSWorkflow。以下是对文中知识点的详细解释: 1. **工作流定义**:OSWorkflow 的核心是工作流定义,它是一个 XML 文件,描述了工作流程的各个步骤和转换。...
1. **入门教程**:介绍如何安装和配置OSWorkflow,以及如何创建第一个工作流实例。 2. **API参考**:详细说明了OSWorkflow的各个类和接口,帮助开发者理解和使用API进行开发。 3. **最佳实践**:提供一些实际案例和...
- **核心库**:OSWorkflow 的核心功能由 `OSWorkflow-2.8.0.jar` 提供,这是运行 OSWorkflow 所必需的基础组件。 - **日志支持**:使用 `commons-logging.jar` 进行日志记录。 - **属性集支持**:使用 `propertyset-...
- **条件**是工作流决策的基础,允许根据数据状态选择不同的路径。 - **SOAP支持**使OSWorkflow能够与远程服务交互,增强了其在网络环境下的集成能力。 **5. GUI设计器** - 尽管OSWorkflow主要依赖XML描述,但它...
- **OSWorkflow核心引用包**:这些包包含了OSWorkflow运行所依赖的基础库,例如`commons-collections.jar`、`commons-lang.jar`等。 - **OSWorkflow可选包**:根据实际需求,可以选择加载额外的功能模块,如报表支持...
2. **快速入门**:介绍基本概念和术语,提供一个简单的示例来展示osworkflow 的基本用法。 3. **API详解**:详尽地解析osworkflow 提供的接口,包括流程定义、流程实例管理、任务处理等。 4. **工作流定义**:解释...
#### 一、工作流基础与概念 **1. 工作流定义** 工作流是指业务过程的部分或整体在计算机应用环境下的自动化,其目的是为了使在多个参与者之间按照某种预定义的规则传递文档、信息或任务的过程能够自动进行,从而...
目前市场上存在多种成熟的工作流框架,如 Jbpm、OSWorkflow、ActiveBPEL 和 YAWL 等。这些框架均提供了强大的工作流管理功能,能够满足不同组织的需求。 #### 五、jBPM 4.4 入门与准备工作 **jBPM** 即 java ...