source: exist/trunk/xquery/stubB_observationStation.xq @ 3118

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/stubB_observationStation.xq@3158
Revision 3118, 8.9 KB checked in by lawrence, 12 years ago (diff)

Splitting out the (authoratative?) python xqueries into named
files within the new egg for exist (and other ndg utilities)

Line 
1(: This query for TargetCollection, RepositoryID and LocalID, will return the stubB for an observation station :)
2declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';
3import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
4import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
5(:
6Will return when scope problem sussed... ;(
7import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery';
8:)
9declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
10declare namespace moles='http://ndg.nerc.ac.uk/moles';
11
12declare variable $targetCollection as xs:string {'TargetCollection'};
13declare variable $repositoryIdentifier as xs:string {'RepositoryID'};
14declare variable $localIdentifier as xs:string {'LocalID'};
15declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
16(: Returns a 'stubB' style activity record to expand an activity record :)
17(: Security not implemented here yet :)
18{
19let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
20moles:dgMetadataID/moles:localIdentifier=$locid
21and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]
22return
23element  {$out-element-name} {
24($SRAct/moles:dgMetadataID),
25($SRAct/moles:dgMetadataDescription),
26($SRAct/moles:name),
27($SRAct/moles:abbreviation),
28($SRAct/moles:logos)
29} (: </activity> :)
30} ;
31
32declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
33(: Returns a 'stubB' style observation station record to expand an data entity record :)
34(: Security not implemented yet :)
35{
36let $SRDE := $DE
37return 
38element {$out-element-name} {
39($SRDE/moles:dgMetadataID),
40($SRDE/moles:dgMetadataDescription),
41($SRDE/moles:name),
42($SRDE/moles:abbreviation)
43} (: </dgDataEntity> :)       
44} ;
45
46declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
47(: Returns a 'stubB' style dpt record to expand a dpt record :)
48(: Security not implemented yet :)
49{
50let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
51moles:dgMetadataID/moles:localIdentifier=$locid
52and
53moles:dgMetadataID/moles:repositoryIdentifier=$repid
54]
55return 
56element {$out-element-name} {
57$SRDPT/moles:dgMetadataID,
58$SRDPT/moles:dgMetadataDescription,
59$SRDPT/moles:name,
60$SRDPT/moles:abbreviation,
61$SRDPT/moles:logos
62} (: </dataproductiontool> :)
63} ;
64
65declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
66(: Returns a 'stubB' style observation station record to expand an observation station record :)
67(: Security not implemented here yet;  :)
68{
69let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
70moles:dgMetadataID/moles:localIdentifier=$locid
71and
72moles:dgMetadataID/moles:repositoryIdentifier=$repid
73]
74return
75element {$out-element-name} {
76($SRObsStn/moles:dgMetadataID),
77($SRObsStn/moles:dgMetadataDescription),
78($SRObsStn/moles:name),
79($SRObsStn/moles:abbreviation),
80($SRObsStn/moles:logos)
81}
82} ;
83
84declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
85(: Returns a 'stubB' style observation station record to expand a person record :)
86(: Security not implemented yet :)
87{
88let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
89moles:dgMetadataID/moles:localIdentifier=$locid
90and
91moles:dgMetadataID/moles:repositoryIdentifier=$repid
92]
93return
94element  {$out-element-name}
95{
96($person/moles:name),
97($person/moles:contactDetails),
98($person/moles:dgMetadataID)
99}
100} ;
101
102declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
103(: Returns a 'stubB' style observation station record to expand an organisation record :)
104(: Security not implemented yet :)
105{
106let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
107moles:dgMetadataID/moles:localIdentifier=$locid
108and
109moles:dgMetadataID/moles:repositoryIdentifier=$repid
110]
111return
112element  {$out-element-name} {
113$org/moles:dgMetadataID,
114$org/moles:name,
115$org/moles:abbreviation,
116$org/moles:contactDetails,
117$org/moles:logos
118}
119} ;
120
121let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
122moles:dgObservationStation!=''
123and moles:dgMetadataID[
124moles:repositoryIdentifier=$repositoryIdentifier
125and moles:localIdentifier=$localIdentifier]]
126return
127utillib:strip-namespace(
128element dgMetadataRecord {
129element dgMetadataID {
130element schemeIdentifier {'NDG-B1'},
131$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
132$ObsStn/moles:dgMetadataID/moles:localIdentifier
133} (: End </dgMetadataID> :),
134$ObsStn/moles:dgMetadataDescription,
135$ObsStn/moles:name,
136$ObsStn/moles:abbreviation,
137element dgObservationStation {
138$ObsStn/moles:dgObservationStation/moles:contactDetails,
139if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
140element dgStationaryPlatform {
141$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
142if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
143element dgMooring {
144$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
145$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
146for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
147return
148f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
149if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
150for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
151return 
152f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
153else ()
154} (: End </dgMooring> :) 
155else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
156element dgStationGroup {
157element dgGroupedStations {
158if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
159for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
160return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
161else ()
162} (: End </dgGroupedStations> :)
163} (: End </dgStationGroup> :)
164else $ObsStn/moles:dgObservationStation/moles:dgLandStation
165} (: End </dgStationaryPlatform>  :) 
166else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
167element DeploymentSummary {
168element activityList {
169for $DepActRepository in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:ActivityID/moles:repositoryIdentifier)
170for $DepActLocal in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:ActivityID/moles:localIdentifier)
171let $DepAct :=  f:return-stub-activity('activity', data($DepActRepository), data($DepActLocal))
172return $DepAct
173},
174element dptList {
175for $DepDPTRepository in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:DataProductionToolID/moles:repositoryIdentifier)
176for $DepDPTLocal in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:DataProductionToolID/moles:localIdentifier)
177let $DepDPT :=  f:return-stub-dpt('dataproductiontool', data($DepDPTRepository), data($DepDPTLocal))
178return $DepDPT
179},
180element dataEntityList {
181for $DE in
182collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment
183/moles:ObservationStationID
184[moles:localIdentifier=$ObsStn/moles:dgMetadataID/moles:localIdentifier
185and moles:repositoryIdentifier=$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier]]
186order by $DE/moles:dgMetadataID
187return f:return-stub-dataentity('dataentity', $DE)
188}
189, element rawDeployments {for $rawDeployments in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment return $rawDeployments}
190} (: </DeploymentSummary> :)
191} (: </dgObservationStation> :),
192for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
193if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
194if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
195} (: End </dgMetadataRecord> :)
196) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.