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

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

XQuery betas

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