source: cats/ISOcat/trunk/mod-ISOcat-manage-system/manage/import.acc @ 3515

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

M various/import/csv2dcif.xsl

  • understand some more colums

-- definition-source
-- access-date

M mod-ISOcat-access-data/access/dc_touch.acc
M mod-ISOcat-access-data/access/dc_hug.acc

  • if dir is not specified the default is down, unless the DC is a simple one then hug both up (super simple DCs and closed DCs) and down (sub simple DCs)

M mod-ISOcat-manage-system/manage/import.acc

  • turn a user login into an id
File size: 33.9 KB
Line 
1<accessor debug="false" trace="false" deadlock="true">
2        <name>/isocat/manage/import</name>
3        <descr>Import a DCIF document into the registry</descr>
4        <param mandatory="true">
5                <name>action</name>
6                <descr>what should we do?</descr>
7                <type canonical="true">string</type>
8                <source>
9                        <param/>
10                        <nvp/>
11                        <default>
12                                <string>refresh</string>
13                        </default>
14                </source>
15        </param>
16        <param>
17                <name>id</name>
18                <descr>import id</descr>
19                <type canonical="true">string</type>
20                <source>
21                        <nvp/>
22                        <default>
23                                <string/>
24                        </default>
25                </source>
26        </param>
27        <param>
28                <name>dcif</name>
29                <descr>DCIF document to import</descr>
30                <source>
31                        <param/>
32                        <default>
33                                <null/>
34                        </default>
35                </source>
36        </param>
37        <param>
38                <name>owner</name>
39                <descr>user id</descr>
40                <type canonical="true">string</type>
41                <source>
42                        <nvp/>
43                        <default>
44                                <string/>
45                        </default>
46                </source>
47        </param>
48        <param>
49                <name>external</name>
50                <descr>external DCs</descr>
51                <type canonical="true">string</type>
52                <source>
53                        <nvp/>
54                        <default>
55                                <string>false</string>
56                        </default>
57                </source>
58        </param>
59        <params/>
60        <idoc>
61                <accessor-debug>
62                        <instr>
63                                <type>log</type>
64                                <operand>var:params</operand>
65                        </instr>
66                </accessor-debug>
67                <if>
68                        <cond>
69                                <instr>
70                                        <type>sloot.xpath2eval</type>
71                                        <operand>var:action</operand>
72                                        <operator>
73                                                <xpath>(normalize-space(.)='') or (normalize-space(.)='init')</xpath>
74                                        </operator>
75                                        <target>this:cond</target>
76                                </instr>
77                        </cond>
78                        <then>
79                                <!-- create an import id -->
80                                <instr>
81                                        <type>xslt2</type>
82                                        <operand>
83                                                <null/>
84                                        </operand>
85                                        <operator>
86                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
87                                                        <xsl:template match="/">
88                                                                <string>
89                                                                        <xsl:value-of select="format-dateTime(current-dateTime(),'[Y][M01][D01][H01][m01][s01][f01]')"/>
90                                                                </string>
91                                                        </xsl:template>
92                                                </xsl:stylesheet>
93                                        </operator>
94                                        <target>var:id</target>
95                                </instr>
96                                <accessor-debug>
97                                        <instr>
98                                                <type>sloot.log</type>
99                                                <operand>var:id</operand>
100                                        </instr>
101                                </accessor-debug>
102                                <!-- create a DCIF import directory -->
103                                <instr>
104                                        <type>xslt2</type>
105                                        <operand>var:id</operand>
106                                        <operator>
107                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
108                                                        <xsl:template match="/">
109                                                                <uri>
110                                                                        <xsl:text>ffcpl:/import/</xsl:text>
111                                                                        <xsl:value-of select="."/>
112                                                                        <xsl:text>/</xsl:text>
113                                                                </uri>
114                                                        </xsl:template>
115                                                </xsl:stylesheet>
116                                        </operator>
117                                        <target>var:dir</target>
118                                </instr>
119                                <accessor-debug>
120                                        <instr>
121                                                <type>sloot.log</type>
122                                                <operand>var:dir</operand>
123                                        </instr>
124                                </accessor-debug>
125                                <!-- put the DCIF document in the import directory -->
126                                <instr>
127                                        <type>resolveURI</type>
128                                        <operand>
129                                                <uri>dcif.xml</uri>
130                                        </operand>
131                                        <operator>var:dir</operator>
132                                        <target>var:loc</target>
133                                </instr>
134                                <instr>
135                                        <type>copy</type>
136                                        <operand>var:dcif</operand>
137                                        <target>curi:var:loc</target>
138                                </instr>
139                                <!-- lookup the owner id -->
140                                <instr>
141                                        <type>ISOcat.access.data.user.id</type>
142                                        <user>var:owner</user>
143                                        <target>var:owner</target>
144                                </instr>
145                                <instr>
146                                        <type>sloot.xquery</type>
147                                        <operator>
148                                                <sql>
149                                                        SELECT
150                                                                view_owner.id,
151                                                                name,
152                                                                login,
153                                                                CASE
154                                                                        WHEN (login IS NULL)
155                                                                        THEN 'TDG'
156                                                                        ELSE 'user'
157                                                                END AS type
158                                                        FROM
159                                                                view_owner
160                                                        LEFT JOIN
161                                                                core_user
162                                                        ON
163                                                                view_owner.id = core_user.id
164                                                        WHERE
165                                                                view_owner.id = {string($owner)}
166                                                ;
167                                                </sql>
168                                        </operator>
169                                        <owner>var:owner</owner>
170                                        <target>var:sql</target>
171                                </instr>
172                                <instr>
173                                        <type>ISOcat.access.data.query</type>
174                                        <query>var:sql</query>
175                                        <target>var:owner</target>
176                                </instr>
177                                <!-- create an initial status document -->
178                                <instr>
179                                        <type>sloot.xquery</type>
180                                        <operator>
181                                                <xquery>
182                                                        declare variable $id as node() external;
183                                                        declare variable $params as node() external;
184                                                        declare variable $owner as node() external;
185                                                        &lt;import id="{string($id)}">
186                                                                &lt;config>
187                                                                        {$params}
188                                                                &lt;/config>
189                                                                &lt;owner>
190                                                                        {$owner}
191                                                                &lt;/owner>
192                                                                &lt;valid/>
193                                                                &lt;check/>
194                                                                &lt;result/>
195                                                        &lt;/import>
196                                                </xquery>
197                                        </operator>
198                                        <params>var:params</params>
199                                        <owner>var:owner</owner>
200                                        <id>var:id</id>
201                                        <target>var:status</target>
202                                </instr>
203                                <instr>
204                                        <type>resolveURI</type>
205                                        <operand>
206                                                <uri>status.xml</uri>
207                                        </operand>
208                                        <operator>var:dir</operator>
209                                        <target>var:loc</target>
210                                </instr>
211                                <instr>
212                                        <type>copy</type>
213                                        <operand>var:status</operand>
214                                        <target>curi:var:loc</target>
215                                </instr>
216                        </then>
217                        <else>
218                                <!-- determine the import directory -->
219                                <instr>
220                                        <type>xslt2</type>
221                                        <operand>var:id</operand>
222                                        <operator>
223                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
224                                                        <xsl:template match="/">
225                                                                <uri>
226                                                                        <xsl:text>ffcpl:/import/</xsl:text>
227                                                                        <xsl:value-of select="."/>
228                                                                        <xsl:text>/</xsl:text>
229                                                                </uri>
230                                                        </xsl:template>
231                                                </xsl:stylesheet>
232                                        </operator>
233                                        <target>var:dir</target>
234                                </instr>
235                                <!-- load the status -->
236                                <instr>
237                                        <type>resolveURI</type>
238                                        <operand>
239                                                <uri>status.xml</uri>
240                                        </operand>
241                                        <operator>var:dir</operator>
242                                        <target>var:loc</target>
243                                </instr>
244                                <instr>
245                                        <type>copy</type>
246                                        <operand>curi:var:loc</operand>
247                                        <target>var:status</target>
248                                </instr>
249                        </else>
250                </if>
251                <!-- execute the requested action -->
252                <choose>
253                        <cond>
254                                <instr>
255                                        <type>sloot.xpath2eval</type>
256                                        <operand>var:action</operand>
257                                        <operator>
258                                                <xpath>.='validate'</xpath>
259                                        </operator>
260                                        <target>this:cond</target>
261                                </instr>
262                        </cond>
263                        <then>
264                                <!-- validate the DCIF -->
265                                <instr>
266                                        <type>resolveURI</type>
267                                        <operand>
268                                                <uri>dcif.xml</uri>
269                                        </operand>
270                                        <operator>var:dir</operator>
271                                        <target>var:loc</target>
272                                </instr>
273                                <instr>
274                                        <type>validateRNG</type>
275                                        <operand>curi:var:loc</operand>
276                                        <operator>active:ISOcat.access.data.dcif.schema</operator>
277                                        <target>var:valid</target>
278                                </instr>
279                                <!-- dump the validation result -->
280                                <instr>
281                                        <type>resolveURI</type>
282                                        <operand>
283                                                <uri>validation.xml</uri>
284                                        </operand>
285                                        <operator>var:dir</operator>
286                                        <target>var:loc</target>
287                                </instr>
288                                <instr>
289                                        <type>copy</type>
290                                        <operand>var:valid</operand>
291                                        <target>curi:var:loc</target>
292                                </instr>
293                                <!-- update the validation status -->
294                                <instr>
295                                        <type>xslt2</type>
296                                        <operand>var:status</operand>
297                                        <operator>
298                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
299                                                        <xsl:param name="valid"/>
300                                                        <xsl:template match="@*|node()">
301                                                                <xsl:copy>
302                                                                        <xsl:apply-templates select="@*|node()"/>
303                                                                </xsl:copy>
304                                                        </xsl:template>
305                                                        <xsl:template match="valid">
306                                                                <xsl:copy>
307                                                                        <xsl:copy-of select="$valid"/>
308                                                                </xsl:copy>
309                                                        </xsl:template>
310                                                </xsl:stylesheet>
311                                        </operator>
312                                        <valid>var:valid</valid>
313                                        <target>var:status</target>
314                                </instr>
315                                <instr>
316                                        <type>resolveURI</type>
317                                        <operand>
318                                                <uri>status.xml</uri>
319                                        </operand>
320                                        <operator>var:dir</operator>
321                                        <target>var:loc</target>
322                                </instr>
323                                <instr>
324                                        <type>copy</type>
325                                        <operand>var:status</operand>
326                                        <target>curi:var:loc</target>
327                                </instr>
328                        </then>
329                        <cond>
330                                <instr>
331                                        <type>sloot.xpath2eval</type>
332                                        <operand>var:action</operand>
333                                        <operator>
334                                                <xpath>.='check'</xpath>
335                                        </operator>
336                                        <target>this:cond</target>
337                                </instr>
338                        </cond>
339                        <then>
340                                <!-- check the DCIF -->
341                                <instr>
342                                        <type>resolveURI</type>
343                                        <operand>
344                                                <uri>dcif.xml</uri>
345                                        </operand>
346                                        <operator>var:dir</operator>
347                                        <target>var:loc</target>
348                                </instr>
349                                <!-- lookup the PID's and collect them in a DCS -->
350                                <instr>
351                                        <type>xslt2</type>
352                                        <operand>curi:var:loc</operand>
353                                        <operator>
354                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
355                                                        xmlns:dcif="http://www.isocat.org/ns/dcif"
356                                                        exclude-result-prefixes="dcif"
357                                                >
358                                                        <xsl:template match="text()"/>
359                                                        <xsl:template match="/dcif:dataCategorySelection">
360                                                                <script>
361                                                                        <batch>
362                                                                                <sql>CREATE TEMPORARY TABLE DCIFimport (pid character varying,tpe character varying,action character varying) ON COMMIT DROP;</sql>
363                                                                                <xsl:apply-templates/>
364                                                                        </batch>
365                                                                        <sql>
366                                                                                SELECT
367                                                                                        CASE
368                                                                                          WHEN id IS NULL
369                                                                                          THEN nextval('core_data_category_id_seq'::regclass)
370                                                                                          ELSE id
371                                                                                        END AS id,
372                                                                                        DCIFimport.pid,
373                                                                                        DCIFimport.tpe,
374                                                                                        CASE
375                                                                                                WHEN action IS NOT NULL
376                                                                                                THEN action
377                                                                                                WHEN id IS NULL
378                                                                                                THEN 'create'
379                                                                                                --WHEN view_data_category.private
380                                                                                                --THEN 'update'
381                                                                                                --ELSE 'revision'
382                                                                                                ELSE 'update'
383                                                                                        END AS action
384                                                                                FROM
385                                                                                        DCIFimport
386                                                                                LEFT JOIN
387                                                                                        view_data_category
388                                                                                ON
389                                                                                        view_data_category.pid = DCIFimport.pid
390                                                                                ORDER BY tpe DESC
391                                                                                ;
392                                                                        </sql>
393                                                                </script>
394                                                        </xsl:template>
395                                                        <xsl:template match="dcif:dataCategory[exists(*)]">
396                                                                <sql>
397                                                                        <xsl:text>INSERT INTO DCIFimport (pid,tpe) VALUES ('</xsl:text>
398                                                                        <xsl:value-of select="replace(@pid,'''','''''')"/>
399                                                                        <xsl:text>','</xsl:text>
400                                                                        <xsl:value-of select="@type"/>
401                                                                        <xsl:text>');</xsl:text>
402                                                                </sql>
403                                                        </xsl:template>
404                                                        <xsl:template match="dcif:dataCategory[empty(*)]">
405                                                                <sql>
406                                                                        <xsl:text>INSERT INTO DCIFimport (pid,tpe,action) VALUES ('</xsl:text>
407                                                                        <xsl:value-of select="replace(@pid,'''','''''')"/>
408                                                                        <xsl:text>','</xsl:text>
409                                                                        <xsl:value-of select="@type"/>
410                                                                        <xsl:text>','select');</xsl:text>
411                                                                </sql>
412                                                        </xsl:template>
413                                                </xsl:stylesheet>
414                                        </operator>
415                                        <target>var:sql</target>
416                                </instr>
417                                <accessor-debug>
418                                        <instr>
419                                                <type>copy</type>
420                                                <operand>var:sql</operand>
421                                                <target>ffcpl:/trace/DCIFimport.sql.xml</target>
422                                        </instr>
423                                </accessor-debug>
424                                <instr>
425                                        <type>ISOcat.access.data.query</type>
426                                        <query>var:sql</query>
427                                        <target>var:check</target>
428                                </instr>
429                                <!-- annotate the dcif with the ids -->
430                                <instr>
431                                        <type>xslt2</type>
432                                        <operand>curi:var:loc</operand>
433                                        <operator>
434                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
435                                                        xmlns:dcif="http://www.isocat.org/ns/dcif"
436                                                        xmlns:isocat="http://www.isocat.org/"
437                                                >
438                                                        <xsl:param name="check"/>
439                                                        <xsl:template match="@*|node()">
440                                                                <xsl:copy>
441                                                                        <xsl:apply-templates select="@*|node()"/>
442                                                                </xsl:copy>
443                                                        </xsl:template>
444                                                        <xsl:template match="dcif:*[exists(self::dcif:isA|self::dcif:value)][exists(@pid)]" priority="1">
445                                                                <xsl:copy>
446                                                                        <xsl:apply-templates select="@*"/>
447                                                                        <xsl:variable name="row" select="$check//row[pid=current()/@pid]"/>
448                                                                        <xsl:choose>
449                                                                                <xsl:when test="exists($row)">
450                                                                                        <xsl:attribute name="isocat:id" select="$row/id"/>
451                                                                                </xsl:when>
452                                                                                <xsl:otherwise>
453                                                                                        <xsl:variable name="uri" select="concat('active:ISOcat.access.data.dc.pid2id+pid@data:text/plain,',encode-for-uri(current()/@pid))"/>
454                                                                                        <!--<xsl:message>NK URI[<xsl:value-of select="$uri"/>]</xsl:message>-->
455                                                                                        <xsl:variable name="id" select="doc($uri)"/>
456                                                                                        <xsl:choose>
457                                                                                                <xsl:when test="normalize-space($id)!=''">
458                                                                                                        <xsl:attribute name="isocat:id" select="normalize-space($id)"/>
459                                                                                                </xsl:when>
460                                                                                                <xsl:otherwise>
461                                                                                                        <xsl:message>ERR: unresolvable PID[<xsl:value-of select="current()/@pid"/>]!</xsl:message>
462                                                                                                </xsl:otherwise>
463                                                                                        </xsl:choose>
464                                                                                </xsl:otherwise>
465                                                                        </xsl:choose>
466                                                                        <xsl:apply-templates select="node()"/>
467                                                                </xsl:copy>
468                                                        </xsl:template>
469                                                </xsl:stylesheet>
470                                        </operator>
471                                        <check>var:check</check>
472                                        <target>curi:var:loc</target>
473                                </instr>
474                                <!-- add the is-a info to the check result  -->
475                                <instr>
476                                        <type>xslt2</type>
477                                        <operand>var:check</operand>
478                                        <operator>
479                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
480                                                        xmlns:dcif="http://www.isocat.org/ns/dcif"
481                                                        xmlns:isocat="http://www.isocat.org/"
482                                                        exclude-result-prefixes="dcif isocat"
483                                                >
484                                                        <xsl:param name="dcif"/>
485                                                        <xsl:template match="@*|node()">
486                                                                <xsl:copy>
487                                                                        <xsl:apply-templates select="@*|node()"/>
488                                                                </xsl:copy>
489                                                        </xsl:template>
490                                                        <xsl:template match="row[tpe='simple']" priority="1">
491                                                                <xsl:copy>
492                                                                        <xsl:apply-templates select="@*"/>
493                                                                        <xsl:variable name="dc" select="$dcif//dcif:dataCategory[@pid=current()/pid]"/>
494                                                                        <xsl:if test="exists($dc/dcif:isA/@isocat:id)">
495                                                                                <isa>
496                                                                                        <xsl:value-of select="$dc/dcif:isA/@isocat:id"/>
497                                                                                </isa>
498                                                                        </xsl:if>
499                                                                        <xsl:apply-templates select="node()"/>
500                                                                </xsl:copy>
501                                                        </xsl:template>
502                                                </xsl:stylesheet>
503                                        </operator>
504                                        <dcif>curi:var:loc</dcif>
505                                        <target>var:check</target>
506                                </instr>
507                                <!-- sort the check result -->
508                                <instr>
509                                        <type>xslt2</type>
510                                        <operand>var:check</operand>
511                                        <operator>
512                                                <xsl:stylesheet
513                                                        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
514                                                        xmlns:isocat="http://www.isocat.org/"
515                                                >
516                                                        <xsl:variable name="rows" select="//row"/>
517                                                        <xsl:template match="@*|node()">
518                                                                <xsl:copy>
519                                                                        <xsl:apply-templates select="@*|node()"/>
520                                                                </xsl:copy>
521                                                        </xsl:template>
522                                                        <xsl:function name="isocat:path">
523                                                                <xsl:param name="row"/>
524                                                                <xsl:choose>
525                                                                        <xsl:when test="exists($row/isa)">
526                                                                                <xsl:variable name="isa" select="$rows[id=$row/isa]"/>
527                                                                                <xsl:sequence select="concat(isocat:path($isa),'/',$row/id)"/>
528                                                                        </xsl:when>
529                                                                        <xsl:otherwise>
530                                                                                <xsl:sequence select="concat('/',$row/id)"/>
531                                                                        </xsl:otherwise>
532                                                                </xsl:choose>
533                                                        </xsl:function>
534                                                        <xsl:template match="results" priority="1">
535                                                                <xsl:copy>
536                                                                        <xsl:apply-templates select="row[tpe='simple']">
537                                                                                <xsl:sort select="isocat:path(.)"/>
538                                                                        </xsl:apply-templates>
539                                                                        <xsl:apply-templates select="row[tpe!='simple']"/>
540                                                                </xsl:copy>
541                                                        </xsl:template>
542                                                </xsl:stylesheet>
543                                        </operator>
544                                        <target>var:check</target>
545                                </instr>
546                                <!-- dump the check result -->
547                                <instr>
548                                        <type>resolveURI</type>
549                                        <operand>
550                                                <uri>check.xml</uri>
551                                        </operand>
552                                        <operator>var:dir</operator>
553                                        <target>var:loc</target>
554                                </instr>
555                                <instr>
556                                        <type>copy</type>
557                                        <operand>var:check</operand>
558                                        <target>curi:var:loc</target>
559                                </instr>
560                                <!-- update the check status -->
561                                <instr>
562                                        <type>xslt2</type>
563                                        <operand>var:status</operand>
564                                        <operator>
565                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
566                                                        <xsl:param name="check"/>
567                                                        <xsl:template match="@*|node()">
568                                                                <xsl:copy>
569                                                                        <xsl:apply-templates select="@*|node()"/>
570                                                                </xsl:copy>
571                                                        </xsl:template>
572                                                        <xsl:template match="check">
573                                                                <xsl:copy>
574                                                                        <xsl:copy-of select="$check"/>
575                                                                </xsl:copy>
576                                                        </xsl:template>
577                                                </xsl:stylesheet>
578                                        </operator>
579                                        <check>var:check</check>
580                                        <target>var:status</target>
581                                </instr>
582                                <instr>
583                                        <type>resolveURI</type>
584                                        <operand>
585                                                <uri>status.xml</uri>
586                                        </operand>
587                                        <operator>var:dir</operator>
588                                        <target>var:loc</target>
589                                </instr>
590                                <instr>
591                                        <type>copy</type>
592                                        <operand>var:status</operand>
593                                        <target>curi:var:loc</target>
594                                </instr>
595                        </then>
596                        <cond>
597                                <instr>
598                                        <type>sloot.xpath2eval</type>
599                                        <operand>var:action</operand>
600                                        <operator>
601                                                <xpath>.='disable' or .='disable-all' or .='enable-all'</xpath>
602                                        </operator>
603                                        <target>this:cond</target>
604                                </instr>
605                        </cond>
606                        <then>
607                                <!-- en/disable import actions -->
608                                <instr>
609                                        <type>xslt2</type>
610                                        <operand>var:status</operand>
611                                        <operator>
612                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
613                                                        <xsl:param name="action"/>
614                                                        <xsl:param name="actions"/>
615                                                        <xsl:template match="@*|node()">
616                                                                <xsl:copy>
617                                                                        <xsl:apply-templates select="@*|node()"/>
618                                                                </xsl:copy>
619                                                        </xsl:template>
620                                                        <xsl:template match="enabled"/>
621                                                        <xsl:template match="check//row">
622                                                                <xsl:copy>
623                                                                        <xsl:apply-templates select="@*|node()"/>
624                                                                        <xsl:variable name="row" select="count(preceding::row) + 1"/>
625                                                                        <xsl:choose>
626                                                                                <xsl:when test="$action='enable-all'">
627                                                                                        <enabled>true</enabled>
628                                                                                </xsl:when>
629                                                                                <xsl:when test="$action='disable-all'">
630                                                                                        <enabled>false</enabled>
631                                                                                </xsl:when>
632                                                                                <xsl:when test="exists($actions//*[name()=concat('enabled-row-',$row)])">
633                                                                                        <enabled>true</enabled>
634                                                                                </xsl:when>
635                                                                                <xsl:otherwise>
636                                                                                        <enabled>false</enabled>
637                                                                                </xsl:otherwise>
638                                                                        </xsl:choose>
639                                                                </xsl:copy>
640                                                        </xsl:template>
641                                                </xsl:stylesheet>
642                                        </operator>
643                                        <action>var:action</action>
644                                        <actions>var:params</actions>
645                                        <target>var:status</target>
646                                </instr>
647                                <instr>
648                                        <type>resolveURI</type>
649                                        <operand>
650                                                <uri>status.xml</uri>
651                                        </operand>
652                                        <operator>var:dir</operator>
653                                        <target>var:loc</target>
654                                </instr>
655                                <instr>
656                                        <type>copy</type>
657                                        <operand>var:status</operand>
658                                        <target>curi:var:loc</target>
659                                </instr>
660                        </then>
661                        <cond>
662                                <instr>
663                                        <type>sloot.xpath2eval</type>
664                                        <operand>var:action</operand>
665                                        <operator>
666                                                <xpath>.='backup'</xpath>
667                                        </operator>
668                                        <target>this:cond</target>
669                                </instr>
670                        </cond>
671                        <then>
672                                <!-- backup existing DCs to DCIF -->
673                                <instr>
674                                        <type>xslt2</type>
675                                        <operand>var:status</operand>
676                                        <operator>
677                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
678                                                        xmlns:dcif="http://www.isocat.org/ns/dcif"
679                                                        exclude-result-prefixes="dcif"
680                                                >
681                                                        <xsl:template match="text()"/>
682                                                        <xsl:template match="/import">
683                                                                <dcs type="dcs" key="import-{@id}">
684                                                                        <xsl:apply-templates select="check//row"/>
685                                                                </dcs>
686                                                        </xsl:template>
687                                                        <xsl:template match="row[normalize-space(id)!=''][action='update' or action='revision'][empty(enabled) or enabled='true']">
688                                                                <dc ref="{id}"/>
689                                                        </xsl:template>
690                                                </xsl:stylesheet>
691                                        </operator>
692                                        <target>var:dcs</target>
693                                </instr>
694                                <accessor-debug>
695                                        <instr>
696                                                <type>log</type>
697                                                <operand>var:dcs</operand>
698                                        </instr>
699                                </accessor-debug>
700                                <instr>
701                                        <type>ISOcat.access.data.dcs.to.dcif</type>
702                                        <dcs>var:dcs</dcs>
703                                        <target>var:backup</target>
704                                </instr>
705                                <!-- put the backup DCIF document in the import directory -->
706                                <instr>
707                                        <type>resolveURI</type>
708                                        <operand>
709                                                <uri>backup.xml</uri>
710                                        </operand>
711                                        <operator>var:dir</operator>
712                                        <target>var:loc</target>
713                                </instr>
714                                <instr>
715                                        <type>copy</type>
716                                        <operand>var:backup</operand>
717                                        <target>curi:var:loc</target>
718                                </instr>
719                        </then>
720                        <cond>
721                                <instr>
722                                        <type>sloot.xpath2eval</type>
723                                        <operand>var:action</operand>
724                                        <operator>
725                                                <xpath>.='import'</xpath>
726                                        </operator>
727                                        <target>this:cond</target>
728                                </instr>
729                        </cond>
730                        <then>
731                                <!-- the actual import -->
732                                <instr>
733                                        <type>resolveURI</type>
734                                        <operand>
735                                                <uri>dcif.xml</uri>
736                                        </operand>
737                                        <operator>var:dir</operator>
738                                        <target>var:loc</target>
739                                </instr>
740                                <instr>
741                                        <type>copy</type>
742                                        <operand>curi:var:loc</operand>
743                                        <target>var:dcif</target>
744                                </instr>
745                                <!-- loop over the enabled rows: -->
746                                <while>
747                                        <cond>
748                                                <instr>
749                                                        <type>sloot.xpath2eval</type>
750                                                        <operand>var:status</operand>
751                                                        <operator>
752                                                                <xpath>exists(//check//row[empty(enabled) or enabled='true'][empty(imported) or imported='false'][action!='select'])</xpath>
753                                                        </operator>
754                                                        <target>this:cond</target>
755                                                </instr>
756                                        </cond>
757                                        <seq>
758                                                <!-- spin of a batch import -->
759                                                <accessor-trace name="batch">
760                                                        <instr>
761                                                                <type>ISOcat.manage.system.import.batch</type>
762                                                                <id>var:id</id>
763                                                                <target>var:void</target>
764                                                        </instr>
765                                                </accessor-trace>
766                                                <!-- reload the status document -->
767                                                <instr>
768                                                        <type>resolveURI</type>
769                                                        <operand>
770                                                                <uri>status.xml</uri>
771                                                        </operand>
772                                                        <operator>var:dir</operator>
773                                                        <target>var:loc</target>
774                                                </instr>
775                                                <instr>
776                                                        <type>copy</type>
777                                                        <operand>curi:var:loc</operand>
778                                                        <target>var:status</target>
779                                                </instr>
780                                        </seq>
781                                </while>
782                                <!-- need a DPML statement here, otherwise DPML bails out and NK gets a void response -->
783                                <instr>
784                                        <type>sloot.log</type>
785                                        <operand>
786                                                <msg>INF: finished import loop</msg>
787                                        </operand>
788                                </instr>
789                        </then>
790                        <cond>
791                                <instr>
792                                        <type>sloot.xpath2eval</type>
793                                        <operand>var:action</operand>
794                                        <operator>
795                                                <xpath>.='dcs'</xpath>
796                                        </operator>
797                                        <target>this:cond</target>
798                                </instr>
799                        </cond>
800                        <then>
801                                <!-- create a DCS with the result of the import -->
802                                <instr>
803                                        <type>sloot.xquery</type>
804                                        <operator>
805                                                <xquery>
806                                                        declare variable $status as node() external;
807                                                       
808                                                        &lt;dcs owner="{string($status//owner//login)}" name="{$status/import/@id} DCIF import">
809                                                        {
810                                                        for $row in $status//check//row[imported='true' or (action='select' and (empty(enabled) or enabled='true'))]
811                                                                return
812                                                                        &lt;dc ref="{string($row/id)}" type="{string($row/tpe)}"/>
813                                                        }
814                                                        &lt;/dcs>
815                                                </xquery>
816                                        </operator>
817                                        <status>var:status</status>
818                                        <target>var:dcs</target>
819                                </instr>
820                                <!--<accessor-debug>-->
821                                        <instr>
822                                                <type>log</type>
823                                                <operand>var:dcs</operand>
824                                        </instr>
825                                <!--</accessor-debug>-->
826                                <instr>
827                                        <type>ISOcat.access.data.dcs.new</type>
828                                        <dcs>var:dcs</dcs>
829                                        <target>var:dcs</target>
830                                </instr>
831                                <!-- update status -->
832                                <instr>
833                                        <type>xslt2</type>
834                                        <operand>var:status</operand>
835                                        <operator>
836                                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
837                                                        <xsl:param name="actions"/>
838                                                        <xsl:template match="@*|node()">
839                                                                <xsl:copy>
840                                                                        <xsl:apply-templates select="@*|node()"/>
841                                                                </xsl:copy>
842                                                        </xsl:template>
843                                                        <xsl:template match="/import">
844                                                                <xsl:copy>
845                                                                        <xsl:apply-templates select="@*"/>
846                                                                        <xsl:attribute name="dcs" select="concat(@id,' DCIF import')"/>
847                                                                        <xsl:apply-templates select="node()"/>
848                                                                </xsl:copy>
849                                                        </xsl:template>
850                                                </xsl:stylesheet>
851                                        </operator>
852                                        <actions>var:params</actions>
853                                        <target>var:status</target>
854                                </instr>
855                                <instr>
856                                        <type>resolveURI</type>
857                                        <operand>
858                                                <uri>status.xml</uri>
859                                        </operand>
860                                        <operator>var:dir</operator>
861                                        <target>var:loc</target>
862                                </instr>
863                                <instr>
864                                        <type>copy</type>
865                                        <operand>var:status</operand>
866                                        <target>curi:var:loc</target>
867                                </instr>
868                        </then>
869                </choose>
870                <!-- create an output document based on the curent status -->
871                <instr>
872                        <type>xslt2</type>
873                        <operand>var:status</operand>
874                        <operator>
875                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
876                                        <xsl:template match="/import">
877                                                <xsl:variable name="owned" select="exists(owner//id)"/>
878                                                <xsl:variable name="valid" select="valid/b/(text())[1]='t'"/>
879                                                <xsl:variable name="checked" select="exists(check/*)"/>
880                                                <xsl:variable name="import" select="exists(check//row[enabled!='false' and imported!='true'])"/>
881                                                <xsl:variable name="imported" select="exists(check//row[imported='true'])"/>
882                                                <html>
883                                                        <head>
884                                                                <title>ISOcat DCIF import</title>
885                                                        </head>
886                                                        <body>
887                                                                <form action="/isocat/manage/import" method="post">
888                                                                        <input type="hidden" name="id" value="{@id}"/>
889                                                                        <table>
890                                                                                <tr>
891                                                                                        <th colspan="3" align="left">
892                                                                                                <xsl:text>DCIF import: </xsl:text>
893                                                                                                <a href="import?action=refresh&amp;id={@id}">
894                                                                                                        <xsl:value-of select="@id"/>
895                                                                                                </a>
896                                                                                        </th>
897                                                                                </tr>
898                                                                                <tr>
899                                                                                        <td colspan="3">
900                                                                                                <hr/>
901                                                                                        </td>
902                                                                                </tr>
903                                                                                <tr>
904                                                                                        <td valign="top">Owner: </td>
905                                                                                        <td valign="top">
906                                                                                                <xsl:choose>
907                                                                                                        <xsl:when test="$owned">
908                                                                                                                <xsl:value-of select="owner//type"/>
909                                                                                                                <xsl:text>: </xsl:text>
910                                                                                                                <xsl:value-of select="owner//name"/>
911                                                                                                                <xsl:if test="exists(owner//login)">
912                                                                                                                        <xsl:text> (</xsl:text>
913                                                                                                                        <xsl:value-of select="owner//login"/>
914                                                                                                                        <xsl:text>)</xsl:text>
915                                                                                                                </xsl:if>
916                                                                                                                <xsl:text> [</xsl:text>
917                                                                                                                <xsl:value-of select="owner//id"/>
918                                                                                                                <xsl:text>]</xsl:text>
919                                                                                                        </xsl:when>
920                                                                                                        <xsl:otherwise>
921                                                                                                                <b>unknown</b>
922                                                                                                        </xsl:otherwise>
923                                                                                                </xsl:choose>
924                                                                                        </td>
925                                                                                        <td/>
926                                                                                </tr>
927                                                                                <tr>
928                                                                                        <td valign="top">Document: </td>
929                                                                                        <td valign="top">
930                                                                                                <xsl:value-of select="config/nvp/dcif"/>
931                                                                                        </td>
932                                                                                        <td/>
933                                                                                </tr>
934                                                                                <tr>
935                                                                                        <td valign="top">External: </td>
936                                                                                        <td valign="top">
937                                                                                                <xsl:choose>
938                                                                                                        <xsl:when test="config/nvp/external='true'">
939                                                                                                                <xsl:text>external PIDs are kept</xsl:text>
940                                                                                                        </xsl:when>
941                                                                                                        <xsl:otherwise>
942                                                                                                                <xsl:text>external PIDs are replaced by ISOcat PIDs</xsl:text>
943                                                                                                        </xsl:otherwise>
944                                                                                                </xsl:choose>
945                                                                                        </td>
946                                                                                        <td/>
947                                                                                </tr>
948                                                                                <tr>
949                                                                                        <td valign="top">Validate </td>
950                                                                                        <td valign="top">
951                                                                                                <xsl:choose>
952                                                                                                        <xsl:when test="$valid">
953                                                                                                                <xsl:text>valid</xsl:text>
954                                                                                                        </xsl:when>
955                                                                                                        <xsl:when test="valid/b/(text())[1]='f'">
956                                                                                                                <b>invalid</b>
957                                                                                                                <!-- show warnings/errors -->
958                                                                                                                <div>
959                                                                                                                        <xsl:if test="exists(valid/b/warnings/warning)">
960                                                                                                                                Warnings:
961                                                                                                                                <ol>
962                                                                                                                                        <xsl:for-each select="valid/b/warnings/warning">
963                                                                                                                                                <li>
964                                                                                                                                                        <xsl:value-of select="."/>
965                                                                                                                                                        <br/>
966                                                                                                                                                        <xsl:text>(</xsl:text>
967                                                                                                                                                        <xsl:value-of select="@xpath"/>
968                                                                                                                                                        <xsl:text>)</xsl:text>
969                                                                                                                                                </li>   
970                                                                                                                                        </xsl:for-each>
971                                                                                                                                </ol>
972                                                                                                                        </xsl:if>
973                                                                                                                        <xsl:if test="exists(valid/b/errors/error)">
974                                                                                                                                Errors:
975                                                                                                                                <ol>
976                                                                                                                                        <xsl:for-each select="valid/b/errors/error">
977                                                                                                                                                <li>
978                                                                                                                                                        <xsl:value-of select="."/>
979                                                                                                                                                        <br/>
980                                                                                                                                                        <xsl:text>(</xsl:text>
981                                                                                                                                                        <xsl:value-of select="@xpath"/>
982                                                                                                                                                        <xsl:text>)</xsl:text>
983                                                                                                                                                </li>   
984                                                                                                                                        </xsl:for-each>
985                                                                                                                                </ol>
986                                                                                                                        </xsl:if>
987                                                                                                                </div>
988                                                                                                        </xsl:when>
989                                                                                                        <xsl:otherwise>
990                                                                                                                <xsl:text>unknown</xsl:text>
991                                                                                                        </xsl:otherwise>
992                                                                                                </xsl:choose>
993                                                                                        </td>
994                                                                                        <td valign="top">
995                                                                                                <button type="submit" name="action" value="validate">validate DCIF</button>
996                                                                                        </td>
997                                                                                </tr>
998                                                                                <tr>
999                                                                                        <td valign="top">Check </td>
1000                                                                                        <td>
1001                                                                                                <xsl:choose>
1002                                                                                                        <xsl:when test="$checked">
1003                                                                                                                <xsl:text>Actions:</xsl:text>
1004                                                                                                                <ul>
1005                                                                                                                        <xsl:for-each-group select="check//row" group-by="action">
1006                                                                                                                                <li>
1007                                                                                                                                        <xsl:value-of select="count(current-group())"/>
1008                                                                                                                                        <xsl:text> </xsl:text>
1009                                                                                                                                        <xsl:value-of select="current-grouping-key()"/>
1010                                                                                                                                        <xsl:text> actions</xsl:text>
1011                                                                                                                                </li>
1012                                                                                                                        </xsl:for-each-group>
1013                                                                                                                </ul>
1014                                                                                                        </xsl:when>
1015                                                                                                        <xsl:otherwise>
1016                                                                                                                <xsl:text>unchecked</xsl:text>
1017                                                                                                        </xsl:otherwise>
1018                                                                                                </xsl:choose>
1019                                                                                        </td>
1020                                                                                        <td valign="top">
1021                                                                                                <button type="submit" name="action" value="check">
1022                                                                                                        <xsl:if test="not($owned) or not($valid)">
1023                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1024                                                                                                        </xsl:if>
1025                                                                                                        <xsl:text>check actions</xsl:text>
1026                                                                                                </button>
1027                                                                                        </td>
1028                                                                                </tr>
1029                                                                                <tr>
1030                                                                                        <td valign="top">Disable</td>
1031                                                                                        <td>
1032                                                                                                <xsl:choose>
1033                                                                                                        <xsl:when test="$checked">
1034                                                                                                                <table border="1" rules="cols" frame="box">
1035                                                                                                                        <tr style="border-bottom:1px solid black;">
1036                                                                                                                                <th>id</th>
1037                                                                                                                                <th>DC PID</th>
1038                                                                                                                                <th>type</th>
1039                                                                                                                                <th>is-a</th>
1040                                                                                                                                <th>action</th>
1041                                                                                                                                <th>enabled</th>
1042                                                                                                                        </tr>
1043                                                                                                                        <xsl:for-each select="check//row">
1044                                                                                                                                <tr>
1045                                                                                                                                        <td align="left">
1046                                                                                                                                                <xsl:value-of select="id"/>
1047                                                                                                                                        </td>
1048                                                                                                                                        <td align="left">
1049                                                                                                                                                <a href="{pid}" target="other">
1050                                                                                                                                                        <xsl:value-of select="pid"/>
1051                                                                                                                                                </a>
1052                                                                                                                                        </td>
1053                                                                                                                                        <td align="left">
1054                                                                                                                                                <xsl:value-of select="tpe"/>
1055                                                                                                                                        </td>
1056                                                                                                                                        <td align="left">
1057                                                                                                                                                <xsl:value-of select="isa"/>
1058                                                                                                                                        </td>
1059                                                                                                                                        <td align="center">
1060                                                                                                                                                <xsl:value-of select="action"/>
1061                                                                                                                                        </td>
1062                                                                                                                                        <td align="center">
1063                                                                                                                                                <input type="checkbox" name="enabled-row-{count(preceding::row) + 1}" value="{count(preceding::row) + 1}">
1064                                                                                                                                                        <xsl:choose>
1065                                                                                                                                                                <xsl:when test="enabled='true'">
1066                                                                                                                                                                        <xsl:attribute name="checked" select="'checked'"/>
1067                                                                                                                                                                </xsl:when>
1068                                                                                                                                                                <xsl:when test="empty(enabled)">
1069                                                                                                                                                                        <xsl:attribute name="checked" select="'checked'"/>
1070                                                                                                                                                                </xsl:when>
1071                                                                                                                                                        </xsl:choose>
1072                                                                                                                                                        <xsl:if test="imported='true'">
1073                                                                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1074                                                                                                                                                        </xsl:if>
1075                                                                                                                                                </input>
1076                                                                                                                                        </td>
1077                                                                                                                                </tr>
1078                                                                                                                        </xsl:for-each>
1079                                                                                                                </table>
1080                                                                                                        </xsl:when>
1081                                                                                                        <xsl:otherwise>
1082                                                                                                                <xsl:text>unchecked</xsl:text>
1083                                                                                                        </xsl:otherwise>
1084                                                                                                </xsl:choose>
1085                                                                                        </td>
1086                                                                                        <td valign="top">
1087                                                                                                <button type="submit" name="action" value="disable">
1088                                                                                                        <xsl:if test="not($checked)">
1089                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1090                                                                                                        </xsl:if>
1091                                                                                                        <xsl:text>en/disable actions</xsl:text>
1092                                                                                                </button>
1093                                                                                                <br/>
1094                                                                                                <button type="submit" name="action" value="disable-all">
1095                                                                                                        <xsl:if test="not($checked)">
1096                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1097                                                                                                        </xsl:if>
1098                                                                                                        <xsl:text>disable all actions</xsl:text>
1099                                                                                                </button>
1100                                                                                                <br/>
1101                                                                                                <button type="submit" name="action" value="enable-all">
1102                                                                                                        <xsl:if test="not($checked)">
1103                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1104                                                                                                        </xsl:if>
1105                                                                                                        <xsl:text>enable all actions</xsl:text>
1106                                                                                                </button>
1107                                                                                        </td>
1108                                                                                </tr>
1109                                                                                <tr>
1110                                                                                        <td valign="top">Backup </td>
1111                                                                                        <td valign="top">
1112                                                                                                <xsl:if test="$checked">
1113                                                                                                        <xsl:value-of select="count(check//row[action='update' or action='revision'][empty(enabled) or enabled='true'])"/>
1114                                                                                                        <xsl:text> enabled and existing DCs</xsl:text>
1115                                                                                                </xsl:if>
1116                                                                                        </td>
1117                                                                                        <td valign="top">
1118                                                                                                <button type="submit" name="action" value="backup">
1119                                                                                                        <xsl:if test="empty(check//row[action='update' or action='revision'])">
1120                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1121                                                                                                        </xsl:if>
1122                                                                                                        <xsl:text>backup DCs to DCIF</xsl:text>
1123                                                                                                </button>
1124                                                                                        </td>
1125                                                                                </tr>
1126                                                                                <tr>
1127                                                                                        <td valign="top">Import </td>
1128                                                                                        <td valign="top">
1129                                                                                                <xsl:value-of select="count(check//row[empty(enabled) or enabled='true'])"/>
1130                                                                                                <xsl:text> enabled import actions</xsl:text>
1131                                                                                        </td>
1132                                                                                        <td valign="top">
1133                                                                                                <button type="submit" name="action" value="import">
1134                                                                                                        <xsl:if test="not($checked) and not($import)">
1135                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1136                                                                                                        </xsl:if>
1137                                                                                                        <xsl:text>import</xsl:text>
1138                                                                                                </button>
1139                                                                                        </td>
1140                                                                                </tr>
1141                                                                                <tr>
1142                                                                                        <td valign="top">DCS </td>
1143                                                                                        <td valign="top">
1144                                                                                                <xsl:choose>
1145                                                                                                        <xsl:when test="normalize-space(@dcs)!=''">
1146                                                                                                                <xsl:value-of select="@dcs"/>
1147                                                                                                        </xsl:when>
1148                                                                                                        <xsl:otherwise>
1149                                                                                                                <i>none</i>
1150                                                                                                        </xsl:otherwise>
1151                                                                                                </xsl:choose>
1152                                                                                        </td>
1153                                                                                        <td valign="top">
1154                                                                                                <button type="submit" name="action" value="dcs">
1155                                                                                                        <xsl:if test="not($imported)">
1156                                                                                                                <xsl:attribute name="disabled" select="'disabled'"/>
1157                                                                                                        </xsl:if>
1158                                                                                                        <xsl:text>create</xsl:text>
1159                                                                                                </button>
1160                                                                                        </td>
1161                                                                                </tr>
1162                                                                        </table>
1163                                                                </form>
1164                                                        </body>
1165                                                </html>
1166                                        </xsl:template>
1167                                </xsl:stylesheet>
1168                        </operator>
1169                        <target>this:response</target>
1170                </instr>
1171        </idoc>
1172        <exception>
1173                <debug/>
1174                <trace>ffcpl:/trace/import.exception.xml</trace>
1175                <throw/>
1176        </exception>
1177        <response>
1178                <mime>text/html</mime>
1179        </response>
1180</accessor>
Note: See TracBrowser for help on using the repository browser.