工作流内容处理

时间:2012-12-31 11:24:51

标签: java liferay liferay-6

我正在使用Liferay 6.1.1 CE。

通过在xml文件(leaveapproval.xml)中编写定义并将其加载到服务器,我创建了一个多级kaleo工作流(即具有两个级别的批准)。它工作正常,因为我在博客中测试了这个工作流程。

现在,我希望在完成第二级审批后将工作流程的内容提交给Web服务。

我如何处理工作流程的内容?

有可能吗?

<?xml version="1.0"?>
<workflow-definition
        xmlns="urn:liferay.com:liferay-workflow_6.1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:liferay.com:liferay-workflow_6.1.0 http://www.liferay.com/dtd/liferay-workflow-definition_6_1_0.xsd">
    <name>LEAVE IN ACTION USER ACTION</name>
    <description>A sample multilevel approver can approve a workflow content.</description>
    <version>1</version>

    <state>
        <name>created</name>
        <metadata>
            <![CDATA[
            {"xy":[36,51]}
            ]]>
        </metadata>
        <initial>true</initial>
        <transitions>
            <transition>
                <name>review</name>
                <target>review</target>
                <default>true</default>
            </transition>
        </transitions>
    </state>

    <task>
        <name>review</name>
        <metadata>
            <![CDATA[
            {"xy":[168,36]}
            ]]>
        </metadata>
        <actions>
            <notification>
                <name>Review Notification</name>
                <template>You have a new submission waiting for review in the workflow.</template>
                <template-language>text</template-language>
                <notification-type>email</notification-type>
                <execution-type>onAssignment</execution-type>
            </notification>
            <notification>
                <name>Review Completion Notification</name>
                <template>
                    Your submission has been reviewed and the reviewer has applied the following ${taskComments}.</template>
                <template-language>freemarker</template-language>
                <notification-type>email</notification-type>
                <recipients>
                    <user />
                </recipients>
                <execution-type>onExit</execution-type>
            </notification>
        </actions>
        <assignments>
            <roles>
                <role>
                    <role-type>regular</role-type>
                    <name>Portal Head</name>
                </role>
                <role>
                    <role-type>regular</role-type>
                    <name>Portal Content Reviewer</name>
                </role>
            </roles>
        </assignments>
        <transitions>
            <transition>
                <name>approve</name>
                <target>recommended</target>
            </transition>
            <transition>
                <name>reject</name>
                <target>update</target>
                <default>false</default>
            </transition>
        </transitions>
     </task>

     <task>
        <name>recommended</name>
        <metadata>
            <![CDATA[{"xy":[168,36]}]]>
        </metadata>
        <actions>
            <notification>
                <name>Review Notification</name>
                <template>You have a new submission waiting for your review in the workflow.</template>
                <template-language>text</template-language>
                <notification-type>email</notification-type>
                <execution-type>onAssignment</execution-type>
            </notification>
            <notification>
                <name>Review Completion Notification</name>
                <template>
                    Your submission has been reviewed and the reviewer has applied the following ${taskComments}.</template>
                <template-language>freemarker</template-language>
                <notification-type>email</notification-type>
                <recipients>
                    <user />
                </recipients>
                <execution-type>onExit</execution-type>
            </notification>
        </actions>
        <assignments>
            <user>
                <user-id>13379</user-id>
            </user>
        </assignments>
        <transitions>
            <transition>
                <name>approve</name>
                <target>approved</target>
            </transition>
            <transition>
                <name>reject</name>
                <target>update</target>
                <default>false</default>
            </transition>
        </transitions>
    </task>

    <task>
        <name>update</name>
        <metadata>
            <![CDATA[
            {"transitions":{"resubmit":{"bendpoints":[[303,140]]}},"xy":[328,199]}
            ]]>
        </metadata>
        <actions>
            <action>
                <name>reject</name>
                <script>
                    <![CDATA[
                    Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(
                        Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("denied"),
                        workflowContext);

                    Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(
                        Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("pending"),
                        workflowContext);
                    ]]>
                </script>
                <script-language>javascript</script-language>
                <execution-type>onAssignment</execution-type>
            </action>
            <notification>
                <name>Creator Modification Notification</name>
                <template>Your submission was rejected by a reviewer, please modify and resubmit.</template>
                <template-language>text</template-language>
                <notification-type>email</notification-type>
                <execution-type>onAssignment</execution-type>
            </notification>
        </actions>
        <assignments>
            <user />
        </assignments>
        <transitions>
            <transition>
                <name>resubmit</name>
                <target>review</target>
            </transition>
        </transitions>
    </task>

    <state>
        <name>approved</name>
        <metadata>
            <![CDATA[
                {"xy":[380,51]}
            ]]>
        </metadata>
        <actions>
            <action>
                <name>approve</name>
                <script>
                    <![CDATA[Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus      (Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("approved"), workflowContext);]]>

                </script>
                <script-language>javascript</script-language>
                <execution-type>onEntry</execution-type>
            </action>
        </actions>
    </state>
</workflow-definition>

帮帮我......

1 个答案:

答案 0 :(得分:0)

要在某个工作流程步骤中以编程方式运行任何内容,您通常只需要<script>标记,就像您正在更新状态一样。

因此,在您批准的<state>中,您可能希望添加另一个<action>标记,这个标记用于处理Web服务调用(并让其他操作保持原样) )。

您用于脚本的语言取决于您的习惯。我使用groovy,因为它很好地处理普通的java代码,这就是我所知道的。

以下是它的外观(仅包含最后<state>代码):

<state>
    <name>approved</name>
    <metadata>
        <![CDATA[
        {"xy":[380,51]}
        ]]> 
    </metadata>
    <actions>
        <action>
            <name>approve</name>
            <script>
                <![CDATA[
                Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(
                    Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("approved"),
                    workflowContext);
                ]]>
            </script>
            <script-language>javascript</script-language>
            <execution-type>onEntry</execution-type>
        </action>
        <action>
            <name>submit-web-service</name>
            <script>
                <![CDATA[
                import java.io.*
                import java.net.*

                URL url = new URL(
                    "www.my-web-service.com/api/whatever?theParam=" +
                        ${theRelevantContextVariable});

                URLConnection urlConnection = url.openConnection();

                // if necessary to read response data:
                // BufferedReader bufferedReader = new BufferedReader(
                //    new InputStreamReader(urlConnection.getInputStream()));
                // String something = bufferedReader.readLine();
                // etc.
                ]]>
            </script>
            <script-language>groovy</script-language>
            <execution-type>onEntry</execution-type>
        </action>
    </actions>
</state>

您可能需要POST请求,在这种情况下,您将以不同方式实施Web服务调用。但无论如何,您都要在动作标签中编写Web服务代码。这样的事情应该有效。