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

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

Fix for #799, and update examples

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