source: TI07-MOLES/trunk/StubB/XQuery/NDG-DEStubBFull.xquery @ 2583

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-DEStubBFull.xquery@2660
Revision 2583, 15.0 KB checked in by ko23, 13 years ago (diff)

New version of ndg_xqueries.py and examples of new StubBs?

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),
60element dgDataEntity {
61($SRDE/moles:dgDataEntity/moles:dgDataSetType),
62($SRDE/moles:dgDataEntity/moles:dgDataGranule),
63($SRDE/moles:dgDataEntity/moles:dgDataSummary)
64} (: </dgDataEntity> :)       
65}
66} ;
67
68declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
69(: Returns a 'stubB' style dpt record to expand a dpt record :)
70(: Security not implemented yet :)
71{
72let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
73moles:dgMetadataID/moles:localIdentifier=$locid
74and
75moles:dgMetadataID/moles:repositoryIdentifier=$repid
76]
77return 
78element {$out-element-name} {
79$SRDPT/moles:dgMetadataID,
80$SRDPT/moles:dgMetadataDescription,
81$SRDPT/moles:name,
82$SRDPT/moles:abbreviation,
83$SRDPT/moles:logos,
84element dgDataProductionTool {
85$SRDPT/moles:dgDataProductionTool/moles:contactDetails,
86if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then
87$SRDPT/moles:dgDataProductionTool/moles:dgModel
88else (),
89if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then
90$SRDPT/moles:dgDataProductionTool/moles:dgInstrument
91else ()
92} (: </dgDataProductionTool> :)
93} (: </dataproductiontool> :)
94} ;
95
96declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
97(: Returns a 'stubB' style observation station record to expand an observation station record :)
98(: Security not implemented here yet;  :)
99{
100let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
101moles:dgMetadataID/moles:localIdentifier=$locid
102and
103moles:dgMetadataID/moles:repositoryIdentifier=$repid
104]
105return
106element {$out-element-name} {
107($SRObsStn/moles:dgMetadataID),
108($SRObsStn/moles:dgMetadataDescription),
109($SRObsStn/moles:name),
110($SRObsStn/moles:abbreviation),
111($SRObsStn/moles:logos),
112element dgObservationStation {
113($SRObsStn/moles:dgObservationStation/moles:contactDetails),
114if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
115element dgStationaryPlatform {
116$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
117if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''}
118else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''}
119else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''}
120else ()
121}
122else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then
123$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform
124else ()
125} (: </dgObservationStation> :)
126}
127} ;
128
129declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
130(: Returns a 'stubB' style observation station record to expand a person record :)
131(: Security not implemented yet :)
132{
133let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
134moles:dgMetadataID/moles:localIdentifier=$locid
135and
136moles:dgMetadataID/moles:repositoryIdentifier=$repid
137]
138return
139element  {$out-element-name}
140{
141($person/moles:name),
142($person/moles:contactDetails),
143($person/moles:dgMetadataID)
144}
145} ;
146
147declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
148(: Returns a 'stubB' style observation station record to expand an organisation record :)
149(: Security not implemented yet :)
150{
151let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
152moles:dgMetadataID/moles:localIdentifier=$locid
153and
154moles:dgMetadataID/moles:repositoryIdentifier=$repid
155]
156return
157element  {$out-element-name} {
158$org/moles:dgMetadataID,
159$org/moles:name,
160$org/moles:abbreviation,
161$org/moles:contactDetails,
162$org/moles:logos
163}
164} ;
165
166for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
167exists(moles:dgDataEntity)
168and moles:dgMetadataID[
169moles:schemeIdentifier='NDG-B0'
170and moles:repositoryIdentifier=$repositoryIdentifier
171and moles:localIdentifier=$localIdentifier]]
172return
173utillib:strip-namespace(element dgMetadataRecord {
174    element dgMetadataID {
175        element schemeIdentifier {'NDG-B1'},
176        $DE/moles:dgMetadataID/moles:repositoryIdentifier,
177        $DE/moles:dgMetadataID/moles:localIdentifier
178    }, (: </dgMetadataID> :)
179    $DE/moles:dgMetadataDescription,
180    $DE/moles:name,
181    $DE/moles:abbreviation,
182    element dgDataEntity {
183        $DE/moles:dgDataEntity/moles:dgDataSetType,
184        $DE/moles:dgDataEntity/moles:dgDataObjectType,
185        $DE/moles:dgDataEntity/moles:dgDataGranule,
186        $DE/moles:dgDataEntity/moles:dgDataSummary,
187        element dgDataRoles {
188            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then
189                element dgDataCreator {
190                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID,
191                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName,
192                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation,
193                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails,
194                for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder
195                    order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least
196                    return
197                        element dgRoleHolder {
198                            if (exists($DataCreatorRole/moles:dgOrganisationID)) then
199                                f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier))
200                             else if (exists($DataCreatorRole/moles:dgPersonID)) then
201                                f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier))
202                             else (),
203                            $DataCreatorRole/moles:startDate,
204                            $DataCreatorRole/moles:endDate,
205                            $DataCreatorRole/moles:localName
206                        } (: </dgRoleHolder> :)
207                    } (: </dgDataCreator>) :)
208            else (),
209            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then
210                element dgDataCurator {
211                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID,
212                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName,
213                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation,
214                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails,
215                for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder
216                    order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least
217                    return
218                        element dgRoleHolder {
219                            if (exists($DataCuratorRole/moles:dgOrganisationID)) then
220                                f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier))
221                             else if (exists($DataCuratorRole/moles:dgPersonID)) then
222                                f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier))
223                             else (),
224                            $DataCuratorRole/moles:startDate,
225                            $DataCuratorRole/moles:endDate,
226                            $DataCuratorRole/moles:localName
227                        } (: </dgRoleHolder> :)
228            } (: </dgDataCurator> :)
229            else (),
230            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then
231                element dgDataOtherRoles {
232                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID,
233                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName,
234                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation,
235                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails,
236                for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder
237                    order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least
238                    return
239                        element dgRoleHolder {
240                            if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then
241                                f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier))
242                             else if (exists($DataOtherRolesRole/moles:dgPersonID)) then
243                                f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier))
244                             else (),
245                            $DataOtherRolesRole/moles:startDate,
246                            $DataOtherRolesRole/moles:endDate,
247                            $DataOtherRolesRole/moles:localName
248                        } (: </dgRoleHolder> :)
249            } (: </dgDataOtherRoles> :)
250            else ()
251        } , (: </dgDataRoles> :)
252        for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment
253            return
254            element RelatedDeployment {
255            $RelDep/moles:DateStart,
256            $RelDep/moles:DateEnd,
257            $RelDep/moles:dgMetadataID,
258            f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
259            f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
260            f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),
261            $RelDep/moles:Coverage
262        } (: </RelatedDeployment> :)
263        ,
264        for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity
265            return
266                element relateddataentity {
267                element relation {
268                    $RelatedDataEntity/moles:RelationID/moles:dgValidTerm,
269                    $RelatedDataEntity/moles:RelationID/moles:dgValidTermID
270                }, (: </relation> :)
271                let $DE := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:repositoryIdentifier
272                      and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:localIdentifier]
273                 return
274                    f:return-stub-dataentity('dataentity', $DE)
275                }
276} (: </dgDataEntity> :),
277    for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd,
278    if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (),
279    if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else ()
280} (: </dgMetadataRecord> :)
281) (: end of namespace strip :)
Note: See TracBrowser for help on using the repository browser.