source: TI07-MOLES/trunk/StubB/XQuery/NDG-ObsStnStubB.xquery @ 2466

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-ObsStnStubB.xquery@2466
Revision 2466, 10.5 KB checked in by ko23, 14 years ago (diff)

Updated XQueries for BADC 'worst cases so far'

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';
2import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
3import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
4(:
5Will return when scope problem sussed... ;(
6import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery';
7:)
8declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
9declare namespace moles='http://ndg.nerc.ac.uk/moles';
10
11declare variable $targetCollection as xs:string {'/db/ndg_B_metadata'};
12declare variable $repositoryIdentifier as xs:string {'badc.nerc.ac.uk'};
13declare variable $localIdentifier as xs:string {'obs_1162914786499342'};
14(: replacable parameters
15declare variable $targetCollection as xs:string {'TargetCollection'};
16declare variable $repositoryIdentifier as xs:string {'RepositoryID'};
17declare variable $localIdentifier as xs:string {'LocalID'};
18:)
19declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
20(: Returns a 'stubB' style activity record to expand an activity record :)
21(: Security not implemented here yet :)
22{
23let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
24moles:dgMetadataID/moles:localIdentifier=$locid
25and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]
26return
27element  {$out-element-name} {
28($SRAct/moles:dgMetadataID),
29($SRAct/moles:dgMetadataDescription),
30($SRAct/moles:name),
31($SRAct/moles:abbreviation),
32($SRAct/moles:logos),
33element dgActivity {
34if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCollection)) then
35($SRAct/*/moles:dgActivityDataCollection)
36else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataProject)) then
37($SRAct/*/moles:dgActivityDataProject)
38else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)) then
39($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)
40else
41($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),
42($SRAct/moles:dgActivity/moles:dgActivityCoverage),
43($SRAct/moles:dgActivity/moles:dgActivityDuration)
44} (: </dgActivity> :)
45} (: </activity> :)
46} ;
47
48declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
49(: Returns a 'stubB' style observation station record to expand an data entity record :)
50(: Security not implemented yet :)
51{
52let $SRDE := $DE
53return 
54element {$out-element-name} {
55($SRDE/moles:dgMetadataID),
56($SRDE/moles:dgMetadataDescription),
57($SRDE/moles:name),
58($SRDE/moles:abbreviation),
59($SRDE/moles:abbreviation),
60element dgDataEntity {
61($SRDE/moles:dgDataEntity/moles:dgDataSetType),
62($SRDE/moles:dgDataEntity/moles:dgDataGranule),
63($SRDE/moles:dgDataEntity/moles:dgDataSummary)
64} (: </dgDataEntity> :)       
65}
66} ;
67
68declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
69(: Returns a 'stubB' style dpt record to expand a dpt record :)
70(: Security not implemented yet :)
71{
72let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
73moles:dgMetadataID/moles:localIdentifier=$locid
74and
75moles:dgMetadataID/moles:repositoryIdentifier=$repid
76]
77return 
78element {$out-element-name} {
79$SRDPT/moles:dgMetadataID,
80$SRDPT/moles:dgMetadataDescription,
81$SRDPT/moles:name,
82$SRDPT/moles:abbreviation,
83$SRDPT/moles:logos,
84element dgDataProductionTool {
85$SRDPT/moles:dgDataProductionTool/moles:contactDetails,
86if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then
87$SRDPT/moles:dgDataProductionTool/moles:dgModel
88else (),
89if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then
90$SRDPT/moles:dgDataProductionTool/moles:dgInstrument
91else ()
92} (: </dgDataProductionTool> :)
93} (: </dataproductiontool> :)
94} ;
95
96declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
97(: Returns a 'stubB' style observation station record to expand an observation station record :)
98(: Security not implemented here yet;  :)
99{
100let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
101moles:dgMetadataID/moles:localIdentifier=$locid
102and
103moles:dgMetadataID/moles:repositoryIdentifier=$repid
104]
105return
106element {$out-element-name} {
107($SRObsStn/moles:dgMetadataID),
108($SRObsStn/moles:dgMetadataDescription),
109($SRObsStn/moles:name),
110($SRObsStn/moles:abbreviation),
111($SRObsStn/moles:logos),
112element dgObservationStation {
113($SRObsStn/moles:dgObservationStation/moles:contactDetails),
114if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
115element dgStationaryPlatform {
116$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
117if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''}
118else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''}
119else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''}
120else ()
121}
122else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then
123$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform
124else ()
125} (: </dgObservationStation> :)
126}
127} ;
128
129declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
130(: Returns a 'stubB' style observation station record to expand a person record :)
131(: Security not implemented yet :)
132{
133let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
134moles:dgMetadataID/moles:localIdentifier=$locid
135and
136moles:dgMetadataID/moles:repositoryIdentifier=$repid
137]
138return
139element  {$out-element-name}
140{
141($person/moles:name),
142($person/moles:contactDetails),
143($person/moles:dgMetadataID)
144}
145} ;
146
147declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
148(: Returns a 'stubB' style observation station record to expand an organisation record :)
149(: Security not implemented yet :)
150{
151let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
152moles:dgMetadataID/moles:localIdentifier=$locid
153and
154moles:dgMetadataID/moles:repositoryIdentifier=$repid
155]
156return
157element  {$out-element-name} {
158$org/moles:dgMetadataID,
159$org/moles:name,
160$org/moles:abbreviation,
161$org/moles:contactDetails,
162$org/moles:logos
163}
164} ;
165
166let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
167moles:dgObservationStation!=''
168and moles:dgMetadataID[
169moles:schemeIdentifier='NDG-B0'
170and moles:repositoryIdentifier=$repositoryIdentifier
171and moles:localIdentifier=$localIdentifier]]
172return
173utillib:strip-namespace(
174element dgMetadataRecord {
175element dgMetadataID {
176element schemeIdentifier {'NDG-B1'},
177$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
178$ObsStn/moles:dgMetadataID/moles:localIdentifier
179} (: End </dgMetadataID> :),
180$ObsStn/moles:dgMetadataDescription,
181$ObsStn/moles:name,
182$ObsStn/moles:abbreviation,
183element dgObservationStation {
184$ObsStn/moles:dgObservationStation/moles:contactDetails,
185if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
186element dgStationaryPlatform {
187$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
188if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
189element dgMooring {
190$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
191$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
192for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
193return
194f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
195if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
196for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
197return 
198f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
199else ()
200} (: End </dgMooring> :) 
201else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
202element dgStationGroup {
203element dgGroupedStations {
204if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
205for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
206return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
207else ()
208} (: End </dgGroupedStations> :)
209} (: End </dgStationGroup> :)
210else $ObsStn/moles:dgObservationStation/moles:dgLandStation
211} (: End </dgStationaryPlatform>  :) 
212else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
213for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment
214return
215element ObsStationDeployment {
216$RelDep/moles:DateStart,
217$RelDep/moles:DateEnd,
218$RelDep/moles:dgMetadataID,
219f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
220f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
221for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier
222and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier]
223return
224f:return-stub-dataentity('dataentity', $DE),
225$RelDep/moles:Coverage
226} (: </RelatedDeployment> :)
227} (: </dgObservationStation> :),
228for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
229if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
230if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
231} (: End </dgMetadataRecord> :)
232) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.