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

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

Update of ndg_xqueries.py to include time-out capability

  • 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_1162914661529326'};
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),
59element dgDataEntity {
60($SRDE/moles:dgDataEntity/moles:dgDataSetType),
61($SRDE/moles:dgDataEntity/moles:dgDataGranule),
62($SRDE/moles:dgDataEntity/moles:dgDataSummary)
63} (: </dgDataEntity> :)       
64}
65} ;
66
67declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
68(: Returns a 'stubB' style dpt record to expand a dpt record :)
69(: Security not implemented yet :)
70{
71let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
72moles:dgMetadataID/moles:localIdentifier=$locid
73and
74moles:dgMetadataID/moles:repositoryIdentifier=$repid
75]
76return 
77element {$out-element-name} {
78$SRDPT/moles:dgMetadataID,
79$SRDPT/moles:dgMetadataDescription,
80$SRDPT/moles:name,
81$SRDPT/moles:abbreviation,
82$SRDPT/moles:logos,
83element dgDataProductionTool {
84$SRDPT/moles:dgDataProductionTool/moles:contactDetails,
85if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then
86$SRDPT/moles:dgDataProductionTool/moles:dgModel
87else (),
88if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then
89$SRDPT/moles:dgDataProductionTool/moles:dgInstrument
90else ()
91} (: </dgDataProductionTool> :)
92} (: </dataproductiontool> :)
93} ;
94
95declare 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{
99let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
100moles:dgMetadataID/moles:localIdentifier=$locid
101and
102moles:dgMetadataID/moles:repositoryIdentifier=$repid
103]
104return
105element {$out-element-name} {
106($SRObsStn/moles:dgMetadataID),
107($SRObsStn/moles:dgMetadataDescription),
108($SRObsStn/moles:name),
109($SRObsStn/moles:abbreviation),
110($SRObsStn/moles:logos),
111element dgObservationStation {
112($SRObsStn/moles:dgObservationStation/moles:contactDetails),
113if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
114element dgStationaryPlatform {
115$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
116if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''}
117else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''}
118else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''}
119else ()
120}
121else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then
122$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform
123else ()
124} (: </dgObservationStation> :)
125}
126} ;
127
128declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
129(: Returns a 'stubB' style observation station record to expand a person record :)
130(: Security not implemented yet :)
131{
132let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
133moles:dgMetadataID/moles:localIdentifier=$locid
134and
135moles:dgMetadataID/moles:repositoryIdentifier=$repid
136]
137return
138element  {$out-element-name}
139{
140($person/moles:name),
141($person/moles:contactDetails),
142($person/moles:dgMetadataID)
143}
144} ;
145
146declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
147(: Returns a 'stubB' style observation station record to expand an organisation record :)
148(: Security not implemented yet :)
149{
150let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
151moles:dgMetadataID/moles:localIdentifier=$locid
152and
153moles:dgMetadataID/moles:repositoryIdentifier=$repid
154]
155return
156element  {$out-element-name} {
157$org/moles:dgMetadataID,
158$org/moles:name,
159$org/moles:abbreviation,
160$org/moles:contactDetails,
161$org/moles:logos
162}
163} ;
164
165let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
166moles:dgObservationStation!=''
167and moles:dgMetadataID[
168moles:repositoryIdentifier=$repositoryIdentifier
169and moles:localIdentifier=$localIdentifier]]
170return
171utillib:strip-namespace(
172element dgMetadataRecord {
173element dgMetadataID {
174element schemeIdentifier {'NDG-B1'},
175$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
176$ObsStn/moles:dgMetadataID/moles:localIdentifier
177} (: End </dgMetadataID> :),
178$ObsStn/moles:dgMetadataDescription,
179$ObsStn/moles:name,
180$ObsStn/moles:abbreviation,
181element dgObservationStation {
182$ObsStn/moles:dgObservationStation/moles:contactDetails,
183if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
184element dgStationaryPlatform {
185$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
186if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
187element dgMooring {
188$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
189$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
190for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
191return
192f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
193if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
194for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
195return 
196f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
197else ()
198} (: End </dgMooring> :) 
199else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
200element dgStationGroup {
201element dgGroupedStations {
202if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
203for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
204return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
205else ()
206} (: End </dgGroupedStations> :)
207} (: End </dgStationGroup> :)
208else $ObsStn/moles:dgObservationStation/moles:dgLandStation
209} (: End </dgStationaryPlatform>  :) 
210else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
211for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment
212return
213element ObsStationDeployment {
214$RelDep/moles:DateStart,
215$RelDep/moles:DateEnd,
216$RelDep/moles:dgMetadataID,
217f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
218f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
219for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
220moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier
221and
222moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier]
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.