source: exist/trunk/xquery/stubB_activity.xq @ 3841

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/stubB_activity.xq@4239
Revision 3841, 15.2 KB checked in by cbyrom, 12 years ago (diff)

Various updates to the xquery files - to remove usage of invalid specs
and dependency on obsolete function calls. Also add the inputParse_xquery_lib.xquery
file - referenced from the xquery files but not currently included in codebase.
NB, changes made to allow use of Saxon java library to do xqueries - to
remove the need for the discovery service eXist DB.

  • NB, also changes tested by comparing saxon transforms to eXist ones; these

were found to be identical.

Line 
1(: This query for TargetCollection, RepositoryID and LocalID, will return the stubB for an activity :)
2declare default element namespace 'http://ndg.nerc.ac.uk/moles/activity';
3declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
4declare namespace moles='http://ndg.nerc.ac.uk/moles';
5
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 := 'TargetCollection';
12declare variable $repositoryIdentifier as xs:string := 'RepositoryID';
13declare variable $localIdentifier as xs:string := 'LocalID';
14
15declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
16(: Returns a 'stubB' style activity record to expand an activity record :)
17(: Security not implemented here yet :)
18{
19let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
20moles:dgMetadataID/moles:localIdentifier=$locid
21and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]
22return
23element  {$out-element-name} {
24($SRAct/moles:dgMetadataID),
25($SRAct/moles:dgMetadataDescription),
26($SRAct/moles:name),
27($SRAct/moles:abbreviation),
28($SRAct/moles:logos)
29} (: </activity> :)
30} ;
31
32declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
33(: Returns a 'stubB' style observation station record to expand an data entity record :)
34(: Security not implemented yet :)
35{
36let $SRDE := $DE
37return 
38element {$out-element-name} {
39($SRDE/moles:dgMetadataID),
40($SRDE/moles:dgMetadataDescription),
41($SRDE/moles:name),
42($SRDE/moles:abbreviation)
43} (: </dgDataEntity> :)       
44} ;
45
46declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
47(: Returns a 'stubB' style dpt record to expand a dpt record :)
48(: Security not implemented yet :)
49{
50let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
51moles:dgMetadataID/moles:localIdentifier=$locid
52and
53moles:dgMetadataID/moles:repositoryIdentifier=$repid
54]
55return 
56element {$out-element-name} {
57$SRDPT/moles:dgMetadataID,
58$SRDPT/moles:dgMetadataDescription,
59$SRDPT/moles:name,
60$SRDPT/moles:abbreviation,
61$SRDPT/moles:logos
62} (: </dataproductiontool> :)
63} ;
64
65declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
66(: Returns a 'stubB' style observation station record to expand an observation station record :)
67(: Security not implemented here yet;  :)
68{
69let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
70moles:dgMetadataID/moles:localIdentifier=$locid
71and
72moles:dgMetadataID/moles:repositoryIdentifier=$repid
73]
74return
75element {$out-element-name} {
76($SRObsStn/moles:dgMetadataID),
77($SRObsStn/moles:dgMetadataDescription),
78($SRObsStn/moles:name),
79($SRObsStn/moles:abbreviation),
80($SRObsStn/moles:logos)
81}
82} ;
83
84declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
85(: Returns a 'stubB' style observation station record to expand a person record :)
86(: Security not implemented yet :)
87{
88let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
89moles:dgMetadataID/moles:localIdentifier=$locid
90and
91moles:dgMetadataID/moles:repositoryIdentifier=$repid
92]
93return
94element  {$out-element-name}
95{
96($person/moles:name),
97($person/moles:contactDetails),
98($person/moles:dgMetadataID)
99}
100} ;
101
102declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
103(: Returns a 'stubB' style observation station record to expand an organisation record :)
104(: Security not implemented yet :)
105{
106let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
107moles:dgMetadataID/moles:localIdentifier=$locid
108and
109moles:dgMetadataID/moles:repositoryIdentifier=$repid
110]
111return
112element  {$out-element-name} {
113$org/moles:dgMetadataID,
114$org/moles:name,
115$org/moles:abbreviation,
116$org/moles:contactDetails,
117$org/moles:logos
118}
119} ;
120
121for $Act in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
122    moles:dgActivity!=''
123    and moles:dgMetadataID[
124    moles:schemeIdentifier='NDG-B0'
125    and moles:repositoryIdentifier=$repositoryIdentifier
126    and moles:localIdentifier=$localIdentifier]]
127    return
128utillib:strip-namespace(element dgMetadataRecord {
129    element dgMetadataID {
130        element schemeIdentifier {'NDG-B1'},
131        (element repositoryIdentifier {data($Act/moles:dgMetadataID/moles:repositoryIdentifier)}),
132        element localIdentifier {data($Act/moles:dgMetadataID/moles:localIdentifier)}
133    },
134    $Act/moles:dgMetadataDescription,
135    $Act/moles:name,
136    $Act/moles:abbreviation,
137    element dgActivity {
138        for $RelatedActivities in $Act/dgActivity/moles:relatedActivity
139            return
140                element relatedActivity {
141                    $RelatedActivities/moles:activityRelation,
142                    f:return-stub-activity('activity', data($RelatedActivities/moles:relatedActivityID/moles:repositoryIdentifier), data($RelatedActivities/moles:relatedActivityID/moles:localIdentifier))
143            },    (: </relatedActivity> :)
144        if (exists($Act/moles:dgActivity/moles:dgActivityDataCollection)) then ($Act/moles:dgActivity/moles:dgActivityDataCollection)
145        else if (exists($Act/moles:dgActivity/moles:dgActivityDataProject)) then ($Act/moles:dgActivity/moles:dgActivityDataProject)
146        else if (exists($Act/moles:dgActivity/moles:dgActivityDataInvestigation)) then ($Act/moles:dgActivity/moles:dgActivityDataInvestigation)
147        else if (exists($Act/moles:dgActivity/moles:dgActivityDataCampaign)) then ($Act/moles:dgActivity/moles:dgActivityDataCampaign)
148        else (),
149        element dgActivityRole {
150            element dgInvestigator {
151                element dgPrincipalInvestigator {
152                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgMetadataID),
153                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:roleName),
154                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:abbreviation),
155                    ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:contactDetails),
156                    for $PIRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgRoleHolder
157                        order by $PIRole/moles:startDate empty least, $PIRole/moles:endDate empty least
158                        return
159                        element dgRoleHolder {
160                            if (exists($PIRole/moles:dgOrganisationID)) then
161                                f:return-stub-organisation('organisation', data($PIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PIRole/moles:dgOrganisationID/moles:localIdentifier))
162                             else if (exists($PIRole/moles:dgPersonID)) then
163                                f:return-stub-person('person', string($PIRole/moles:dgPersonID/moles:repositoryIdentifier), string($PIRole/moles:dgPersonID/moles:localIdentifier))
164                             else (),
165                            ($PIRole/moles:startDate),
166                            if (exists($PIRole/moles:endDate)) then
167                                ($PIRole/moles:endDate)
168                            else (),
169                            if (exists($PIRole/moles:localName)) then
170                                ($PIRole/moles:localName)
171                            else ()
172                        } (: </dgRoleHolder> :)
173                }, (: </dgPrincipalInvestigator> :)
174                for $CI in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgCoInvestigator
175                return 
176                    element dgCoInvestigator {
177                        ($CI/moles:dgMetadataID),
178                        ($CI/moles:roleName),
179                        ($CI/moles:abbreviation),
180                        ($CI/moles:contactDetails),
181                        for $CIRole in $CI/moles:dgRoleHolder
182                            order by $CIRole/moles:startDate empty least, $CIRole/moles:endDate empty least
183                        return
184                        element dgRoleHolder {
185                            if (exists(CIRole/moles:dgOrganisationID)) then
186                                f:return-stub-organisation('organisation', data($CIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($CIRole/moles:dgOrganisationID/moles:localIdentifier))
187                             else if (exists($CIRole/moles:dgPersonID)) then
188                                f:return-stub-person('person', string($CIRole/moles:dgPersonID/moles:repositoryIdentifier), string($CIRole/moles:dgPersonID/moles:localIdentifier))
189                             else (),
190                            ($CIRole/moles:startDate),
191                            if (exists($CIRole/moles:endDate)) then
192                                ($CIRole/moles:endDate)
193                            else (),
194                            if (exists($CIRole/moles:localName)) then
195                                ($CIRole/moles:localName)
196                            else ()
197                        } (: </dgRoleHolder> :)
198                } (: </dgCoInvestigator> :)
199        }, (: </dgInvestigator> :)
200        if (exists($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact)) then (
201            element dgTechnicalContact {
202                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgMetadataID),
203                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:roleName),
204                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:abbreviation),
205                ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:contactDetails),
206                for $TechConRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgRoleHolder
207                    order by $TechConRole/moles:startDate empty least, $TechConRole/moles:endDate empty least
208                    return
209                    element dgRoleHolder {
210                        if (exists($TechConRole/moles:dgOrganisationID)) then
211                            f:return-stub-organisation('organisation', data($TechConRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($TechConRole/moles:dgOrganisationID/moles:localIdentifier))
212                         else if (exists($TechConRole/moles:dgPersonID)) then
213                            f:return-stub-person('person', string($TechConRole/moles:dgPersonID/moles:repositoryIdentifier), string($TechConRole/moles:dgPersonID/moles:localIdentifier))
214                         else (),
215                        ($TechConRole/moles:startDate),
216                        if (exists($TechConRole/moles:endDate)) then
217                            ($TechConRole/moles:endDate)
218                        else (),
219                        if (exists($TechConRole/moles:localName)) then
220                                ($TechConRole/moles:localName)
221                           else ()
222                    } (: </dgRoleHolder> :)
223            } (: </dgTechnicalContact> :)
224        )
225        else (),
226        if (exists($Act/dgActivity/dgActivityRole/dgProjectManager)) then (
227            element dgProjectManager {
228                ($Act/dgActivity/dgActivityRole/dgProjectManager/dgMetadataID),
229                ($Act/dgActivity/dgActivityRole/dgProjectManager/roleName),
230                ($Act/dgActivity/dgActivityRole/dgProjectManager/abbreviation),
231                ($Act/dgActivity/dgActivityRole/dgProjectManager/contactDetails),
232                for $PMRole in $Act/dgActivity/dgActivityRole/dgProjectManager/dgRoleHolder
233                    order by $PMRole/startDate empty least, $PMRole/endDate empty least
234                    return
235                    element dgRoleHolder {
236                        if (exists($PMRole/moles:dgOrganisationID)) then
237                            f:return-stub-organisation('organisation', data($PMRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PMRole/moles:dgOrganisationID/moles:localIdentifier))
238                         else if (exists($PMRole/moles:dgPersonID)) then
239                            f:return-stub-person('person', string($PMRole/moles:dgPersonID/moles:repositoryIdentifier), string($PMRole/moles:dgPersonID/moles:localIdentifier))
240                         else (),
241                        ($PMRole/startDate),
242                        if (exists($PMRole/moles:endDate)) then
243                            ($PMRole/moles:endDate)
244                        else (),
245                        if (exists($PMRole/moles:localName)) then
246                            ($PMRole/moles:localName)
247                        else ()
248                    } (: </dgRoleHolder> :)
249            } (: </dgProjectManager> :)
250        )
251        else ()
252    }, (: </dgActivityRole> :)
253element DeploymentSummary {
254element dptList {
255for $DepDPTRepository in distinct-values($Act/moles:dgActivity/moles:ActivityDeployment/moles:DataProductionToolID/moles:repositoryIdentifier)
256for $DepDPTLocal in distinct-values($Act/moles:dgActivity/moles:ActivityDeployment/moles:DataProductionToolID/moles:localIdentifier)
257let $DepDPT :=  f:return-stub-dpt('dataproductiontool', data($DepDPTRepository), data($DepDPTLocal))
258return $DepDPT
259},
260element obsStnList {
261for $DepObsStnRepository in distinct-values($Act/moles:dgActivity/moles:ActivityDeployment/moles:ObservationStationID/moles:repositoryIdentifier)
262for $DepObsStnLocal in distinct-values($Act/moles:dgActivity/moles:ActivityDeployment/moles:ObservationStationID/moles:localIdentifier)
263let $DepObsStn :=  f:return-stub-obsstn('observationstation', data($DepObsStnRepository), data($DepObsStnLocal))
264return $DepObsStn
265},
266element dataEntityList {
267for $DE in
268collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment
269/moles:ActivityID
270[moles:localIdentifier=$Act/moles:dgMetadataID/moles:localIdentifier
271and moles:repositoryIdentifier=$Act/moles:dgMetadataID/moles:repositoryIdentifier]]
272order by $DE/moles:dgMetadataID
273return f:return-stub-dataentity('dataentity', $DE)
274}
275, element rawDeployments {for $rawDeployments in $Act/moles:dgActivity/moles:ActivityDeployment return $rawDeployments}
276}, (: </DeploymentSummary> :)
277        if (exists($Act/dgActivityCoverage)) then
278            ($Act/dgActivityCoverage)
279            else (),
280        if (exists($Act/dgActivityDuration)) then
281            ($Act/dgActivityDuration)
282            else ()
283    } , (: </dgActivity> :)
284    for $strkwrd in $Act/moles:dgStructuredKeyword return $strkwrd,
285    if (exists($Act/moles:dgMetadataProvenance)) then $Act/moles:dgMetadataProvenance else (),
286    if (exists($Act/moles:dgMetadataSecurity)) then $Act/moles:dgMetadataSecurity else ()
287} (:</dgMRecord>:)
288) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.