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

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

Fix for #799, and update examples

  • 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)
34} (: </activity> :)
35} ;
36
37declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
38(: Returns a 'stubB' style observation station record to expand an data entity record :)
39(: Security not implemented yet :)
40{
41let $SRDE := $DE
42return 
43element {$out-element-name} {
44($SRDE/moles:dgMetadataID),
45($SRDE/moles:dgMetadataDescription),
46($SRDE/moles:name),
47($SRDE/moles:abbreviation)
48} (: </dgDataEntity> :)       
49} ;
50
51declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
52(: Returns a 'stubB' style dpt record to expand a dpt record :)
53(: Security not implemented yet :)
54{
55let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
56moles:dgMetadataID/moles:localIdentifier=$locid
57and
58moles:dgMetadataID/moles:repositoryIdentifier=$repid
59]
60return 
61element {$out-element-name} {
62$SRDPT/moles:dgMetadataID,
63$SRDPT/moles:dgMetadataDescription,
64$SRDPT/moles:name,
65$SRDPT/moles:abbreviation,
66$SRDPT/moles:logos
67} (: </dataproductiontool> :)
68} ;
69
70declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
71(: Returns a 'stubB' style observation station record to expand an observation station record :)
72(: Security not implemented here yet;  :)
73{
74let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
75moles:dgMetadataID/moles:localIdentifier=$locid
76and
77moles:dgMetadataID/moles:repositoryIdentifier=$repid
78]
79return
80element {$out-element-name} {
81($SRObsStn/moles:dgMetadataID),
82($SRObsStn/moles:dgMetadataDescription),
83($SRObsStn/moles:name),
84($SRObsStn/moles:abbreviation),
85($SRObsStn/moles:logos)
86}
87} ;
88
89declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
90(: Returns a 'stubB' style observation station record to expand a person record :)
91(: Security not implemented yet :)
92{
93let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
94moles:dgMetadataID/moles:localIdentifier=$locid
95and
96moles:dgMetadataID/moles:repositoryIdentifier=$repid
97]
98return
99element  {$out-element-name}
100{
101($person/moles:name),
102($person/moles:contactDetails),
103($person/moles:dgMetadataID)
104}
105} ;
106
107declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
108(: Returns a 'stubB' style observation station record to expand an organisation record :)
109(: Security not implemented yet :)
110{
111let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
112moles:dgMetadataID/moles:localIdentifier=$locid
113and
114moles:dgMetadataID/moles:repositoryIdentifier=$repid
115]
116return
117element  {$out-element-name} {
118$org/moles:dgMetadataID,
119$org/moles:name,
120$org/moles:abbreviation,
121$org/moles:contactDetails,
122$org/moles:logos
123}
124} ;
125
126for $DPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
127    moles:dgDataProductionTool!=''
128    and moles:dgMetadataID[
129    moles:schemeIdentifier='NDG-B0'
130    and moles:repositoryIdentifier=$repositoryIdentifier
131    and moles:localIdentifier=$localIdentifier]]
132    return
133utillib:strip-namespace(element dgMetadataRecord {
134    $DPT/dgMetadataID,
135        element dgMetadataID {
136            element schemeIdentifier {'NDG-B1'},
137            $DPT/moles:dgMetadataID/moles:repositoryIdentifier,
138            $DPT/moles:dgMetadataID/moles:localIdentifier
139        } (: End </dgMetadataID> :),
140    $DPT/moles:dgMetadataDescription,
141    $DPT/moles:name,
142    $DPT/moles:abbreviation,
143    element dgDataProductionTool {
144        $DPT/moles:contactDetails,
145        if (exists($DPT/moles:dgModel)) then $DPT/moles:dgModel
146        else $DPT/moles:dgInstrument
147    ,
148    if (exists($DPT/moles:dgDPTRoles)) then
149        element dgDPTRoles {'Roles are available, and will be added soon'}
150     else(),
151element DeploymentSummary {
152element activityList {
153for $DepActRepository in distinct-values($DPT/moles:dgDataProductionTool/moles:DPTDeployment/moles:ActivityID/moles:repositoryIdentifier)
154for $DepActLocal in distinct-values($DPT/moles:dgDataProductionTool/moles:DPTDeployment/moles:ActivityID/moles:localIdentifier)
155let $DepAct :=  f:return-stub-activity('activity', data($DepActRepository), data($DepActLocal))
156return $DepAct
157},
158element obsStnList {
159for $DepObsStnRepository in distinct-values($DPT/moles:dgDataProductionTool/moles:DPTDeployment/moles:ObservationStationID/moles:repositoryIdentifier)
160for $DepObsStnLocal in distinct-values($DPT/moles:dgDataProductionTool/moles:DPTDeployment/moles:ObservationStationID/moles:localIdentifier)
161let $DepObsStn :=  f:return-stub-obsstn('observationstation', data($DepObsStnRepository), data($DepObsStnLocal))
162return $DepObsStn
163},
164element dataEntityList {
165for $DE in
166collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment
167/moles:DataProductionToolID
168[moles:localIdentifier=$DPT/moles:dgMetadataID/moles:localIdentifier
169and moles:repositoryIdentifier=$DPT/moles:dgMetadataID/moles:repositoryIdentifier]]
170order by $DE/moles:dgMetadataID
171return f:return-stub-dataentity('dataentity', $DE)
172}
173, element rawDeployments {for $rawDeployments in $DPT/moles:dgDataProductionTool/moles:DPTDeployment return $rawDeployments}
174} (: </DeploymentSummary> :)
175} (: </dgDataProductionTool> :),
176    for $strkwrd in $DPT/moles:dgStructuredKeyword return $strkwrd,
177    if (exists($DPT/moles:dgMetadataProvenance)) then $DPT/moles:dgMetadataProvenance else (),
178    if (exists($DPT/moles:dgMetadataSecurity)) then $DPT/moles:dgMetadataSecurity else ()
179} (:End </dgMetadataRecord> :)
180) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.