当前位置: 首页 > 工具软件 > OSWorkflow > 使用案例 >

学习工作流osworkflow(1)

何兴安
2023-12-01

    做了几个项目,一直被流程的控制所困扰,决定学习工作流方面的知识,从网上了解到osworkflow是一个轻量级的又极为灵活的工作流引擎(详细情况请访问:http://www.opensymphony.com/osworkflow),所以拿来学习。
    折腾了一个下午,终于把自带的example运行起来了。我的测试环境:winxp  tomcat4.1.30   oracle8.05   jdk1.4.2。
    首先,下载https://osworkflow.dev.java.net/files/documents/635/4647/osworkflow-2.7.0.zip 。解压后,将osworkflow-2.7.0-example.war拷贝至tomcat的webapp下,启动tomcat,访问http://localhost/osworkflow-2.7.0-example,一切都很easy。
    osworkflow提供了多种持久化机制MemoryStore (default), SerializableStore, JDBCStore, OfbizStore等等。由于下载的example是为了方便初学者尽快的将程序运行起来,所以采用了MemoryStore。呵呵,实际的系统可不会让数据全呆在内存里哦。改成JDBCStore试试。

    1、修改tomcat的sever.xml,添加:

<Context path="/
osworkflow-2.7.0-example" docBase="osworkflow-2.7.0-example"
        debug="5" reloadable="true" crossContext="true">

  <Logger className="org.apache.catalina.logger.FileLogger"
             prefix="localhost_osworkflow_log." suffix=".txt"
             timestamp="true"/>

  Resource name="jdbc/mydb" auth="Container"
              type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/mydb">
  <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
  </parameter>
  <parameter>
    <name>driverClassName</name>
    <value>oracle.jdbc.driver.OracleDriver</value>
  </parameter>
  <parameter>
    <name>url</name>
    <value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value>
  </parameter>
  <parameter>
    <name>username</name>
    <value>oswf</value>
  </parameter>
  <parameter>
    <name>password</name>
    <value>oswf</value>
  </parameter>
  <parameter>
    <name>maxActive</name>
    <value>20</value>
  </parameter>
  <parameter>
    <name>maxIdle</name>
    <value>10</value>
  </parameter>
  <parameter>
    <name>maxWait</name>
    <value>-1</value>
  </parameter>
</ResourceParams>

</Context>


    2、修改WEB-INF/classes/osworkflow.xml(红色部分根据您的数据库作相应修改)

<osworkflow>
    <persistence class="com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore">
       <!-- For jdbc persistence, all are required. -->
       <property key="datasource" value="jdbc/mydb"/>
       <property key="entry.sequence" value="SELECT seq_os_wfentry.nextVal from dual"/>
       <property key="entry.table" value="OS_WFENTRY"/>
       <property key="entry.id" value="ID"/>
       <property key="entry.name" value="NAME"/>
       <property key="entry.state" value="STATE"/>
       <property key="step.sequence" value="SELECT seq_os_currentsteps.nextVal from dual"/>
       <property key="history.table" value="OS_HISTORYSTEP"/>
       <property key="current.table" value="OS_CURRENTSTEP"/>
       <property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/>
       <property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/>
       <property key="step.id" value="ID"/>
       <property key="step.entryId" value="ENTRY_ID"/>
       <property key="step.stepId" value="STEP_ID"/>
       <property key="step.actionId" value="ACTION_ID"/>
       <property key="step.owner" value="OWNER"/>
       <property key="step.caller" value="CALLER"/>
       <property key="step.startDate" value="START_DATE"/>
       <property key="step.finishDate" value="FINISH_DATE"/>
       <property key="step.dueDate" value="DUE_DATE"/>
       <property key="step.status" value="STATUS"/>
       <property key="step.previousId" value="PREVIOUS_ID"/>
      </persistence>

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


    3、在WEB-INF/classes里新建propertyset.xml

<propertysets>
    <propertyset name="jdbc"
      class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
        <arg name="datasource" value="jdbc/mydb"/>
        <arg name="table.name" value="OS_PROPERTYENTRY"/>
        <arg name="col.globalKey" value="GLOBAL_KEY"/>
        <arg name="col.itemKey" value="ITEM_KEY"/>
        <arg name="col.itemType" value="ITEM_TYPE"/>
        <arg name="col.string" value="STRING_VALUE"/>
        <arg name="col.date" value="DATE_VALUE"/>
        <arg name="col.data" value="DATA_VALUE"/>
        <arg name="col.float" value="FLOAT_VALUE"/>
        <arg name="col.number" value="NUMBER_VALUE"/>
    </propertyset>
</propertysets>


    4、修改WEB-INF/classes下的osuser.xml

<opensymphony-user>

    <provider class="com.opensymphony.user.provider.jdbc.JDBCAccessProvider">
        <property name="user.table">OS_USER</property>
        <property name="group.table">OS_GROUP</property>
        <property name="membership.table">OS_MEMBERSHIP</property>
        <property name="user.name">USERNAME</property>
        <property name="user.password">PASSWORDHASH</property>
        <property name="group.name">GROUPNAME</property>
        <property name="membership.userName">USERNAME</property>
        <property name="membership.groupName">GROUPNAME</property>
        <property name="datasource">java:comp/env/jdbc/mydb</property>
    </provider>
    <provider class="com.opensymphony.user.provider.jdbc.JDBCCredentialsProvider">
        <property name="user.table">OS_USER</property>
        <property name="group.table">OS_GROUP</property>
        <property name="membership.table">OS_MEMBERSHIP</property>
        <property name="user.name">USERNAME</property>
        <property name="user.password">PASSWORDHASH</property>
        <property name="group.name">GROUPNAME</property>
        <property name="membership.userName">USERNAME</property>
        <property name="membership.groupName">GROUPNAME</property>
        <property name="datasource">java:comp/env/jdbc/mydb</property>
    </provider>
    <provider class="com.opensymphony.user.provider.jdbc.JDBCProfileProvider">
        <property name="user.table">OS_USER</property>
        <property name="group.table">OS_GROUP</property>
        <property name="membership.table">OS_MEMBERSHIP</property>
        <property name="user.name">USERNAME</property>
        <property name="user.password">PASSWORDHASH</property>
        <property name="group.name">GROUPNAME</property>
        <property name="membership.userName">USERNAME</property>
        <property name="membership.groupName">GROUPNAME</property>
        <property name="datasource">java:comp/env/jdbc/mydb</property>
    </provider>
   
    <!--
  Authenticators can take properties just like providers.

  This smart authenticator should work for 'most' cases - it dynamically looks up
  the most appropriate authenticator for the current server.
 -->
 <authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />
</opensymphony-user>

    5、在sql-plus里运行下载包里的 src/etc/deployment/jdbc/oracle.sql

    6、启动tomcat

    7、OK。

 类似资料: