source: TI07-MOLES/trunk/StubB/XQuery/NDG-DPTStubB.xquery @ 2466

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-DPTStubB.xquery@2466
Revision 2466, 8.9 KB checked in by ko23, 14 years ago (diff)

Updated XQueries for BADC 'worst cases so far'

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