1 | declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataentity'; |
---|
2 | declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; |
---|
3 | declare namespace moles='http://ndg.nerc.ac.uk/moles'; |
---|
4 | |
---|
5 | import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; |
---|
6 | import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; |
---|
7 | (: |
---|
8 | Will return when scope problem sussed... ;( |
---|
9 | import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery'; |
---|
10 | :) |
---|
11 | declare variable $targetCollection as xs:string {'/db/ndg_B_metadata'}; |
---|
12 | declare variable $repositoryIdentifier as xs:string {'badc.nerc.ac.uk'}; |
---|
13 | declare variable $localIdentifier as xs:string {'dataent_chablis'}; |
---|
14 | (: replacable parameters |
---|
15 | declare variable $targetCollection as xs:string {'TargetCollection'}; |
---|
16 | declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; |
---|
17 | declare variable $localIdentifier as xs:string {'LocalID'}; |
---|
18 | :) |
---|
19 | |
---|
20 | declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() |
---|
21 | (: Returns a 'stubB' style activity record to expand an activity record :) |
---|
22 | (: Security not implemented here yet :) |
---|
23 | { |
---|
24 | for $SRAct in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ |
---|
25 | moles:dgMetadataID/moles:repositoryIdentifier=$repid |
---|
26 | and moles:dgMetadataID/moles:localIdentifier=$locid] |
---|
27 | return |
---|
28 | element {$out-element-name} { |
---|
29 | ($SRAct/moles:dgMetadataID), |
---|
30 | ($SRAct/moles:dgMetadataDescription), |
---|
31 | ($SRAct/moles:name), |
---|
32 | ($SRAct/moles:abbreviation), |
---|
33 | element dgActivity { |
---|
34 | if (exists($SRAct/*/moles:dgActivityDataCollection)) then |
---|
35 | ($SRAct/*/moles:dgActivityDataCollection) |
---|
36 | else if (exists($SRAct/*/moles:dgActivityDataProject)) then |
---|
37 | ($SRAct/*/moles:dgActivityDataProject) |
---|
38 | else if (exists($SRAct/*/dgActivityDataCampaign)) then |
---|
39 | ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) |
---|
40 | else |
---|
41 | ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation), |
---|
42 | ($SRAct/moles:dgActivity/moles:dgActivityCoverage), |
---|
43 | ($SRAct/moles:dgActivity/moles:dgActivityDuration) |
---|
44 | } (: </dgActivity> :) |
---|
45 | } (: </activity> :) |
---|
46 | } ; |
---|
47 | |
---|
48 | declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() |
---|
49 | (: Returns a 'stubB' style observation station record to expand an data entity record :) |
---|
50 | (: Security not implemented yet :) |
---|
51 | { |
---|
52 | for $SRDE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ |
---|
53 | moles:dgMetadataID/moles:repositoryIdentifier=$repid |
---|
54 | and moles:dgMetadataID/moles:localIdentifier=$locid] |
---|
55 | return |
---|
56 | element {$out-element-name} { |
---|
57 | ($SRDE/moles:dgMetadataID), |
---|
58 | ($SRDE/moles:dgMetadataDescription), |
---|
59 | ($SRDE/moles:name), |
---|
60 | ($SRDE/moles:abbreviation), |
---|
61 | element dgDataEntity { |
---|
62 | ($SRDE/moles:dgDataEntity/moles:dgDataSetType), |
---|
63 | ($SRDE/moles:dgDataEntity/moles:dgDataGranule), |
---|
64 | ($SRDE/moles:dgDataEntity/moles:dgDataSummary) |
---|
65 | } (: </dgDataEntity> :) |
---|
66 | } |
---|
67 | } ; |
---|
68 | |
---|
69 | declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() |
---|
70 | (: Returns a 'stubB' style dpt record to expand a dpt record :) |
---|
71 | (: Security not implemented yet :) |
---|
72 | { |
---|
73 | for $SRDPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ |
---|
74 | moles:dgMetadataID/moles:repositoryIdentifier=$repid |
---|
75 | and moles:dgMetadataID/moles:localIdentifier=$locid] |
---|
76 | return |
---|
77 | element {$out-element-name} { |
---|
78 | $SRDPT/moles:dgMetadataID, |
---|
79 | $SRDPT/moles:dgMetadataDescription, |
---|
80 | $SRDPT/moles:name, |
---|
81 | $SRDPT/moles:abbreviation, |
---|
82 | $SRDPT/moles:logos, |
---|
83 | element dgDataProductionTool { |
---|
84 | $SRDPT/moles:dgDataProductionTool/moles:contactDetails, |
---|
85 | if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then |
---|
86 | $SRDPT/moles:dgDataProductionTool/moles:dgModel |
---|
87 | else (), |
---|
88 | if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then |
---|
89 | $SRDPT/moles:dgDataProductionTool/moles:dgInstrument |
---|
90 | else () |
---|
91 | } (: </dgDataProductionTool> :) |
---|
92 | } (: </dataproductiontool> :) |
---|
93 | } ; |
---|
94 | |
---|
95 | declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() |
---|
96 | (: Returns a 'stubB' style observation station record to expand an observation station record :) |
---|
97 | (: Security not implemented here yet; :) |
---|
98 | { |
---|
99 | for $SRObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ |
---|
100 | moles:dgMetadataID/moles:repositoryIdentifier=$repid |
---|
101 | and moles:dgMetadataID/moles:localIdentifier=$locid] |
---|
102 | return |
---|
103 | element {$out-element-name} { |
---|
104 | ($SRObsStn/moles:dgMetadataID), |
---|
105 | ($SRObsStn/moles:dgMetadataDescription), |
---|
106 | ($SRObsStn/moles:name), |
---|
107 | ($SRObsStn/moles:abbreviation), |
---|
108 | element dgObservationStation { |
---|
109 | ($SRObsStn/moles:dgObservationStation/moles:contactDetails), |
---|
110 | if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then |
---|
111 | element dgStationaryPlatform { |
---|
112 | $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, |
---|
113 | if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} |
---|
114 | else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} |
---|
115 | else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} |
---|
116 | else () |
---|
117 | } |
---|
118 | else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then |
---|
119 | $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform |
---|
120 | else () |
---|
121 | } (: </dgObservationStation> :) |
---|
122 | } |
---|
123 | } ; |
---|
124 | |
---|
125 | declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() |
---|
126 | (: Returns a 'stubB' style observation station record to expand a person record :) |
---|
127 | (: Security not implemented yet :) |
---|
128 | { |
---|
129 | for $person in collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ |
---|
130 | moles:dgMetadataID/moles:repositoryIdentifier=$repid |
---|
131 | and moles:dgMetadataID/moles:localIdentifier=$locid] |
---|
132 | return |
---|
133 | element {$out-element-name} |
---|
134 | { |
---|
135 | ($person/moles:name), |
---|
136 | ($person/moles:contactDetails), |
---|
137 | ($person/moles:dgMetadataID) |
---|
138 | } |
---|
139 | } ; |
---|
140 | |
---|
141 | declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() |
---|
142 | (: Returns a 'stubB' style observation station record to expand an organisation record :) |
---|
143 | (: Security not implemented yet :) |
---|
144 | { |
---|
145 | for $org in collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ |
---|
146 | moles:dgMetadataID/moles:repositoryIdentifier=$repid |
---|
147 | and moles:dgMetadataID/moles:localIdentifier=$locid] |
---|
148 | return |
---|
149 | element {$out-element-name} { |
---|
150 | $org/moles:dgMetadataID, |
---|
151 | $org/moles:name, |
---|
152 | $org/moles:abbreviation, |
---|
153 | $org/moles:contactDetails, |
---|
154 | $org/moles:logos |
---|
155 | } |
---|
156 | } ; |
---|
157 | |
---|
158 | for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ |
---|
159 | exists(moles:dgDataEntity) |
---|
160 | and moles:dgMetadataID[ |
---|
161 | moles:schemeIdentifier='NDG-B0' |
---|
162 | and moles:repositoryIdentifier=$repositoryIdentifier |
---|
163 | and moles:localIdentifier=$localIdentifier]] |
---|
164 | return |
---|
165 | utillib:strip-namespace(element dgMetadataRecord { |
---|
166 | element dgMetadataID { |
---|
167 | element schemeIdentifier {'NDG-B1'}, |
---|
168 | $DE/moles:dgMetadataID/moles:repositoryIdentifier, |
---|
169 | $DE/moles:dgMetadataID/moles:localIdentifier |
---|
170 | }, (: </dgMetadataID> :) |
---|
171 | $DE/moles:dgMetadataDescription, |
---|
172 | $DE/moles:name, |
---|
173 | $DE/moles:abbreviation, |
---|
174 | element dgDataEntity { |
---|
175 | $DE/moles:dgDataEntity/moles:dgDataSetType, |
---|
176 | $DE/moles:dgDataEntity/moles:dgDataObjectType, |
---|
177 | $DE/moles:dgDataEntity/moles:dgDataGranule, |
---|
178 | $DE/moles:dgDataEntity/moles:dgDataSummary, |
---|
179 | element dgDataRoles { |
---|
180 | if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then |
---|
181 | element dgDataCreator { |
---|
182 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID, |
---|
183 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName, |
---|
184 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation, |
---|
185 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails, |
---|
186 | for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder |
---|
187 | order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least |
---|
188 | return |
---|
189 | element dgRoleHolder { |
---|
190 | if (exists($DataCreatorRole/moles:dgOrganisationID)) then |
---|
191 | f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier)) |
---|
192 | else if (exists($DataCreatorRole/moles:dgPersonID)) then |
---|
193 | f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier)) |
---|
194 | else (), |
---|
195 | $DataCreatorRole/moles:startDate, |
---|
196 | $DataCreatorRole/moles:endDate, |
---|
197 | $DataCreatorRole/moles:localName |
---|
198 | } (: </dgRoleHolder> :) |
---|
199 | } (: </dgDataCreator>) :) |
---|
200 | else (), |
---|
201 | if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then |
---|
202 | element dgDataCurator { |
---|
203 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID, |
---|
204 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName, |
---|
205 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation, |
---|
206 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails, |
---|
207 | for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder |
---|
208 | order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least |
---|
209 | return |
---|
210 | element dgRoleHolder { |
---|
211 | if (exists($DataCuratorRole/moles:dgOrganisationID)) then |
---|
212 | f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier)) |
---|
213 | else if (exists($DataCuratorRole/moles:dgPersonID)) then |
---|
214 | f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier)) |
---|
215 | else (), |
---|
216 | $DataCuratorRole/moles:startDate, |
---|
217 | $DataCuratorRole/moles:endDate, |
---|
218 | $DataCuratorRole/moles:localName |
---|
219 | } (: </dgRoleHolder> :) |
---|
220 | } (: </dgDataCurator> :) |
---|
221 | else (), |
---|
222 | if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then |
---|
223 | element dgDataOtherRoles { |
---|
224 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID, |
---|
225 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName, |
---|
226 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation, |
---|
227 | $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails, |
---|
228 | for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder |
---|
229 | order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least |
---|
230 | return |
---|
231 | element dgRoleHolder { |
---|
232 | if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then |
---|
233 | f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier)) |
---|
234 | else if (exists($DataOtherRolesRole/moles:dgPersonID)) then |
---|
235 | f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier)) |
---|
236 | else (), |
---|
237 | $DataOtherRolesRole/moles:startDate, |
---|
238 | $DataOtherRolesRole/moles:endDate, |
---|
239 | $DataOtherRolesRole/moles:localName |
---|
240 | } (: </dgRoleHolder> :) |
---|
241 | } (: </dgDataOtherRoles> :) |
---|
242 | else () |
---|
243 | } , (: </dgDataRoles> :) |
---|
244 | for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment |
---|
245 | return |
---|
246 | element RelatedDeployment { |
---|
247 | $RelDep/moles:DateStart, |
---|
248 | $RelDep/moles:DateEnd, |
---|
249 | $RelDep/moles:dgMetadataID, |
---|
250 | f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)), |
---|
251 | f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), |
---|
252 | f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), |
---|
253 | $RelDep/moles:Coverage |
---|
254 | } (: </RelatedDeployment> :) |
---|
255 | , |
---|
256 | for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity |
---|
257 | return |
---|
258 | element relateddataentity { |
---|
259 | element relation { |
---|
260 | $RelatedDataEntity/moles:RelationID/moles:dgValidTerm, |
---|
261 | $RelatedDataEntity/moles:RelationID/moles:dgValidTermID |
---|
262 | }, (: </relation> :) |
---|
263 | f:return-stub-dataentity('dataentity', data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:repositoryIdentifier), data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:localIdentifier)) |
---|
264 | } (: </relateddataentity> :) |
---|
265 | } (: </dgDataEntity> :), |
---|
266 | for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd, |
---|
267 | if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (), |
---|
268 | if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else () |
---|
269 | } (: </dgMetadataRecord> :) |
---|
270 | ) (: end of namespace strip :) |
---|