source: TI07-MOLES/trunk/eXist specific/xqueryLib/StubB/stubb_xquery_lib.xquery @ 2511

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

Update voclib to include Roy's new IDs. Add version variable to libraries. Change ObsStn? xq to point at 375 deployment example

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