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

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

Refactoring intermediate

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