-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxpr.xqm
2657 lines (2520 loc) · 99.2 KB
/
xpr.xqm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
xquery version "3.0";
module namespace xpr.xpr = "xpr.xpr";
(:~
: This xquery module is an application for xpr
:
: @author emchateau & sardinecan (ANR Experts)
: @since 2019-01
: @licence GNU http://www.gnu.org/licenses
: @version 0.2
:
: xpr is free software: you can redistribute it and/or modify
: it under the terms of the GNU General Public License as published by
: the Free Software Foundation, either version 3 of the License, or
: (at your option) any later version.
:
:)
import module namespace G = 'xpr.globals' at './globals.xqm' ;
import module namespace xpr.mappings.html = 'xpr.mappings.html' at './mappings.html.xqm' ;
import module namespace xpr.models.xpr = 'xpr.models.xpr' at './models.xpr.xqm' ;
import module namespace xpr.models.networks = 'xpr.models.networks' at './models.networks.xqm' ;
import module namespace xpr.models.statistics = 'xpr.models.statistics' at './models.statistics.xqm' ;
import module namespace xpr.autosave = 'xpr.autosave' at './autosave.xqm' ;
import module namespace xpr.manifest = 'xpr.manifest' at './manifest.xqm' ;
import module namespace Session = 'http://basex.org/modules/session';
import module namespace functx = "http://www.functx.com";
declare namespace rest = "http://exquery.org/ns/restxq" ;
declare namespace file = "http://expath.org/ns/file" ;
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization" ;
declare namespace db = "http://basex.org/modules/db" ;
declare namespace web = "http://basex.org/modules/web" ;
declare namespace update = "http://basex.org/modules/update" ;
declare namespace perm = "http://basex.org/modules/perm" ;
declare namespace user = "http://basex.org/modules/user" ;
declare namespace session = 'http://basex.org/modules/session' ;
declare namespace http = "http://expath.org/ns/http-client" ;
declare namespace json = "http://basex.org/modules/json" ;
declare namespace ev = "http://www.w3.org/2001/xml-events" ;
(:declare namespace eac = "eac" ;:)
declare namespace eac = "https://archivists.org/ns/eac/v2" ;
declare namespace rico = "rico" ;
declare namespace map = "http://www.w3.org/2005/xpath-functions/map" ;
declare namespace xf = "http://www.w3.org/2002/xforms" ;
declare namespace xlink = "http://www.w3.org/1999/xlink" ;
declare namespace xpr = "xpr" ;
declare default element namespace "xpr" ;
declare default function namespace "xpr.xpr" ;
declare default collation "http://basex.org/collation?lang=fr" ;
(:~
: This resource function defines the application root
: @return redirect to the home page or to the install
:)
declare
%rest:path("/xpr")
%output:method("xml")
function index() {
if (db:exists("xpr"))
then web:redirect("/xpr/home")
else web:redirect("/xpr/install")
};
(:~
: This resource function defines the application root
: @return redirect to the home page or to the install
:)
declare
%rest:path("/")
%output:method("xml")
function root() {
web:redirect("/xpr/about")
};
(:~
: This resource function install
: @return create the db
: @todo create the prosopo db
:)
declare
%rest:path("/xpr/install")
%output:method("xml")
%updating
function install() {
if (db:exists("xpr"))
then (
update:output("La base xpr existe déjà, voulez-vous l’écraser ?")
)
else (
update:output("La base a été créée"),
db:create( "xpr", <xpr/>, "z1j.xml", map {"chop" : fn:false()} )
)
};
(:~
: This resource function export the z1j database into the base-dir
: @return redirect to the expertises list
: @todo change the export path
:)
declare
%rest:path("/xpr/export")
function z1jExport(){
db:export("xpr", '/sites/expertdb/resource/data/db/', map { 'method': 'xml' }),
web:redirect("/xpr/expertises/view")
};
(:~
: This resource function defines the application home
: @return redirect to the expertises list
:)
declare
%rest:path("/xpr/home")
%output:method("xml")
function home() {
web:redirect("/xpr/expertises/view")
};
(:~
: This resource function creates the about page
: @return an about page
:)
declare
%rest:path("/xpr/about")
%output:method("html")
function about() {
let $content := map {
'title' : 'À propos de l’ANR Experts',
'data' :
<div>
<section class="alternate">
<br/>
<br/>
<h2>Pratiques des savoirs entre jugement et innovation. Experts, expertises du bâtiment, Paris 1690-1790 – ANR EXPERTS</h2>
<p>Notre projet vise à examiner, à partir d’un secteur économique majeur — celui du bâtiment à l’époque moderne —, le mécanisme de l’expertise : comment la langue technique régulatrice des experts s’impose à la société, comment leur compétence se convertit en autorité, voire parfois en « abus d’autorité » ? L’existence d’un fonds d’archives exceptionnel (AN Z<sup>1J</sup>) qui conserve l’ensemble des procès-verbaux d’expertise du bâtiment parisien de 1643 à 1792 nous permet de lancer une enquête pluridisciplinaire d’envergure sur la question de l’expertise qui connaît, à partir de 1690, un tournant particulier. En effet, les experts, autrefois uniquement gens de métiers, se divisent en deux branches exerçant deux activités concurrentes, parfois complémentaires : l’architecture et l’entreprise de construction.</p>
<p>La base de notre travail consistera d’abord à établir parallèlement deux corpus : d’une part, un dictionnaire prosopographique des 234 experts exerçant de 1690 à 1790 ; d’autre part, l’inventaire et l’analyse des procès-verbaux d’expertise sur la même période. Au regard de l’immensité du fond, nous travaillerons sur un groupe de près de 10 000 expertises par le biais d’un sondage au 1/10<sup>e</sup> sur les dix années de 1696 à 1786, espacées chacune de 10 ans. Chaque expertise sera inventoriée, indexée, numérisée et analysée dans le détail. L’ensemble fera l’objet d’une étude sérielle sur le siècle parcouru, mais surtout d’un travail approfondi sur son contenu. Deux questions seront résolues : 1° Comment la décision de l’expert se prend-elle ? Quels savoirs y sont convoqués ? 2° Comment ces experts parviennent à innover dans domaine de leur compétence ? Le projet correspond au moins à trois enjeux contemporains.</p>
<p>Le premier concerne le rapport au risque et à l’innovation sociale. Comment affronter des situations à risque permet d’innover techniquement, voire socialement ? La confrontation à des incertitudes ouvre des possibilités de résoudre des conflits entre des communautés opposées. Tenant compte de la partition des fonctions d’experts, la mission d’expertise se différencie-t-elle selon la qualité de son auteur ? Les experts en viennent, souvent grâce à l’expertise, à innover dans le champ d’activité qui est le leur. Ainsi, pourquoi l’expertise induit-elle l’innovation ?</p>
<p>Le second concerne la part du droit dans la prise de décision démocratique. Comment le droit peut-il servir entre les mains de non-juristes ? La diffusion des principes du droit dans la vie citoyenne permet un usage de ces derniers dans la vie publique mais également dans des domaines de la vie privée. Dans le cadre de notre projet, comment et pourquoi des experts, non juristes mais au fait du droit, argumenteront en droit et persuaderont le juge de leur position ?</p>
<p>Le troisième concerne la régulation des valeurs de biens. Quels critères faut-il mettre en avant pour échafauder une hiérarchie des choses ? Une stricte normalisation objective de ces critères peut ne pas apparaître souhaitable face aux lois du marché qui par leur rigueur nécessiteraient un contrebalancement de règles subjectivées. Précisément, comment les experts du bâtiment ont-ils mis en place les critères objectifs et subjectifs d’estimation de la valeur des biens immobiliers ?</p>
<p>Rejoignant l’idée d’« abus d’autorité » de l’expert, le fait que plusieurs types de savoirs, et plusieurs groupes sociaux, partagent l’expertise, diminuerait-il le risque d’abus d’autorité et au-delà le risque technique en général ?</p>
<p>Les résultats de cette recherche sont présentés dans une base de connaissances collaborative accueillie sur un site dédié sur lequel l’ensemble des corpus seront accessibles à la communauté des chercheurs. L’analyse d’<em>exempla</em> fera l’objet d’une éditorialisation particulière sous forme d’exposition virtuelle pour le grand public. La synthèse de nos résultats sera consignée dans un ouvrage et deux rencontres nationale et internationale viendront clore le projet.</p></section>
<section class="alternate">
<div>
<h2>Responsables du projet</h2>
<ul>
<li>Robert Carvais, CNRS (UMR 7074)</li>
<li>Emmanuel Chateau-Dutier, Université de Montréal (CRIHN)</li>
<li>Valérie Nègre, Université Paris I (UMR 8066)</li>
<li>Michela Barbot, CNRS (UMR 8533)</li>
</ul>
</div>
<div>
<h2>Co-chercheurs</h2>
<ul>
<li>Juliette Hernu-Belaud (Chercheuse post-doctorale ANR Experts)</li>
<li>Léonore Losserand (Chercheuse post-doctorale ANR Experts)</li>
<li>Yvon Plouzennec (Chercheur post-doctorale ANR Experts)</li>
</ul>
</div>
<div>
<h2>Ingénieur d’étude</h2>
<ul>
<li>Josselin Morvan</li>
</ul>
</div>
<div>
<h2>Partenaires</h2>
<ul>
<li><a href="https://anr.fr/Projet-ANR-17-CE26-0006">Agence nationale de recherche, projet ANR-17-CE26-0006</a></li>
<li><a href="http://www.gip-recherche-justice.fr">Mission de recherche Droit & Justice (2015-2017)</a></li>
<li><a href="https://www.archives-nationales.culture.gouv.fr">Archives Nationales de France</a></li>
<li>Ce projet a bénéficié du soutien du <a href="https://sites.haa.pitt.edu/na-dah/">Getty Advanced Workshop on Network Analysis and Digital Art History (NA+DAH)</a></li>
</ul>
</div>
</section>
</div>
}
let $outputParam := map {
'layout' : "template.xml"
(: 'mapping' : xpr.mappings.html:listXpr2html(map:get($content, 'data'), map{}) :)
}
return xpr.models.xpr:wrapper($content, $outputParam)
};
(:~ Login page (visible to everyone). :)
declare
%rest:path("xpr/meteo")
%output:method("html")
function meteo() {
let $expertises := getExpertises()
let $biographies := getBiographies()
let $inventories := getInventories()
return
<html>
<head>
<title>!xpr¡</title>
<meta charset="UTF-8"/>
</head>
<body>
<div>
<h1>Météo des experts</h1>
<div class="expertises">
<h2>Expertises</h2>
<ul>
<li>{ fn:count($expertises/expertise) || ' expertises enregistrées dans la base de données' }</li>
<li>{ fn:count($expertises/expertise[descendant::localControl[@localType='detailLevel']/term[fn:normalize-space(.) = 'completed']]) || ' expertises complètes' }</li>
<li>{ fn:count($expertises/expertise[descendant::localControl[@localType='detailLevel']/term[fn:normalize-space(.) = 'in progress']]) || ' expertises en cours de dépouillement' }</li>
<li>{ fn:count($expertises/expertise[descendant::localControl[@localType='detailLevel']/term[fn:normalize-space(.) = 'to revise']]) || ' expertises à revoir' }</li>
<li>{ fn:count(fn:distinct-values($expertises/expertise/descendant::idno[@type='unitid'])) || ' dossiers dépouillés' }
<ul>{
for $unitid in fn:distinct-values($expertises/expertise/descendant::idno[@type='unitid'])
return <li>{ fn:count($expertises/expertise/descendant::idno[@type='unitid'][. = $unitid]) || ' expertises cotées "' || $unitid || '"' }</li>
}</ul>
</li>
</ul>
</div>
<div class="prosopographie">
<h2>Prosopographie</h2>
<ul>
<li>{fn:count($biographies/eac:eac-cpf) || ' fiches prosopographiques enregistrées dans la base de données'}
<ul>{
for $entityType in fn:distinct-values($biographies/descendant::eac:identity/@localType)
return <li>{ fn:count($biographies/eac:eac[descendant::eac:identity[@localType = $entityType]]) || ' entités ayant pour qualité "' ||$entityType || '"' }</li>
}</ul>
</li>
<li>{ fn:count($biographies/eac:eac[descendant::eac:localControl[@localType='detailLevel']/eac:term[fn:normalize-space(.) = 'completed']]) || ' fiches complètes' }</li>
<li>{ fn:count($biographies/eac:eac[descendant::eac:localControl[@localType='detailLevel']/eac:term[fn:normalize-space(.) = 'in progress']]) || ' fiches en cours de dépouillement' }</li>
<li>{ fn:count($biographies/eac:eac[descendant::eac:localControl[@localType='detailLevel']/eac:term[fn:normalize-space(.) = 'to revise']]) || ' fiches à revoir' }</li>
</ul>
</div>
<div class="iad">
<h2>Inventaires après-décès</h2>
<ul>
<li>{ fn:count($inventories/inventory) || ' inventaires après-décès enregistrés dans la base de données' }</li>
<li>{ fn:count($inventories/inventory[descendant::localControl[@localType='detailLevel']/term[fn:normalize-space(.) = 'completed']]) || ' inventaires complets' }</li>
<li>{ fn:count($inventories/inventory[descendant::localControl[@localType='detailLevel']/term[fn:normalize-space(.) = 'in progress']]) || ' inventaires en cours de dépouillement' }</li>
<li>{ fn:count($inventories/inventory[descendant::localControl[@localType='detailLevel']/term[fn:normalize-space(.) = 'to revise']]) || ' inventaires à revoir' }</li>
</ul>
</div>
</div>
</body>
</html>
};
(:~
: this function defines a static files directory for the app
: @param $file file or unknown path
: @return binary file
:)
declare
%rest:path('xpr/files/{$file=.+}')
function xpr.xpr:file($file as xs:string) as item()+ {
let $path := file:base-dir() || 'files/' || $file
return
(
web:response-header( map {'media-type' : web:content-type($path)}),
file:read-binary($path)
)
};
(:~
: this variable defines style for status & query functions
: @rmq to be removed
:)
declare variable $xpr.xpr:style :=
<style>
body {{
font-family: sans-serif; /* 1 */
background-color: #fff;
color: #E73E0D;
}}
html {{
line-height: 1.15; /* 2 */
-ms-text-size-adjust: 100%; /* 3 */
-webkit-text-size-adjust: 100%; /* 3 */
}}
main {{
width: 95%;
margin:auto;
}}
table {{
display: inline;
border-collapse:collapse;
}}
thead td {{
background-color: #E73E0D;
color:#fff;
min-width:50px;
}}
div:not(.detail) thead td {{
height:400px;
writing-mode:vertical-rl;
}}
td {{
border: 0.15em solid ;
}}
tbody td {{
text-align: center;
}}
main div {{
margin-bottom: 3em;
}}
</style>;
(:~
: This resource function lists all the expertises
: @return an ordered list of expertises in xml
:)
declare
%rest:path("/xpr/expertises")
%rest:produces('application/xml')
%output:method("xml")
function getExpertises() {
<expertises>{ db:open('xpr', 'xpr/expertises') }</expertises>
};
(:~
: This resource function edits a new expertise
: @return an xforms to edit an expertise
:)
declare
%rest:path("xpr/expertises/new")
%output:method("xml")
%perm:allow("expertises")
function newExpertise() {
let $content := map {
'instance' : '',
'model' : ('xprExpertiseModel.xml', 'xprAutosaveModel.xml'),
'trigger' : 'xprExpertiseTrigger.xml',
'form' : 'xprExpertiseForm.xml'
}
let $outputParam := map {
'layout' : "template.xml"
}
return
(processing-instruction xml-stylesheet { fn:concat("href='", $G:xsltFormsPath, "'"), "type='text/xsl'"},
<?css-conversion no?>,
xpr.models.xpr:wrapper($content, $outputParam)
)
};
(:~
: This function creates new expertises
: @param $param content to insert in the database
: @param $refere the callback url
: @return update the database with an updated content and an 200 http
: @bug change of cote and dossier doesn’t work
:)
declare
%rest:path("xpr/expertises/put")
%output:method("xml")
%rest:header-param("Referer", "{$referer}", "none")
%rest:PUT("{$param}")
%perm:allow("expertises", "write")
%updating
function putExpertise($param, $referer) {
let $db := db:open("xpr")
let $user := fn:normalize-space(user:list-details(Session:get('id'))/@name)
return
if (fn:ends-with($referer, 'modify')) then
let $location := fn:analyze-string($referer, 'xpr/expertises/(.+?)/modify')//fn:group[@nr='1']
let $id := fn:replace(fn:lower-case($param/expertise/sourceDesc/idno[@type="unitid"]), '/', '-') || 'd' || fn:format-integer($param/expertise/sourceDesc/idno[@type="item"], '000') || $param/expertise/sourceDesc/idno[@type="supplement"]
let $param :=
copy $d := $param
modify(
replace value of node $d/expertise/@xml:id with $id,
replace value of node $d/expertise/control/maintenanceHistory/maintenanceEvent[1]/agent with $user,
for $place at $i in $d/expertise/description[categories/category[@type="estimation"]]/places/place
let $idPlace := fn:generate-id($place)
where $place[fn:not(@xml:id)]
return(
insert node attribute xml:id {$idPlace} into $place,
insert node attribute ref {fn:concat('#', $idPlace)} into $d/expertise/description/conclusions/estimates/place[$i]
)
)
return $d
return(
(:
@rmq avec db:replace, l'ordre des arguments est à l'inverse de db:add : d'abord l'ancien fichier, puis le nouveau
avec Basex 10.x, db:replace devient db:put, et l'ordre est aligné avec db:add
:)
db:replace('xpr', 'xpr/expertises/'|| $location ||'.xml', $param),
db:rename("xpr", 'xpr/expertises/'|| $location ||'.xml', 'xpr/expertises/'|| $id ||'.xml'),
update:output((
<rest:response>
<http:response status="200" message="test">
<http:header name="Content-Language" value="fr"/>
<http:header name="Content-Type" value="text/plain; charset=utf-8"/>
</http:response>
</rest:response>,
<result>
<id>{$id}</id>
<message>La ressource a été modifiée.</message>
<url></url>
</result>
))
)
else
let $id := fn:replace(fn:lower-case($param/expertise/sourceDesc/idno[@type="unitid"]), '/', '-') || 'd' || fn:format-integer($param/expertise/sourceDesc/idno[@type="item"], '000') || $param/expertise/sourceDesc/idno[@type="supplement"]
let $param :=
copy $d := $param
modify(
insert node attribute xml:id {$id} into $d/*,
replace value of node $d/expertise/control/maintenanceHistory/maintenanceEvent[1]/agent with $user,
for $place at $i in $d/expertise/description[categories/category[@type="estimation"]]/places/place
let $idPlace := fn:generate-id($place)
return(
insert node attribute xml:id {$idPlace} into $place,
insert node attribute ref {fn:concat('#', $idPlace)} into $d/expertise/description/conclusions/estimates/place[$i]
)
)
return $d
return(
db:add('xpr', $param, 'xpr/expertises/'|| $id ||'.xml'),
update:output((
<rest:response>
<http:response status="200" message="test">
<http:header name="Content-Language" value="fr"/>
</http:response>
</rest:response>,
<result>
<id>{$id}</id>
<message>La ressource a été créée.</message>
<url></url>
</result>
))
)
};
(:~
: This resource function lists all the expertises
: @return an ordered list of expertises in html
:)
declare
%rest:path("/xpr/expertises/view")
%rest:produces('application/html')
%rest:query-param("start", "{$start}", 1)
%rest:query-param("count", "{$count}", 50)
%output:method("html")
%output:html-version('5.0')
function getExpertisesHtml($start as xs:integer, $count as xs:integer) {
let $content := map {
'title' : 'Liste des expertises',
'data' : getExpertises()
}
let $outputParam := map {
'layout' : "listeExpertise.xml",
'mapping' : xpr.mappings.html:listXpr2html(map:get($content, 'data'), map{})
}
return xpr.models.xpr:wrapper($content, $outputParam)
};
(:~
: This resource function lists all the expertises
: @return an ordered list of expertises in json
: @todo to develop
:)
declare
%rest:path("/xpr/expertises/json")
%rest:POST("{$body}")
%rest:produces('application/json')
%output:media-type('application/json')
%output:method('json')
function getExpertisesJson($body) {
let $body := json:parse( $body, map{"format" : "xquery"})
let $db := db:open('xpr')
let $expertises := getExpertises()
let $prosopo := $db/xpr/bio
(:map:merge(for $x in //emp return map{$x!name : $x!@salary}):)
let $dateCount := map:merge(
for $group in $expertises/expertise
for $year in $group/sourceDesc/unitdate
group by $year
return map { $year : fn:count($group/self::node()) }
)
let $experts := map:merge(
for $expert in $prosopo/eac:eac[descendant::eac:otherEntityType[fn:normalize-space(eac:term)='expert']]/@xml:id
return map { $expert : xpr.mappings.html:getEntityName($expert) }
)
let $meta := map {
'start' : $body?start,
'count' : $body?count,
'totalExpertises' : fn:count($expertises/expertise),
'datesCount' : $dateCount,
'experts' : $experts
}
let $content := array{
for $expertise in fn:subsequence($expertises/expertise, $body?start, $body?count)
return map{
'id' : fn:normalize-space($expertise/@xml:id),
'dates' : array{
fn:sort($expertise//sessions/date/fn:normalize-space(@when[. castable as xs:date]))
},
'experts' : array{ for $expert in $expertise//experts/expert[fn:normalize-space(@ref)!=''] return xpr.mappings.html:getEntityName($expert/fn:substring-after(@ref, '#'))},
'expertsId' : array{
$expertise//participants/experts/expert[fn:normalize-space(@ref)!='']/fn:normalize-space(@ref)
},
'greffiers' : array{
$expertise//clerks/clerk/persName/fn:string-join(*, ', ')
},
'case' : $expertise//procedure/*[fn:local-name() = 'case']/fn:normalize-space(),
'thirdParty' : if($expertise//experts/expert[@context='third-party']) then 'true' else 'false'
}
}
return map{
"meta": $meta,
"content": $content
}
};
(:~
: This resource function lists all the expertises
: @return an ordered list of expertises with saxonjs
:)
declare
%rest:path("/xpr/expertises/saxon")
%rest:produces('application/html')
%output:method("html")
function getExpertisesSaxon() {
let $content := map {
'data' : db:open('xpr', 'xpr/expertises'),
'trigger' : '',
'form' : ''
}
let $outputParam := map {
'layout' : "listeExpertiseSaxon.xml"
}
return xpr.models.xpr:wrapper($content, $outputParam)
};
(:~
: This resource function lists all the expertises
: @return an ordered list of expertises with xforms
:)
declare
%rest:path("/xpr/expertises/xforms")
%rest:produces('text/html')
%output:method("xml")
function getExpertisesXforms() {
let $content := map {
'instance' : '',
'model' : 'xprListModel.xml',
'trigger' : '',
'form' : 'xprList.xml'
}
let $outputParam := map {
'layout' : "template.xml"
}
return(
processing-instruction xml-stylesheet { fn:concat("href='", $G:xsltFormsPath, "'"), "type='text/xsl'"},
<?css-conversion no?>,
xpr.models.xpr:wrapper($content, $outputParam)
)
};
(:~
: This resource function lists all the expertises
: @return an ordered table of expertises in html
:)
declare
%rest:path("/xpr/expertises/table")
(:%rest:POST("{$body}"):)
%rest:produces('application/html')
%output:method("html")
function getExpertisesTable() {
(: let $body := json:parse( $body, map{"format" : "xquery"}) :)
let $db := db:open('xpr')
let $expertises := $db/xpr/expertises
let $prosopo := $db/xpr/bio
(:map:merge(for $x in //emp return map{$x!name : $x!@salary}):)
let $dateCount := map:merge(
for $group in $expertises/expertise
for $year in $group/sourceDesc/unitdate
group by $year
return map { $year : fn:count($group/self::node()) }
)
let $experts := map:merge(
for $expert in $prosopo/eac:eac[descendant::eac:otherEntityType[fn:normalize-space(eac:term)='expert']]/@xml:id
return map { $expert : xpr.mappings.html:getEntityName($expert) }
)
(:let $meta := map {
'start' : $body?start,
'count' : $body?count,
'totalExpertises' : fn:count($expertises/expertise),
'datesCount' : $dateCount,
'experts' : $experts
}:)
let $content :=
<table>
<tbody>
<tr>
<th>id</th>
<th>Dates</th>
<th>Experts</th>
<th>Greffiers</th>
<th>Cas</th>
<th>Tiers expertise</th>
</tr>{
for $expertise in $expertises/expertise
let $dates := fn:sort($expertise//sessions/date/fn:normalize-space(@when[. castable as xs:date]))
let $experts :=
for $expert in $expertise//experts/expert[fn:normalize-space(@ref)!='']
return array{
$expert/fn:substring-after(@ref, '#'),
xpr.mappings.html:getEntityName($expert/fn:substring-after(@ref, '#'))
}
let $clerks :=
for $clerk in $expertise//clerks/clerk[fn:normalize-space(@ref)!='']
return array{
$clerk/fn:substring-after(@ref, '#'),
xpr.mappings.html:getEntityName($clerk/fn:substring-after(@ref, '#'))
}
return
<tr>
<td><a href="/xpr/expertises/{fn:normalize-space($expertise/@xml:id)}/view">{fn:normalize-space($expertise/@xml:id)}</a></td>
<td>{fn:string-join($dates, ' ; ')}</td>
<td>{for $expert at $i in $experts return (<a href="/xpr/biographies/{array:get($expert, 1)}/view">{array:get($expert, 2)}</a>, if(fn:count($experts) > $i) then ' ; ')}</td>
<td>{for $clerk at $i in $clerks return (<a href="/xpr/biographies/{array:get($clerk, 1)}/view">{array:get($clerk, 2)}</a>, if(fn:count($clerk) > $i) then ' ; ')}</td>
<td>{$expertise//procedure/*[fn:local-name() = 'case']/fn:normalize-space()}</td>
<td>{if($expertise//experts/expert[@context='third-party']) then 'true' else 'false'}</td>
</tr>
}
</tbody>
</table>
return $content
};
(:~
: This resource function lists all the expertises’ ids
: @return an xml list the expertises with theire @xml:id
:)
declare
%rest:path("/xpr/expertises/ids")
%rest:produces('application/xml')
%output:method("xml")
function getExpertisesId() {
<expertises>{
for $expertise in getExpertises()/expertise
return <expertise xmlns="xpr" xml:id="{$expertise/@xml:id}"></expertise>
}</expertises>
};
(:~
: This resource function lists all the expertises of an expert
: @return an ordered list of expertises in xml
: @todo check for multiple value for expert
:)
declare
%rest:path("/xpr/expertises/experts")
%rest:produces('application/xml')
%output:method("xml")
%rest:query-param('ids', '{$ids}', 'xpr0001')
function getExpertises($ids as xs:string) {
if($ids) then
<expertises>{ db:open('xpr', 'xpr/expertises')/*:expertise[descendant::*:expert/@ref='#'||$ids] }</expertises>
else
<expertises>{ db:open('xpr', 'xpr/expertises') }</expertises>
};
(:~
: This resource function returns an expertise item
: @param $id the expertise id
: @return an expertise item in xml (xpr)
:)
declare
%rest:path("xpr/expertises/{$id}")
%output:method("xml")
function getExpertise($id) {
db:open('xpr', 'xpr/expertises')/expertise[@xml:id=$id]
};
(:~
: This resource function modify an expertise item
: @param $id the expertise id
: @return an xforms to edit the expertise
:)
declare
%rest:path("xpr/expertises/{$id}/modify")
%output:method("xml")
%perm:allow("expertises")
function modifyExpertise($id) {
let $content := map {
'instance' : $id,
'path' : 'expertises',
'model' : ('xprExpertiseModel.xml', 'xprAutosaveModel.xml'),
'trigger' : 'xprExpertiseTrigger.xml',
'form' : 'xprExpertiseForm.xml'
}
let $outputParam := map {
'layout' : "template.xml"
}
return(
processing-instruction xml-stylesheet { fn:concat("href='", $G:xsltFormsPath, "'"), "type='text/xsl'"},
<?css-conversion no?>,
xpr.models.xpr:wrapper($content, $outputParam)
)
};
(:~
: This resource function returns an expertise item
: @param $id the expertise id
: @return an expertise item in html
: @todo use html templating
:)
declare
%rest:path("xpr/expertises/{$id}/view")
%rest:produces('application/html')
%output:method("html")
function getExpertiseHtml($id) {
let $content := map {
'data' : getExpertise($id),
'trigger' : '',
'form' : ''
}
let $outputParam := map {
'layout' : "ficheExpertise.xml",
'mapping' : xpr.mappings.html:xpr2html(map:get($content, 'data'), map{})
}
return xpr.models.xpr:wrapper($content, $outputParam)
};
(:~
: This resource function returns an expertise item
: @param $id the expertise id
: @return an expertise item in json
: @todo to develop
:)
declare
%rest:path("xpr/expertises/{$id}/json")
%rest:produces('application/json')
%output:media-type('application/json')
%output:method('json')
function getExpertiseJson($id) {
let $expertise := getExpertise($id)
let $meta := map{
'id' : fn:normalize-space($expertise/@xml:id),
'cote' : $expertise/sourceDesc/idno[@type='unitid'] => fn:string(),
'dossier' : $expertise/sourceDesc/idno[@type='item'] => fn:string(),
'unitdate' : $expertise/sourceDesc/unitdate => fn:string(),
'facsimile' : map {
'start' : $expertise/sourceDesc/facsimile/@from => fn:normalize-space(),
'end' : $expertise/sourceDesc/facsimile/@to => fn:normalize-space()
},
'supplement' : $expertise/sourceDesc/idno[@type='supplement'] => fn:string(),
'extent' : $expertise/sourceDesc/physDesc/extent => fn:normalize-space(),
'sketch' : $expertise/sourceDesc/physDesc/extent/@sketch => fn:normalize-space(),
'appendices' : if($expertise/sourceDesc/physDesc/extent/appendices/appendice[fn:normalize-space(.)!='']) then array{
for $appendice in $expertise/sourceDesc/physDesc/extent/appendices/appendice[fn:normalize-space(.)!='']
return map{
'type' : array{
for $type in $appendice/type
return $type => fn:normalize-space()
},
'extent' : $appendice/extent => fn:normalize-space(),
'description' : $appendice/desc => fn:normalize-space(),
'note' : $appendice/note => fn:normalize-space()
}
},
'maintenance' : if($expertise/control/maintenanceHistory/maintenanceEvent[fn:normalize-space(.)!='']) then array {
for $maintenanceEvent in $expertise/control/maintenanceHistory/maintenanceEvent[fn:normalize-space(.)!='']
return xpr.mappings.html:getMaintenanceEvent($maintenanceEvent, map{})
}
}
let $content := map{
'addresses' : if($expertise/description/places/place[fn:normalize-space(.)!='']) then array{
for $place in $expertise/description/places/place[fn:normalize-space(.)!='']
return xpr.mappings.html:getAddress($place, map{}) => fn:string-join() => fn:normalize-space()
},
'dates' : if($expertise//sessions/date[fn:normalize-space(@when)!='']) then array{
fn:sort($expertise//sessions/date/fn:normalize-space(@when[. castable as xs:date]))
},
'sessions' : if($expertise/description/sessions/date[fn:normalize-space(@type)!='' or fn:normalize-space(@when)!='']) then array{
(:@rmq : use array instead of map:merge because the latter combine duplicate keys:)
for $session in $expertise/description/sessions/date[fn:normalize-space(@type)!='' or fn:normalize-space(@when)!='']
return map{
fn:normalize-space($session/@type) : fn:normalize-space($session/@when)
}
},
'designation' : if($expertise/description/categories/designation[@rubric='true'])
then $expertise/description/categories/designation => fn:normalize-space() || ' (en rubrique)'
else $expertise/description/categories/designation => fn:normalize-space(),
'categories' : if($expertise/description/categories/category[fn:normalize-space(.)!='']) then array{
for $category in $expertise/description/categories/category[fn:normalize-space(.)!='']
return $category => fn:normalize-space()
},
'framework' : if($expertise/description/procedure/framework[fn:normalize-space(.)!='']) then $expertise/description/procedure/framework/@type || ' - ' || fn:normalize-space($expertise/description/procedure/framework) else '',
'origination' : $expertise/description/procedure/origination => fn:normalize-space(),
'sentences' : if($expertise/description/procedure/sentences/sentence[fn:normalize-space(.)!='']) then array{
for $sentence in $expertise/description/procedure/sentences/sentence[fn:normalize-space(.)!='']
return map {
'orgName' : $sentence/orgName => fn:normalize-space(),
'dates' : if($sentence/date[fn:normalize-space(@when)!='']) then array{
for $date in $sentence/date[fn:normalize-space(@when)!='']
return $date/@when => fn:normalize-space()
}
}
},
'case' : $expertise/description/procedure/case => fn:normalize-space(),
'objects' : if($expertise/description/procedure/objects/object[fn:normalize-space(.)!='']) then array{
for $object in $expertise/description/procedure/objects/object[fn:normalize-space(.)!='']
return $object => fn:normalize-space()
},
'experts' : if($expertise//experts/expert[fn:normalize-space(@ref)!='']) then array{
for $expert in $expertise//experts/expert[fn:normalize-space(@ref)!='']
return map{
'id' : $expert/fn:substring-after(@ref, '#'),
'name' : xpr.mappings.html:getEntityName($expert/fn:substring-after(@ref, '#')),
(:'quality' : ($expert/title[fn:normalize-space(.)!=''], $context, $appointment) => fn:string-join(', ') || '.',:)
'title' : $expert/title => fn:normalize-space(),
'context' : $expert/@context => fn:normalize-space(),
'appointment' : $expert/@appointment => fn:normalize-space()
}
},
'clerks' : if($expertise/description/participants/clerks/clerk[fn:normalize-space(.)!='']) then array{
for $clerk in $expertise/description/participants/clerks/clerk[fn:normalize-space(.)!='']
return fn:string-join($clerk/persName/*[fn:normalize-space(.)!='']/functx:capitalize-first(fn:normalize-space()), ', ')
},
'parties' : if($expertise/description/participants/parties/party[fn:normalize-space(.)!='']) then array {
for $party in $expertise/description/participants/parties/party[fn:normalize-space(.)!='']
return map{
'role' : $party/@role => fn:normalize-space(),
'presence' : $party/@presence => fn:normalize-space(),
'intervention' : $party/@intervention => fn:normalize-space(),
'persons' : if($party/person[fn:normalize-space(.)!='']) then array{
for $person in $party/person[fn:normalize-space(.)!='']
return map{
'name' : fn:string-join($person/persName/*[fn:normalize-space(.)!='']/functx:capitalize-first(fn:normalize-space()), ', '),
'occupation' : $person/occupation => fn:normalize-space()
}
},
'status' : $party/status => fn:normalize-space(),
'expert' : if($party/expert[fn:normalize-space(@ref) !='']) then map {
'id' : $party/expert/fn:substring-after(fn:normalize-space(@ref), '#'),
'name' : xpr.mappings.html:getEntityName($party/expert/fn:substring-after(@ref, '#'))
},
'representatives' : if($party/representative[fn:normalize-space(.)!='']) then array{
for $representative in $party/representative[fn:normalize-space(.)!='']
return map {
'name' : fn:string-join($representative/persName/*[fn:normalize-space(.)!='']/functx:capitalize-first(fn:normalize-space()), ', '),
'occupation' : $representative/occupation => fn:normalize-space()
}
},
'prosecutors' : if($party/prosecutor[fn:normalize-space(.)!='']) then array{
for $prosecutor in $party/prosecutor[fn:normalize-space(.)!='']
return fn:string-join($prosecutor/persName/*[fn:normalize-space(.)!='']/functx:capitalize-first(fn:normalize-space()), ', ')
}
}
},
'craftmen' : if($expertise/description/participants/craftmen/craftman[fn:normalize-space(.) != '']) then array{
for $craftman in $expertise/description/participants/craftmen/craftman[fn:normalize-space(.) != '']
return map{
'name' : fn:string-join($craftman/persName/*[fn:normalize-space(.)!='']/functx:capitalize-first(fn:normalize-space()), ', '),
'occupation' : $craftman/occupation => fn:normalize-space()
}
},
'agreement' : $expertise/description/conclusions/agreement => fn:normalize-space(),
'opinions' : if($expertise/description/conclusions/opinion[fn:normalize-space(.)!='']) then array{
for $opinion in $expertise/description/conclusions/opinion[fn:normalize-space(.)!='']
return map {
'experts' : if($opinion[fn:normalize-space(@ref)!='']) then array{
for $expert in fn:tokenize($opinion/@ref)
return map{
'id': fn:substring-after($expert, '#') => fn:normalize-space(),
'name' : xpr.mappings.html:getEntityName(fn:substring-after($expert, '#'))
}
},
'opinion' : $opinion => fn:normalize-space()
}
},
'arrangement' : $expertise/description/conclusions/arrangement => fn:normalize-space(),
'estimate' : xpr.mappings.html:getValue($expertise/description/conclusions/estimate[fn:string-join(@*)!=''], map{}),
'estimates' : if($expertise/description/conclusions/estimates/place[fn:normalize-space(.)!='' or appraisal[fn:string-join((@l, @s, @d))!='']]) then array{
for $place in $expertise/description/conclusions/estimates/place[fn:normalize-space(.)!='' or appraisal[fn:string-join((@l, @s, @d))!='']]
let $ref := fn:substring-after($place/@ref, '#')
let $placeName := xpr.mappings.html:getAddress($expertise/description/places/place[@xml:id=$ref], map{}) => fn:string-join() => fn:normalize-space()
return map{
'placeName' : $placeName,
'appraisals' : if($place/appraisal[fn:normalize-space(.)!='' or fn:string-join((@l, @s, @d))!='']) then array{
for $appraisal in $place/appraisal[fn:normalize-space(.)!='' or fn:string-join((@l, @s, @d))!='']
return map{
'description' : fn:normalize-space($appraisal/desc),
'value' : xpr.mappings.html:getValue($appraisal, map{})
}
}
}
},
'fees' : if($expertise/description/conclusions/fees/fee[fn:string-join((@l, @s, @d))!='']) then array{
for $fee in $expertise/description/conclusions/fees/fee[fn:string-join((@l, @s, @d))!='']
return xpr.mappings.html:getFee($fee, map{})
},
'totalFees' : xpr.mappings.html:getValue($expertise/description/conclusions/fees/total, map{}),
'expertsExpense' : xpr.mappings.html:getValue($expertise/description/conclusions/expenses/expense[@type='expert'], map{}),
'clerksExpense' : xpr.mappings.html:getValue($expertise/description/conclusions/expenses/expense[@type='clerk'], map{}),
'analysis' : $expertise/description/analysis => fn:normalize-space(),
'noteworthy' : $expertise/description/noteworthy => fn:normalize-space()
}
return map {
'meta' : $meta,
'content' : $content
}
};
(:~
: This resource function returns an expertise item
: @param $id the expertise id
: @return an expertise item in html with saxon
:)
declare
%rest:path("xpr/expertises/{$id}/saxon")
%rest:produces('application/html')
%output:method("html")
function getExpertiseSaxon($id) {
let $content := map {
'data' : getExpertise($id),
'trigger' : '',
'form' : ''
}
let $outputParam := map {
'layout' : "ficheExpertiseSaxon.xml"
}
return xpr.models.xpr:wrapper($content, $outputParam)
};
(:~
: Permissions: expertises
: Checks if the current user is granted; if not, redirects to the login page.
: @param $perm map with permission data
:)
declare
%perm:check('xpr/expertises', '{$perm}')
function permExpertise($perm) {
let $user := Session:get('id')
return
if((fn:empty($user) or fn:not(user:list-details($user)/*:info/*:grant/@type = $perm?allow)) and fn:ends-with($perm?path, 'new'))
then web:redirect('/xpr/login/')
else if((fn:empty($user) or fn:not(user:list-details($user)/*:info/*:grant/@type = $perm?allow)) and fn:ends-with($perm?path, 'modify'))
then web:redirect('/xpr/login')
else if((fn:empty($user) or fn:not(user:list-details($user)/*:info/*:grant/@type = $perm?allow[1] and user:list-details($user)/*:database[@pattern='xpr']/@permission = $perm?allow[2])) and fn:ends-with($perm?path, 'put'))
then web:redirect('/xpr/login')
};
(:~
: This resource function lists the entities
: @return an xml list of persons/corporate bodies
:)
declare
%rest:path("/xpr/biographies")
%rest:produces('application/xml')
%output:method("xml")
function getBiographies() {
<bio>{ db:open('xpr', 'xpr/biographies') }</bio>
};
(:~
: This resource function creates an new entity
: @return an xforms for the entity
:)
declare
%rest:path("xpr/biographies/new")
%output:method("xml")
%perm:allow("prosopography")
function newBiography() {
let $content := map {
'instance' : '',
'model' : ('xprEacModel.xml', 'xprEacNoValidationModel.xml'),
'trigger' : 'xprEacTrigger.xml',
'form' : 'xprEacForm.xml'
}
let $outputParam := map {
'layout' : "template.xml"
}
return(
processing-instruction xml-stylesheet { fn:concat("href='", $G:xsltForms16Path, "'"), "type='text/xsl'"},
<?css-conversion no?>,
xpr.models.xpr:wrapper($content, $outputParam)
)
};
(:~
: This function consumes new entity
: @param $param content
:)
declare
%rest:path("xpr/biographies/put")
%output:method("xml")
%rest:header-param("Referer", "{$referer}", "none")
%rest:PUT("{$param}")
%perm:allow("prosopography")
%updating
function putBiography($param, $referer) {
let $db := db:open("xpr")
(:let $user := fn:normalize-space(user:list-details(Session:get('id'))/@name):)
return
if ($param/*/@xml:id) then