forked from COATnor/coat2pycsw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.j2
377 lines (374 loc) · 17.3 KB
/
main.j2
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
{
{# INSPIRE ISO19139 Metadata Schema #}
{% set language = record['language']|get_raw_value_from_ckan_schema(ckan_schema, 'language')%}
{% set dcat_type = record['dcat_type'].rsplit('/', 1)[-1] %}
"mcf": {"version": 1.0},
"metadata": {
"identifier": "{{ record['id'] }}",
"language": "{{ language }}",
"charset": "UTF-8",
{% if record['source'] %}
"parentidentifier": "{{ record['source'].rsplit('/', 1)[-1] }}",
{% endif %}
"datestamp": "{{ record['metadata_modified']|normalize_datetime }}",
"dataseturi": "{{ url }}",
{% if dcat_type == 'service' %}
{% if "catalog" in record['title'].lower() or "csw" in record['title'].lower() %}
"servicetype": "discovery",
{% elif "wfs" in record['title'].lower() or "descarg" in record['title'].lower() %}
"servicetype": "download",
{% elif "wms" in record['title'].lower() or "wmts" in record['title'].lower() or "wcs" in record['title'].lower() or "map" in record['title'].lower() %}
"servicetype": "view",
{% else %}
"servicetype": "other",
{% endif %}
{% endif %}
"hierarchylevel": {
"value": "{{ dcat_type }}",
"uri": "{{ record['dcat_type'] }}"
}
},
"spatial": {
{% if record['reference_system'] is defined %}
"crs": {
"value": "{{ record['reference_system'].rsplit('/', 1)[-1] }}",
"uri": "{{ record['reference_system'] }}"
},
{% elif record['conforms_to'] %}
{% for conform in record['conforms_to'] %}
{% if "epsg" in conform.lower() %}
"crs": {
"value": "{{ conform.rsplit('/', 1)[-1] }}",
"uri": "{{ conform }}"
},
{% else %}
"crs": {
"value": "4326",
"uri": "http://www.opengis.net/def/crs/EPSG/0/4326"
},
{% endif %}
{% endfor %}
{% else %}
"crs": {
"value": "4326",
"uri": "http://www.opengis.net/def/crs/EPSG/0/4326"
},
{% endif %}
{# MD_GeometricObjectTypeCode: Not in INSPIRE #}
{% if record['spatial_resolution_in_meters'] %}
"spatialresolution": "{{ record['spatial_resolution_in_meters'] }}",
{% endif %}
{% if record['representation_type'] %}
"datatype": "{{ record['representation_type']|get_raw_value_from_ckan_schema(ckan_schema, 'representation_type') }}"
{% else %}
"datatype": "vector"
{% endif %}
},
"identification": {
"language": "{{ language }}",
"languagelabel": "{{ language|get_mapping_value_from_yaml_list(input_field="value", output_field='label', codelist="language",mappings_folder=mappings_folder + "/ckan_geodcatap")}}",
"charset": "utf8",
"title": "{{ record['title'] }}",
"abstract": "{{ record['notes'] }}",
{% if record['version'] %}
"edition": "{{ record['version'] }}",
{% endif %}
"dates": {
{% if record['created'] %}
"creation": "{{ record['created']|normalize_datetime }}",
{% else %}
"creation": "{{ '1900-01-01T00:00:00Z'|normalize_datetime }}",
{% endif %}
{% if record['issued'] or record['metadata_created'] %}
{% if record['issued'] %}
"publication": "{{ record['issued']|normalize_datetime }}",
{% else %}
"publication": "{{ record['metadata_created']|normalize_datetime }}",
{% endif %}
{% endif %}
{% if record['modified'] or record['metadata_created'] %}
{% if record['modified'] %}
"revision": "{{ record['modified']|normalize_datetime }}"
{% else %}
"revision": "{{ record['metadata_modified']|normalize_datetime }}"
{% endif %}
{% endif %}
},
{# INSPIRE Themes #}
"keywords": {
{% if record['theme'] %}
"inspire": {
"keywords": [
{% for theme in record['theme'] %}
{
"label": "{{ theme|get_mapping_value_from_yaml_list(input_field="theme", output_field='label', codelist="theme-dcat_ap",mappings_folder=mappings_folder + "/ckan_geodcatap") }}",
"uri": "{{ theme }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
],
"vocabulary": {
"name": "GEMET - INSPIRE themes, version 1.0",
"url" : "http://www.eionet.europa.eu/gemet/inspire_themes",
"date": "2008-06-01"
}
},
{% endif %}
{#TODO: Add INSPIRE Priority dataset URI to CKAN #}
{% if record['priority_dataset'] %}
"prioritydataset": {
"keywords": [{
"label": "{{ record['priority_dataset'].rsplit('/', 1)[-1] }}",
"value": "{{ record['priority_dataset'].rsplit('/', 1)[-1] }}",
"uri": "{{ record['priority_dataset'] }}"
}],
"vocabulary": {
"name": "INSPIRE priority data set",
"url" : "http://inspire.ec.europa.eu/metadata-codelist/PriorityDataset",
"date": "2018-04-04"
}
},
{% endif %}
{#TODO: Improve tag/tag_uri info to provide a label #}
{% set keywords_gemet = [] %}
{% set keywords_spatialscope = [] %}
{% set keywords_spatialdataservice = [] %}
{% for keyword in record['tag_uri'] %}
{% if 'gemet' in keyword.lower() %}
{% set gemet_keyword = {
"value": keyword.rsplit('/', 1)[-1],
"uri": keyword
} %}
{% set _ = keywords_gemet.append(gemet_keyword) %}
{% elif 'spatialscope' in keyword.lower() %}
{% set spatial_keyword = {
"label": keyword|get_mapping_value_from_yaml_list(input_field="uri", output_field='label', codelist="spatial_scope",mappings_folder=mappings_folder + "/ckan_geodcatap"),
"value": keyword.rsplit('/', 1)[-1],
"uri": keyword
} %}
{% set _ = keywords_spatialscope.append(spatial_keyword) %}
{% elif 'spatialdataservice ' in keyword.lower() %}
{% set spatialdataservice_keyword = {
"label": keyword|get_mapping_value_from_yaml_list(input_field="uri", output_field='label', codelist="spatial_data_service_category",mappings_folder=mappings_folder + "/ckan_geodcatap"),
"value": keyword.rsplit('/', 1)[-1],
"uri": keyword
} %}
{% set _ = keywords_spatialdataservice.append(spatialdataservice_keyword) %}
{% endif %}
{% endfor %}
{# GEMET Keywords #}
"gemet": {
{% if keywords_gemet %}
"keywords": {{ keywords_gemet|tojson }},
{% else %}
"keywords": [{
"label": "Spatial distribution",
"value": "11118",
"uri": "https://www.eionet.europa.eu/gemet/en/concept/11118"
}],
{% endif %}
"vocabulary": {
"name": "GEMET - Concepts, version 4.2.3",
"url" : "http://www.eionet.europa.eu/gemet",
"date": "2021-12-06"
}
},
{# Classification of spatial data services #}
{% if dcat_type == 'service' %}
"spatialdataservice": {
{% if keywords_spatialdataservice %}
"keywords": {{ keywords_spatialdataservice|tojson }},
{% else %}
"keywords": [{
"label": "Geographic model/information management service",
"value": "infoManagementService",
"uri": "http://inspire.ec.europa.eu/metadata-codelist/SpatialDataServiceCategory/infoManagementService"
}],
{% endif %}
"vocabulary": {
"name": "Commission Regulation (EC) No 1205/2008 of 3 December 2008 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards metadata",
"url" : "http://data.europa.eu/eli/reg/2008/1205",
"date": "2008-12-03"
}
},
{% endif %}
{# Spatial Scope #}
"spatialscope": {
{% if keywords_spatialscope %}
"keywords": {{ keywords_spatialscope|tojson }},
{% else %}
"keywords": [{
"label": "National",
"value": "national",
"uri": "http://inspire.ec.europa.eu/metadata-codelist/SpatialScope/national"
}],
{% endif %}
"vocabulary": {
"name": "Spatial scope",
"url" : "http://inspire.ec.europa.eu/metadata-codelist/SpatialScope",
"date": "2019-05-22"
}
}
},
"topiccategory": [
{% if record['topic'] %}
"{{ record['topic'].rsplit('/', 1)[-1] }}"
{% else %}
"biota"
{% endif %}
],
"extents": {
{% if record['spatial'] %}
{% set spatial_data = record['spatial'] %}
{% elif record['extras'] and record['extras']["key"] == "spatial"%}
{% set spatial_data = record['extras']["value"]%}
{% endif %}
"spatial": [
{
{% if spatial_data %}
"bbox": "{{ spatial_data|get_bbox }}",
{% else %}
{# Spain BBox #}
"bbox": "[-19.00, 27.60, 4.30, 44.60]",
{% endif %}
"crs": 4326
}
]
{% if record['temporal_start'] and record['temporal_end'] %}
,
"temporal": [
{
"begin": "{{ record['temporal_start'] }}",
"end": "{{ record['temporal_end'] }}"
}
]
{% endif %}
},
"fees": "None",
{% if record['license_title'] and record['license_url'] %}
"uselimitation": {
"label": "{{record['license_title'] }}",
"url" : "{{ record['license_url'] }}"
},
{% else %}
"otherconstraints": "noConditionsApply",
{% endif %}
{% if record['access_rights']%}
{% if dcat_type == "service" %}
"accessconstraints": {
"label": "Public access to spatial data sets and services would adversely affect the confidentiality of commercial or industrial information, where such confidentiality is provided for by national or Community law to protect a legitimate economic interest, including the public interest in maintaining statistical confidentiality and tax secrecy.",
"uri": "http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/INSPIRE_Directive_Article13_1d"
},
{% else %}
"accessconstraints": {
"label": "{{ record['access_rights']|get_mapping_value_from_yaml_list(input_field="uri", output_field='definition', codelist="rights",mappings_folder=mappings_folder + "/ckan_geodcatap") }}",
"uri": "{{ record['access_rights'] }}"
},
{% endif %}
{% endif %}
"url": "{{ url }}",
"status": "UnderDevelopment",
{#TODO: https://inspire.ec.europa.eu/metadata-codelist/MaintenanceFrequency #}
"maintenancefrequency": "continual"
},
"contact": {
{% if record['publisher_name'] is defined %}
"publisher": {
{% if record['publisher_name'] %}
"organization": "{{ record['publisher_name'] }}",
{% endif %}
{% if record['publisher_email'] %}
"email": "{{ record['publisher_email'] }}",
{% endif %}
{% if record['publisher_url'] %}
"url": "{{ record['publisher_url'] }}"
{% endif %}
},
{% endif %}
{% if record['author_name'] is defined %}
"author": {
{% if record['author_name'] %}
"individualname": "{{ record['author_name'] }}",
{% endif %}
{% if record['author_email'] %}
"email": "{{ record['author_email'] }}",
{% endif %}
{% if record['author_url'] %}
"url": "{{ record['author_url'] }}"
{% endif %}
},
{% endif %}
"pointOfContact": {
"organization": "{{ record['contact_name'] }}",
"email": "{{ record['contact_email'] }}",
"url": "{{ record['contact_url'] }}"
}
},
"distribution": {
{% for resource in record['resources'] %}
{% if resource.format is not none and resource.format != "" %}
{% set distribution_type = resource.format.rsplit('/', 1)[-1]|get_mapping_values_dict_from_yaml_list(input_field='format', output_field='identifier', codelist='distribution_type', mappings_folder=mappings_folder + '/inspire') %}
"{{ resource.format.lower() }}": {
"name": "{{ resource['name'] }}",
{% if resource_type == "service" and 'wms' in resource['format'] or 'wfs' in resource['format'] or 'wmts' in resource['format'] or 'wcs' in resource['format'] or 'ogc' in resource['format'] %}
"description": "{{ resource['description'] }}",
{% elif resource['description'] is not none and resource['description'] != "" %}
"description": "{{ resource['description'] }}",
{% endif %}
"format": "{{ resource['format'] }}",
{% if distribution_type is mapping %}
"format_uri": "{{ distribution_type['uri'] }}",
{% elif resource['mimetype'] is not none and resource['mimetype'] != "" %}
"format_uri": "{{ resource['mimetype'] }}",
{% endif %}
{% if resource['format_version'] %}
"format_version": "{{ resource['format_version'] }}",
{% else %}
"format_version": "{{ resource['format_version'] }}",
{% endif %}
{% if distribution_type is mapping and distribution_type['identifier'] %}
"type": "{{ distribution_type['identifier'] }}",
{% else %}
"type": "{{ resource['format'] }}",
{% endif %}
"url": "{{ resource['url'] }}",
{% if 'wfs' in resource['format'] %}
"function": "download"
{% else %}
"function": "information"
{% endif %}
}
{% if not loop.last %},{% endif %}
{% endif %}
{% endfor %}
},
"dataquality": {
"scope": {
"level": "{{ record['dcat_type'].rsplit('/', 1)[-1] }}"
},
"lineage": {
{% if record['lineage_process_steps'] %}
"processstep": [
{% for step in record['lineage_process_steps'] %}
{
"description": "{{ step }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
],
{% endif %}
{% if record['lineage_source'] %}
"source": [
{% for source in record['lineage_source'] %}
{
"description": "{{ source }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
],
{% endif %}
{% if record['lineage_statement'] %}
"statement": "{{ record['provenance'] }}"
{% else %}
"statement": "No lineage statement provided"
{% endif %}
}
}
}