Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagetext
titleapprove-work-item.bat
curl.exe --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "http://localhost:8080/midpoint/ws/rest/rpc/executeScript" --data-binary @approve-work-item.xml

(--data-binary is there because otherwise the lines in script got concatenated, at least sometimes on Windows)

Code Block
languagexml
titleapprove-work-item.xml
<?xml version="1.0"?>
<s:executeScript xmlns:s="http://midpoint.evolveum.com/xml/ns/public/model/scripting-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <s:action>
        <s:type>execute-script</s:type>
        <s:parameter>
            <s:name>script</s:name>
            <c:value xsi:type="c:ScriptExpressionEvaluatorType">
                <c:code>
                    import com.evolveum.midpoint.schema.util.WorkItemId
                    import com.evolveum.midpoint.xml.ns._public.common.common_3.*

                    caseOid = '492f3ff0-b0c7-4e97-86ff-730dc2bd8529' /* this is the OID of the approval case */
                    localId = 4                                      /* this is 'local' work item ID */
                    workItemId = WorkItemId.create(caseOid, localId)

                    output = new AbstractWorkItemOutputType(prismContext)
                        .outcome('http://midpoint.evolveum.com/xml/ns/public/model/approval/outcome#approve')

                    midpoint.workflowService.completeWorkItem(workItemId, output, midpoint.currentTask, midpoint.currentResult)
                </c:code>
            </c:value>
        </s:parameter>
        <s:parameter>
            <s:name>forWholeInput</s:name>
            <c:value>true</c:value>
        </s:parameter>
    </s:action>
</s:executeScript>

Unfortunately, the approval/rejection is logged under administrator account. It is not possible to use non-admin account to carry out this action, because Groovy script execution requires the strongest authorization (because of the security implications). But, as said, this is more-or-less for demonstration purposes.

(--data-binary is there because otherwise the lines in script got concatenated, at least sometimes on Windows)