source: TI07-MOLES/trunk/xqueryLib/StubB/stubb_xquery_lib.xquery @ 2236

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/xqueryLib/StubB/stubb_xquery_lib.xquery@2236
Revision 2236, 8.9 KB checked in by ko23, 13 years ago (diff)

Refactoring - working versions. Still slow though.

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