source: exist/trunk/xquery/stubB_dataEntity.xq @ 3118

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/stubB_dataEntity.xq@3118
Revision 3118, 13.2 KB checked in by lawrence, 12 years ago (diff)

Splitting out the (authoratative?) python xqueries into named
files within the new egg for exist (and other ndg utilities)

Line 
1(: This query for TargetCollection, RepositoryID and LocalID, will return the stubB for a data entity :)
2declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataentity';
3declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
4declare namespace moles='http://ndg.nerc.ac.uk/moles';
5
6import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
7import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
8(:
9Will return when scope problem sussed... ;(
10import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery';
11:)
12declare variable $targetCollection as xs:string {'TargetCollection'};
13declare variable $repositoryIdentifier as xs:string {'RepositoryID'};
14declare variable $localIdentifier as xs:string {'LocalID'};
15
16declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
17(: Returns a 'stubB' style activity record to expand an activity record :)
18(: Security not implemented here yet :)
19{
20let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
21moles:dgMetadataID/moles:localIdentifier=$locid
22and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]
23return
24element  {$out-element-name} {
25($SRAct/moles:dgMetadataID),
26($SRAct/moles:dgMetadataDescription),
27($SRAct/moles:name),
28($SRAct/moles:abbreviation),
29($SRAct/moles:logos)
30} (: </activity> :)
31} ;
32
33declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
34(: Returns a 'stubB' style observation station record to expand an data entity record :)
35(: Security not implemented yet :)
36{
37let $SRDE := $DE
38return 
39element {$out-element-name} {
40($SRDE/moles:dgMetadataID),
41($SRDE/moles:dgMetadataDescription),
42($SRDE/moles:name),
43($SRDE/moles:abbreviation)
44} (: </dgDataEntity> :)       
45} ;
46
47declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
48(: Returns a 'stubB' style dpt record to expand a dpt record :)
49(: Security not implemented yet :)
50{
51let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
52moles:dgMetadataID/moles:localIdentifier=$locid
53and
54moles:dgMetadataID/moles:repositoryIdentifier=$repid
55]
56return 
57element {$out-element-name} {
58$SRDPT/moles:dgMetadataID,
59$SRDPT/moles:dgMetadataDescription,
60$SRDPT/moles:name,
61$SRDPT/moles:abbreviation,
62$SRDPT/moles:logos
63} (: </dataproductiontool> :)
64} ;
65
66declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
67(: Returns a 'stubB' style observation station record to expand an observation station record :)
68(: Security not implemented here yet;  :)
69{
70let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
71moles:dgMetadataID/moles:localIdentifier=$locid
72and
73moles:dgMetadataID/moles:repositoryIdentifier=$repid
74]
75return
76element {$out-element-name} {
77($SRObsStn/moles:dgMetadataID),
78($SRObsStn/moles:dgMetadataDescription),
79($SRObsStn/moles:name),
80($SRObsStn/moles:abbreviation),
81($SRObsStn/moles:logos)
82}
83} ;
84
85declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
86(: Returns a 'stubB' style observation station record to expand a person record :)
87(: Security not implemented yet :)
88{
89let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
90moles:dgMetadataID/moles:localIdentifier=$locid
91and
92moles:dgMetadataID/moles:repositoryIdentifier=$repid
93]
94return
95element  {$out-element-name}
96{
97($person/moles:name),
98($person/moles:contactDetails),
99($person/moles:dgMetadataID)
100}
101} ;
102
103declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
104(: Returns a 'stubB' style observation station record to expand an organisation record :)
105(: Security not implemented yet :)
106{
107let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
108moles:dgMetadataID/moles:localIdentifier=$locid
109and
110moles:dgMetadataID/moles:repositoryIdentifier=$repid
111]
112return
113element  {$out-element-name} {
114$org/moles:dgMetadataID,
115$org/moles:name,
116$org/moles:abbreviation,
117$org/moles:contactDetails,
118$org/moles:logos
119}
120} ;
121
122for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
123exists(moles:dgDataEntity)
124and moles:dgMetadataID[
125moles:schemeIdentifier='NDG-B0'
126and moles:repositoryIdentifier=$repositoryIdentifier
127and moles:localIdentifier=$localIdentifier]]
128return
129utillib:strip-namespace(element dgMetadataRecord {
130    element dgMetadataID {
131        element schemeIdentifier {'NDG-B1'},
132        $DE/moles:dgMetadataID/moles:repositoryIdentifier,
133        $DE/moles:dgMetadataID/moles:localIdentifier
134    }, (: </dgMetadataID> :)
135    $DE/moles:dgMetadataDescription,
136    $DE/moles:name,
137    $DE/moles:abbreviation,
138    element dgDataEntity {
139        $DE/moles:dgDataEntity/moles:dgDataSetType,
140        $DE/moles:dgDataEntity/moles:dgDataObjectType,
141        $DE/moles:dgDataEntity/moles:dgDataGranule,
142        $DE/moles:dgDataEntity/moles:dgDataSummary,
143        element dgDataRoles {
144            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then
145                element dgDataCreator {
146                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID,
147                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName,
148                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation,
149                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails,
150                for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder
151                    order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least
152                    return
153                        element dgRoleHolder {
154                            if (exists($DataCreatorRole/moles:dgOrganisationID)) then
155                                f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier))
156                             else if (exists($DataCreatorRole/moles:dgPersonID)) then
157                                f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier))
158                             else (),
159                            $DataCreatorRole/moles:startDate,
160                            $DataCreatorRole/moles:endDate,
161                            $DataCreatorRole/moles:localName
162                        } (: </dgRoleHolder> :)
163                    } (: </dgDataCreator>) :)
164            else (),
165            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then
166                element dgDataCurator {
167                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID,
168                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName,
169                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation,
170                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails,
171                for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder
172                    order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least
173                    return
174                        element dgRoleHolder {
175                            if (exists($DataCuratorRole/moles:dgOrganisationID)) then
176                                f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier))
177                             else if (exists($DataCuratorRole/moles:dgPersonID)) then
178                                f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier))
179                             else (),
180                            $DataCuratorRole/moles:startDate,
181                            $DataCuratorRole/moles:endDate,
182                            $DataCuratorRole/moles:localName
183                        } (: </dgRoleHolder> :)
184            } (: </dgDataCurator> :)
185            else (),
186            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then
187                element dgDataOtherRoles {
188                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID,
189                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName,
190                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation,
191                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails,
192                for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder
193                    order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least
194                    return
195                        element dgRoleHolder {
196                            if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then
197                                f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier))
198                             else if (exists($DataOtherRolesRole/moles:dgPersonID)) then
199                                f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier))
200                             else (),
201                            $DataOtherRolesRole/moles:startDate,
202                            $DataOtherRolesRole/moles:endDate,
203                            $DataOtherRolesRole/moles:localName
204                        } (: </dgRoleHolder> :)
205            } (: </dgDataOtherRoles> :)
206            else ()
207        } , (: </dgDataRoles> :)
208element DeploymentSummary {
209element activityList {
210for $DepActRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID/moles:repositoryIdentifier)
211for $DepActLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID/moles:localIdentifier)
212let $DepAct :=  f:return-stub-activity('activity', data($DepActRepository), data($DepActLocal))
213return $DepAct
214},
215element dptList {
216for $DepDPTRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID/moles:repositoryIdentifier)
217for $DepDPTLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID/moles:localIdentifier)
218let $DepDPT :=  f:return-stub-dpt('dataproductiontool', data($DepDPTRepository), data($DepDPTLocal))
219return $DepDPT
220},
221element obsStnList {
222for $DepObsStnRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID/moles:repositoryIdentifier)
223for $DepObsStnLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID/moles:localIdentifier)
224let $DepObsStn :=  f:return-stub-obsstn('observationstation', data($DepObsStnRepository), data($DepObsStnLocal))
225return $DepObsStn
226}
227, element rawDeployments {for $rawDeployments in $DE/moles:dgDataEntity/moles:RelatedDeployment return $rawDeployments}
228} (: </DeploymentSummary> :) ,
229        for $RelatedDataEntity in $DE/moles:dgActivity/moles:dgRelatedDataEntity
230            return
231                element relateddataentity {
232                element relation {
233                    $RelatedDataEntity/moles:RelationID/moles:dgValidTerm,
234                    $RelatedDataEntity/moles:RelationID/moles:dgValidTermID
235                }, (: </relation> :)
236                let $DE := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:repositoryIdentifier
237                      and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:localIdentifier]
238                 return
239                    f:return-stub-dataentity('dataentity', $DE)
240                }
241} (: </dgDataEntity> :),
242    for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd,
243    if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (),
244    if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else ()
245} (: </dgMetadataRecord> :)
246) (: end of namespace strip :)
Note: See TracBrowser for help on using the repository browser.