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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-DEStubB.xquery@2466
Revision 2466, 14.7 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/dataentity';
2declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
3declare namespace moles='http://ndg.nerc.ac.uk/moles';
4
5import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
6import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
7(:
8Will return when scope problem sussed... ;(
9import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery';
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 {'dataent_11738907158217423'};
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 $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
168exists(moles:dgDataEntity)
169and moles:dgMetadataID[
170moles:schemeIdentifier='NDG-B0'
171and moles:repositoryIdentifier=$repositoryIdentifier
172and moles:localIdentifier=$localIdentifier]]
173return
174utillib:strip-namespace(element dgMetadataRecord {
175    element dgMetadataID {
176        element schemeIdentifier {'NDG-B1'},
177        $DE/moles:dgMetadataID/moles:repositoryIdentifier,
178        $DE/moles:dgMetadataID/moles:localIdentifier
179    }, (: </dgMetadataID> :)
180    $DE/moles:dgMetadataDescription,
181    $DE/moles:name,
182    $DE/moles:abbreviation,
183    element dgDataEntity {
184        $DE/moles:dgDataEntity/moles:dgDataSetType,
185        $DE/moles:dgDataEntity/moles:dgDataObjectType,
186        $DE/moles:dgDataEntity/moles:dgDataGranule,
187        $DE/moles:dgDataEntity/moles:dgDataSummary,
188        element dgDataRoles {
189            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then
190                element dgDataCreator {
191                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID,
192                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName,
193                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation,
194                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails,
195                for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder
196                    order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least
197                    return
198                        element dgRoleHolder {
199                            if (exists($DataCreatorRole/moles:dgOrganisationID)) then
200                                f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier))
201                             else if (exists($DataCreatorRole/moles:dgPersonID)) then
202                                f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier))
203                             else (),
204                            $DataCreatorRole/moles:startDate,
205                            $DataCreatorRole/moles:endDate,
206                            $DataCreatorRole/moles:localName
207                        } (: </dgRoleHolder> :)
208                    } (: </dgDataCreator>) :)
209            else (),
210            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then
211                element dgDataCurator {
212                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID,
213                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName,
214                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation,
215                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails,
216                for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder
217                    order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least
218                    return
219                        element dgRoleHolder {
220                            if (exists($DataCuratorRole/moles:dgOrganisationID)) then
221                                f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier))
222                             else if (exists($DataCuratorRole/moles:dgPersonID)) then
223                                f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier))
224                             else (),
225                            $DataCuratorRole/moles:startDate,
226                            $DataCuratorRole/moles:endDate,
227                            $DataCuratorRole/moles:localName
228                        } (: </dgRoleHolder> :)
229            } (: </dgDataCurator> :)
230            else (),
231            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then
232                element dgDataOtherRoles {
233                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID,
234                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName,
235                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation,
236                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails,
237                for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder
238                    order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least
239                    return
240                        element dgRoleHolder {
241                            if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then
242                                f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier))
243                             else if (exists($DataOtherRolesRole/moles:dgPersonID)) then
244                                f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier))
245                             else (),
246                            $DataOtherRolesRole/moles:startDate,
247                            $DataOtherRolesRole/moles:endDate,
248                            $DataOtherRolesRole/moles:localName
249                        } (: </dgRoleHolder> :)
250            } (: </dgDataOtherRoles> :)
251            else ()
252        } , (: </dgDataRoles> :)
253        for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment
254            return
255            element RelatedDeployment {
256            $RelDep/moles:DateStart,
257            $RelDep/moles:DateEnd,
258            $RelDep/moles:dgMetadataID,
259            f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
260            f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
261            f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),
262            $RelDep/moles:Coverage
263        } (: </RelatedDeployment> :)
264        ,
265        for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity
266            return
267                element relateddataentity {
268                element relation {
269                    $RelatedDataEntity/moles:RelationID/moles:dgValidTerm,
270                    $RelatedDataEntity/moles:RelationID/moles:dgValidTermID
271                }, (: </relation> :)
272                let $DE := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:repositoryIdentifier
273                      and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:localIdentifier]
274                 return
275                    f:return-stub-dataentity('dataentity', $DE)
276                }
277} (: </dgDataEntity> :),
278    for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd,
279    if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (),
280    if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else ()
281} (: </dgMetadataRecord> :)
282) (: end of namespace strip :)
Note: See TracBrowser for help on using the repository browser.