Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 0d51d63

Browse files
committed
Merge branch 'master' into develop - to include user locking of queue work items #100
2 parents e10f224 + 5161c97 commit 0d51d63

14 files changed

+233
-14
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {"host":"192.168.123.4","port":"6061","database":"workflow-content",
1+
{"host":"192.168.123.4","port":"6061","database":"workflow-content",
22
"username":"admin","password":"admin","auth":"digest","defaultuser":"nobody","webport":5001,
33
"alertport":5002,"apppath":"./app","defaultpath":"/workplace.html5","modulesport":6060,
44
"modulesdatabase":"workflow-modules","ssl":false,"adminport":8002,"triggersdatabase":"Triggers"}

rest-api/ext/process.xqy

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ function ext:get(
134134

135135

136136

137-
(: POST - update a process instance, potentially completing it (e.g. human step) :)
137+
(:
138+
: POST - update a process instance, potentially completing it (e.g. human step)
139+
:
140+
: POST process?processid=1234 -> Updates data only, does not lock or unlock item. DEPRECATED in current form - In future this will respect locks. Does not yet.
141+
: POST process?processid=1234&complete=true -> Completes work item. Respects locks. (optionally) updates work item data.
142+
: POST process?processid=1234&lock=true -> Locks the work item for the current user. (optionally) updates work item data. Respects locks.
143+
: POST process?processid=1234&unlock=true -> Unlocks the work item if locked by current user. (optionally) update work item data. Respects locks.
144+
:)
138145
declare
139146
%roxy:params("")
140147
%rapi:transaction-mode("update")
@@ -146,6 +153,8 @@ function ext:post(
146153

147154
let $preftype := if ("application/xml" = map:get($context,"accept-types")) then "application/xml" else "application/json"
148155

156+
let $part := (map:get($params,"part"),"document")[1]
157+
149158
let $_ := xdmp:log($input)
150159
let $pid := map:get($params,"processid")
151160
(:let $proc := wfu:get($pid):)
@@ -175,8 +184,63 @@ function ext:post(
175184
(: error - cannot call complete on non completable task :)
176185
<ext:updateResponse><ext:outcome>FAILURE</ext:outcome><ext:message>Cannot call complete on non completable task: {$props/wf:step-type/text()}</ext:message></ext:updateResponse>
177186
else
178-
(: TODO perform a data update but leave incomplete :)
179-
<ext:updateResponse><ext:outcome>SUCCESS</ext:outcome><ext:message>No complete parameter, or complete parameter false. Leaving incomplete.</ext:message></ext:updateResponse>
187+
188+
if ("true" = map:get($params,"lock")) then
189+
(: Lock the work item, and return its details as if get had been called. If already locked, instead return an error :)
190+
let $feedback := wfu:lock($pid)
191+
let $update :=
192+
if (fn:empty($feedback)) then
193+
<ext:readResponse><ext:outcome>SUCCESS</ext:outcome>
194+
{if ($part = "document") then
195+
<ext:document>{wfu:get(map:get($params,"processid"))}</ext:document>
196+
else if ($part = "properties") then
197+
<ext:properties>{wfu:getProperties(map:get($params,"processid"))}</ext:properties>
198+
else
199+
(<ext:document>{wfu:get(map:get($params,"processid"))}</ext:document>,
200+
<ext:properties>{wfu:getProperties(map:get($params,"processid"))}</ext:properties>)
201+
}
202+
</ext:readResponse>
203+
else
204+
<ext:updateResponse><ext:outcome>FAILURE</ext:outcome><ext:message>Work item could not be locked by user.</ext:message><ext:feedback>{$feedback}</ext:feedback></ext:updateResponse>
205+
return
206+
if (fn:empty($feedback)) then
207+
let $fb := wfa:update-userTask($pid,$input/ext:updateRequest/wf:data/node(),$input/ext:updateRequest/wf:attachments/node())
208+
return
209+
if (fn:not(fn:empty($fb))) then
210+
<ext:updateResponse><ext:outcome>FAILURE</ext:outcome><ext:message>Could not update userTask</ext:message><ext:feedback>{$fb}</ext:feedback></ext:updateResponse>
211+
else
212+
$update
213+
else
214+
$update
215+
else
216+
if ("true" = map:get($params,"unlock")) then
217+
let $feedback := wfu:unlock($pid)
218+
let $update :=
219+
if (fn:empty($feedback)) then
220+
<ext:readResponse><ext:outcome>SUCCESS</ext:outcome>
221+
{if ($part = "document") then
222+
<ext:document>{wfu:get(map:get($params,"processid"))}</ext:document>
223+
else if ($part = "properties") then
224+
<ext:properties>{wfu:getProperties(map:get($params,"processid"))}</ext:properties>
225+
else
226+
(<ext:document>{wfu:get(map:get($params,"processid"))}</ext:document>,
227+
<ext:properties>{wfu:getProperties(map:get($params,"processid"))}</ext:properties>)
228+
}
229+
</ext:readResponse>
230+
else
231+
<ext:updateResponse><ext:outcome>FAILURE</ext:outcome><ext:message>Work item could not be unlocked by user.</ext:message><ext:feedback>{$feedback}</ext:feedback></ext:updateResponse>
232+
return
233+
if (fn:empty($feedback)) then
234+
let $fb := wfa:update-userTask($pid,$input/ext:updateRequest/wf:data/node(),$input/ext:updateRequest/wf:attachments/node())
235+
return
236+
if (fn:not(fn:empty($fb))) then
237+
<ext:updateResponse><ext:outcome>FAILURE</ext:outcome><ext:message>Could not update userTask</ext:message><ext:feedback>{$fb}</ext:feedback></ext:updateResponse>
238+
else
239+
$update
240+
else
241+
$update
242+
else
243+
() (: Just default to updating the data, but doing nothing around locking :)
180244

181245

182246
let $out := ($res,<ext:updateResponse><ext:outcome>SUCCESS</ext:outcome></ext:updateResponse>)[1]
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
. ../config/webserver-settings.sh
44

5-
echo "starting 11-process-update.sh"
5+
sleep 5
6+
7+
echo "starting 11-process-update-lock.sh"
68

79
PID=`cat 06-process-create-out.txt`
810

911
curl -v --anyauth --user $MLADMINUSER:$MLADMINPASS -X POST \
1012
-d@"./11-payload.xml" \
1113
-H "Content-type: application/xml" -H "Accept: application/xml" \
12-
"http://$RESTHOST:$RESTPORT/v1/resources/process?rs:processid=$PID&rs:complete=true" > 11-process-update-out.txt
14+
"http://$RESTHOST:$RESTPORT/v1/resources/process?rs:processid=$PID&rs:lock=true" > 11-process-update-lock-out.txt
1315

14-
echo "11-process-update.sh complete"
16+
echo "11-process-update-lock.sh complete"

shtests/12-payload.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<ext:updateRequest xmlns:ext="http://marklogic.com/rest-api/resource/process" xmlns:wf="http://marklogic.com/workflow">
2+
<ext:processId>{PID}</ext:processId>
3+
<wf:data>
4+
</wf:data>
5+
<wf:attachments>
6+
</wf:attachments>
7+
</ext:updateRequest>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
. ../config/webserver-settings.sh
4+
5+
sleep 5
6+
7+
echo "starting 12-process-update-lock-fail.sh"
8+
9+
PID=`cat 06-process-create-out.txt`
10+
11+
curl -v --anyauth --user workflow-manager:workflow-manager -X POST \
12+
-d@"./12-payload.xml" \
13+
-H "Content-type: application/xml" -H "Accept: application/xml" \
14+
"http://$RESTHOST:$RESTPORT/v1/resources/process?rs:processid=$PID&rs:lock=true" > 12-process-update-lock-fail-out.txt
15+
16+
echo "12-process-update-lock-fail.sh complete"

shtests/13-payload.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<ext:updateRequest xmlns:ext="http://marklogic.com/rest-api/resource/process" xmlns:wf="http://marklogic.com/workflow">
22
<ext:processId>{PID}</ext:processId>
33
<wf:data>
4+
<unlock-new-data>Some data created on request to unlock</unlock-new-data>
45
</wf:data>
56
<wf:attachments>
67
</wf:attachments>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
. ../config/webserver-settings.sh
4+
5+
sleep 5
6+
7+
echo "starting 13-process-update-unlock.sh"
8+
9+
PID=`cat 06-process-create-out.txt`
10+
11+
curl -v --anyauth --user $MLADMINUSER:$MLADMINPASS -X POST \
12+
-d@"./13-payload.xml" \
13+
-H "Content-type: application/xml" -H "Accept: application/xml" \
14+
"http://$RESTHOST:$RESTPORT/v1/resources/process?rs:processid=$PID&rs:unlock=true" > 13-process-update-unlock-out.txt
15+
16+
echo "13-process-update-unlock.sh complete"

shtests/14-process-update-lock.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
. ../config/webserver-settings.sh
4+
5+
sleep 5
6+
7+
echo "starting 14-process-update-lock.sh"
8+
9+
PID=`cat 06-process-create-out.txt`
10+
11+
curl -v --anyauth --user $MLADMINUSER:$MLADMINPASS -X POST \
12+
-d@"./14-payload.xml" \
13+
-H "Content-type: application/xml" -H "Accept: application/xml" \
14+
"http://$RESTHOST:$RESTPORT/v1/resources/process?rs:processid=$PID&rs:lock=true" > 14-process-update-lock-out.txt
15+
16+
echo "14-process-update-lock.sh complete"

shtests/15-payload.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ext:updateRequest xmlns:ext="http://marklogic.com/rest-api/resource/process" xmlns:wf="http://marklogic.com/workflow">
2+
<ext:processId>{PID}</ext:processId>
3+
<wf:data>
4+
<complete-data>Some data added by complete action</complete-data>
5+
</wf:data>
6+
<wf:attachments>
7+
</wf:attachments>
8+
</ext:updateRequest>

shtests/15-process-update.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
. ../config/webserver-settings.sh
4+
5+
sleep 5
6+
7+
echo "starting 15-process-update.sh"
8+
9+
PID=`cat 06-process-create-out.txt`
10+
11+
curl -v --anyauth --user $MLADMINUSER:$MLADMINPASS -X POST \
12+
-d@"./15-payload.xml" \
13+
-H "Content-type: application/xml" -H "Accept: application/xml" \
14+
"http://$RESTHOST:$RESTPORT/v1/resources/process?rs:processid=$PID&rs:complete=true" > 15-process-update-out.txt
15+
16+
echo "15-process-update.sh complete"

0 commit comments

Comments
 (0)