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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-ActStubBFull.xquery@2660
Revision 2583, 17.4 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/activity';
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 {'activity_11680365144712080'};
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 $Act in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
167    moles:dgActivity!=''
168    and moles:dgMetadataID[
169    moles:schemeIdentifier='NDG-B0'
170    and moles:repositoryIdentifier=$repositoryIdentifier
171    and moles:localIdentifier=$localIdentifier]]
172    return
173utillib:strip-namespace(element dgMetadataRecord {
174    element dgMetadataID {
175        element schemeIdentifier {'NDG-B1'},
176        (element repositoryIdentifier {data($Act/moles:dgMetadataID/moles:repositoryIdentifier)}),
177        element localIdentifier {data($Act/moles:dgMetadataID/moles:localIdentifier)}
178    },
179    $Act/moles:dgMetadataDescription,
180    $Act/moles:name,
181    $Act/moles:abbreviation,
182    element dgActivity {
183        for $RelatedActivities in $Act/dgActivity/moles:relatedActivity
184            return
185                element relatedActivity {
186                    $RelatedActivities/moles:activityRelation,
187                    f:return-stub-activity('activity', data($RelatedActivities/moles:relatedActivityID/moles:repositoryIdentifier), data($RelatedActivities/moles:relatedActivityID/moles:localIdentifier))
188            },    (: </relatedActivity> :)
189        if (exists($Act/moles:dgActivity/moles:dgActivityDataCollection)) then ($Act/moles:dgActivity/moles:dgActivityDataCollection)
190        else if (exists($Act/moles:dgActivity/moles:dgActivityDataProject)) then ($Act/moles:dgActivity/moles:dgActivityDataProject)
191        else if (exists($Act/moles:dgActivity/moles:dgActivityDataInvestigation)) then ($Act/moles:dgActivity/moles:dgActivityDataInvestigation)
192        else if (exists($Act/moles:dgActivity/moles:dgActivityDataCampaign)) then ($Act/moles:dgActivity/moles:dgActivityDataCampaign)
193        else (),
194        element dgActivityRole {
195            element dgInvestigator {
196                element dgPrincipalInvestigator {
197                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgMetadataID),
198                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:roleName),
199                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:abbreviation),
200                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:contactDetails),
201                    for $PIRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgRoleHolder
202                        order by $PIRole/moles:startDate empty least, $PIRole/moles:endDate empty least
203                        return
204                        element dgRoleHolder {
205                            if (exists($PIRole/moles:dgOrganisationID)) then
206                                f:return-stub-organisation('organisation', data($PIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PIRole/moles:dgOrganisationID/moles:localIdentifier))
207                             else if (exists($PIRole/moles:dgPersonID)) then
208                                f:return-stub-person('person', string($PIRole/moles:dgPersonID/moles:repositoryIdentifier), string($PIRole/moles:dgPersonID/moles:localIdentifier))
209                             else (),
210                            ($PIRole/moles:startDate),
211                            if (exists($PIRole/moles:endDate)) then
212                                ($PIRole/moles:endDate)
213                            else (),
214                            if (exists($PIRole/moles:localName)) then
215                                ($PIRole/moles:localName)
216                            else ()
217                        } (: </dgRoleHolder> :)
218                }, (: </dgPrincipalInvestigator> :)
219                for $CI in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgCoInvestigator
220                return 
221                    element dgCoInvestigator {
222                        ($CI/moles:dgMetadataID),
223                        ($CI/moles:roleName),
224                        ($CI/moles:abbreviation),
225                        ($CI/moles:contactDetails),
226                        for $CIRole in $CI/moles:dgRoleHolder
227                            order by $CIRole/moles:startDate empty least, $CIRole/moles:endDate empty least
228                        return
229                        element dgRoleHolder {
230                            if (exists(CIRole/moles:dgOrganisationID)) then
231                                f:return-stub-organisation('organisation', data($CIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($CIRole/moles:dgOrganisationID/moles:localIdentifier))
232                             else if (exists($CIRole/moles:dgPersonID)) then
233                                f:return-stub-person('person', string($CIRole/moles:dgPersonID/moles:repositoryIdentifier), string($CIRole/moles:dgPersonID/moles:localIdentifier))
234                             else (),
235                            ($CIRole/moles:startDate),
236                            if (exists($CIRole/moles:endDate)) then
237                                ($CIRole/moles:endDate)
238                            else (),
239                            if (exists($CIRole/moles:localName)) then
240                                ($CIRole/moles:localName)
241                            else ()
242                        } (: </dgRoleHolder> :)
243                } (: </dgCoInvestigator> :)
244        }, (: </dgInvestigator> :)
245        if (exists($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact)) then (
246            element dgTechnicalContact {
247                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgMetadataID),
248                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:roleName),
249                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:abbreviation),
250                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:contactDetails),
251                for $TechConRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgRoleHolder
252                    order by $TechConRole/moles:startDate empty least, $TechConRole/moles:endDate empty least
253                    return
254                    element dgRoleHolder {
255                        if (exists($TechConRole/moles:dgOrganisationID)) then
256                            f:return-stub-organisation('organisation', data($TechConRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($TechConRole/moles:dgOrganisationID/moles:localIdentifier))
257                         else if (exists($TechConRole/moles:dgPersonID)) then
258                            f:return-stub-person('person', string($TechConRole/moles:dgPersonID/moles:repositoryIdentifier), string($TechConRole/moles:dgPersonID/moles:localIdentifier))
259                         else (),
260                        ($TechConRole/moles:startDate),
261                        if (exists($TechConRole/moles:endDate)) then
262                            ($TechConRole/moles:endDate)
263                        else (),
264                        if (exists($TechConRole/moles:localName)) then
265                                ($TechConRole/moles:localName)
266                           else ()
267                    } (: </dgRoleHolder> :)
268            } (: </dgTechnicalContact> :)
269        )
270        else (),
271        if (exists($Act/dgActivity/dgActivityRole/dgProjectManager)) then (
272            element dgProjectManager {
273                ($Act/dgActivity/dgActivityRole/dgProjectManager/dgMetadataID),
274                ($Act/dgActivity/dgActivityRole/dgProjectManager/roleName),
275                ($Act/dgActivity/dgActivityRole/dgProjectManager/abbreviation),
276                ($Act/dgActivity/dgActivityRole/dgProjectManager/contactDetails),
277                for $PMRole in $Act/dgActivity/dgActivityRole/dgProjectManager/dgRoleHolder
278                    order by $PMRole/startDate empty least, $PMRole/endDate empty least
279                    return
280                    element dgRoleHolder {
281                        if (exists($PMRole/moles:dgOrganisationID)) then
282                            f:return-stub-organisation('organisation', data($PMRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PMRole/moles:dgOrganisationID/moles:localIdentifier))
283                         else if (exists($PMRole/moles:dgPersonID)) then
284                            f:return-stub-person('person', string($PMRole/moles:dgPersonID/moles:repositoryIdentifier), string($PMRole/moles:dgPersonID/moles:localIdentifier))
285                         else (),
286                        ($PMRole/startDate),
287                        if (exists($PMRole/moles:endDate)) then
288                            ($PMRole/moles:endDate)
289                        else (),
290                        if (exists($PMRole/moles:localName)) then
291                            ($PMRole/moles:localName)
292                        else ()
293                    } (: </dgRoleHolder> :)
294            } (: </dgProjectManager> :)
295        )
296        else ()
297    }, (: </dgActivityRole> :)
298    for $RelDep in $Act/moles:dgActivity/moles:ActivityDeployment
299        return
300        element ActivityDeployment {
301            ($RelDep/moles:DateStart),
302            if (exists($RelDep/moles:DateEnd)) then
303                ($RelDep/moles:DateEnd)
304            else (),
305            ($RelDep/moles:dgMetadataID),
306            f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
307            f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),
308                for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier
309and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier]
310return
311f:return-stub-dataentity('dataentity', $DE)
312        }, (: </ActivityDeployment> :)
313        if (exists($Act/dgActivityCoverage)) then
314            ($Act/dgActivityCoverage)
315            else (),
316        if (exists($Act/dgActivityDuration)) then
317            ($Act/dgActivityDuration)
318            else ()
319    } , (: </dgActivity> :)
320    for $strkwrd in $Act/moles:dgStructuredKeyword return $strkwrd,
321    if (exists($Act/moles:dgMetadataProvenance)) then $Act/moles:dgMetadataProvenance else (),
322    if (exists($Act/moles:dgMetadataSecurity)) then $Act/moles:dgMetadataSecurity else ()
323} (:</dgMRecord>:)
324) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.