-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtapis.js
7991 lines (7244 loc) · 350 KB
/
tapis.js
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
"use strict"
/*
This file is part of TAPIS. TAPIS is a web page and a Javascript code
that builds queries and explore the STAplus content, saves it as CSV or
GeoJSON and connects with the MiraMon Map Browser. While the project is
completely independent from the Orange data mining software, it has been
inspired by its GUI. The general idea of the application is to be able
to work with STA data as tables.
The TAPIS client is free software under the terms of the MIT License
Copyright (c) 2023 Joan Masó
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The TAPIS can be updated from https://github.com/joanma747/tapis.
Aquest codi JavaScript ha estat idea de Joan Masó Pau (joan maso at uab cat)
dins del grup del MiraMon. MiraMon és un projecte del
CREAF que elabora programari de Sistema d'Informació Geogràfica
i de Teledetecció per a la visualització, consulta, edició i anàlisi
de mapes ràsters i vectorials. Aquest progamari programari inclou
aplicacions d'escriptori i també servidors i clients per Internet.
No tots aquests productes són gratuïts o de codi obert.
En particular, el TAPIS es distribueix sota els termes de la llicència MIT.
El TAPIS es pot actualitzar des de https://github.com/joanma747/tapis.
*/
var config;
const ServicesAndAPIs = {sta: {name: "STA plus", description: "STA service", startNode: true, help: "Connects to a SensorThings API or a STAplus instance and returns a table with the list of entities suported by the API."},
ogcAPICols: {name: "OGC API cols", description: "OAPI Collections", startNode: true, help: "Connects to the collections page of a OGC Web API instance and returns a table with the list collections available."},
ogcAPIItems: {name: "OGC API items", description: "OAPI items", help: "Connects to a collection page on an OGC Web API Features or derivatives and returns a table with the items available. One of the columns contains the geometry JSON object."},
csw: {name: "Catalogue", description: "OGC CSW", startNode: true, help: "Connects to a OGC CSW cataloge service. The result is a table with a list of records in the catalogue that have data associated with them."},
s3Service: {name: "S3 Service", description: "S3 Service", startNode: true, help: "Connects to a Amazon S3 compatible service (e.g. MinIO) and return the list of buckets available as a table."},
s3Bucket: {name: "S3 Bucket", description: "S3 Bucket", help: "Connects to a Amazon S3 backet (e.g. MinIO) and return the list of files available (in the root folder and all subfolders as a table."},
edc: {name: "DataSpace cat.", description: "DataSpace cat.", startNode: true, help: "Connects to an Eclipse Data Connector (EDC) Catalogue and returns the list of assets available as a table."},
edcAsset: {name: "DataSpace asset", description: "DataSpace asset", help: "Prepares an Eclipse Data Connector (EDC) Asset."},
ImportCSV: {name: "CSV", description: "CSV", startNode: true, help: "Imports data from a CSV file and returns a table."},
ImportDBF: {name: "DBF", description: "DBF", startNode: true, help: "Imports data from a DBASE III+ or IV file and returns a table."},
ImportJSONLD: {name: "JSON-LD", description: "JSON-LD", startNode: true, help: "Imports data from a JSON-LD file and returns a table."},
ImportJSON: {name: "JSON", description: "JSON", startNode: true, help: "Imports data from a JSON file and returns a table."},
ImportGeoJSON: {name: "GeoJSON", description: "GeoJSON", startNode: true, help: "Imports the features of a GeoJSON and returns a table where each feature is a record. One of the columns contains the geometry JSON object."},
staRoot: {name: "STA root", description: "STA root", help:"Returns to the root of the SensorThings API or STSTAplus service in use. In other words, removes the path and query parameters of the previous node."}};
const ServicesAndAPIsArray = Object.keys(ServicesAndAPIs);
const ServicesAndAPIsType = {singular: "Data input tool", plural: "Data input tools"};
const STAEntities = {
ObservedProperties: { singular: "ObservedProperty", entities: [{ name: "Datastreams", required: "false" }, { name: "MultiDatastreams", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "definition", dataType: "URI", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "properties", dataType: "JSON", required: "false" }], help: "Visualize through a table the ObservedProperties of this STAPlus service.", helpEdit: "Create, edit or delete an ObservedProperty in a STAPlus service."},
Observations: { singular: "Observation", entities: [{ name: "Datastream", required: "true" }, { name: "MultiDatastream", required: "true" }, { name: "FeatureOfInterest", required: "false" }, { name: "ObservationGroups", required: "false" }, { name: "Subjects", required: "false" }, { name: "Objects", required: "false" }], properties: [{ name: "phenomenonTime", dataType: "object", required: "true" }, { name: "resultTime", dataType: "isodatetime", required: "true" }, { name: "result", dataType: "", required: "true" }, { name: "resultQuality", dataType: "object", required: "false" }, { name: "validTime", dataType: "data_isoperiod", required: "false" }, { name: "parameters", dataType: "JSON", required: "false" }], entityRelations: ["Object", "Subject"], help:"Visualize through a table the Observations of this STAPlus service.", helpEdit: "Create, edit or delete an Observation in a STAPlus service."},
FeaturesOfInterest: { singular: "FeatureOfInterest", entities: [{ name: "Observations", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "encodingType", dataType: "string", required: "true" }, { name: "feature", dataType: "", required: "true" }, { name: "properties", dataType: "JSON", required: "false" }],help:"Visualize through a table the FeaturesOfInterest of this STAPlus service.", helpEdit: "Create, edit or delete a FeatureOFInterest in a STAPlus service." },
Sensors: { singular: "Sensor", entities: [{ name: "Datastreams", required: "false" }, { name: "MultiDatastreams", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "encodingType", dataType: "string", required: "true" }, { name: "metadata", dataType: "", required: "true" }, { name: "properties", dataType: "JSON", required: "false" }], help: "Visualize through a table the Sensors of this STAPlus service.", helpEdit: "Create, edit or delete a Sensor in a STAPlus service."},
Things: { singular: "Thing", entities: [{ name: "Datastreams", required: "false" }, { name: "MultiDatastreams", required: "false" }, { name: "Party", required: "true" }, { name: "Locations", required: "false" }, { name: "HistoricalLocations", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "properties", dataType: "JSON", required: "false" }], help: "Visualize through a table the Things of this STAPlus service.", helpEdit: "Create, edit or delete a Thing in a STAPlus service."},
Locations: { singular: "Location", entities: [{ name: "Things", required: "false" }, { name: "HistoricalLocations", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "encodingType", dataType: "string", required: "true" }, { name: "location", dataType: "", required: "true" }, { name: "properties", dataType: "JSON", required: "false" }], help: "Visualize through a table the Locations of this STAPlus service.", helpEdit: "Create, edit or delete a Location in a STAPlus service."},
HistoricalLocations: { singular: "HistoricalLocation", entities: [{ name: "Thing", required: "true" }, { name: "Locations", required: "true" }], properties: [{ name: "time", dataType: "isodatetime", required: "true" }], help:"Visualize through a table the HistoricalLocations of this STAPlus service" },
Datastreams: { singular: "Datastream", entities: [{ name: "Party", required: "true" }, { name: "Sensor", required: "true" }, { name: "ObservedProperty", required: "true" }, { name: "Campaigns", required: "false" }, { name: "License", required: "false" }, { name: "Observations", required: "false" }, { name: "Thing", required: "true" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "observationType", dataType: "string", required: "true" }, { name: "unitOfMeasurement", dataType: "JSON", required: "true" }, { name: "observedArea", dataType: "object", required: "false" }, { name: "phenomenonTime", dataType: "data_isoperiod", required: "false" }, { name: "resultTime", dataType: "data_isoperiod", required: "false" }, { name: "properties", dataType: "JSON", required: "false" }], help: "Visualize through a table the Datastreams of this STAPlus service.", helpEdit: "Create, edit or delete a Datastream in a STAPlus service."},
MultiDatastreams: { singular: "MultiDatastream", entities: [{ name: "Party", required: "true" }, { name: "Sensor", required: "true" }, { name: "ObservedProperty", required: "true" }, { name: "Campaigns", required: "false" }, { name: "License", required: "false" }, { name: "Observations", required: "false" }, { name: "Thing", required: "true" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "observationType", dataType: "string", required: "true" }, { name: "unitOfMeasurement", dataType: "JSON", required: "true" }, { name: " observedArea", dataType: "object", required: "false" }, { name: "phenomenonTime", dataType: "data_isoperiod", required: "false" }, { name: "resultTime", dataType: "data_isoperiod", required: "false" }, { name: "multiObservationDataType", dataType: "JSON", required: "true" }, { name: "properties", dataType: "JSON", required: "false" }],help:"Visualize through a table the MultiDatastreams of this STAPlus service.", helpEdit: "Create, edit or delete a MultiDatastream in a STAPlus service."},
Parties: { singular: "Party", entities: [{ name: "Datastreams", required: "false" }, { name: "MultiDatastreams", required: "false" }, { name: "Campaigns", required: "false" }, { name: "ObservationGroups", required: "false" }, { name: "Things", required: "false" }], properties: [{ name: "description", dataType: "string", required: "false" }, { name: "authId", dataType: "string", required: "false" }, { name: "role", dataType: "PartyRoleCode", required: "true" }, { name: "displayName", dataType: "string", required: "false" }], help: "Visualize through a table the Parties of this STAPlus service.", helpEdit: "Create, edit or delete a Party in a STAPlus service."},
Campaigns: { singular: "Campaign", entities: [{ name: "Datastreams", required: "false" }, { name: "MultiDatastreams", required: "false" }, { name: "Party", required: "true" }, { name: "License", required: "false" }, {name:"ObservationGroups", required:"false"}], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "classification", dataType: "string", required: "false" }, { name: "termsOfUse", dataType: "string", required: "true" }, { name: "privacyPolicy", dataType: "string", required: "false" }, { name: "creationTime", dataType: "isodatetime", required: "true" }, { name: "url", dataType: "URI", required: "false" }, { name: "startTime", dataType: "isodatetime", required: "false" }, { name: "endTime", dataType: "isodatetime", required: "false" }, { name: "properties", dataType: "JSON", required: "false" }], help: "Visualize through a table the Campaigns of this STAPlus service.", helpEdit: "Create, edit or delete an Campaign in a STAPlus service."},
Licenses: { singular: "License", entities: [{ name: "Datastreams", required: "false" }, { name: "MultiDatastreams", required: "false" }, { name: "Campaigns", required: "false" }, { name: "ObservationGroups", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "definition", dataType: "URI", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "logo", dataType: "string", required: "false" }, { name: "attributionText", dataType: "JSON", required: "false" }],help: "Visualize through a table the Licenses of this STAPlus service.", helpEdit: "Create, edit or delete a License in a STAPlus service."},
ObservationGroups: { singular: "ObservationGroup", entities: [{ name: "Party", required: "true" }, { name: "Campaigns", required: "false" }, { name: "License", required: "false" }, { name: "Observations", required: "false" }, { name: "Relations", required: "false" }], properties: [{ name: "name", dataType: "string", required: "true" }, { name: "description", dataType: "string", required: "true" }, { name: "purpose", dataType: "string", required: "false" }, { name: "creationTime", dataType: "isodatetime", required: "false" }, { name: "endTime", dataType: "isodatetime", required: "false" }, { name: "termsOfUsed", dataType: "string", required: "false" }, { name: "privacyPolicy", dataType: "string", required: "false" }, { name: "dataQuality", dataType: "JSON", required: "false" }, { name: "properties", dataType: "JSON", required: "false" }],help: "Visualize through a table the ObservationGroups of this STAPlus service.", helpEdit: "Create, edit or delete an ObservationGroup in a STAPlus service."},
Relations: { singular: "Relation", entities: [{ name: "Object", required: "true" }, { name: "Subject", required: "true" }, { name: "ObservationGroups", required: "false" }], properties: [{ name: "role", dataType: "URI", required: "true" }, { name: "description", dataType: "string", required: "false" }, { name: "externalObject", dataType: "URI", required: "false" }, { name: "properties", dataType: "JSON", required: "false" }], entityRelations: ["Objects", "Subjects"], help: "Visualize through a table the Relations of this STAPlus service", helpEdit: "Create, edit or delete an Relation in a STAPlus service."}
};
const STAEntitiesArray = Object.keys(STAEntities);
const STAEntitiesType = {singular: "STA entity reading tool", plural: "STA entities reading tool",
singularEdit: "STA entity transaction tool", pluralEdit: "STA entities create, edit or delete tool"};
const STASpecialQueries = {ObsLayer: {description: "Observations Layer", query: "Observations?$orderby=phenomenonTime%20desc&$expand=Datastream($select=unitOfMeasurement),Datastream/ObservedProperty($select=name,description,definition),FeatureOfInterest($select=description,feature)&$select=phenomenonTime,result", help: "Link to STAplus service to add a query to this url to obtain a table with phenomenomTime and results from Observations, unitsOfMeasurements and ObservedProperty from Datastreams and a description from the featureOfInterest related."}};
const STASpecialQueriesArray = Object.keys(STASpecialQueries);
const STASpecialQueriesType = {singular: "Complex query", plural: "Complex queries"};
const STAOperations = {RecursiveExpandSTA: {description: "Recursive Expand", callSTALoad: true, help: "Gets a table by selecting some columns and adding columns by expanding the properties of linked entities recursively. Needs to be connected to a SensorThings API or a STAplus node."},
ExpandColumnSTA: {description: "Expand entity", callSTALoad: true, help: "Gets a table by adding columns resulting of the expansion of the properties of a linked entity. For example, in a Datastream add properties of ObservedProperties. Requeres to be connected to a SensorThings API or a STAplus node."},
MergeExpandsSTA: {description: "Merge Expands", callSTALoad: true, help: "Gets a table by merging the fields of two branches originated as an expansion of the same entity. For example, in a Datastream node, a branch started by expanding ObservedProperties properties and a branch started by expanding Thing properties can be merged in a single branch by connecting the two branches as inputs to this node."},
SelectColumnsSTA: {description: "Select Columns", callSTALoad: true, help:"Gets a table only with columns selected. Requeres to be connected to a SensorThings API or a STAplus node."},
SelectRowSTA: {description: "Select Row", callSTALoad: true, help: "Gets a table only with the selected record. Requeres to be connected to another SensorThings API or a STAplus entity. A single record is required to related entities to this one and navegate the SensorThings API or a STAplus data model."},
FilterRowsSTA: {description: "Filter Rows", callSTALoad: true, help: "Gets a table with the records that match your conditions. Requeres to be connected to a SensorThings API or a STAplus node."},
FilterRowsByTime: {description: "Filter Rows by time", help: "Gets a table with records that match with a time interval. It is possible to group them by time periods. Requeres to be connected to a SensorThings API or a STAplus node."},
GeoFilterPolSTA: {description: "Filter Rows by Polygon", callSTALoad: true, help: "Gets a table with the records within a polygon. Requeres to be connected to another SensorThings API or a STAplus entity and to a table with a record that has a geometry (polygon)."},
GeoFilterPntSTA: {description: "Filter Rows by Distance", callSTALoad: true, help: "Gets a table with the records that are closer that a given distance of a point. Requeres to be connected to a SensorThings API or a STAplus node."},
SortBySTA: {description: "Sort by", callSTALoad: true, help: "Gets a table with data sorted by a given criteria. Requeres to be connected to a SensorThings API or a STAplus node."},
RangeSTA: {description: "Record range", callSTALoad: true, help: "Gets a table with a subset of the records limiting the number of records and skiping some initial records. <hr><small>Implements $top and $skip. Requeres to be connected to a SensorThings API or a STAplus node</small>."},
UploadObservations: {description: "Upload in STA", leafNode: true, help: "Saves some observations to a SensorThings API or a STAplus server."},
//UploadTimeAverages: {description: "Upload time averages", leafNode: true},
OneValueSTA: {description: "One Value", leafNode: true, help: "Shows the last posted value. This value is updated according to the time period you set. Requeres to be connected to another SensorThings API or a STAplus entity. Do not requre to connect to previous sort by time. This node can not be connected to other dependend nodes."},
CountResultsSTA: { description: "Count results", leafNode: true, help: "Returns the total number of records returned by the API query without loading them in a table. Only with STA data. Requeres to be connected to another SensorThings API or a STAplus entity. This node can not be connected to other dependend nodes."}};
const STAOperationsArray = Object.keys(STAOperations);
const STAOperationsType = {singular: "STA tool", plural: "STA tools"};
const TableOperations = {Table: {description: "View Table", leafNode: true, help: "Shows a table of the dependent node in a dialog box. Since the table behind the active node is represented in the table area, the use of this operation is no longer recommended."},
ViewQuerySTA: {description: "View Query", leafNode: true, help: "Shows the completed URL that is used to make the query to obtain the data from a service or an API of the depended node in a dialog box. Since the URL behind the active node is always represented in the query and table area, the use of this operation is no longer recommended."},
EditRecord: {description: "Edit record", help: "Shows and allows editing a record in the table of the related node. NOTE: If you are using data from a web service and you ask for data again, this change will be lost."},
Meaning: {description: "Column meaning", help: "Shows and allows editing the semantics (definition and units of measure) of the table columns."},
SelectColumnsTable: {description: "Select Columns", help: "Obtains a table only with the selected columns. Not recommended for SensorThings API or a STAplus entities as it removes the STA URL."},
SelectRowTable: {description: "Select Row", help: "Obtains a table only with the selected record. Not recommended for SensorThings API or a STAplus entities as it removes the STA URL."},
FilterRowsTable: {description: "Filter Rows", help: "Obtain a table with the records that match the contitions. Not recommended for SensorThings API or a STAplus entities as it removes the STA URL."},
JoinTables: {description: "Join Tables", help:"Creates a single table that is the result of joining two tables using some selected column values in both tables to defined the merge criteria."},
ConcatenateTables: {description: "Concatenate Columns", help: "Create a single table by adding the records of the second table to the first one. The columns with the same name in both tables are merged in a sigle column."},
GroupBy: {description: "Group by", help: "Creates a table will the columns containng selected statistics of the aggregation of some records that have the same values other selected columns."},
SortByTables: {description: "Sort by", callSTALoad: true, help: "Gets a table with data sorted by a given criteria."},
AggregateColumns: {description: "Aggregate Columns", help: "Adds a new column to a table with the aggregation of other previous selected columns."},
CreateColumns: {description: "Create Columns", help: "Adds a new column to your table. This column can be left empty, filled with a constant value or filled with an autoincremental value."},
ColumnsCalculator: {description: "Columns calculator", help: "Adds a new column to your table where for each record the new column contains the result of an operation involving other column values of that record."},
PivotTable: {description: "Pivot table", help:"Create a new table where some column content is transponsed into new columns" },
ColumnStatistics: {description:"Columns statistics", help: "Create a table where, for each column the main statistics for the column values of all records are recorded."},
SeparateColumns: {description: "Separate Columns", help: "Splits a column containing a JSON object into separated new columns and removes the original column."},
ScatterPlot: {description: "Scatter Plot", leafNode: true, help: "Creates a scatter plot with a the values of the column of a table."},
BarPlot: {description: "Bar Plot", leafNode: true, help: "Create a bar or pie chart with a the values of the column of a table."},
ImageViewer: {description: "Image Viewer", leafNode: true, help: "Shows the pictures referenced by a column. Assumes that the content of the column are url to images supported by the browser (commonly in JPEG or PNG format)."},
SaveTable: {description: "Save Table", leafNode: true, help: "Saves the table contained in the node as a CSV (and CSVW if the column definition is semantically enriched; see 'meaning')."},
SaveLayer: {description: "Save Layer", leafNode: true, help: "Saves the table as a GeoJSON. It requires two columns with a latitude and longitude values."},
OpenMap: {description: "Open Map", leafNode: true, help: "Opens a table as a map in a map browser interface. It requires two columns with a latitude and longitude values."},
guf: {description: "Feedback", help: "Retreives the geospatial user feedback related to the single row present in the table (e.g. a record forma CSW catalogue). It also allows for adding or editing feedback. It uses the NiMMbus repository and interface."}};
const TableOperationsArray = Object.keys(TableOperations);
const TableOperationsType = {singular: "Generic table tool", plural: "Generic table tools"};
//If the two nodes cannot connect it returns null. It transforms a plural to singular if needed.
function transformToSingularIfNeededSTAEntity(parentEntity, entityName) {
//Determinino si ha de ser singular o plural
for (var i=0; i<parentEntity.entities.length; i++)
{
if (parentEntity.entities[i].name==entityName)
return entityName;
else if (parentEntity.entities[i].name==STAEntities[entityName].singular)
return STAEntities[entityName].singular;
}
return null;
}
//considerEntityRelations means that in some paths you can find "Subject, Object..." that are relations to "Observations" Entity
function getSTAEntityPlural(entityName, considerEntityRelations) {
for (var i=0; i<STAEntitiesArray.length; i++) {
if (STAEntities[STAEntitiesArray[i]].singular==entityName)
return STAEntitiesArray[i];
}
if (considerEntityRelations) {
for (var i=0; i<STAEntitiesArray.length; i++) {
if ( STAEntities[STAEntitiesArray[i]].entityRelations) {
for (var j=0; j<STAEntities[STAEntitiesArray[i]].entityRelations.length; j++) {
if (STAEntities[STAEntitiesArray[i]].entityRelations[j]==entityName)
return STAEntitiesArray[i];
}
}
}
}
return entityName;
}
function getDataAttributeArraySTAEntity(name) {
var entity=STAEntities[getSTAEntityPlural(name, true)];
if (!entity)
return [];
var dataAttributeArray=["@iot.selfLink", "@iot.id"];
for (var e=0; e < entity.properties.length; e++)
dataAttributeArray.push(entity.properties[e].name);
for (var e=0; e < entity.entities.length; e++)
dataAttributeArray.push(entity.entities[e].name+"@iot.navigationLink");
return dataAttributeArray;
}
function getConnectionSTAEntity(parentNode, node) {
var parentPlural, parentEntity;
var idNode=IdOfSTAEntity(node);
if (idNode<0)
return {error: "Node is not a STA entity"};
var parentLastEntity=getSTAURLLastEntity(parentNode.STAURL);
if (STAEntities[parentLastEntity]){
parentPlural=true;
parentEntity=STAEntities[parentLastEntity];
} else {
for (var i=0; i<STAEntitiesArray.length; i++)
{
if (STAEntities[STAEntitiesArray[i]].singular==parentLastEntity)
{
parentPlural=false;
parentEntity=STAEntities[STAEntitiesArray[i]];
break;
}
}
if (i==STAEntitiesArray.length)
return {error: "Parent node is not a STA entity"};
}
var nextEntity=removeExtension(node.image);
if (!STAEntities[nextEntity])
return {error: "Child node is not a STA entity"};
if (parentPlural)
{
if (null!=getSTAURLSelectingARow(parentNode.STAURL))
{
//Determinino si ha de ser singular o plural
var entityName=transformToSingularIfNeededSTAEntity(parentEntity, nextEntity)
if (entityName)
return {entity: entityName};
else{
var n=parentEntity.entities.length, s= n ? parentEntity.entities[0].name : "";
for (var t=1; t<n; t++)
s+=", " + parentEntity.entities[t].name;
return {error: "The node connection does not match the STA data model. Connect '" + parentLastEntity + "' to one of the following: " + s};
}
}
else
{
//Is parentNode plural? Everything is incompatible
return {error: "A plural parent node requires \"select row\" before connecting to another STA entity (resulting in path parameters). Alternatively, use \"Expand entity\" to get each entity as a JSON in a single column that can be later separated in columns with \"Separate columns\"."};
}
}
//else
//Is parentNode singular?
var entityName=transformToSingularIfNeededSTAEntity(parentEntity, nextEntity);
if (entityName)
return {entity: entityName};
else{
var n=parentEntity.entities.length, s= n ? parentEntity.entities[0].name : "";
for (var t=1; t<n; t++)
s+=", " + parentEntity.entities[t].name;
return {error: "The node connection does not match the STA data model. Connect '"+ parentLastEntity +"' to one of the following: " + s};
}
}
//Return null if there is no reason (and there is a "fit").
function reasonNodeDoesNotFitWithPrevious(node, parentNode) {
if (parentNode.image == "sta.png" && (node.image == "FilterRowsSTA.png" || node.image == "SelectRowSTA.png" || node.image == "GeoFilterPolSTA.png" || node.image == "SelectColumnsSTA.png" || node.image == "ExpandColumnSTA.png" || node.image == "MergeExpandsSTA.png" || node.image == "RecursiveExpandSTA.png" || node.image == "SortBySTA.png" || node.image == "RangeSTA.png" || node.image == "OneValueSTA.png" || node.image == "SubscribeSTA.png" || node.image == "CountResultsSTA.png" ) )
return "The operation cannot be applied to the root of an STA. (Suggestion: connect a STA Entity first)";
if (parentNode.image=="sta.png" || parentNode.image=="staRoot.png" || parentNode.image=="edcAsset.png" || parentNode.image=="ogcAPICols.png" || parentNode.image=="csw.png")
return null;
if ((STAOperations[removeExtension(parentNode.image)] && STAOperations[removeExtension(parentNode.image)].leafNode==true) ||
(TableOperations[removeExtension(parentNode.image)] && TableOperations[removeExtension(parentNode.image)].leafNode==true))
return "Parent node is a leaf node and cannot be connected with any other node";
if (node.image == "SelectRowSTA.png" && parentNode.STASelectedExpands && parentNode.STASelectedExpands.expanded && Object.keys(parentNode.STASelectedExpands.expanded).length)
return "'Select Row' for STA node cannot be connected to an expanded branch. Use 'Filter row' for STA instead or select a row before expanding";
if (node.image == "OneValueSTA.png" && parentNode.STAEntityName!="Observations" && parentNode.image!="Observations.png")
return "'One value' node is designed be connected to an 'Observations' node only.";
var idNode=IdOfSTAEntity(node);
if (idNode<0)
return null;
if (!parentNode.STAURL)
return null;
if (node.image == "MergeExpandsSTA.png" && STAOperations[removeExtension(parentNode.image)])
return null;
var getCon=getConnectionSTAEntity(parentNode, node)
if (getCon.error)
return getCon.error;
return null;
}
window.onbeforeunload = function () { return "Your work will be lost."; }
function showInfoMessage(msg){
var elem=document.getElementById("clarification");
elem.innerHTML += (msg + "<br>");
elem.scrollTop=elem.scrollHeight; //https://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page
}
//Returns the id of the selected resource in the last part of the path. So extracts in the "entities(id)" extracts the id
function getSTAURLSelectingARow(url)
{
var s=getURLWithoutQueryParams(url);
var i=(s.charAt(s.length-1)=='/')? s.length-2 : s.length-1
if (s.charAt(i)!=')')
return null;
var ii=s.lastIndexOf('(');
if (ii==-1)
return null;
if (ii>s.lastIndexOf('/')+2)
{
var id=s.substring(ii+1, i);
if (id.charAt(0)=='\'' && id.charAt(id.length-1)=='\'')
return id.substring(1, id.length-1);
return id;
}
return null;
}
//Get the last entity of the path (without the filter, selection, expantion... or selection of a single entity by using (id))
function getSTAURLLastEntity(url)
{
var s=getURLWithoutQueryParams(url);
var i=(s.charAt(s.length-1)=='/')? s.length-2 : s.length-1;
if (s.charAt(i)!=')')
{
i=s.lastIndexOf('/')
if (-1!=s)
return s.substring(i+1);
return s;
}
i=s.lastIndexOf('(');
if (i==-1)
return s;
var ii=s.lastIndexOf('/');
if (i>ii+2)
return s.substring(ii+1, i);
return s.substring(ii+1);
}
function removeSTAURLNoQueryLastEntity(s)
{
var entity;
var i=(s.charAt(s.length-1)=='/')? s.length-2 : s.length-1;
if (s.charAt(i)!=')')
{
i=s.lastIndexOf('/')
if (-1==s)
return null;
entity=s.substring(i+1);
return STAEntities[getSTAEntityPlural(entity, false)] ? s.substring(0, i) : null;
}
i=s.lastIndexOf('(');
if (i==-1)
return null;
var ii=s.lastIndexOf('/');
if (i>ii+2) {
entity=s.substring(ii+1, i);
return STAEntities[getSTAEntityPlural(entity, false)] ? s.substring(0, ii) : null;
}
entity=s.substring(ii+1);
return STAEntities[getSTAEntityPlural(entity, false)] ? s.substring(0, ii) : null;
}
function getSTAURLRoot(url) {
var s, urlRoot=getURLWithoutQueryParams(url);
while (null!=(s=removeSTAURLNoQueryLastEntity(urlRoot))) {
urlRoot=s;
}
return urlRoot;
}
function getLang() {
if (navigator.languages != undefined)
return navigator.languages[0];
return navigator.language;
}
function removeExtraAmpersand(queryparams) {
if (!queryparams)
return queryparams;
var s;
if (queryparams.charAt(0)=='&') {
s=queryparams.substring(1);
if (!s)
return s;
}
else
s=queryparams;
if (queryparams.charAt(s.length-1)=='&')
return s.substring(0, queryparams.length-1);
return s;
}
//https://stackoverflow.com/questions/50036922/change-a-css-stylesheets-selectors-properties/50036923#50036923
function changeCSSStyle(selector, cssProp, cssVal) {
var cssRules = (document.all) ? 'rules': 'cssRules';
for (var ss=0, sslen=document.styleSheets.length; ss<sslen; ss++) {
for (var i=0, ilen=document.styleSheets[ss][cssRules].length; i<ilen; i++) {
if (document.styleSheets[ss][cssRules][i].selectorText === selector) {
document.styleSheets[ss][cssRules][i].style[cssProp] = cssVal;
return;
}
}
}
}
var currentNode=null, connectionInProcess=false, startingNodeContextId=null, startingEdgeContextId=null;
function ChangeToHTTPS(question) {
var response=true, s_protocol=getProtocol(location.href);
if (s_protocol && s_protocol.toLowerCase()!="https:") {
if (!question)
location.replace("https:" + location.href.substring(s_protocol.length));
else {
response=confirm("The page is not using secured HTTPS. Do you want to change to HTTPS?")
if (response)
location.replace("https:" + location.href.substring(s_protocol.length));
}
}
return response;
}
function StartSTAPage() {
ChangeToHTTPS(true);
//document.getElementById("UserInfoText").innerHTML="";
network=new vis.Network(document.getElementById("mynetwork"), {
nodes: networkNodes,
edges: networkEdges
}, networkOptions);
setEventFunctionsNetwork();
PrepareTextAreaCalculator();
UpdateConfiguration();
InitSTAPage(); //promise
}
function PlaceButtonsSTAEntities() {
var cdns = [];
var startButtonsOnly=document.getElementById("DialogConfigurationOnlyStartNodeButtons").checked
for (var i = 0; i < ServicesAndAPIsArray.length; i++) {
if (!startButtonsOnly || ServicesAndAPIs[ServicesAndAPIsArray[i]].startNode)
cdns.push(textOperationButton(null, "", ServicesAndAPIsArray[i], ServicesAndAPIs[ServicesAndAPIsArray[i]].name, ServicesAndAPIs[ServicesAndAPIsArray[i]].description, ServicesAndAPIs[ServicesAndAPIsArray[i]].help, ServicesAndAPIs[ServicesAndAPIsArray[i]], ServicesAndAPIsType.singular));
}
cdns.push("<br>");
if (!startButtonsOnly) {
for (var i = 0; i < STAEntitiesArray.length; i++)
cdns.push(textOperationButton(null, "", STAEntitiesArray[i], STAEntitiesArray[i], STAEntitiesArray[i], STAEntities[STAEntitiesArray[i]].help, null, STAEntitiesType.singular));
cdns.push("<br>");
/*for (var i = 0; i < STAEntitiesArray.length; i++)
cdns.push(textOperationButton(null, "", STAEntities[STAEntitiesArray[i]].singular, STAEntities[STAEntitiesArray[i]].singular, STAEntities[STAEntitiesArray[i]].singular, STAEntities[STAEntitiesArray[i]].helpEdit, null, STAEntitiesType.singularEdit));
cdns.push("<br>");*/
for (var i = 0; i < STASpecialQueriesArray.length; i++)
cdns.push(textOperationButton(null, "", STASpecialQueriesArray[i], STASpecialQueriesArray[i], STASpecialQueries[STASpecialQueriesArray[i]].description, STASpecialQueries[STASpecialQueriesArray[i]].help, null, STASpecialQueriesType.singular));
cdns.push("<br>");
}
for (var i = 0; i < STAOperationsArray.length; i++) {
if (!startButtonsOnly || STAOperations[STAOperationsArray[i]].startNode)
cdns.push(textOperationButton(null, "", STAOperationsArray[i], STAOperations[STAOperationsArray[i]].description, STAOperations[STAOperationsArray[i]].description, STAOperations[STAOperationsArray[i]].help, STAOperations[STAOperationsArray[i]], STAOperationsType.singular));
}
cdns.push("<br>");
for (var i = 0; i < TableOperationsArray.length; i++) {
if (!startButtonsOnly || TableOperations[TableOperationsArray[i]].startNode)
cdns.push(textOperationButton(null, "", TableOperationsArray[i], TableOperations[TableOperationsArray[i]].description, TableOperations[TableOperationsArray[i]].description, TableOperations[TableOperationsArray[i]].help, TableOperations[TableOperationsArray[i]], TableOperationsType.singular));
}
if (!startButtonsOnly)
cdns.push("<br>");
document.getElementById("ButtonsSTAEntities").innerHTML = cdns.join("");
}
var timeoutHelpToolTip=null;
function timeoutShowHelpToolTip(div) {
div.style.display="block";
timeoutHelpToolTip=null;
}
function showHelpToolTip(event, prefix, text) {
var div=document.getElementById(prefix+"HelpToolTip");
div.innerHTML=text;
moveHelpToolTip(event, prefix);
timeoutHelpToolTip=setTimeout(timeoutShowHelpToolTip, 1000, div);
return false;
}
function moveHelpToolTip(event, prefix) {
var div=document.getElementById(prefix+"HelpToolTip");
div.style.left=(event.clientX+2) + "px";
div.style.top=(event.clientY-div.offsetHeight+2) + "px";
return false;
}
function hideHelpToolTip(event, prefix) {
document.getElementById(prefix+"HelpToolTip").style.display="none";
if (timeoutHelpToolTip) {
clearTimeout(timeoutHelpToolTip);
timeoutHelpToolTip=null;
}
return false;
}
function textOperationButton(parentDivId, prefixDivId, operation, name, description, help, options, type) {
var s = "<button ";
if (help)
s+="onmouseover='showHelpToolTip(event, \"" + (prefixDivId ? prefixDivId : "") +"\", \"" +
"<b>" + (description ? description : name) + "</b><hr>" + help + "<hr>" + (type ? type + "<br>" : "") + (options?.startNode ? "<i>Start node</i><br>" : "") + (options?.leafNode ? "<i>Leaf node</i><br>" : "") +
"\")' onmousemove='moveHelpToolTip(event, \"" + (prefixDivId ? prefixDivId : "") +"\")' onmouseout='hideHelpToolTip(event, \"" + (prefixDivId ? prefixDivId : "") +"\")' "
return s + "onclick='addCircularImage(" + (parentDivId ? "event" : "null") + ", "+ (parentDivId ? ("\""+parentDivId+"\"") : "null") +", \"" + name + "\", \"" + operation + ".png\");'><img src='" + operation + ".png' height='20' valign='middle'> " + (description ? description : name) + "</button> ";
}
async function InitSTAPage() {
var response=await HTTPJSONData("config.json");
const nCol=4;
config=(response && response.obj) ? response.obj : null;
if (!config)
{
showInfoMessage("Error loading \'config.json\'");
return;
}
PlaceButtonsSTAEntities();
var s = ServicesAndAPIsType.plural + ":<br>";
for (var i = 0; i < ServicesAndAPIsArray.length; i++) {
s += textOperationButton("DialogContextMenu", "ContextMenu", ServicesAndAPIsArray[i], ServicesAndAPIs[ServicesAndAPIsArray[i]].name, ServicesAndAPIs[ServicesAndAPIsArray[i]].description, ServicesAndAPIs[ServicesAndAPIsArray[i]].help, ServicesAndAPIs[ServicesAndAPIsArray[i]], "Data Input tool", ServicesAndAPIsType.singular);
s += (i+1)%nCol==0 || i == ServicesAndAPIsArray.length-1 ? "<br>" : " ";
}
s += "<small><br></small>" + STAEntitiesType.plural + ":<br>";
for (var i = 0; i < STAEntitiesArray.length; i++) {
s += textOperationButton("DialogContextMenu", "ContextMenu", STAEntitiesArray[i], STAEntitiesArray[i], STAEntitiesArray[i], STAEntities[STAEntitiesArray[i]].help, null, STAEntitiesType.singular);
s += (i+1)%nCol==0 || i == STAEntitiesArray.length-1 ? "<br>" : " ";
}
s += "<small><br></small>" + STAEntitiesType.pluralEdit+ ":<br>";
for (var i = 0; i < STAEntitiesArray.length; i++)
{
s += textOperationButton("DialogContextMenu", "ContextMenu", STAEntities[STAEntitiesArray[i]].singular, STAEntities[STAEntitiesArray[i]].singular, STAEntities[STAEntitiesArray[i]].singular, STAEntities[STAEntitiesArray[i]].helpEdit, null, STAEntitiesType.singularEdit);
s += (i+1)%nCol==0 || i == STAEntitiesArray.length-1 ? "<br>" : " ";
}
s += "<small><br></small>" + STASpecialQueriesType.plural + ":<br>";
for (var i = 0; i < STASpecialQueriesArray.length; i++)
{
s += textOperationButton("DialogContextMenu", "ContextMenu", STASpecialQueriesArray[i], STASpecialQueriesArray[i], STASpecialQueries[STASpecialQueriesArray[i]].description, STASpecialQueries[STASpecialQueriesArray[i]].help, null, STASpecialQueriesType.singular);
s += (i+1)%nCol==0 || i == STASpecialQueriesArray.length-1 ? "<br>" : " ";
}
s += "<small><br></small>" + STAOperationsType.plural + ":<br>";
for (var i = 0; i < STAOperationsArray.length; i++)
{
s += textOperationButton("DialogContextMenu", "ContextMenu", STAOperationsArray[i], STAOperations[STAOperationsArray[i]].description, STAOperations[STAOperationsArray[i]].description, STAOperations[STAOperationsArray[i]].help, STAOperations[STAOperationsArray[i]], STAOperationsType.singular);
s += (i+1)%nCol==0 || i == STAOperationsArray.length-1 ? "<br>" : " ";
}
s += "<small><br></small>" + TableOperationsType.plural + "<br>";
for (var i = 0; i < TableOperationsArray.length; i++)
{
s += textOperationButton("DialogContextMenu", "ContextMenu", TableOperationsArray[i], TableOperations[TableOperationsArray[i]].description, TableOperations[TableOperationsArray[i]].description, TableOperations[TableOperationsArray[i]].help, TableOperations[TableOperationsArray[i]], TableOperationsType.singular);
s += (i+1)%nCol==0 || i == TableOperationsArray.length-1 ? "<br>" : " ";
}
document.getElementById("ButtonsContextMenuObjects").innerHTML = s;
window.addEventListener("message", ProcessMessageFromMiraMonMapBrowser);
if (window.opener)
window.opener.postMessage(JSON.stringify({msg: "Tapis is listening"}), "*");
}
//Works with JSON links.
//'type' is optional
function getLinkRelInLinks(links, rel, type) {
if (!links)
return null;
for (var i=0; i<links.length; i++) {
var link=links[i];
if (link?.rel==rel){
if (!link.type || !type || link.type==type)
return link.href;
}
}
return null;
}
function simplifyOGCAPICollections(collections){
var simpleCollecs=[], len=collections.length ? collections.length : 1;
for (var i=0; i<len; i++) {
var collection=collections.length ? collections[i] : collections;
simpleCollecs.push({id: collection?.id,
title: collection?.title,
link: getLinkRelInLinks(collection?.links, "self", "application/json"),
extent: collection?.extent,
itemType: collection?.itemType,
storageCrs: collection?.storageCrs,
defaultStyle: collection?.defaultStyle});
}
return simpleCollecs;
}
function addOnlinesDigitalTransferOption(simpleUrlRecords, digitalTransfer, id, title, schema, bbox) {
if (!digitalTransfer || !digitalTransfer['gmd:onLine'])
return;
var ol_len=(typeof digitalTransfer['gmd:onLine'].length==="undefined") ? 1 : digitalTransfer['gmd:onLine'].length;
for (var ol=0; ol<ol_len; ol++) {
var online=(typeof digitalTransfer['gmd:onLine'].length==="undefined") ? digitalTransfer['gmd:onLine']['gmd:CI_OnlineResource'] : digitalTransfer['gmd:onLine'][ol]['gmd:CI_OnlineResource'];
if (!online['gmd:linkage'] || !online['gmd:linkage']['gmd:URL'])
continue;
simpleUrlRecords.push({
id: id,
title: title,
dataURL: online['gmd:linkage']['gmd:URL'],
schemaURL: schema});
if (online['gmd:name'] && online['gmd:name']['gco:CharacterString'])
simpleUrlRecords[simpleUrlRecords.length-1].distribution=online['gmd:name']['gco:CharacterString'];
if (bbox.length)
simpleUrlRecords[simpleUrlRecords.length-1].extent=bbox;
}
}
function getSimplifyOGCCSWRecord(metadatas){
var simpleUrlRecords=[], id, title, bbox, schema;
for (var i=0; i<metadatas.length; i++)
{
var metadata=metadatas[i];
if (!metadata || !metadata['gmd:distributionInfo'])
continue;
id=""
if (metadata['gmd:fileIdentifier'] && metadata['gmd:fileIdentifier']['gco:CharacterString'])
id=metadata['gmd:fileIdentifier']['gco:CharacterString'];
title="";
schema="";
bbox=[];
if (metadata['gmd:identificationInfo']) {
var identification=(typeof metadata['gmd:identificationInfo'].length==="undefined") ? (metadata['gmd:identificationInfo']['gmd:MD_DataIdentification'] ? metadata['gmd:identificationInfo']['gmd:MD_DataIdentification'] : metadata['gmd:identificationInfo']['srv:SV_ServiceIdentification']) : (metadata['gmd:identificationInfo'][0]['gmd:MD_DataIdentification'] ? metadata['gmd:identificationInfo'][0]['gmd:MD_DataIdentification'] : metadata['gmd:identificationInfo'][0]['srv:SV_ServiceIdentification']);
if (identification && identification['gmd:citation']) {
var citation=identification['gmd:citation']['gmd:CI_Citation'];
if (citation && citation['gmd:title']['gco:CharacterString'])
title=citation['gmd:title']['gco:CharacterString'];
}
//Detemine the extent
if (identification && (identification['srv:extent'] || identification['gmd:extent'])) {
var extents=identification['srv:extent'] ? identification['srv:extent'] : identification['gmd:extent'];
var ex_len=(typeof extents.length==="undefined") ? 1 : extents.length;
for (var ex=0; ex<ex_len; ex++) {
var extent=(typeof extents.length==="undefined") ? extents['gmd:EX_Extent'] : extents[ex]['gmd:EX_Extent'];
if (extent && extent['gmd:geographicElement']) {
var ge_len=(typeof extent['gmd:geographicElement'].length==="undefined") ? 1 : extent['gmd:geographicElement'].length;
for (var ge=0; ge<ge_len; ge++) {
var gbb=(typeof extent['gmd:geographicElement'].length==="undefined") ? extent['gmd:geographicElement']['gmd:EX_GeographicBoundingBox'] : extent['gmd:geographicElement'][ge]['gmd:EX_GeographicBoundingBox'];
if (gbb) {
var n=0;
if (gbb['gmd:westBoundLongitude'] && gbb['gmd:westBoundLongitude']['gco:Decimal']) {
bbox.push(parseFloat(gbb['gmd:westBoundLongitude']['gco:Decimal']));
n++;
}
if (gbb['gmd:southBoundLatitude'] && gbb['gmd:southBoundLatitude']['gco:Decimal']) {
bbox.push(parseFloat(gbb['gmd:southBoundLatitude']['gco:Decimal']));
n++;
}
if (gbb['gmd:eastBoundLongitude'] && gbb['gmd:eastBoundLongitude']['gco:Decimal']) {
bbox.push(parseFloat(gbb['gmd:eastBoundLongitude']['gco:Decimal']));
n++;
}
if (gbb['gmd:northBoundLatitude'] && gbb['gmd:northBoundLatitude']['gco:Decimal']) {
bbox.push(parseFloat(gbb['gmd:northBoundLatitude']['gco:Decimal']));
n++;
}
if (n!=4)
bbox=[];
}
}
}
}
}
}
if (metadata['gmd:applicationSchemaInfo']) {
var asi_len=(typeof metadata['gmd:applicationSchemaInfo'].length==="undefined") ? 1 : metadata['gmd:applicationSchemaInfo'].length;
for (var asi=0; asi<asi_len; asi++) {
var appSchemaInfo=(typeof metadata['gmd:applicationSchemaInfo'].length==="undefined") ? metadata['gmd:applicationSchemaInfo']['gmd:MD_ApplicationSchemaInformation'] : metadata['gmd:applicationSchemaInfo'][asi]['gmd:MD_ApplicationSchemaInformation'];
if (appSchemaInfo['gmd:schemaLanguage'] && appSchemaInfo['gmd:schemaLanguage']['gco:CharacterString'].toLowerCase()=="json" &&
appSchemaInfo['gmd:constraintLanguage'] && appSchemaInfo['gmd:constraintLanguage']['gco:CharacterString'].toLowerCase()=="csvw")
{
if (appSchemaInfo['gmd:name']['gmd:CI_Citation']['gmd:title'] && appSchemaInfo['gmd:name']['gmd:CI_Citation']['gmd:title']['gmx:Anchor'] && appSchemaInfo['gmd:name']['gmd:CI_Citation']['gmd:title']['gmx:Anchor']['@xlink:href']) {
schema=appSchemaInfo['gmd:name']['gmd:CI_Citation']['gmd:title']['gmx:Anchor']['@xlink:href'];
break;
}
}
}
}
//There can be many online resources. For each online resource, a record is create.
var d_len=(typeof metadata['gmd:distributionInfo'].length==="undefined") ? 1 : metadata['gmd:distributionInfo'].length
for (var d=0; d<d_len; d++) {
var distribution=(typeof metadata['gmd:distributionInfo'].length==="undefined") ? metadata['gmd:distributionInfo']['gmd:MD_Distribution'] : metadata['gmd:distributionInfo'][d]['gmd:MD_Distribution'];
if (!distribution)
continue;
if (distribution['gmd:transferOptions']) {
var dt_len=(typeof distribution['gmd:transferOptions'].length==="undefined") ? 1 : distribution['gmd:transferOptions'].length;
for (var dt=0; dt<dt_len; dt++) {
addOnlinesDigitalTransferOption(simpleUrlRecords,
(typeof distribution['gmd:transferOptions'].length==="undefined") ? distribution['gmd:transferOptions']['gmd:MD_DigitalTransferOptions'] : distribution['gmd:transferOptions'][dt]['gmd:MD_DigitalTransferOptions'],
id, title, schema, bbox);
}
}
if (distribution['gmd:distributor']) {
var dtor_len=(typeof distribution['gmd:distributor'].length==="undefined") ? 1 : distribution['gmd:distributor'].length;
for (var dtor=0; dtor<dtor_len; dtor++) {
var distributor=(typeof distribution['gmd:distributor'].length==="undefined") ? distribution['gmd:distributor']['gmd:MD_Distributor'] : distribution['gmd:distributor'][dtor]['gmd:MD_Distributor'];
if (!distributor)
continue;
if (distributor['gmd:distributorTransferOptions']) {
var dt_len=(typeof distributor['gmd:distributorTransferOptions'].length==="undefined") ? 1 : distributor['gmd:distributorTransferOptions'].length;
for (var dt=0; dt<dt_len; dt++) {
addOnlinesDigitalTransferOption(simpleUrlRecords,
(typeof distributor['gmd:distributorTransferOptions'].length==="undefined") ? distributor['gmd:distributorTransferOptions']['gmd:MD_DigitalTransferOptions'] : distributor['gmd:distributorTransferOptions'][dt]['gmd:MD_DigitalTransferOptions'],
id, title, schema, bbox);
}
}
}
}
}
}
return simpleUrlRecords;
}
async function getSimplifyGUFRecord(metadata){
var simpleUrlRecord={
id: metadata['id'],
title: metadata['title'],
updated: metadata['updated']};
var response=await HTTPJSONData(metadata['link']['@href']);
var wpsexecute=(response && response.text) ? response.text : null;
if (!wpsexecute) {
showInfoMessage("Error retrieving "+metadata['link']['@href']);
return simpleUrlRecord;
}
var wpsex=JSON.parse(xml2json(parseXml(wpsexecute), false, null));
if (!wpsex || !wpsex['wps:ExecuteResponse'] || !wpsex['wps:ExecuteResponse']['wps:ProcessOutputs'] || !wpsex['wps:ExecuteResponse']['wps:ProcessOutputs']['wps:Output'] || !wpsex['wps:ExecuteResponse']['wps:ProcessOutputs']['wps:Output'].length) {
showInfoMessage("Error retrieving "+metadata['link']['@href']);
return simpleUrlRecord;
}
var outp=wpsex['wps:ExecuteResponse']['wps:ProcessOutputs']['wps:Output'][wpsex['wps:ExecuteResponse']['wps:ProcessOutputs']['wps:Output'].length-1]
if (!outp || !outp['wps:Data'] || !outp['wps:Data']['wps:ComplexData'] || !outp['wps:Data']['wps:ComplexData']['guf:GUF_FeedbackItem']) {
showInfoMessage("Error retrieving "+metadata['link']['@href']);
return simpleUrlRecord;
}
var feedbackItem=outp['wps:Data']['wps:ComplexData']['guf:GUF_FeedbackItem'];
if (feedbackItem['guf:abstract'] && feedbackItem['guf:abstract']['gco:CharacterString'])
simpleUrlRecord.abstract=feedbackItem['guf:abstract']['gco:CharacterString'];
if (feedbackItem['guf:contact'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails']['cit:CI_Individual'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails']['cit:CI_Individual']['cit:partyIdentifier'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails']['cit:CI_Individual']['cit:partyIdentifier']['mcc:MD_Identifier'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails']['cit:CI_Individual']['cit:partyIdentifier']['mcc:MD_Identifier']['mcc:description'] &&
feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails']['cit:CI_Individual']['cit:partyIdentifier']['mcc:MD_Identifier']['mcc:description']['gco:CharacterString'])
simpleUrlRecord.owner=feedbackItem['guf:contact']['guf:GUF_UserInformation']['guf:userDetails']['cit:CI_Individual']['cit:partyIdentifier']['mcc:MD_Identifier']['mcc:description']['gco:CharacterString']
if (feedbackItem['guf:rating'] &&
feedbackItem['guf:rating']['guf:GUF_Rating'] &&
feedbackItem['guf:rating']['guf:GUF_Rating']['guf:rating'] &&
feedbackItem['guf:rating']['guf:GUF_Rating']['guf:rating']['guf:GUF_RatingCode'] &&
feedbackItem['guf:rating']['guf:GUF_Rating']['guf:rating']['guf:GUF_RatingCode']['@codeListValue'])
simpleUrlRecord.rating=feedbackItem['guf:rating']['guf:GUF_Rating']['guf:rating']['guf:GUF_RatingCode']['@codeListValue'];
if (feedbackItem['guf:userComment'] &&
feedbackItem['guf:userComment']['guf:GUF_UserComment'] &&
feedbackItem['guf:userComment']['guf:GUF_UserComment']['guf:comment'] &&
feedbackItem['guf:userComment']['guf:GUF_UserComment']['guf:comment']['gco:CharacterString'])
simpleUrlRecord.comment=feedbackItem['guf:userComment']['guf:GUF_UserComment']['guf:comment']['gco:CharacterString'];
return simpleUrlRecord;
}
async function getSimplifyGUFRecords(metadatas){
var simpleUrlRecords=[], id, title;
if (!metadatas)
return null;
if (metadatas.length) {
for (var i=0; i<metadatas.length; i++) {
var metadata=metadatas[i];
if (!metadata)
continue;
simpleUrlRecords.push(await getSimplifyGUFRecord(metadata));
}
} else
simpleUrlRecords.push(await getSimplifyGUFRecord(metadatas));
return simpleUrlRecords;
}
function updateQueryAndTableArea(node) {
var nodeId = network.getSelectedNodes();
for (var i=0; i<nodeId.length; i++) {
if (nodeId[i]==node.id) {
ShowQueryNode(node);
ShowTableNode(node);
}
}
}
async function LoadJSONNodeSTAData(node, callback, url) {
var response, jsonData, options={};
try {
var url_fetch;
if (url)
url_fetch=url;
else if ((typeof node.OGCExpectedLength==="undefined" && (!node.STASelectedExpands || typeof node.top==="undefined")) || node?.OGCType == "OGCAPIcollection")
url_fetch=node.STAURL;
else if (node.STASelectedExpands && typeof node.STASelectedExpands.top!=="undefined")
url_fetch=AddQueryParamsToURL(node.STAURL, "$top=" + node.STASelectedExpands.top);
else
url_fetch=AddQueryParamsToURL(node.STAURL, ((node.OGCType == "OGCAPIcollections" || node.OGCType == "OGCAPIitems") ? "limit=" : ((node.OGCType == "GUF") ? "COUNT=" : "$top=")) + node.OGCExpectedLength);
AddHeadersIfNeeded(options, node.STAsecurity);
if (options.headers)
response = await fetch(url_fetch, options);
else
response = await fetch(url_fetch);
}
catch (error) {
showInfoMessage('There was an error with ' + node.STAURL + ": " + error.message);
console.log('There was an error', error);
node.STAdata = null;
networkNodes.update(node);
return;
}
// Uses the 'optional chaining' operator
if (!(response?.ok)) {
showInfoMessage("HTTP Response Code: " + response?.status + " reading <small>" + node.STAURL + "</small>: " + response?.statusText);
console.log("HTTP Response Code: " + response?.status + ": " + response?.statusText);
node.STAdata = null;
networkNodes.update(node);
return;
}
try {
if (node.OGCType=="OGCCSW" || node.OGCType=="GUF")
jsonData = JSON.parse(xml2json(parseXml(await response.text()), false, null));
else
jsonData = await response.json();
} catch (error) {
if (error instanceof SyntaxError) {
showInfoMessage('Syntax error reading ' + node.STAURL + ": " + error.message);
console.log('There was a SyntaxError', error);
node.STAdata = null;
networkNodes.update(node);
return;
}
else {
showInfoMessage('Error interpreting ' + node.STAURL + ": " + error.message);
console.log('There was an error', error);
node.STAdata = null;
networkNodes.update(node);
return;
}
}
var nextLink;
if (url && (typeof node.OGCExpectedLength!=="undefined" || (node.STASelectedExpands && typeof node.STASelectedExpands.top!=="undefined"))) {
if (node.OGCType=="OGCAPIcollections")
node.STAdata.push(...simplifyOGCAPICollections(jsonData.collections));
if (node.OGCType=="OGCAPIcollection")
node.STAdata.push(...simplifyOGCAPICollections(jsonData));
else if (node.OGCType=="OGCAPIitems")
node.STAdata.push(...TransformGeoJSONToTable(jsonData));
else if (node.OGCType=="OGCCSW")
node.STAdata.push(...getSimplifyOGCCSWRecord(jsonData['csw:GetRecordsResponse']['csw:SearchResults']['gmd:MD_Metadata']));
else if (node.OGCType=="GUF")
node.STAdata.push(...await getSimplifyGUFRecords(jsonData['feed']['entry']));
else {
node.STAdata.push(...jsonData.value);
nextLink = jsonData["@iot.nextLink"];
}
if (node.STASelectedExpands && typeof node.STASelectedExpands.top!=="undefined") {
if (node.STAdata.length>node.STASelectedExpands.top) {
node.STAdata.length=node.STASelectedExpands.top; //too much data. Trucating
nextLink=null;
}
} else if (node.STAdata.length>node.OGCExpectedLength && node.STAdata.length>node.OGCExpectedLength) {
if (node.STAdata.length>node.OGCExpectedLength) {
node.STAdata.length=node.OGCExpectedLength; //too much data. Trucating
nextLink=null;
}
}
} else {
if (node.OGCType=="OGCAPIcollections") {
node.STAdata = (typeof jsonData.collections!=="undefined") ? simplifyOGCAPICollections(jsonData.collections) : [jsonData];
nextLink = getLinkRelInLinks(jsonData["links"], "next", "application/json");
} else if(node.OGCType=="OGCAPIcollection") {
node.STAdata = simplifyOGCAPICollections(jsonData);
//nextLink: This should be one object without "next".
} else if (node.OGCType=="OGCAPIitems") {
node.STAdata = (jsonData.type=="FeatureCollection") ? TransformGeoJSONToTable(jsonData) : [jsonData];
nextLink = getLinkRelInLinks(jsonData["links"], "next", "application/geo+json");
} else if(node.OGCType=="OGCAPIitem") {
node.STAdata = (jsonData.type=="FeatureCollection") ? TransformGeoJSONToTable(jsonData) : [jsonData];
//nextLink: This should be one object without "next".
} else if (node.OGCType=="OGCCSW") {
node.STAdata = getSimplifyOGCCSWRecord(jsonData['csw:GetRecordsResponse']['csw:SearchResults']['gmd:MD_Metadata']);
} else if (node.OGCType=="GUF") {
node.STAdata = await getSimplifyGUFRecords(jsonData['feed']['entry']);
} else {
node.STAdata = (typeof jsonData.value!=="undefined") ? jsonData.value : [jsonData];
nextLink = jsonData["@iot.nextLink"];
}
}
if (jsonData.value && (
(node.STASelectedExpands && typeof node.STASelectedExpands.top!=="undefined" && node.STAdata.length<node.STASelectedExpands.top) ||
(node.OGCExpectedLength && node.STAdata.length<node.OGCExpectedLength)
) && nextLink)
{
networkNodes.update(node);
await LoadJSONNodeSTAData(node, callback, jsonData["@iot.nextLink"]);
}
else
{
if (node.image!="sta.png" && !node.OGCType && node.image!="staRoot.png")
{
node.STAdataAttributes=getDataAttributes(node.STAdata);
addSemanticsSTADataAttributes(node.STAdataAttributes, node.STAURL);
}
networkNodes.update(node);
if (node.image!="FilterRowsByTime.png"){
showInfoMessage("Completed.");
}
updateQueryAndTableArea(node);
await UpdateChildenLoadJSONCallback(node);
if (callback)
callback(node); //The callback function is never used yet.
}
}
var savedFile = null;
function MakeHrefData(data, mediatype)
{
var blobData = new Blob([data], {type: mediatype});
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (savedFile !== null)
window.URL.revokeObjectURL(savedFile);
savedFile = window.URL.createObjectURL(blobData);
return savedFile;
}
//type should be "CSV", "DBF", "JSON", "JSONLD" or "GeoJSON"
function SelectImportFileSource(event, type) {
if (document.getElementById("DialogImport"+type+"SourceFile").checked) {
document.getElementById("DialogImport"+type+"SourceFileText").disabled=false;
document.getElementById("DialogImport"+type+"SourceURLInput").disabled=true;
document.getElementById("DialogImport"+type+"SourceURLButton").disabled=true;
} else /*if (document.getElementById("DialogImport"+type+"SourceURL").checked)*/ {
document.getElementById("DialogImport"+type+"SourceFileText").disabled=true;
document.getElementById("DialogImport"+type+"SourceURLInput").disabled=false;
document.getElementById("DialogImport"+type+"SourceURLButton").disabled=false;
}
}
//type should be "CSV", "DBF", "JSON", "JSONLD" or "GeoJSON"
function SelectImportMeaningFileSource(event, type) {
if (document.getElementById("DialogImportMeaning"+type+"SourceFile").checked) {
document.getElementById("DialogImportMeaning"+type+"SourceFileText").disabled=false;
document.getElementById("DialogImportMeaning"+type+"SourceURLInput").disabled=true;
document.getElementById("DialogImportMeaning"+type+"SourceURLButton").disabled=true;
} else if (document.getElementById("DialogImportMeaning"+type+"SourceURL").checked) {
document.getElementById("DialogImportMeaning"+type+"SourceFileText").disabled=true;
document.getElementById("DialogImportMeaning"+type+"SourceURLInput").disabled=false;
document.getElementById("DialogImportMeaning"+type+"SourceURLButton").disabled=false;
} else /*if (document.getElementById("DialogImportMeaning"+type+"SourceAuto").checked)*/ {
document.getElementById("DialogImportMeaning"+type+"SourceFileText").disabled=true;
document.getElementById("DialogImportMeaning"+type+"SourceURLInput").disabled=true;
document.getElementById("DialogImportMeaning"+type+"SourceURLButton").disabled=true;
}
}
function RetrieveMeaningTableCallback(usage_descr, params_function) {
if (usage_descr.codeMediaType=="application/json" && usage_descr.schema==urlSchemaMeaning)
params_function.node.STAdataAttributes=JSON.parse(usage_descr.code); //The saved format is tha TAPIS internal format
networkNodes.update(params_function.node);
showInfoMessage("Meaning retrieved from NiMMbus.");
}
function RetrieveMeaningTable(event, type) {
event.preventDefault(); // We don't want to submit this form
if (document.getElementById("DialogImportMeaning"+type+"SourceAuto")?.checked &&
document.getElementById("DialogImport"+type+"SourceURL").checked &&
document.getElementById("DialogImport"+type+"SourceURLInput").value) {
var urlCSV=document.getElementById("DialogImport"+type+"SourceURLInput").value
GUFLoadLastPreviousReproducibleUsageCode(getFileName(urlCSV),
getAddressPath(getAbsoluteURL(urlCSV)),
{ru_platform: "https://github.com/joanma747/TAPIS",
ru_version: 0.9
//ru_schema: urlSchemaMeaning
}, "eng", null, RetrieveMeaningTableCallback, {node: currentNode});
}
UpdateChildenTable(currentNode);
if (!currentNode.STAdata) {
if (confirm("No data has been loaded. Do you want to close this window anyway?"))
document.getElementById("DialogImport"+type).close();
}
else{
currentNode.STAdataAttributes= getDataAttributes(currentNode.STAdata); //It is necessary when you load new csv, because it remember dataAttributes from old csv
networkNodes.update(currentNode)
document.getElementById("DialogImport"+type).close();
}
}
function TransformTextCSVWToDataAttributes(csvwText)
{
var data_csvw=JSON.parse(csvwText);
currentNode.STAdataAttributes=getDataAttributesCSVW(data_csvw);
networkNodes.update(currentNode);
UpdateChildenTable(currentNode);
var csvReadParams = getCSVReadParams(data_csvw);