1 | (: Version for one DIF per dgMetadata instance :) |
---|
2 | (: Note algoritm for creating non-pre-existing organisations :) |
---|
3 | (: dgPersons are not created as one can't tell automatically which are people and which are orgs, and orgs are simpler :) |
---|
4 | import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; |
---|
5 | import module namespace inputParse='http://ndg.nerc.ac.uk/xquery/lib/inputParse' at 'xmldb:exist:///db/xqueryLib/Utilities/inputParse_xquery_lib.xquery'; |
---|
6 | declare default element namespace 'http://ndg.nerc.ac.uk/moles'; |
---|
7 | declare namespace dif='http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'; |
---|
8 | declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance'; |
---|
9 | |
---|
10 | (: Replacable parameters :) |
---|
11 | declare variable $targetCollection as xs:string {'/db/discovery'}; |
---|
12 | declare variable $input_repository as xs:string {'Input_Repository_Code'}; |
---|
13 | declare variable $input_repository_local as xs:string {'Input_Repository_LocalID'}; |
---|
14 | declare variable $input_entry_id as xs:string {'ndg.noc.soton.ac.uk__DIF__NOCSDAT110'}; |
---|
15 | declare variable $localIdentifier as xs:string {'ndg.noc.soton.ac.uk__DIF__NOCSDAT110'}; |
---|
16 | |
---|
17 | declare variable $output_local_id as xs:string {'Output_LocalID'}; |
---|
18 | (: Keep |
---|
19 | declare variable $targetCollection as xs:string {'TargetCollection'}; |
---|
20 | declare variable $input_repository as xs:string {'Input_Repository_Code'}; |
---|
21 | declare variable $input_repository_local as xs:string {'Input_Repository_LocalID'}; |
---|
22 | declare variable $input_entry_id as xs:string {'Input_Entry_ID'}; |
---|
23 | declare variable $output_local_id as xs:string {'Output_LocalID'}; |
---|
24 | :) |
---|
25 | for $DIF in collection($targetCollection)/dif:DIF[dif:Entry_ID=$input_entry_id] |
---|
26 | return |
---|
27 | element dgMetadata { |
---|
28 | element dgMetadataRecord { |
---|
29 | element dgMetadataID { |
---|
30 | element schemeIdentifier {'NDG-B0'}, |
---|
31 | element repositoryIdentifier {$input_repository}, |
---|
32 | if ($output_local_id != 'Output_LocalID') then |
---|
33 | element localIdentifier {$output_local_id} |
---|
34 | else |
---|
35 | element localIdentifier {data($DIF/dif:Entry_ID)} |
---|
36 | }, |
---|
37 | element dgMetadataDescription { |
---|
38 | element metadataDescriptionID { |
---|
39 | element schemeIdentifier {'NDG-B0'}, |
---|
40 | element repositoryIdentifier {$input_repository}, |
---|
41 | if ($output_local_id != 'Output_LocalID') then |
---|
42 | element localIdentifier {concat('generated_desc-', $output_local_id)} |
---|
43 | else |
---|
44 | element localIdentifier {concat('generated_desc-', escape-uri(string($DIF/dif:Entry_ID), true()))} |
---|
45 | }, |
---|
46 | element metadataDescriptionLastUpdated {current-date()} , |
---|
47 | element abstract { |
---|
48 | element abstractText {string($DIF/dif:Summary)} |
---|
49 | } |
---|
50 | , |
---|
51 | for $descOnline in $DIF/dif:Related_URL |
---|
52 | return |
---|
53 | element descriptionSection { |
---|
54 | element descriptionOnlineReference { |
---|
55 | element dgSimpleLink {escape-uri(data($descOnline/dif:URL), true())}}, |
---|
56 | if (exists($descOnline/dif:URL_Content_Type)) then |
---|
57 | element dgReferenceName {data($descOnline/dif:URL_Content_Type)} |
---|
58 | else () |
---|
59 | } |
---|
60 | }, |
---|
61 | element name {string($DIF/dif:Entry_Title)}, |
---|
62 | element abbreviation {string($DIF/dif:Entry_Title)}, |
---|
63 | element dgDataEntity { |
---|
64 | element dgDataSetType {''}, |
---|
65 | element dgDataSummary { |
---|
66 | for $parameter in $DIF/dif:Parameters |
---|
67 | return |
---|
68 | element dgParameterSummary { |
---|
69 | element dgParameterValue { |
---|
70 | element dgValueDataParameter { |
---|
71 | element Value {''}, |
---|
72 | element dgStandardUnit { |
---|
73 | element dgValidTerm {'dummy'}, |
---|
74 | element dgValidTermID { |
---|
75 | element ParentListID {$voclib:unknown_vocab_id}, |
---|
76 | element TermID {escape-uri('dummy unit', true())} |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | }, |
---|
81 | element dgStdParameterMeasured { |
---|
82 | if ($parameter/dif:Category!='') then element dgValidTerm {string($parameter/dif:Category)} |
---|
83 | else element dgValidTerm {'unknown'}, |
---|
84 | element dgValidTermID { |
---|
85 | element ParentListID {concat($voclib:gcmd_science_valids_categories, '/current')}, |
---|
86 | element TermID {escape-uri($parameter/dif:Category, true())} |
---|
87 | }, |
---|
88 | element dgValidSubterm { |
---|
89 | if ($parameter/dif:Topic!='') then element dgValidTerm {string($parameter/dif:Topic)} |
---|
90 | else element dgValidTerm {'unknown'}, |
---|
91 | element dgValidTermID { |
---|
92 | element ParentListID {concat($voclib:gcmd_science_valids_topics, '/current')}, |
---|
93 | element TermID {escape-uri($parameter/dif:Topic, true())} |
---|
94 | }, |
---|
95 | element dgValidSubterm { |
---|
96 | if ($parameter/dif:Term!='') then element dgValidTerm {string($parameter/dif:Term)} |
---|
97 | else element dgValidTerm {'unknown'}, |
---|
98 | element dgValidTermID { |
---|
99 | element ParentListID {concat($voclib:gcmd_science_valids_terms, '/current')}, |
---|
100 | element TermID {escape-uri($parameter/dif:Term, true())} |
---|
101 | }, |
---|
102 | if (exists($parameter/dif:Variable) and $parameter/dif:Variable!='') then |
---|
103 | element dgValidSubterm { |
---|
104 | element dgValidTerm {string($parameter/dif:Variable)}, |
---|
105 | element dgValidTermID { |
---|
106 | element ParentListID {concat($voclib:gcmd_science_valids_variables, '/current')}, |
---|
107 | element TermID {escape-uri($parameter/dif:Variable, true())} |
---|
108 | }, |
---|
109 | if (exists($parameter/dif:Detailed_Variable) and $parameter/dif:Detailed_Variable!='') then |
---|
110 | element dgValidSubterm { |
---|
111 | element dgValidTerm {string($parameter/dif:Detailed_Variable)}, |
---|
112 | element dgValidTermID { |
---|
113 | element ParentListID {$voclib:unknown_vocab_id}, |
---|
114 | element TermID {escape-uri($parameter/dif:Detailed_Variable, true())} |
---|
115 | }, |
---|
116 | element ListLevel {4}} |
---|
117 | else (), |
---|
118 | element ListLevel {3} |
---|
119 | } |
---|
120 | else (), |
---|
121 | element ListLevel {2} |
---|
122 | }, |
---|
123 | element ListLevel {1} |
---|
124 | }, |
---|
125 | element ListLevel {0} |
---|
126 | }, |
---|
127 | element ParameterName { |
---|
128 | concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)), |
---|
129 | if (exists($parameter/dif:Variable) and $parameter/dif:Variable!='') then |
---|
130 | concat(' > ', string($parameter/dif:Variable)) |
---|
131 | else (), |
---|
132 | if (exists($parameter/dif:Detailed_Variable) and $parameter/dif:Detailed_Variable!='') then |
---|
133 | concat(' > ', string($parameter/dif:Detailed_Variable)) |
---|
134 | else () |
---|
135 | }, |
---|
136 | element ParameterAbbreviation { |
---|
137 | concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)), |
---|
138 | if (exists($parameter/dif:Variable) and $parameter/dif:Variable!='') then |
---|
139 | concat(' > ', string($parameter/dif:Variable)) |
---|
140 | else (), |
---|
141 | if (exists($parameter/dif:Detailed_Variable) and $parameter/dif:Detailed_Variable!='') then |
---|
142 | concat(' > ', string($parameter/dif:Detailed_Variable)) |
---|
143 | else () |
---|
144 | } |
---|
145 | }, |
---|
146 | if (exists($DIF/dif:Spatial_Coverage) or exists($DIF/dif:Paleo_Temporal_Coverage) or exists($DIF/dif:Location) or exists($DIF/dif:Temporal_Coverage)) then |
---|
147 | element dgDataCoverage { |
---|
148 | if (exists($DIF/dif:Spatial_Coverage) or exists($DIF/dif:Location)) then |
---|
149 | element dgSpatialCoverage { |
---|
150 | for $boundingbox in $DIF/dif:Spatial_Coverage[exists(dif:Northernmost_Latitude) |
---|
151 | and exists(dif:Southernmost_Latitude) |
---|
152 | and exists(dif:Easternmost_Longitude) |
---|
153 | and exists(dif:Westernmost_Longitude)] |
---|
154 | return |
---|
155 | element BoundingBox { |
---|
156 | element LimitNorth {data(inputParse:fix-coord($boundingbox/dif:Northernmost_Latitude))}, |
---|
157 | element LimitSouth {data(inputParse:fix-coord($boundingbox/dif:Southernmost_Latitude))}, |
---|
158 | element LimitWest {data(inputParse:fix-coord($boundingbox/dif:Westernmost_Longitude))}, |
---|
159 | element LimitEast {data(inputParse:fix-coord($boundingbox/dif:Easternmost_Longitude))} |
---|
160 | }, |
---|
161 | for $location in $DIF/dif:Location |
---|
162 | return |
---|
163 | element dgArea { |
---|
164 | element dgValidTerm {string($location)}, |
---|
165 | element dgValidTermID { |
---|
166 | element ParentListID {concat($voclib:gcmd_location_valids, '/current')}, |
---|
167 | element TermID {escape-uri($location, true())} |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | else (), |
---|
172 | if (exists($DIF/dif:Temporal_Coverage) or exists($DIF/dif:Paleo_Temporal_Coverage) or exists($DIF/dif:Chronostratigraphic_Unit)) then |
---|
173 | element dgTemporalCoverage { |
---|
174 | for $temporalcoverage in $DIF/dif:Temporal_Coverage[exists(dif:Start_Date)] |
---|
175 | return |
---|
176 | element DateRange { |
---|
177 | element DateRangeStart {string($temporalcoverage/dif:Start_Date)}, |
---|
178 | element DateRangeEnd {string($temporalcoverage/dif:Stop_Date)} |
---|
179 | }, |
---|
180 | for $paleotemporalcoverage in $DIF/dif:Paleo_Temporal_Coverage[exists(dif:Paleo_Start_Date)] |
---|
181 | return |
---|
182 | element DateRange { |
---|
183 | element DateRangeStart {string($paleotemporalcoverage/dif:Paleo_Start_Date)}, |
---|
184 | element DateRangeEnd {string($paleotemporalcoverage/dif:Paleo_Stop_Date)} |
---|
185 | }, |
---|
186 | for $chronostratigraphic in $DIF/dif:Chronostratigraphic_Unit |
---|
187 | return |
---|
188 | element dgChronostratigraphicTerm { |
---|
189 | element dgValidTerm {string($chronostratigraphic)}, |
---|
190 | element dgValidTermID { |
---|
191 | element ParentListID {concat($voclib:gcmd_chronostratigraphic_valids, '/current')}, |
---|
192 | element TermID {escape-uri($chronostratigraphic, true())} |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | else () |
---|
197 | } |
---|
198 | else () |
---|
199 | }, |
---|
200 | element dgDataRoles { |
---|
201 | if (exists($DIF/dif:Data_Set_Citation/dif:Dataset_Creator)) then |
---|
202 | element dgDataCreator { |
---|
203 | element dgMetadataID { |
---|
204 | element schemeIdentifier {'NDG-B0'}, |
---|
205 | element repositoryIdentifier {$input_repository}, |
---|
206 | if ($output_local_id != 'Output_LocalID') then |
---|
207 | element localIdentifier {concat('generated_creator-', $output_local_id)} |
---|
208 | else |
---|
209 | element localIdentifier {concat('generated_creator-', escape-uri(string($DIF/dif:Entry_ID), true()))} |
---|
210 | }, |
---|
211 | element roleName {'Data Creator'}, |
---|
212 | element abbreviation {'Creator'}, |
---|
213 | for $creatorID in $DIF/dif:Data_Set_Citation/dif:Dataset_Creator |
---|
214 | return |
---|
215 | element dgRoleHolder { |
---|
216 | element dgMetadataID { |
---|
217 | element schemeIdentifier {'NDG-B0'}, |
---|
218 | element repositoryIdentifier {$input_repository}, |
---|
219 | if ($output_local_id != 'Output_LocalID') then |
---|
220 | element localIdentifier {escape-uri(concat('generated_orgcit-', string($creatorID), '-', $output_local_id), true())} |
---|
221 | else |
---|
222 | element localIdentifier {escape-uri(concat('generated_orgcit-', string($creatorID), '-', data($DIF/dif:Entry_ID)), true())} |
---|
223 | }, |
---|
224 | element startDate {current-date()} |
---|
225 | } |
---|
226 | } |
---|
227 | else if (exists($DIF/dif:Originating_Center)) then |
---|
228 | element dgDataCreator { |
---|
229 | element dgMetadataID { |
---|
230 | element schemeIdentifier {'NDG-B0'}, |
---|
231 | element repositoryIdentifier {$input_repository}, |
---|
232 | if ($output_local_id != 'Output_LocalID') then |
---|
233 | element localIdentifier {escape-uri(concat('generated_creator-', $output_local_id), true())} |
---|
234 | else |
---|
235 | element localIdentifier {escape-uri(concat('generated_creator-', data($DIF/dif:Entry_ID)), true())} |
---|
236 | }, |
---|
237 | element roleName {'Data Creator'}, |
---|
238 | element abbreviation {'Creator'}, |
---|
239 | for $creatorID in $DIF/dif:Originating_Center |
---|
240 | return |
---|
241 | element dgRoleHolder { |
---|
242 | element dgOrganisationID { |
---|
243 | element schemeIdentifier {'NDG-B0'}, |
---|
244 | element repositoryIdentifier {$input_repository}, |
---|
245 | if ($output_local_id != 'Output_LocalID') then |
---|
246 | element localIdentifier {escape-uri(concat('generated_orgcit-', string($creatorID), '-', $output_local_id), true())} |
---|
247 | else |
---|
248 | element localIdentifier {escape-uri(concat('generated_orgcit-', string($creatorID), '-', data($DIF/dif:Entry_ID)), true())} |
---|
249 | }, |
---|
250 | element startDate {current-date()} |
---|
251 | } |
---|
252 | } |
---|
253 | else (), |
---|
254 | element dgDataCurator { |
---|
255 | element dgMetadataID { |
---|
256 | element schemeIdentifier {'NDG-B0'}, |
---|
257 | element repositoryIdentifier {$input_repository}, |
---|
258 | if ($output_local_id != 'Output_LocalID') then |
---|
259 | element localIdentifier {escape-uri(concat('generated_curator-', $output_local_id), true())} |
---|
260 | else |
---|
261 | element localIdentifier {escape-uri(concat('generated_curator-', data($DIF/dif:Entry_ID)), true())} |
---|
262 | }, |
---|
263 | element roleName {'Data Curator'}, |
---|
264 | element abbreviation {'Curator'}, |
---|
265 | element dgRoleHolder { |
---|
266 | element dgOrganisationID { |
---|
267 | element schemeIdentifier {'NDG-B0'}, |
---|
268 | element repositoryIdentifier {$input_repository}, |
---|
269 | element localIdentifier {$input_repository_local} |
---|
270 | }, |
---|
271 | element startDate {current-date()} |
---|
272 | } |
---|
273 | } |
---|
274 | } |
---|
275 | }, |
---|
276 | element dgStructuredKeyword { |
---|
277 | element dgValidTerm {'d2b converted record'}, |
---|
278 | element dgValidTermID { |
---|
279 | element ParentListID {$voclib:unknown_vocab_id}, |
---|
280 | element TermID {'d2b'} |
---|
281 | } |
---|
282 | }, |
---|
283 | for $structuredKeywords in $DIF/dif:Keyword |
---|
284 | return |
---|
285 | element dgStructuredKeyword { |
---|
286 | element dgValidTerm {string($structuredKeywords)}, |
---|
287 | element dgValidTermID { |
---|
288 | if ($structuredKeywords='MDIP' or $structuredKeywords='NERC' or $structuredKeywords='NERC_DDC' or $structuredKeywords='DDDP') then |
---|
289 | element ParentListID {concat($voclib:ndg_data_provider_vocab, '/current')} |
---|
290 | else |
---|
291 | element ParentListID {$voclib:unknown_vocab_id} |
---|
292 | , |
---|
293 | element TermID {escape-uri($structuredKeywords, true())} |
---|
294 | } |
---|
295 | }, |
---|
296 | for $structuredKeywords in $DIF/dif:ISO_Topic_Category |
---|
297 | return |
---|
298 | element dgStructuredKeyword { |
---|
299 | element dgValidTerm {string($structuredKeywords)}, |
---|
300 | element dgValidTermID { |
---|
301 | element ParentListID {concat($voclib:iso_topic_list, '/current')}, |
---|
302 | element TermID {escape-uri($structuredKeywords, true())} |
---|
303 | } |
---|
304 | }, |
---|
305 | if (exists($DIF/dif:DIF_Creation_Date) or exists($DIF/dif:Last_DIF_Revision_Date)) then |
---|
306 | element dgMetadataProvenance { |
---|
307 | if (exists($DIF/dif:DIF_Creation_Date)) then |
---|
308 | element RecordCreation { |
---|
309 | element CreatedDate { |
---|
310 | if (string($DIF/dif:DIF_Creation_Date) castable as xs:date) then |
---|
311 | string($DIF/dif:DIF_Creation_Date) cast as xs:date |
---|
312 | else (current-date()) |
---|
313 | }, |
---|
314 | element CreatedBy {$input_repository} |
---|
315 | } |
---|
316 | else |
---|
317 | element RecordCreation { |
---|
318 | element CreatedDate {current-date()}, |
---|
319 | element CreatedBy {'MOLES Import'} |
---|
320 | }, |
---|
321 | if (exists($DIF/dif:Last_DIF_Revision_Date)) then |
---|
322 | element RecordUpdate { |
---|
323 | element UpdateDate { |
---|
324 | if (string($DIF/dif:Last_DIF_Revision_Date) castable as xs:dateTime) then |
---|
325 | string($DIF/dif:Last_DIF_Revision_Date) cast as xs:dateTime |
---|
326 | else (current-dateTime()) |
---|
327 | }, |
---|
328 | element UpdatedBy {$input_repository} |
---|
329 | } |
---|
330 | else () |
---|
331 | } |
---|
332 | else () |
---|
333 | } (: </dgMetadataRecord>:), |
---|
334 | for $creator in distinct-values($DIF/(dif:Data_Set_Citation/dif:Dataset_Creator | dif:Originating_Center)) |
---|
335 | return |
---|
336 | element dgOrganisation { |
---|
337 | element dgMetadataID { |
---|
338 | element schemeIdentifier {'NDG-B0'}, |
---|
339 | element repositoryIdentifier {$input_repository}, |
---|
340 | if ($output_local_id != 'Output_LocalID') then |
---|
341 | element localIdentifier {escape-uri(concat('generated_orgcit-', string($creator), '-', $output_local_id), true())} |
---|
342 | else |
---|
343 | element localIdentifier {escape-uri(concat('generated_orgcit-', string($creator), '-', data($DIF/dif:Entry_ID)), true())} |
---|
344 | }, |
---|
345 | element name {string($creator)}, |
---|
346 | element abbreviation {string($creator)}, |
---|
347 | element contactDetails {''} |
---|
348 | } |
---|
349 | } (: </dgMetadata> :) |
---|