1 | <accessor debug="false"> |
---|
2 | <name>/rest/user/lock</name> |
---|
3 | <descr>Manage a lock.</descr> |
---|
4 | <param mandatory="true"> |
---|
5 | <name>method</name> |
---|
6 | <descr>what do we want to do?</descr> |
---|
7 | <type canonical="true">string</type> |
---|
8 | </param> |
---|
9 | <param mandatory="true"> |
---|
10 | <name>user</name> |
---|
11 | <descr>the user login</descr> |
---|
12 | <type canonical="true">string</type> |
---|
13 | </param> |
---|
14 | <param mandatory="true"> |
---|
15 | <name>session</name> |
---|
16 | <descr>the session key</descr> |
---|
17 | <type canonical="true">string</type> |
---|
18 | </param> |
---|
19 | <param mandatory="true"> |
---|
20 | <name>lock</name> |
---|
21 | <descr>the lock key</descr> |
---|
22 | <type canonical="true">string</type> |
---|
23 | <source> |
---|
24 | <param/> |
---|
25 | <nvp/> |
---|
26 | <default> |
---|
27 | <string>0</string> |
---|
28 | </default> |
---|
29 | </source> |
---|
30 | </param> |
---|
31 | <param> |
---|
32 | <name>type</name> |
---|
33 | <descr>the lock type</descr> |
---|
34 | <type canonical="true">string</type> |
---|
35 | <source> |
---|
36 | <param/> |
---|
37 | <nvp/> |
---|
38 | <default> |
---|
39 | <string>data category</string> |
---|
40 | </default> |
---|
41 | </source> |
---|
42 | </param> |
---|
43 | <param> |
---|
44 | <name>dc</name> |
---|
45 | <descr>the DC to lock (if type='dc')</descr> |
---|
46 | <type canonical="true">string</type> |
---|
47 | <source> |
---|
48 | <param/> |
---|
49 | <nvp/> |
---|
50 | <default> |
---|
51 | <string>0</string> |
---|
52 | </default> |
---|
53 | </source> |
---|
54 | </param> |
---|
55 | <param> |
---|
56 | <name>credentials</name> |
---|
57 | <descr>the user credentials</descr> |
---|
58 | <source> |
---|
59 | <param/> |
---|
60 | <default>data:text/plain,guest:guest</default> |
---|
61 | </source> |
---|
62 | </param> |
---|
63 | <params/> |
---|
64 | <idoc> |
---|
65 | <!-- create the generic object variable --> |
---|
66 | <choose> |
---|
67 | <cond> |
---|
68 | <instr> |
---|
69 | <type>sloot.xpath2eval</type> |
---|
70 | <operand>var:type</operand> |
---|
71 | <operator> |
---|
72 | <xpath>.='data category'</xpath> |
---|
73 | </operator> |
---|
74 | <target>this:cond</target> |
---|
75 | </instr> |
---|
76 | </cond> |
---|
77 | <then> |
---|
78 | <instr> |
---|
79 | <type>copy</type> |
---|
80 | <operand>var:dc</operand> |
---|
81 | <target>var:object</target> |
---|
82 | </instr> |
---|
83 | </then> |
---|
84 | <else> |
---|
85 | <instr> |
---|
86 | <type>throw</type> |
---|
87 | <operand> |
---|
88 | <ex> |
---|
89 | <id>ISOcat[BAD REQUEST]</id> |
---|
90 | <message>Don't know what to lock.</message> |
---|
91 | </ex> |
---|
92 | </operand> |
---|
93 | </instr> |
---|
94 | </else> |
---|
95 | </choose> |
---|
96 | <choose> |
---|
97 | <!-- POST: acquire a new lock --> |
---|
98 | <cond> |
---|
99 | <instr> |
---|
100 | <type>sloot.xpath2eval</type> |
---|
101 | <operand>var:method</operand> |
---|
102 | <operator> |
---|
103 | <xpath>.='POST'</xpath> |
---|
104 | </operator> |
---|
105 | <target>this:cond</target> |
---|
106 | </instr> |
---|
107 | </cond> |
---|
108 | <then> |
---|
109 | <if> |
---|
110 | <cond> |
---|
111 | <instr> |
---|
112 | <type>sloot.xpath2eval</type> |
---|
113 | <operand>var:lock</operand> |
---|
114 | <operator> |
---|
115 | <xpath>.!='0'</xpath> |
---|
116 | </operator> |
---|
117 | <target>this:cond</target> |
---|
118 | </instr> |
---|
119 | </cond> |
---|
120 | <then> |
---|
121 | <instr> |
---|
122 | <type>throw</type> |
---|
123 | <operand> |
---|
124 | <ex> |
---|
125 | <id>ISOcat[BAD REQUEST]</id> |
---|
126 | <message>The new lock can't have an id yet.</message> |
---|
127 | </ex> |
---|
128 | </operand> |
---|
129 | </instr> |
---|
130 | </then> |
---|
131 | </if> |
---|
132 | <accessor-debug> |
---|
133 | <instr> |
---|
134 | <type>xquery</type> |
---|
135 | <operator> |
---|
136 | <xquery> |
---|
137 | declare variable $ltype as node() external; |
---|
138 | declare variable $dc as node() external; |
---|
139 | declare variable $user as node() external; |
---|
140 | declare variable $session as node() external; |
---|
141 | <msg>DBG: new lock on {string($ltype)}[{string($dc)}] for user[{string($user)}] session[{string($session)}]</msg> |
---|
142 | </xquery> |
---|
143 | </operator> |
---|
144 | <ltype>var:type</ltype> |
---|
145 | <dc>var:dc</dc> |
---|
146 | <user>var:user</user> |
---|
147 | <session>var:session</session> |
---|
148 | <target>var:msg</target> |
---|
149 | </instr> |
---|
150 | <instr> |
---|
151 | <type>sloot.debug</type> |
---|
152 | <operand>var:msg</operand> |
---|
153 | </instr> |
---|
154 | </accessor-debug> |
---|
155 | <if> |
---|
156 | <cond> |
---|
157 | <instr> |
---|
158 | <type>sloot.xpath2eval</type> |
---|
159 | <operand>var:object</operand> |
---|
160 | <operator> |
---|
161 | <xpath>.='0'</xpath> |
---|
162 | </operator> |
---|
163 | <target>this:cond</target> |
---|
164 | </instr> |
---|
165 | </cond> |
---|
166 | <then> |
---|
167 | <instr> |
---|
168 | <type>throw</type> |
---|
169 | <operand> |
---|
170 | <ex> |
---|
171 | <id>ISOcat[BAD REQUEST]</id> |
---|
172 | <message>The object to lock needs to have an id.</message> |
---|
173 | </ex> |
---|
174 | </operand> |
---|
175 | </instr> |
---|
176 | </then> |
---|
177 | </if> |
---|
178 | <instr> |
---|
179 | <type>ISOcat.session.lock.new</type> |
---|
180 | <user>var:user</user> |
---|
181 | <session>var:session</session> |
---|
182 | <credentials>var:credentials</credentials> |
---|
183 | <ltype>var:type</ltype> |
---|
184 | <object>var:object</object> |
---|
185 | <target>this:response</target> |
---|
186 | </instr> |
---|
187 | <accessor-debug> |
---|
188 | <instr> |
---|
189 | <type>sloot.debug</type> |
---|
190 | <debug>var:accessor-debug</debug> |
---|
191 | <operand>this:response</operand> |
---|
192 | </instr> |
---|
193 | </accessor-debug> |
---|
194 | <choose> |
---|
195 | <cond> |
---|
196 | <instr> |
---|
197 | <type>sloot.xpath2eval</type> |
---|
198 | <operand>this:response</operand> |
---|
199 | <operator> |
---|
200 | <xpath>exists(/lock)</xpath> |
---|
201 | </operator> |
---|
202 | <target>this:cond</target> |
---|
203 | </instr> |
---|
204 | </cond> |
---|
205 | <then> |
---|
206 | <instr> |
---|
207 | <type>copy</type> |
---|
208 | <operand> |
---|
209 | <HTTPResponseCode> |
---|
210 | <code>201</code> |
---|
211 | </HTTPResponseCode> |
---|
212 | </operand> |
---|
213 | <target>var:code</target> |
---|
214 | </instr> |
---|
215 | </then> |
---|
216 | <else> |
---|
217 | <instr> |
---|
218 | <type>copy</type> |
---|
219 | <operand> |
---|
220 | <HTTPResponseCode> |
---|
221 | <code>409</code> |
---|
222 | </HTTPResponseCode> |
---|
223 | </operand> |
---|
224 | <target>var:code</target> |
---|
225 | </instr> |
---|
226 | </else> |
---|
227 | </choose> |
---|
228 | <instr> |
---|
229 | <type>HTTPResponseCode</type> |
---|
230 | <operand>this:response</operand> |
---|
231 | <param>var:code</param> |
---|
232 | <target>this:response</target> |
---|
233 | </instr> |
---|
234 | </then> |
---|
235 | <!-- GET: access an existing lock --> |
---|
236 | <cond> |
---|
237 | <instr> |
---|
238 | <type>sloot.xpath2eval</type> |
---|
239 | <operand>var:method</operand> |
---|
240 | <operator> |
---|
241 | <xpath>.='GET'</xpath> |
---|
242 | </operator> |
---|
243 | <target>this:cond</target> |
---|
244 | </instr> |
---|
245 | </cond> |
---|
246 | <then> |
---|
247 | <if> |
---|
248 | <cond> |
---|
249 | <instr> |
---|
250 | <type>sloot.xpath2eval</type> |
---|
251 | <operand>var:lock</operand> |
---|
252 | <operator> |
---|
253 | <xpath>.='0'</xpath> |
---|
254 | </operator> |
---|
255 | <target>this:cond</target> |
---|
256 | </instr> |
---|
257 | </cond> |
---|
258 | <then> |
---|
259 | <instr> |
---|
260 | <type>throw</type> |
---|
261 | <operand> |
---|
262 | <ex> |
---|
263 | <id>ISOcat[BAD REQUEST]</id> |
---|
264 | <message>The lock to be retrieved should already have an id.</message> |
---|
265 | </ex> |
---|
266 | </operand> |
---|
267 | </instr> |
---|
268 | </then> |
---|
269 | </if> |
---|
270 | <instr> |
---|
271 | <type>ISOcat.session.lock</type> |
---|
272 | <lock>var:lock</lock> |
---|
273 | <session>var:session</session> |
---|
274 | <user>var:user</user> |
---|
275 | <credentials>var:credentials</credentials> |
---|
276 | <target>this:response</target> |
---|
277 | </instr> |
---|
278 | </then> |
---|
279 | <!-- PUT: use an existing lock --> |
---|
280 | <cond> |
---|
281 | <instr> |
---|
282 | <type>sloot.xpath2eval</type> |
---|
283 | <operand>var:method</operand> |
---|
284 | <operator> |
---|
285 | <xpath>.='PUT'</xpath> |
---|
286 | </operator> |
---|
287 | <target>this:cond</target> |
---|
288 | </instr> |
---|
289 | </cond> |
---|
290 | <then> |
---|
291 | <choose> |
---|
292 | <cond> |
---|
293 | <instr> |
---|
294 | <type>sloot.xpath2eval</type> |
---|
295 | <operand>var:type</operand> |
---|
296 | <operator> |
---|
297 | <xpath>.='data category'</xpath> |
---|
298 | </operator> |
---|
299 | <target>this:cond</target> |
---|
300 | </instr> |
---|
301 | </cond> |
---|
302 | <then> |
---|
303 | <!-- check if the object lock and the DC match --> |
---|
304 | <instr> |
---|
305 | <type>ISOcat.session.lock</type> |
---|
306 | <lock>var:lock</lock> |
---|
307 | <session>var:session</session> |
---|
308 | <user>var:user</user> |
---|
309 | <credentials>var:credentials</credentials> |
---|
310 | <target>var:lock</target> |
---|
311 | </instr> |
---|
312 | <accessor-debug> |
---|
313 | <instr> |
---|
314 | <type>log</type> |
---|
315 | <operand>var:lock</operand> |
---|
316 | </instr> |
---|
317 | </accessor-debug> |
---|
318 | <choose> |
---|
319 | <cond> |
---|
320 | <instr> |
---|
321 | <type>sloot.xquery</type> |
---|
322 | <operator> |
---|
323 | <xquery> |
---|
324 | declare variable $lock as node() external; |
---|
325 | declare variable $ltype as node() external; |
---|
326 | declare variable $dc as node() external; |
---|
327 | <b>{ |
---|
328 | if ( |
---|
329 | $lock//type = string($ltype) |
---|
330 | and |
---|
331 | $lock//object = string($dc) |
---|
332 | ) |
---|
333 | then ('t') |
---|
334 | else ('f') |
---|
335 | }</b> |
---|
336 | </xquery> |
---|
337 | </operator> |
---|
338 | <lock>var:lock</lock> |
---|
339 | <ltype>var:type</ltype> |
---|
340 | <dc>var:dc</dc> |
---|
341 | <target>this:cond</target> |
---|
342 | </instr> |
---|
343 | </cond> |
---|
344 | <then> |
---|
345 | <instr> |
---|
346 | <type>ISOcat.manage.dc.update</type> |
---|
347 | <id>var:dc</id> |
---|
348 | <dc>var:params</dc> |
---|
349 | <user>var:user</user> |
---|
350 | <credentials>var:credentials</credentials> |
---|
351 | <target>this:response</target> |
---|
352 | </instr> |
---|
353 | <instr> |
---|
354 | <type>cast</type> |
---|
355 | <operand>this:response</operand> |
---|
356 | <operator> |
---|
357 | <cast> |
---|
358 | <mimetype>application/x-dcif+xml</mimetype> |
---|
359 | </cast> |
---|
360 | </operator> |
---|
361 | <target>this:response</target> |
---|
362 | </instr> |
---|
363 | </then> |
---|
364 | <else> |
---|
365 | <instr> |
---|
366 | <type>throw</type> |
---|
367 | <operand> |
---|
368 | <ex> |
---|
369 | <id>ISOcat[FORBIDDEN]</id> |
---|
370 | <message>This user isn't allowed to carry out this action.</message> |
---|
371 | </ex> |
---|
372 | </operand> |
---|
373 | </instr> |
---|
374 | </else> |
---|
375 | </choose> |
---|
376 | </then> |
---|
377 | <else> |
---|
378 | <instr> |
---|
379 | <type>throw</type> |
---|
380 | <operand> |
---|
381 | <ex> |
---|
382 | <id>ISOcat[BAD REQUEST]</id> |
---|
383 | <message>Don't know what to lock.</message> |
---|
384 | </ex> |
---|
385 | </operand> |
---|
386 | </instr> |
---|
387 | </else> |
---|
388 | </choose> |
---|
389 | </then> |
---|
390 | <!-- DELETE: release an existing lock --> |
---|
391 | <cond> |
---|
392 | <instr> |
---|
393 | <type>sloot.xpath2eval</type> |
---|
394 | <operand>var:method</operand> |
---|
395 | <operator> |
---|
396 | <xpath>.='DELETE'</xpath> |
---|
397 | </operator> |
---|
398 | <target>this:cond</target> |
---|
399 | </instr> |
---|
400 | </cond> |
---|
401 | <then> |
---|
402 | <if> |
---|
403 | <cond> |
---|
404 | <instr> |
---|
405 | <type>sloot.xpath2eval</type> |
---|
406 | <operand>var:lock</operand> |
---|
407 | <operator> |
---|
408 | <xpath>.='0'</xpath> |
---|
409 | </operator> |
---|
410 | <target>this:cond</target> |
---|
411 | </instr> |
---|
412 | </cond> |
---|
413 | <then> |
---|
414 | <instr> |
---|
415 | <type>throw</type> |
---|
416 | <operand> |
---|
417 | <ex> |
---|
418 | <id>ISOcat[BAD REQUEST]</id> |
---|
419 | <message>The lock to be deleted should already have an id.</message> |
---|
420 | </ex> |
---|
421 | </operand> |
---|
422 | </instr> |
---|
423 | </then> |
---|
424 | </if> |
---|
425 | <accessor-debug> |
---|
426 | <instr> |
---|
427 | <type>sloot.debug</type> |
---|
428 | <debug>var:accessor-debug</debug> |
---|
429 | <operand> |
---|
430 | <msg>DBG: delete lock</msg> |
---|
431 | </operand> |
---|
432 | </instr> |
---|
433 | <instr> |
---|
434 | <type>sloot.debug</type> |
---|
435 | <debug>var:accessor-debug</debug> |
---|
436 | <operand> |
---|
437 | <msg>DBG: with id</msg> |
---|
438 | </operand> |
---|
439 | </instr> |
---|
440 | <instr> |
---|
441 | <type>sloot.debug</type> |
---|
442 | <debug>var:accessor-debug</debug> |
---|
443 | <operand>var:lock</operand> |
---|
444 | </instr> |
---|
445 | <instr> |
---|
446 | <type>sloot.debug</type> |
---|
447 | <debug>var:accessor-debug</debug> |
---|
448 | <operand> |
---|
449 | <msg>DBG: for</msg> |
---|
450 | </operand> |
---|
451 | </instr> |
---|
452 | <instr> |
---|
453 | <type>sloot.debug</type> |
---|
454 | <debug>var:accessor-debug</debug> |
---|
455 | <operand>var:user</operand> |
---|
456 | </instr> |
---|
457 | <instr> |
---|
458 | <type>sloot.debug</type> |
---|
459 | <debug>var:accessor-debug</debug> |
---|
460 | <operand> |
---|
461 | <msg>DBG: in session</msg> |
---|
462 | </operand> |
---|
463 | </instr> |
---|
464 | <instr> |
---|
465 | <type>sloot.debug</type> |
---|
466 | <debug>var:accessor-debug</debug> |
---|
467 | <operand>var:session</operand> |
---|
468 | </instr> |
---|
469 | </accessor-debug> |
---|
470 | <instr> |
---|
471 | <type>ISOcat.session.lock.delete</type> |
---|
472 | <lock>var:lock</lock> |
---|
473 | <session>var:session</session> |
---|
474 | <user>var:user</user> |
---|
475 | <credentials>var:credentials</credentials> |
---|
476 | <target>this:response</target> |
---|
477 | </instr> |
---|
478 | <accessor-debug> |
---|
479 | <instr> |
---|
480 | <type>sloot.debug</type> |
---|
481 | <debug>var:accessor-debug</debug> |
---|
482 | <operand>this:response</operand> |
---|
483 | </instr> |
---|
484 | </accessor-debug> |
---|
485 | </then> |
---|
486 | <else> |
---|
487 | <instr> |
---|
488 | <type>throw</type> |
---|
489 | <operand> |
---|
490 | <ex> |
---|
491 | <id>ISOcat[METHOD NOT ALLOWED]</id> |
---|
492 | <message>This method is not allowed for this resource.</message> |
---|
493 | </ex> |
---|
494 | </operand> |
---|
495 | </instr> |
---|
496 | </else> |
---|
497 | </choose> |
---|
498 | </idoc> |
---|
499 | <exception> |
---|
500 | <debug/> |
---|
501 | <trace>ffcpl:/trace/lock.exception.xml</trace> |
---|
502 | <throw/> |
---|
503 | </exception> |
---|
504 | <response> |
---|
505 | <debug>ffcpl:/trace/lock.response.xml</debug> |
---|
506 | <mime>application/xml</mime> |
---|
507 | <expire>now</expire> |
---|
508 | </response> |
---|
509 | </accessor> |
---|