source: exist/branches/proglue_production_rev4605_xquery4884/xquery/stubB_dataEntity.xq @ 4886

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/branches/proglue_production_rev4605_xquery4884/xquery/stubB_dataEntity.xq@4886
Revision 4886, 13.0 KB checked in by sdonegan, 10 years ago (diff)

Creating operational branch for ndgUtils as used on proglue

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 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 $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
122exists(moles:dgDataEntity)
123and moles:dgMetadataID[
124moles:schemeIdentifier='NDG-B0'
125and moles:repositoryIdentifier=$repositoryIdentifier
126and moles:localIdentifier=$localIdentifier]]
127return
128utillib:strip-namespace(element dgMetadataRecord {
129    element dgMetadataID {
130        element schemeIdentifier {'NDG-B1'},
131        $DE/moles:dgMetadataID/moles:repositoryIdentifier,
132        $DE/moles:dgMetadataID/moles:localIdentifier
133    }, (: </dgMetadataID> :)
134    $DE/moles:dgMetadataDescription,
135    $DE/moles:name,
136    $DE/moles:abbreviation,
137    element dgDataEntity {
138        $DE/moles:dgDataEntity/moles:dgDataSetType,
139        $DE/moles:dgDataEntity/moles:dgDataObjectType,
140        $DE/moles:dgDataEntity/moles:dgDataGranule,
141        $DE/moles:dgDataEntity/moles:dgDataSummary,
142        element dgDataRoles {
143            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then
144                element dgDataCreator {
145                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID,
146                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName,
147                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation,
148                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails,
149                for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder
150                    order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least
151                    return
152                        element dgRoleHolder {
153                            if (exists($DataCreatorRole/moles:dgOrganisationID)) then
154                                f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier))
155                             else if (exists($DataCreatorRole/moles:dgPersonID)) then
156                                f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier))
157                             else (),
158                            $DataCreatorRole/moles:startDate,
159                            $DataCreatorRole/moles:endDate,
160                            $DataCreatorRole/moles:localName
161                        } (: </dgRoleHolder> :)
162                    } (: </dgDataCreator>) :)
163            else (),
164            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then
165                element dgDataCurator {
166                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID,
167                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName,
168                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation,
169                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails,
170                for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder
171                    order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least
172                    return
173                        element dgRoleHolder {
174                            if (exists($DataCuratorRole/moles:dgOrganisationID)) then
175                                f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier))
176                             else if (exists($DataCuratorRole/moles:dgPersonID)) then
177                                f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier))
178                             else (),
179                            $DataCuratorRole/moles:startDate,
180                            $DataCuratorRole/moles:endDate,
181                            $DataCuratorRole/moles:localName
182                        } (: </dgRoleHolder> :)
183            } (: </dgDataCurator> :)
184            else (),
185            if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then
186                element dgDataOtherRoles {
187                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID,
188                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName,
189                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation,
190                $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails,
191                for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder
192                    order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least
193                    return
194                        element dgRoleHolder {
195                            if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then
196                                f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier))
197                             else if (exists($DataOtherRolesRole/moles:dgPersonID)) then
198                                f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier))
199                             else (),
200                            $DataOtherRolesRole/moles:startDate,
201                            $DataOtherRolesRole/moles:endDate,
202                            $DataOtherRolesRole/moles:localName
203                        } (: </dgRoleHolder> :)
204            } (: </dgDataOtherRoles> :)
205            else ()
206        } , (: </dgDataRoles> :)
207element DeploymentSummary {
208element activityList {
209for $DepActRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID/moles:repositoryIdentifier)
210for $DepActLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID/moles:localIdentifier)
211let $DepAct :=  f:return-stub-activity('activity', data($DepActRepository), data($DepActLocal))
212return $DepAct
213},
214element dptList {
215for $DepDPTRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID/moles:repositoryIdentifier)
216for $DepDPTLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID/moles:localIdentifier)
217let $DepDPT :=  f:return-stub-dpt('dataproductiontool', data($DepDPTRepository), data($DepDPTLocal))
218return $DepDPT
219},
220element obsStnList {
221for $DepObsStnRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID/moles:repositoryIdentifier)
222for $DepObsStnLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID/moles:localIdentifier)
223let $DepObsStn :=  f:return-stub-obsstn('observationstation', data($DepObsStnRepository), data($DepObsStnLocal))
224return $DepObsStn
225}
226, element rawDeployments {for $rawDeployments in $DE/moles:dgDataEntity/moles:RelatedDeployment return $rawDeployments}
227} (: </DeploymentSummary> :) ,
228        for $RelatedDataEntity in $DE/moles:dgActivity/moles:dgRelatedDataEntity
229            return
230                element relateddataentity {
231                element relation {
232                    $RelatedDataEntity/moles:RelationID/moles:dgValidTerm,
233                    $RelatedDataEntity/moles:RelationID/moles:dgValidTermID
234                }, (: </relation> :)
235                let $DE := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:repositoryIdentifier
236                      and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:localIdentifier]
237                 return
238                    f:return-stub-dataentity('dataentity', $DE)
239                }
240} (: </dgDataEntity> :),
241    for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd,
242    if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (),
243    if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else ()
244} (: </dgMetadataRecord> :)
245) (: end of namespace strip :)
Note: See TracBrowser for help on using the repository browser.