source: cats/ISOcat/trunk/mod-ISOcat-access-data/access/group_new.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: 7.5 KB
Line 
1<accessor debug="false">
2        <name>ISOcat.access.data.group.new</name>
3        <descr>Insert a new group.</descr>
4        <param mandatory="true">
5                <name>group</name>
6                <descr>the new group</descr>
7        </param>
8        <idoc>
9                <!-- validate the new group content -->
10                <instr>
11                        <type>validateRNG</type>
12                        <operand>var:group</operand>
13                        <operator>active:ISOcat.access.data.group.schema</operator>
14                        <target>var:valid</target>
15                </instr>
16                <if>
17                        <cond>
18                                <instr>
19                                        <type>copy</type>
20                                        <operand>var:valid</operand>
21                                        <target>this:cond</target>
22                                </instr>
23                        </cond>
24                        <then>
25                                <instr>
26                                        <type>sloot.xpath2eval</type>
27                                        <operand>var:group</operand>
28                                        <operator>
29                                                <xpath>/group/@owner</xpath>
30                                        </operator>
31                                        <param>
32                                                <return>
33                                                        <canonical/>
34                                                        <string/>
35                                                </return>
36                                        </param>
37                                        <target>var:owner</target>
38                                </instr>
39                                <instr>
40                                        <type>sloot.xpath2eval</type>
41                                        <operand>var:group</operand>
42                                        <operator>
43                                                <xpath>/group/name</xpath>
44                                        </operator>
45                                        <param>
46                                                <return>
47                                                        <canonical/>
48                                                        <string/>
49                                                </return>
50                                        </param>
51                                        <target>var:name</target>
52                                </instr>
53                                <accessor-debug>
54                                        <instr>
55                                                <type>sloot.xquery</type>
56                                                <operator>
57                                                        <xquery>
58                                                                declare variable $owner as node() external;
59                                                                declare variable $name as node() external;
60                                                       
61                                                                &lt;msg>new group[{string($name)}] for owner[{string($owner)}]&lt;/msg>
62                                                        </xquery>
63                                                </operator>
64                                                <owner>var:owner</owner>
65                                                <name>var:name</name>
66                                                <target>var:msg</target>
67                                        </instr>
68                                        <instr>
69                                                <type>sloot.log</type>
70                                                <operand>var:msg</operand>
71                                        </instr>
72                                </accessor-debug>
73                                <instr>
74                                        <type>ISOcat.access.data.user.id</type>
75                                        <user>var:owner</user>
76                                        <target>var:uid</target>
77                                </instr>
78                                <!-- check if a group with this name already exists -->
79                                <instr>
80                                        <type>ISOcat.access.data.group.id</type>
81                                        <name>var:name</name>
82                                        <target>var:dup</target>
83                                </instr>
84                                <if>
85                                        <cond>
86                                                <instr>
87                                                        <type>sloot.xpath2eval</type>
88                                                        <operand>var:dup</operand>
89                                                        <operator>
90                                                                <xpath>normalize-space(/string)!=''</xpath>
91                                                        </operator>
92                                                        <target>this:cond</target>
93                                                </instr>
94                                        </cond>
95                                        <then>
96                                                <instr>
97                                                        <type>throw</type>
98                                                        <operand>
99                                                                <ex>
100                                                                        <id>ISOcat[CONFLICT]</id>
101                                                                        <message>A group with this name already exists.</message>
102                                                                </ex>
103                                                        </operand>
104                                                </instr>
105                                        </then>
106                                </if>
107                                <instr>
108                                        <type>xslt2</type>
109                                        <operand>var:group</operand>
110                                        <operator>
111                                                <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:isocat="http://www.isocat.org/">
112                                                        <xsl:param name="uid"/>
113                                                        <xsl:param name="name"/>
114                                                       
115                                                        <xsl:template match="/group">
116                                                                <batch>
117                                                                        <sql>
118                                                                                INSERT INTO
119                                                                                        core_account
120                                                                                DEFAULT VALUES
121                                                                                ;
122                                                                        </sql>
123                                                                        <sql>
124                                                                                INSERT INTO
125                                                                                        core_group
126                                                                                (
127                                                                                        id
128                                                                                )
129                                                                                VALUES
130                                                                                (
131                                                                                        currval('core_account_id_seq'::regclass)
132                                                                                )
133                                                                                ;
134                                                                        </sql>
135                                                                        <sql>
136                                                                                INSERT INTO
137                                                                                        core_adhoc_group
138                                                                                (
139                                                                                        id,
140                                                                                        owner,
141                                                                                        name,
142                                                                                        description
143                                                                                )
144                                                                                VALUES
145                                                                                (
146                                                                                        currval('core_account_id_seq'::regclass),       
147                                                                                        <xsl:value-of select="string($uid)"/>,
148                                                                                        '<xsl:value-of select="replace(string($name),&quot;&apos;&quot;,&quot;\\&apos;&quot;)"/>',
149                                                                                        '<xsl:value-of select="replace(string(description),&quot;&apos;&quot;,&quot;\\&apos;&quot;)"/>'
150                                                                                )
151                                                                                ;
152                                                                        </sql>
153                                                                        <xsl:apply-templates/>
154                                                                        <!-- sync all (new) users -->
155                                                                        <sql>
156                                                                                UPDATE
157                                                                                        core_user
158                                                                                SET
159                                                                                        sync = true
160                                                                                FROM
161                                                                                        link_group_members
162                                                                                WHERE
163                                                                                        link_group_members."group" = currval('core_account_id_seq'::regclass)
164                                                                                AND
165                                                                                        link_group_members.member = core_user.id
166                                                                                AND
167                                                                                        link_group_members.status = 'accepted'
168                                                                                ;
169                                                                        </sql>
170                                                                </batch>
171                                                        </xsl:template>
172
173                                                        <xsl:template match="member">
174                                                                <sql>
175                                                                        INSERT INTO
176                                                                                link_group_members
177                                                                        (
178                                                                                "group",
179                                                                                member,
180                                                                                status
181                                                                        )
182                                                                        VALUES
183                                                                        (
184                                                                                currval('core_account_id_seq'::regclass),
185                                                                                <xsl:value-of select="@ref"/>,
186                                                                                '<xsl:value-of select="@status"/>'
187                                                                        )
188                                                                        ;
189                                                                </sql>
190                                                        </xsl:template>
191                                                </xsl:stylesheet>
192                                        </operator>
193                                        <uid>var:uid</uid>
194                                        <name>var:name</name>
195                                        <target>var:sql</target>
196                                </instr>
197                                <accessor-debug>
198                                        <instr>
199                                                <type>copy</type>
200                                                <operand>var:sql</operand>
201                                                <target>ffcpl:/trace/group_new.sql.xml</target>
202                                        </instr>
203                                </accessor-debug>
204                                <instr>
205                                        <type>isocat.sqlBatch</type>
206                                        <operand>var:sql</operand>
207                                        <target>var:result</target>
208                                </instr>
209                                <accessor-debug>
210                                        <instr>
211                                                <type>copy</type>
212                                                <operand>var:result</operand>
213                                                <target>ffcpl:/trace/group_new.result.xml</target>
214                                        </instr>
215                                </accessor-debug>
216                                <instr>
217                                        <type>ISOcat.access.data.group.id</type>
218                                        <name>var:name</name>
219                                        <target>var:id</target>
220                                </instr>
221                                <!-- send out the invitations to join the group -->
222                                <instr>
223                                        <type>ISOcat.access.data.group.invite</type>
224                                        <group>var:id</group>
225                                </instr>
226                                <!-- return the new group -->
227                                <instr>
228                                        <type>ISOcat.access.data.group</type>
229                                        <group>var:id</group>
230                                        <target>this:response</target>
231                                </instr>
232                                <instr>
233                                        <type>xslt2</type>
234                                        <operand>this:response</operand>
235                                        <operator>
236                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
237                                                        <xsl:template match="/group">
238                                                                <msg>INF: <xsl:value-of select="current-dateTime()"/>: new group[<xsl:value-of select="@key"/>][<xsl:value-of select="@name"/>] owner[<xsl:value-of select="@owner"/>]</msg>
239                                                        </xsl:template>
240                                                </xsl:stylesheet>
241                                        </operator>
242                                        <target>var:msg</target>
243                                </instr>
244                                <instr>
245                                        <type>sloot.log</type>
246                                        <operand>var:msg</operand>
247                                </instr>
248                                <accessor-debug>
249                                        <instr>
250                                                <type>copy</type>
251                                                <operand>this:response</operand>
252                                                <target>ffcpl:/trace/group_new.response.xml</target>
253                                        </instr>
254                                </accessor-debug>
255                                <!-- cut the golden thread of the user's WS -->
256                                <instr>
257                                        <type>sloot.xquery</type>
258                                        <operator>
259                                                <xquery>
260                                                        declare variable $owner as node() external;
261                                                       
262                                                        &lt;string>goldenthread:/user/{string($owner)}/workspace&lt;/string>
263                                                </xquery>
264                                        </operator>
265                                        <owner>var:owner</owner>
266                                        <target>var:thread</target>
267                                </instr>
268                                <instr>
269                                        <type>sloot.cutGoldenThread</type>
270                                        <param>var:thread</param>
271                                </instr>
272                        </then>
273                        <else>
274                                <instr>
275                                        <type>copy</type>
276                                        <operand>var:group</operand>
277                                        <target>ffcpl:/trace/group_new.group.xml</target>
278                                </instr>
279                                <instr>
280                                        <type>copy</type>
281                                        <operand>var:valid</operand>
282                                        <target>ffcpl:/trace/group_new.group.invalid.xml</target>
283                                </instr>
284                                <instr>
285                                        <type>throw</type>
286                                        <operand>
287                                                <ex>
288                                                        <id>ISOcat[BAD REQUEST]</id>
289                                                        <message>The new group is invalid.</message>
290                                                </ex>
291                                        </operand>
292                                </instr>
293                        </else>
294                </if>
295        </idoc>
296        <exception>
297                <debug/>
298                <trace>ffcpl:/trace/group_new.exception.xml</trace>
299                <throw/>
300        </exception>
301        <response>
302                <mime>application/xml</mime>
303                <expire>now</expire>
304        </response>
305</accessor>
Note: See TracBrowser for help on using the repository browser.