source: cats/ISOcat/trunk/mod-ISOcat-access-data/access/group_update.acc @ 2686

Last change on this file since 2686 was 2686, checked in by mwindhouwer, 11 years ago

Fixed the throtteling:

  • all SQL request go through the ISOcat.database throttle (settings in the ISOcat config), also the indirect DBX ones
  • big (more then 100 DCs) DCS to DCIF go through the big-dcif throttle (hardcoded settings)
File size: 9.6 KB
Line 
1<accessor debug="false">
2        <name>ISOcat.access.data.group.update</name>
3        <descr>Update an existing group.</descr>
4        <param mandatory="true">
5                <name>id</name>
6                <descr>the group to update</descr>
7        </param>
8        <param mandatory="true">
9                <name>group</name>
10                <descr>the group update</descr>
11        </param>
12        <idoc>
13                <!-- validate the new group content -->
14                <instr>
15                        <type>validateRNG</type>
16                        <operand>var:group</operand>
17                        <operator>active:ISOcat.access.data.group.schema</operator>
18                        <target>var:valid</target>
19                </instr>
20                <if>
21                        <cond>
22                                <instr>
23                                        <type>copy</type>
24                                        <operand>var:valid</operand>
25                                        <target>this:cond</target>
26                                </instr>
27                        </cond>
28                        <then>
29                                <instr>
30                                        <type>sloot.xpath2eval</type>
31                                        <operand>var:group</operand>
32                                        <operator>
33                                                <xpath>/group/@owner</xpath>
34                                        </operator>
35                                        <param>
36                                                <return>
37                                                        <canonical/>
38                                                        <string/>
39                                                </return>
40                                        </param>
41                                        <target>var:owner</target>
42                                </instr>
43                                <instr>
44                                        <type>sloot.xpath2eval</type>
45                                        <operand>var:group</operand>
46                                        <operator>
47                                                <xpath>/group/name</xpath>
48                                        </operator>
49                                        <param>
50                                                <return>
51                                                        <canonical/>
52                                                        <string/>
53                                                </return>
54                                        </param>
55                                        <target>var:name</target>
56                                </instr>
57                                <accessor-debug>
58                                        <instr>
59                                                <type>sloot.xquery</type>
60                                                <operator>
61                                                        <xquery>
62                                                                declare variable $owner as node() external;
63                                                                declare variable $name as node() external;
64                                                       
65                                                                &lt;msg>update group[{string($name)}] for owner[{string($owner)}]&lt;/msg>
66                                                        </xquery>
67                                                </operator>
68                                                <owner>var:owner</owner>
69                                                <name>var:name</name>
70                                                <target>var:msg</target>
71                                        </instr>
72                                        <instr>
73                                                <type>sloot.log</type>
74                                                <operand>var:msg</operand>
75                                        </instr>
76                                </accessor-debug>
77                                <instr>
78                                        <type>ISOcat.access.data.user.id</type>
79                                        <user>var:owner</user>
80                                        <target>var:uid</target>
81                                </instr>
82                                <!-- check if a group with this name already exists -->
83                                <instr>
84                                        <type>ISOcat.access.data.group.id</type>
85                                        <name>var:name</name>
86                                        <target>var:dup</target>
87                                </instr>
88                                <if>
89                                        <cond>
90                                                <instr>
91                                                        <type>sloot.xquery</type>
92                                                        <operator>
93                                                                <xquery>
94                                                                        declare variable $id as node() external;
95                                                                        declare variable $dup as node() external;
96                                                                       
97                                                                        &lt;b>{
98                                                                                if (string($dup)!='' and string($dup)!=string($id))
99                                                                                then ('t')
100                                                                                else ('f')
101                                                                        }&lt;/b>
102                                                                </xquery>
103                                                        </operator>
104                                                        <id>var:id</id>
105                                                        <dup>var:dup</dup>
106                                                        <target>this:cond</target>
107                                                </instr>
108                                        </cond>
109                                        <then>
110                                                <instr>
111                                                        <type>throw</type>
112                                                        <operand>
113                                                                <ex>
114                                                                        <id>ISOcat[CONFLICT]</id>
115                                                                        <message>A group with this name already exists.</message>
116                                                                </ex>
117                                                        </operand>
118                                                </instr>
119                                        </then>
120                                </if>
121                                <!-- save the status of existing users to prevent lost updates -->
122                                <instr>
123                                        <type>ISOcat.access.data.group</type>
124                                        <group>var:id</group>
125                                        <target>var:cur</target>
126                                </instr>
127                                <instr>
128                                        <type>xslt2</type>
129                                        <operand>var:group</operand>
130                                        <operator>
131                                                <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:isocat="http://www.isocat.org/">
132                                                       
133                                                        <xsl:output method="xml" encoding="utf-8"/>
134                                                       
135                                                        <xsl:param name="cur"/>
136                                                       
137                                                        <xsl:template match="@*|node()">
138                                                                <xsl:copy>
139                                                                        <xsl:apply-templates select="@*|node()"/>
140                                                                </xsl:copy>
141                                                        </xsl:template>
142                                                       
143                                                        <xsl:template match="member">
144                                                                <xsl:copy>
145                                                                        <xsl:apply-templates select="@* except @status"/>
146                                                                        <xsl:choose>
147                                                                                <xsl:when test="exists($cur//member[@ref=current()/@ref])">
148                                                                                        <xsl:attribute name="status">
149                                                                                                <xsl:value-of select="$cur//member[@ref=current()/@ref]/@status"/>
150                                                                                        </xsl:attribute>
151                                                                                </xsl:when>
152                                                                                <xsl:otherwise>
153                                                                                        <xsl:apply-templates select="@status"/>
154                                                                                </xsl:otherwise>
155                                                                        </xsl:choose>
156                                                                        <xsl:apply-templates select="node()"/>
157                                                                </xsl:copy>
158                                                        </xsl:template>
159                                                       
160                                                </xsl:stylesheet>
161                                        </operator>
162                                        <cur>var:cur</cur>
163                                        <target>var:group</target>
164                                </instr>
165                                <!-- create the SQL script -->
166                                <instr>
167                                        <type>xslt2</type>
168                                        <operand>var:group</operand>
169                                        <operator>
170                                                <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:isocat="http://www.isocat.org/">
171                                                        <xsl:param name="id"/>
172                                                        <xsl:param name="uid"/>
173                                                        <xsl:param name="name"/>
174                                                       
175                                                        <xsl:template match="text()"/>
176
177                                                        <xsl:template match="/group">
178                                                                <batch>
179                                                                        <sql>
180                                                                                UPDATE
181                                                                                        core_adhoc_group
182                                                                                SET
183                                                                                        name = '<xsl:value-of select="replace(string($name),&quot;&apos;&quot;,&quot;\\&apos;&quot;)"/>',
184                                                                                    description = '<xsl:value-of select="replace(string(description),&quot;&apos;&quot;,&quot;\\&apos;&quot;)"/>'
185                                                                                WHERE
186                                                                                    id = <xsl:value-of select="$id"/>
187                                                                                ;
188                                                                        </sql>
189                                                                        <!-- sync all (old) users -->
190                                                                        <sql>
191                                                                                UPDATE
192                                                                                        core_user
193                                                                                SET
194                                                                                        sync = true
195                                                                                FROM
196                                                                                        link_group_members
197                                                                                WHERE
198                                                                                        link_group_members."group" = <xsl:value-of select="$id"/>
199                                                                                 AND
200                                                                                        link_group_members.member = core_user.id
201                                                                                ;
202                                                                        </sql>
203                                                                        <sql>
204                                                                                DELETE FROM
205                                                                                    link_group_members
206                                                                                WHERE
207                                                                                    "group" = <xsl:value-of select="$id"/>
208                                                                                ;
209                                                                        </sql>
210                                                                        <xsl:apply-templates/>
211                                                                        <!-- sync all (new) users -->
212                                                                        <sql>
213                                                                                UPDATE
214                                                                                        core_user
215                                                                                SET
216                                                                                        sync = true
217                                                                                FROM
218                                                                                        link_group_members
219                                                                                WHERE
220                                                                                        link_group_members."group" = <xsl:value-of select="$id"/>
221                                                                                AND
222                                                                                        link_group_members.member = core_user.id
223                                                                                AND
224                                                                                        link_group_members.status = 'accepted'
225                                                                                ;
226                                                                        </sql>
227                                                                </batch>
228                                                        </xsl:template>
229
230                                                        <xsl:template match="member">
231                                                                <sql>
232                                                                        INSERT INTO
233                                                                                link_group_members
234                                                                        (
235                                                                                "group",
236                                                                                member,
237                                                                                status
238                                                                        )
239                                                                        VALUES
240                                                                        (
241                                                                                <xsl:value-of select="$id"/>,
242                                                                                <xsl:value-of select="@ref"/>,
243                                                                                '<xsl:value-of select="@status"/>'
244                                                                        )
245                                                                        ;
246                                                                </sql>
247                                                        </xsl:template>
248                                                </xsl:stylesheet>
249                                        </operator>
250                                        <id>var:id</id>
251                                        <uid>var:uid</uid>
252                                        <name>var:name</name>
253                                        <target>var:sql</target>
254                                </instr>
255                                <accessor-debug>
256                                        <instr>
257                                                <type>copy</type>
258                                                <operand>var:sql</operand>
259                                                <target>ffcpl:/trace/group_update.sql.xml</target>
260                                        </instr>
261                                </accessor-debug>
262                                <instr>
263                                        <type>isocat.sqlBatch</type>
264                                        <operand>var:sql</operand>
265                                        <target>var:result</target>
266                                </instr>
267                                <accessor-debug>
268                                        <instr>
269                                                <type>copy</type>
270                                                <operand>var:result</operand>
271                                                <target>ffcpl:/trace/group_update.result.xml</target>
272                                        </instr>
273                                </accessor-debug>
274                                <!-- cut the golden thread of the group -->
275                                <instr>
276                                        <type>sloot.xquery</type>
277                                        <operator>
278                                                <string>goldenthread:/group/{string($id)}</string>
279                                        </operator>
280                                        <id>var:id</id>
281                                        <target>var:thread</target>
282                                </instr>
283                                <instr>
284                                        <type>sloot.cutGoldenThread</type>
285                                        <param>var:thread</param>
286                                </instr>
287                                <!-- send out the invitations to join the group -->
288                                <instr>
289                                        <type>ISOcat.access.data.group.invite</type>
290                                        <group>var:id</group>
291                                </instr>
292                                <!-- return the updated group -->
293                                <instr>
294                                        <type>ISOcat.access.data.group</type>
295                                        <group>var:id</group>
296                                        <target>this:response</target>
297                                </instr>
298                                <instr>
299                                        <type>xslt2</type>
300                                        <operand>this:response</operand>
301                                        <operator>
302                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
303                                                        <xsl:template match="/group">
304                                                                <msg>INF: <xsl:value-of select="current-dateTime()"/>: updated group[<xsl:value-of select="@key"/>][<xsl:value-of select="@name"/>] owner[<xsl:value-of select="@owner"/>]</msg>
305                                                        </xsl:template>
306                                                </xsl:stylesheet>
307                                        </operator>
308                                        <target>var:msg</target>
309                                </instr>
310                                <instr>
311                                        <type>sloot.log</type>
312                                        <operand>var:msg</operand>
313                                </instr>
314                                <accessor-debug>
315                                        <instr>
316                                                <type>copy</type>
317                                                <operand>this:response</operand>
318                                                <target>ffcpl:/trace/group_update.response.xml</target>
319                                        </instr>
320                                </accessor-debug>
321                                <!-- cut the golden thread of the user's WS as the group name might have changed -->
322                                <instr>
323                                        <type>sloot.xquery</type>
324                                        <operator>
325                                                <xquery>
326                                                        declare variable $owner as node() external;
327                                                       
328                                                        &lt;string>goldenthread:/user/{string($owner)}/workspace&lt;/string>
329                                                </xquery>
330                                        </operator>
331                                        <owner>var:owner</owner>
332                                        <target>var:thread</target>
333                                </instr>
334                                <instr>
335                                        <type>sloot.cutGoldenThread</type>
336                                        <param>var:thread</param>
337                                </instr>
338                        </then>
339                        <else>
340                                <instr>
341                                        <type>copy</type>
342                                        <operand>var:group</operand>
343                                        <target>ffcpl:/trace/group_update.group.xml</target>
344                                </instr>
345                                <instr>
346                                        <type>copy</type>
347                                        <operand>var:valid</operand>
348                                        <target>ffcpl:/trace/group_update.group.invalid.xml</target>
349                                </instr>
350                                <instr>
351                                        <type>throw</type>
352                                        <operand>
353                                                <ex>
354                                                        <id>ISOcat[BAD REQUEST]</id>
355                                                        <message>The group update is invalid.</message>
356                                                </ex>
357                                        </operand>
358                                </instr>
359                        </else>
360                </if>
361        </idoc>
362        <exception>
363                <debug/>
364                <trace>ffcpl:/trace/group_update.exception.xml</trace>
365                <throw/>
366        </exception>
367        <response>
368                <mime>application/xml</mime>
369                <expire>now</expire>
370        </response>
371</accessor>
Note: See TracBrowser for help on using the repository browser.