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

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

Updated DIF queries

  • 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{
23for $SRAct in 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),
32element dgActivity {
33if (exists($SRAct/*/moles:dgActivityDataCollection)) then
34($SRAct/*/moles:dgActivityDataCollection)
35else if (exists($SRAct/*/moles:dgActivityDataProject)) then
36($SRAct/*/moles:dgActivityDataProject)
37else if (exists($SRAct/*/dgActivityDataCampaign)) then
38($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)
39else
40($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),
41($SRAct/moles:dgActivity/moles:dgActivityCoverage),
42($SRAct/moles:dgActivity/moles:dgActivityDuration)
43} (: </dgActivity> :)
44} (: </activity> :)
45} ;
46
47declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
48(: Returns a 'stubB' style observation station record to expand an data entity record :)
49(: Security not implemented yet :)
50{
51for $SRDE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
52moles:dgMetadataID/moles:localIdentifier=$locid
53and
54moles:dgMetadataID/moles:repositoryIdentifier=$repid
55]
56return 
57element {$out-element-name} {
58($SRDE/moles:dgMetadataID),
59($SRDE/moles:dgMetadataDescription),
60($SRDE/moles:name),
61($SRDE/moles:abbreviation),
62element dgDataEntity {
63($SRDE/moles:dgDataEntity/moles:dgDataSetType),
64($SRDE/moles:dgDataEntity/moles:dgDataGranule),
65($SRDE/moles:dgDataEntity/moles:dgDataSummary)
66} (: </dgDataEntity> :)       
67}
68} ;
69
70declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
71(: Returns a 'stubB' style dpt record to expand a dpt record :)
72(: Security not implemented yet :)
73{
74for $SRDPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
75moles:dgMetadataID/moles:localIdentifier=$locid
76and
77moles:dgMetadataID/moles:repositoryIdentifier=$repid
78]
79return 
80element {$out-element-name} {
81$SRDPT/moles:dgMetadataID,
82$SRDPT/moles:dgMetadataDescription,
83$SRDPT/moles:name,
84$SRDPT/moles:abbreviation,
85$SRDPT/moles:logos,
86element dgDataProductionTool {
87$SRDPT/moles:dgDataProductionTool/moles:contactDetails,
88if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then
89$SRDPT/moles:dgDataProductionTool/moles:dgModel
90else (),
91if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then
92$SRDPT/moles:dgDataProductionTool/moles:dgInstrument
93else ()
94} (: </dgDataProductionTool> :)
95} (: </dataproductiontool> :)
96} ;
97
98declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
99(: Returns a 'stubB' style observation station record to expand an observation station record :)
100(: Security not implemented here yet;  :)
101{
102for $SRObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
103moles:dgMetadataID/moles:localIdentifier=$locid
104and
105moles:dgMetadataID/moles:repositoryIdentifier=$repid
106]
107return
108element {$out-element-name} {
109($SRObsStn/moles:dgMetadataID),
110($SRObsStn/moles:dgMetadataDescription),
111($SRObsStn/moles:name),
112($SRObsStn/moles:abbreviation),
113element dgObservationStation {
114($SRObsStn/moles:dgObservationStation/moles:contactDetails),
115if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
116element dgStationaryPlatform {
117$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
118if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''}
119else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''}
120else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''}
121else ()
122}
123else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then
124$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform
125else ()
126} (: </dgObservationStation> :)
127}
128} ;
129
130declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
131(: Returns a 'stubB' style observation station record to expand a person record :)
132(: Security not implemented yet :)
133{
134for $person in collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
135moles:dgMetadataID/moles:localIdentifier=$locid
136and
137moles:dgMetadataID/moles:repositoryIdentifier=$repid
138]
139return
140element  {$out-element-name}
141{
142($person/moles:name),
143($person/moles:contactDetails),
144($person/moles:dgMetadataID)
145}
146} ;
147
148declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
149(: Returns a 'stubB' style observation station record to expand an organisation record :)
150(: Security not implemented yet :)
151{
152for $org in collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
153moles:dgMetadataID/moles:localIdentifier=$locid
154and
155moles:dgMetadataID/moles:repositoryIdentifier=$repid
156]
157return
158element  {$out-element-name} {
159$org/moles:dgMetadataID,
160$org/moles:name,
161$org/moles:abbreviation,
162$org/moles:contactDetails,
163$org/moles:logos
164}
165} ;
166
167for $ObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
168moles:dgObservationStation!=''
169and moles:dgMetadataID[
170moles:schemeIdentifier='NDG-B0'
171and moles:repositoryIdentifier=$repositoryIdentifier
172and moles:localIdentifier=$localIdentifier]]
173return
174utillib:strip-namespace(
175element dgMetadataRecord {
176element dgMetadataID {
177element schemeIdentifier {'NDG-B1'},
178$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
179$ObsStn/moles:dgMetadataID/moles:localIdentifier
180} (: End </dgMetadataID> :),
181$ObsStn/moles:dgMetadataDescription,
182$ObsStn/moles:name,
183$ObsStn/moles:abbreviation,
184element dgObservationStation {
185$ObsStn/moles:dgObservationStation/moles:contactDetails,
186if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
187element dgStationaryPlatform {
188$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
189if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
190element dgMooring {
191$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
192$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
193for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
194return
195f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
196if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
197for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
198return 
199f:return-stub-obsstn('stationgrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
200else ()
201} (: End </dgMooring> :) 
202else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
203element dgStationGroup {
204element dgGroupedStations {
205if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
206for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
207return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
208else ()
209} (: End </dgGroupedStations> :)
210} (: End </dgStationGroup> :)
211else $ObsStn/moles:dgObservationStation/moles:dgLandStation
212} (: End </dgStationaryPlatform>  :) 
213else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
214for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment
215return
216element ObsStationDeployment {
217$RelDep/moles:DateStart,
218$RelDep/moles:DateEnd,
219$RelDep/moles:dgMetadataID,
220f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
221f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
222for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord
223where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier
224and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier
225return
226f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),
227$RelDep/moles:Coverage
228} (: </RelatedDeployment> :)
229} (: </dgObservationStation> :),
230for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
231if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
232if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
233} (: End </dgMetadataRecord> :)
234) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.