source: cats/ISOcat/trunk/mod-ISOcat-interface-rest/interface/lock.acc @ 5612

Last change on this file since 5612 was 5612, checked in by Menzo Windhouwer, 10 years ago

M dc-scope.acc
M lock.acc

  • added some more debugging options
File size: 12.4 KB
Line 
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            <accessor-debug>
97                <instr>
98                    <type>log</type>
99                    <operand>var:user</operand>
100                </instr>
101                <instr>
102                    <type>log</type>
103                    <operand>var:session</operand>
104                </instr>
105                <instr>
106                    <type>log</type>
107                    <operand>var:method</operand>
108                </instr>
109                <instr>
110                    <type>log</type>
111                    <operand>var:lock</operand>
112                </instr>
113                <instr>
114                    <type>log</type>
115                    <operand>var:type</operand>
116                </instr>
117                <instr>
118                    <type>log</type>
119                    <operand>var:object</operand>
120                </instr>
121            </accessor-debug>
122                <choose>
123                        <!-- POST: acquire a new lock -->
124                        <cond>
125                                <instr>
126                                        <type>sloot.xpath2eval</type>
127                                        <operand>var:method</operand>
128                                        <operator>
129                                                <xpath>.='POST'</xpath>
130                                        </operator>
131                                        <target>this:cond</target>
132                                </instr>
133                        </cond>
134                        <then>
135                                <if>
136                                        <cond>
137                                                <instr>
138                                                        <type>sloot.xpath2eval</type>
139                                                        <operand>var:lock</operand>
140                                                        <operator>
141                                                                <xpath>.!='0'</xpath>
142                                                        </operator>
143                                                        <target>this:cond</target>
144                                                </instr>
145                                        </cond>
146                                        <then>
147                                                <instr>
148                                                        <type>throw</type>
149                                                        <operand>
150                                                                <ex>
151                                                                        <id>ISOcat[BAD REQUEST]</id>
152                                                                        <message>The new lock can't have an id yet.</message>
153                                                                </ex>
154                                                        </operand>
155                                                </instr>
156                                        </then>
157                                </if>
158                                <accessor-debug>
159                                        <instr>
160                                                <type>xquery</type>
161                                                <operator>
162                                                        <xquery>
163                                                                declare variable $ltype as node() external;
164                                                                declare variable $dc as node() external;
165                                                                declare variable $user as node() external;
166                                                                declare variable $session as node() external;
167                                                                &lt;msg>DBG: new lock on {string($ltype)}[{string($dc)}] for user[{string($user)}] session[{string($session)}]&lt;/msg>
168                                                        </xquery>
169                                                </operator>
170                                                <ltype>var:type</ltype>
171                                                <dc>var:dc</dc>
172                                                <user>var:user</user>
173                                                <session>var:session</session>
174                                                <target>var:msg</target>
175                                        </instr>
176                                        <instr>
177                                                <type>sloot.debug</type>
178                                                <operand>var:msg</operand>
179                                        </instr>
180                                </accessor-debug>
181                                <if>
182                                        <cond>
183                                                <instr>
184                                                        <type>sloot.xpath2eval</type>
185                                                        <operand>var:object</operand>
186                                                        <operator>
187                                                                <xpath>.='0'</xpath>
188                                                        </operator>
189                                                        <target>this:cond</target>
190                                                </instr>
191                                        </cond>
192                                        <then>
193                                                <instr>
194                                                        <type>throw</type>
195                                                        <operand>
196                                                                <ex>
197                                                                        <id>ISOcat[BAD REQUEST]</id>
198                                                                        <message>The object to lock needs to have an id.</message>
199                                                                </ex>
200                                                        </operand>
201                                                </instr>
202                                        </then>
203                                </if>
204                                <instr>
205                                        <type>ISOcat.session.lock.new</type>
206                                        <user>var:user</user>
207                                        <session>var:session</session>
208                                        <credentials>var:credentials</credentials>
209                                        <ltype>var:type</ltype>
210                                        <object>var:object</object>
211                                        <target>this:response</target>
212                                </instr>
213                                <accessor-debug>
214                                        <instr>
215                                                <type>sloot.debug</type>
216                                                <debug>var:accessor-debug</debug>
217                                                <operand>this:response</operand>
218                                        </instr>
219                                </accessor-debug>
220                                <choose>
221                                        <cond>
222                                                <instr>
223                                                        <type>sloot.xpath2eval</type>
224                                                        <operand>this:response</operand>
225                                                        <operator>
226                                                                <xpath>exists(/lock)</xpath>
227                                                        </operator>
228                                                        <target>this:cond</target>
229                                                </instr>
230                                        </cond>
231                                        <then>
232                                                <instr>
233                                                        <type>copy</type>
234                                                        <operand>
235                                                                <HTTPResponseCode>
236                                                                        <code>201</code>
237                                                                </HTTPResponseCode>
238                                                        </operand>
239                                                        <target>var:code</target>
240                                                </instr>
241                                        </then>
242                                        <else>
243                                                <instr>
244                                                        <type>copy</type>
245                                                        <operand>
246                                                                <HTTPResponseCode>
247                                                                        <code>409</code>
248                                                                </HTTPResponseCode>
249                                                        </operand>
250                                                        <target>var:code</target>
251                                                </instr>
252                                        </else>
253                                </choose>
254                                <instr>
255                                        <type>HTTPResponseCode</type>
256                                        <operand>this:response</operand>
257                                        <param>var:code</param>
258                                        <target>this:response</target>
259                                </instr>
260                        </then>
261                        <!-- GET: access an existing lock -->
262                        <cond>
263                                <instr>
264                                        <type>sloot.xpath2eval</type>
265                                        <operand>var:method</operand>
266                                        <operator>
267                                                <xpath>.='GET'</xpath>
268                                        </operator>
269                                        <target>this:cond</target>
270                                </instr>
271                        </cond>
272                        <then>
273                                <if>
274                                        <cond>
275                                                <instr>
276                                                        <type>sloot.xpath2eval</type>
277                                                        <operand>var:lock</operand>
278                                                        <operator>
279                                                                <xpath>.='0'</xpath>
280                                                        </operator>
281                                                        <target>this:cond</target>
282                                                </instr>
283                                        </cond>
284                                        <then>
285                                                <instr>
286                                                        <type>throw</type>
287                                                        <operand>
288                                                                <ex>
289                                                                        <id>ISOcat[BAD REQUEST]</id>
290                                                                        <message>The lock to be retrieved should already have an id.</message>
291                                                                </ex>
292                                                        </operand>
293                                                </instr>
294                                        </then>
295                                </if>
296                                <instr>
297                                        <type>ISOcat.session.lock</type>
298                                        <lock>var:lock</lock>
299                                        <session>var:session</session>
300                                        <user>var:user</user>
301                                        <credentials>var:credentials</credentials>
302                                        <target>this:response</target>
303                                </instr>
304                        </then>
305                        <!-- PUT: use an existing lock -->
306                        <cond>
307                                <instr>
308                                        <type>sloot.xpath2eval</type>
309                                        <operand>var:method</operand>
310                                        <operator>
311                                                <xpath>.='PUT'</xpath>
312                                        </operator>
313                                        <target>this:cond</target>
314                                </instr>
315                        </cond>
316                        <then>
317                                <choose>
318                                        <cond>
319                                                <instr>
320                                                        <type>sloot.xpath2eval</type>
321                                                        <operand>var:type</operand>
322                                                        <operator>
323                                                                <xpath>.='data category'</xpath>
324                                                        </operator>
325                                                        <target>this:cond</target>
326                                                </instr>
327                                        </cond>
328                                        <then>
329                                                <!-- check if the object lock and the DC match -->
330                                                <instr>
331                                                        <type>ISOcat.session.lock</type>
332                                                        <lock>var:lock</lock>
333                                                        <session>var:session</session>
334                                                        <user>var:user</user>
335                                                        <credentials>var:credentials</credentials>
336                                                        <target>var:lock</target>
337                                                </instr>
338                                                <accessor-debug>
339                                                        <instr>
340                                                                <type>log</type>
341                                                                <operand>var:lock</operand>
342                                                        </instr>
343                                                </accessor-debug>
344                                                <choose>
345                                                        <cond>
346                                                                <instr>
347                                                                        <type>sloot.xquery</type>
348                                                                        <operator>
349                                                                                <xquery>
350                                                                                        declare variable $lock as node() external;
351                                                                                        declare variable $ltype as node() external;
352                                                                                        declare variable $dc as node() external;
353                                                                                        &lt;b&gt;{
354                                                                                                if              (
355                                                                                                                        $lock//type = string($ltype)
356                                                                                                                and
357                                                                                                                        $lock//object = string($dc)
358                                                                                                                )
359                                                                                                then    ('t')
360                                                                                                else    ('f')
361                                                                                        }&lt;/b&gt;
362                                                                                </xquery>
363                                                                        </operator>
364                                                                        <lock>var:lock</lock>
365                                                                        <ltype>var:type</ltype>
366                                                                        <dc>var:dc</dc>
367                                                                        <target>this:cond</target>
368                                                                </instr>
369                                                        </cond>
370                                                        <then>
371                                                                <instr>
372                                                                        <type>ISOcat.manage.dc.update</type>
373                                                                        <id>var:dc</id>
374                                                                        <dc>var:params</dc>
375                                                                        <user>var:user</user>
376                                                                        <credentials>var:credentials</credentials>
377                                                                        <target>this:response</target>
378                                                                </instr>
379                                                                <instr>
380                                                                        <type>cast</type>
381                                                                        <operand>this:response</operand>
382                                                                        <operator>
383                                                                                <cast>
384                                                                                        <mimetype>application/x-dcif+xml</mimetype>
385                                                                                </cast>
386                                                                        </operator>
387                                                                        <target>this:response</target>
388                                                                </instr>
389                                                        </then>
390                                                        <else>
391                                                                <instr>
392                                                                        <type>throw</type>
393                                                                        <operand>
394                                                                                <ex>
395                                                                                        <id>ISOcat[FORBIDDEN]</id>
396                                                                                        <message>This user isn't allowed to carry out this action.</message>
397                                                                                </ex>
398                                                                        </operand>
399                                                                </instr>
400                                                        </else>
401                                                </choose>
402                                        </then>
403                                        <else>
404                                                <instr>
405                                                        <type>throw</type>
406                                                        <operand>
407                                                                <ex>
408                                                                        <id>ISOcat[BAD REQUEST]</id>
409                                                                        <message>Don't know what to lock.</message>
410                                                                </ex>
411                                                        </operand>
412                                                </instr>
413                                        </else>
414                                </choose>
415                        </then>
416                        <!-- DELETE: release an existing lock -->
417                        <cond>
418                                <instr>
419                                        <type>sloot.xpath2eval</type>
420                                        <operand>var:method</operand>
421                                        <operator>
422                                                <xpath>.='DELETE'</xpath>
423                                        </operator>
424                                        <target>this:cond</target>
425                                </instr>
426                        </cond>
427                        <then>
428                                <if>
429                                        <cond>
430                                                <instr>
431                                                        <type>sloot.xpath2eval</type>
432                                                        <operand>var:lock</operand>
433                                                        <operator>
434                                                                <xpath>.='0'</xpath>
435                                                        </operator>
436                                                        <target>this:cond</target>
437                                                </instr>
438                                        </cond>
439                                        <then>
440                                                <instr>
441                                                        <type>throw</type>
442                                                        <operand>
443                                                                <ex>
444                                                                        <id>ISOcat[BAD REQUEST]</id>
445                                                                        <message>The lock to be deleted should already have an id.</message>
446                                                                </ex>
447                                                        </operand>
448                                                </instr>
449                                        </then>
450                                </if>
451                                <accessor-debug>
452                                        <instr>
453                                                <type>sloot.debug</type>
454                                                <debug>var:accessor-debug</debug>
455                                                <operand>
456                                                        <msg>DBG: delete lock</msg>
457                                                </operand>
458                                        </instr>
459                                        <instr>
460                                                <type>sloot.debug</type>
461                                                <debug>var:accessor-debug</debug>
462                                                <operand>
463                                                        <msg>DBG: with id</msg>
464                                                </operand>
465                                        </instr>
466                                        <instr>
467                                                <type>sloot.debug</type>
468                                                <debug>var:accessor-debug</debug>
469                                                <operand>var:lock</operand>
470                                        </instr>
471                                        <instr>
472                                                <type>sloot.debug</type>
473                                                <debug>var:accessor-debug</debug>
474                                                <operand>
475                                                        <msg>DBG: for</msg>
476                                                </operand>
477                                        </instr>
478                                        <instr>
479                                                <type>sloot.debug</type>
480                                                <debug>var:accessor-debug</debug>
481                                                <operand>var:user</operand>
482                                        </instr>
483                                        <instr>
484                                                <type>sloot.debug</type>
485                                                <debug>var:accessor-debug</debug>
486                                                <operand>
487                                                        <msg>DBG: in session</msg>
488                                                </operand>
489                                        </instr>
490                                        <instr>
491                                                <type>sloot.debug</type>
492                                                <debug>var:accessor-debug</debug>
493                                                <operand>var:session</operand>
494                                        </instr>
495                                </accessor-debug>
496                                <instr>
497                                        <type>ISOcat.session.lock.delete</type>
498                                        <lock>var:lock</lock>
499                                        <session>var:session</session>
500                                        <user>var:user</user>
501                                        <credentials>var:credentials</credentials>
502                                        <target>this:response</target>
503                                </instr>
504                                <accessor-debug>
505                                        <instr>
506                                                <type>sloot.debug</type>
507                                                <debug>var:accessor-debug</debug>
508                                                <operand>this:response</operand>
509                                        </instr>
510                                </accessor-debug>
511                        </then>
512                        <else>
513                                <instr>
514                                        <type>throw</type>
515                                        <operand>
516                                                <ex>
517                                                        <id>ISOcat[METHOD NOT ALLOWED]</id>
518                                                        <message>This method is not allowed for this resource.</message>
519                                                </ex>
520                                        </operand>
521                                </instr>
522                        </else>
523                </choose>
524            <accessor-debug>
525                <instr>
526                    <type>log</type>
527                    <operand>this:response</operand>
528                </instr>
529            </accessor-debug>
530        </idoc>
531        <exception>
532                <debug/>
533                <trace>ffcpl:/trace/lock.exception.xml</trace>
534                <throw/>
535        </exception>
536        <response>
537                <debug>ffcpl:/trace/lock.response.xml</debug>
538                <mime>application/xml</mime>
539                <expire>now</expire>
540        </response>
541</accessor>
Note: See TracBrowser for help on using the repository browser.