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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-ObsStnStubB.xquery@2572
Revision 2572, 9.9 KB checked in by ko23, 12 years ago (diff)
  • 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)
33} (: </activity> :)
34} ;
35
36declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
37(: Returns a 'stubB' style observation station record to expand an data entity record :)
38(: Security not implemented yet :)
39{
40let $SRDE := $DE
41return 
42element {$out-element-name} {
43($SRDE/moles:dgMetadataID),
44($SRDE/moles:dgMetadataDescription),
45($SRDE/moles:name),
46($SRDE/moles:abbreviation)
47} (: </dgDataEntity> :)       
48} ;
49
50declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
51(: Returns a 'stubB' style dpt record to expand a dpt record :)
52(: Security not implemented yet :)
53{
54let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
55moles:dgMetadataID/moles:localIdentifier=$locid
56and
57moles:dgMetadataID/moles:repositoryIdentifier=$repid
58]
59return 
60element {$out-element-name} {
61$SRDPT/moles:dgMetadataID,
62$SRDPT/moles:dgMetadataDescription,
63$SRDPT/moles:name,
64$SRDPT/moles:abbreviation,
65$SRDPT/moles:logos
66} (: </dataproductiontool> :)
67} ;
68
69declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
70(: Returns a 'stubB' style observation station record to expand an observation station record :)
71(: Security not implemented here yet;  :)
72{
73let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
74moles:dgMetadataID/moles:localIdentifier=$locid
75and
76moles:dgMetadataID/moles:repositoryIdentifier=$repid
77]
78return
79element {$out-element-name} {
80($SRObsStn/moles:dgMetadataID),
81($SRObsStn/moles:dgMetadataDescription),
82($SRObsStn/moles:name),
83($SRObsStn/moles:abbreviation),
84($SRObsStn/moles:logos)
85}
86} ;
87
88declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
89(: Returns a 'stubB' style observation station record to expand a person record :)
90(: Security not implemented yet :)
91{
92let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
93moles:dgMetadataID/moles:localIdentifier=$locid
94and
95moles:dgMetadataID/moles:repositoryIdentifier=$repid
96]
97return
98element  {$out-element-name}
99{
100($person/moles:name),
101($person/moles:contactDetails),
102($person/moles:dgMetadataID)
103}
104} ;
105
106declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
107(: Returns a 'stubB' style observation station record to expand an organisation record :)
108(: Security not implemented yet :)
109{
110let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
111moles:dgMetadataID/moles:localIdentifier=$locid
112and
113moles:dgMetadataID/moles:repositoryIdentifier=$repid
114]
115return
116element  {$out-element-name} {
117$org/moles:dgMetadataID,
118$org/moles:name,
119$org/moles:abbreviation,
120$org/moles:contactDetails,
121$org/moles:logos
122}
123} ;
124
125let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
126moles:dgObservationStation!=''
127and moles:dgMetadataID[
128moles:repositoryIdentifier=$repositoryIdentifier
129and moles:localIdentifier=$localIdentifier]]
130return
131utillib:strip-namespace(
132element dgMetadataRecord {
133element dgMetadataID {
134element schemeIdentifier {'NDG-B1'},
135$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
136$ObsStn/moles:dgMetadataID/moles:localIdentifier
137} (: End </dgMetadataID> :),
138$ObsStn/moles:dgMetadataDescription,
139$ObsStn/moles:name,
140$ObsStn/moles:abbreviation,
141element dgObservationStation {
142$ObsStn/moles:dgObservationStation/moles:contactDetails,
143if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
144element dgStationaryPlatform {
145$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
146if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
147element dgMooring {
148$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
149$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
150for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
151return
152f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
153if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
154for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
155return 
156f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
157else ()
158} (: End </dgMooring> :) 
159else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
160element dgStationGroup {
161element dgGroupedStations {
162if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
163for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
164return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
165else ()
166} (: End </dgGroupedStations> :)
167} (: End </dgStationGroup> :)
168else $ObsStn/moles:dgObservationStation/moles:dgLandStation
169} (: End </dgStationaryPlatform>  :) 
170else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
171
172
173element ObsStationDeploymentSummary {
174element activityList {
175for $DepActRepository in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:ActivityID/moles:repositoryIdentifier)
176for $DepActLocal in distinct-values(($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment)/moles:ActivityID/moles:localIdentifier)
177let $DepAct :=  f:return-stub-activity('activity', data($DepActRepository), data($DepActLocal))
178return $DepAct
179},
180element dptList {
181for $DepDPTRepository in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:DataProductionToolID/moles:repositoryIdentifier)
182for $DepDPTLocal in distinct-values(($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment)/moles:DataProductionToolID/moles:localIdentifier)
183let $DepDPT :=  f:return-stub-dpt('dataproductiontool', data($DepDPTRepository), data($DepDPTLocal))
184return $DepDPT
185},
186element dataEntityList {
187$ObsStn/moles:dgMetadataID,
188for $DE in
189collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment
190/moles:ObservationStationID
191[moles:localIdentifier=$ObsStn/moles:dgMetadataID/moles:localIdentifier
192and moles:repositoryIdentifier=$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier]]
193return f:return-stub-dataentity('dataentity', $DE)
194}
195(:
196for $DERepository in distinct-values(
197collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord/moles:dgDataEntity/moles:RelatedDeployment
198[moles:ObservationStationID
199[moles:localIdentifier=$ObsStn/moles:dgMetadataID/moles:localIdentifier
200and moles:repositoryIdentifier=$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier]]
201/moles:repositoryIdentifier)
202for $DELocal in (collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord/moles:dgDataEntity/moles:RelatedDeployment
203[moles:ObservationStationID
204[moles:localIdentifier=$ObsStn/moles:dgMetadataID/moles:localIdentifier
205and moles:repositoryIdentifier=$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier]]
206/moles:localIdentifier)
207let $DERecord := collection('/db/ndg_B_metadata/badc.nerc.ac.uk')/moles:dgMetadata/moles:dgMetadataRecord
208[moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID
209[moles:localIdentifier=$DELocal
210and moles:repositoryIdentifier=$DERepository]]
211return f:return-stub-dataentity('dataentity', $DERecord)
212:)
213} (: </ObsStationDeploymentSummary> :)
214} (: </dgObservationStation> :),
215for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
216if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
217if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
218} (: End </dgMetadataRecord> :)
219) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.