Changeset 2467 for TI07-MOLES/trunk


Ignore:
Timestamp:
11/05/07 12:34:53 (12 years ago)
Author:
ko23
Message:

Update ndg_xqueries.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/ndg_xqueries.py

    r2464 r2467  
    2222import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery'; 
    2323:) 
     24 
    2425declare variable $targetCollection as xs:string {'TargetCollection'}; 
    2526declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; 
     
    3031(: Security not implemented here yet :) 
    3132{ 
    32 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    33             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    34             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    35 return   
    36     if ($found = 0) then  
    37         element {$out-element-name} { 
    38             element error {'not found'}, 
    39             element repositoryIdentifier {$repid}, 
    40             element localIdentifier {$locid} 
    41         }  
    42     else ( 
    43         for $SRAct in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    44             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    45             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    46         return  
    47             element  {$out-element-name} {  
    48                 ($SRAct/moles:dgMetadataID), 
    49                 ($SRAct/moles:dgMetadataDescription), 
    50                 ($SRAct/moles:name), 
    51                 ($SRAct/moles:abbreviation), 
    52                 element dgActivity { 
    53                     if (exists($SRAct/*/moles:dgActivityDataCollection)) then  
    54                         ($SRAct/*/moles:dgActivityDataCollection) 
    55                     else if (exists($SRAct/*/moles:dgActivityDataProject)) then  
    56                         ($SRAct/*/moles:dgActivityDataProject) 
    57                     else if (exists($SRAct/*/dgActivityDataCampaign)) then 
    58                         ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
    59                     else  
    60                         ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),  
    61                     ($SRAct/moles:dgActivity/moles:dgActivityCoverage), 
    62                     ($SRAct/moles:dgActivity/moles:dgActivityDuration) 
    63                 } (: </dgActivity> :)  
    64             } (: </activity> :)  
    65     ) 
    66 } ; 
    67  
    68 declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()  
     33let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     34moles:dgMetadataID/moles:localIdentifier=$locid 
     35and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]  
     36return  
     37element  {$out-element-name} {  
     38($SRAct/moles:dgMetadataID), 
     39($SRAct/moles:dgMetadataDescription), 
     40($SRAct/moles:name), 
     41($SRAct/moles:abbreviation), 
     42($SRAct/moles:logos), 
     43element dgActivity { 
     44if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCollection)) then  
     45($SRAct/*/moles:dgActivityDataCollection) 
     46else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataProject)) then  
     47($SRAct/*/moles:dgActivityDataProject) 
     48else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)) then 
     49($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
     50else  
     51($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),  
     52($SRAct/moles:dgActivity/moles:dgActivityCoverage), 
     53($SRAct/moles:dgActivity/moles:dgActivityDuration) 
     54} (: </dgActivity> :)  
     55} (: </activity> :)  
     56} ; 
     57 
     58declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()  
    6959(: Returns a 'stubB' style observation station record to expand an data entity record :) 
    7060(: Security not implemented yet :) 
    7161{ 
    72 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    73         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    74         and moles:dgMetadataID/moles:localIdentifier=$locid]) 
     62let $SRDE := $DE 
    7563return   
    76     if ($found = 0) then  
    77         element {$out-element-name} { 
    78             element error {'not found'}, 
    79             element repositoryIdentifier {$repid}, 
    80             element localIdentifier {$locid} 
    81         }  
    82     else ( 
    83         for $SRDE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    84             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    85             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    86         return   
    87             element {$out-element-name} { 
    88                 ($SRDE/moles:dgMetadataID), 
    89                 ($SRDE/moles:dgMetadataDescription), 
    90                 ($SRDE/moles:name), 
    91                 ($SRDE/moles:abbreviation), 
    92                 element dgDataEntity { 
    93                     ($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
    94                     ($SRDE/moles:dgDataEntity/moles:dgDataGranule), 
    95                     ($SRDE/moles:dgDataEntity/moles:dgDataSummary) 
    96                 } (: </dgDataEntity> :)         
    97             } 
    98     ) 
     64element {$out-element-name} { 
     65($SRDE/moles:dgMetadataID), 
     66($SRDE/moles:dgMetadataDescription), 
     67($SRDE/moles:name), 
     68($SRDE/moles:abbreviation), 
     69($SRDE/moles:abbreviation), 
     70element dgDataEntity { 
     71($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
     72($SRDE/moles:dgDataEntity/moles:dgDataGranule), 
     73($SRDE/moles:dgDataEntity/moles:dgDataSummary) 
     74} (: </dgDataEntity> :)         
     75} 
    9976} ; 
    10077 
     
    10380(: Security not implemented yet :) 
    10481{ 
    105 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    106         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    107         and moles:dgMetadataID/moles:localIdentifier=$locid]) 
     82let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     83moles:dgMetadataID/moles:localIdentifier=$locid 
     84and 
     85moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     86] 
    10887return   
    109     if ($found = 0) then  
    110         element {$out-element-name} { 
    111             element error {'not found'}, 
    112             element repositoryIdentifier {$repid}, 
    113             element localIdentifier {$locid} 
    114         }  
    115     else ( 
    116         for $SRDPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    117                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    118                 and moles:dgMetadataID/moles:localIdentifier=$locid] 
    119         return   
    120             element {$out-element-name} { 
    121                 $SRDPT/moles:dgMetadataID, 
    122                 $SRDPT/moles:dgMetadataDescription, 
    123                 $SRDPT/moles:name, 
    124                 $SRDPT/moles:abbreviation, 
    125                 $SRDPT/moles:logos, 
    126                 element dgDataProductionTool { 
    127                     $SRDPT/moles:dgDataProductionTool/moles:contactDetails, 
    128                     if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then 
    129                         $SRDPT/moles:dgDataProductionTool/moles:dgModel 
    130                     else (), 
    131                     if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then 
    132                         $SRDPT/moles:dgDataProductionTool/moles:dgInstrument 
    133                     else () 
    134                     } (: </dgDataProductionTool> :) 
    135                 } (: </dataproductiontool> :) 
    136     ) 
     88element {$out-element-name} { 
     89$SRDPT/moles:dgMetadataID, 
     90$SRDPT/moles:dgMetadataDescription, 
     91$SRDPT/moles:name, 
     92$SRDPT/moles:abbreviation, 
     93$SRDPT/moles:logos, 
     94element dgDataProductionTool { 
     95$SRDPT/moles:dgDataProductionTool/moles:contactDetails, 
     96if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then 
     97$SRDPT/moles:dgDataProductionTool/moles:dgModel 
     98else (), 
     99if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then 
     100$SRDPT/moles:dgDataProductionTool/moles:dgInstrument 
     101else () 
     102} (: </dgDataProductionTool> :) 
     103} (: </dataproductiontool> :) 
    137104} ; 
    138105 
     
    141108(: Security not implemented here yet;  :) 
    142109{ 
    143 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    144             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    145             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    146 return   
    147     if ($found = 0) then  
    148         element {$out-element-name} { 
    149             element error {'not found'}, 
    150             element repositoryIdentifier {$repid}, 
    151             element localIdentifier {$locid} 
    152         }  
    153     else ( 
    154         for $SRObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    155             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    156             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    157         return 
    158             element {$out-element-name} { 
    159                 ($SRObsStn/moles:dgMetadataID), 
    160                 ($SRObsStn/moles:dgMetadataDescription), 
    161                 ($SRObsStn/moles:name), 
    162                 ($SRObsStn/moles:abbreviation), 
    163                 element dgObservationStation { 
    164                     ($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
    165                     if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then 
    166                         element dgStationaryPlatform { 
    167                             $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
    168                             if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} 
    169                             else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} 
    170                             else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} 
    171                             else () 
    172                             } 
    173                     else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then  
    174                         $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform 
    175                     else () 
    176                 } (: </dgObservationStation> :) 
    177             } 
    178     ) 
     110let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     111moles:dgMetadataID/moles:localIdentifier=$locid 
     112and 
     113moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     114]  
     115return 
     116element {$out-element-name} { 
     117($SRObsStn/moles:dgMetadataID), 
     118($SRObsStn/moles:dgMetadataDescription), 
     119($SRObsStn/moles:name), 
     120($SRObsStn/moles:abbreviation), 
     121($SRObsStn/moles:logos), 
     122element dgObservationStation { 
     123($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
     124if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then 
     125element dgStationaryPlatform { 
     126$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
     127if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''} 
     128else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''} 
     129else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''} 
     130else () 
     131} 
     132else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then  
     133$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform 
     134else () 
     135} (: </dgObservationStation> :) 
     136} 
    179137} ; 
    180138 
     
    183141(: Security not implemented yet :) 
    184142{ 
    185 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    186             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    187             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    188 return   
    189     if ($found = 0) then  
    190         element {$out-element-name} { 
    191             element error {'not found'}, 
    192             element repositoryIdentifier {$repid}, 
    193             element localIdentifier {$locid} 
    194         }  
    195     else ( 
    196     for $person in collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    197         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    198         and moles:dgMetadataID/moles:localIdentifier=$locid]  
    199     return  
    200         element  {$out-element-name}  
    201         { 
    202             ($person/moles:name), 
    203             ($person/moles:contactDetails), 
    204             ($person/moles:dgMetadataID) 
    205         } 
    206     ) 
     143let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
     144moles:dgMetadataID/moles:localIdentifier=$locid 
     145and 
     146moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     147]  
     148return  
     149element  {$out-element-name}  
     150{ 
     151($person/moles:name), 
     152($person/moles:contactDetails), 
     153($person/moles:dgMetadataID) 
     154} 
    207155} ; 
    208156 
     
    211159(: Security not implemented yet :) 
    212160{ 
    213     let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    214                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    215                 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    216     return   
    217         if ($found = 0) then  
    218             element {$out-element-name} { 
    219                 element error {'not found'}, 
    220                 element repositoryIdentifier {$repid}, 
    221                 element localIdentifier {$locid} 
    222             }  
    223         else ( 
    224             for $org in collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    225                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    226                 and moles:dgMetadataID/moles:localIdentifier=$locid]  
    227             return  
    228                 element  {$out-element-name} { 
    229                     $org/moles:dgMetadataID, 
    230                     $org/moles:name, 
    231                     $org/moles:abbreviation, 
    232                     $org/moles:contactDetails, 
    233                     $org/moles:logos 
    234                 } 
    235         ) 
     161let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
     162moles:dgMetadataID/moles:localIdentifier=$locid 
     163and 
     164moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     165]  
     166return  
     167element  {$out-element-name} { 
     168$org/moles:dgMetadataID, 
     169$org/moles:name, 
     170$org/moles:abbreviation, 
     171$org/moles:contactDetails, 
     172$org/moles:logos 
     173} 
    236174} ; 
    237175 
     
    341279                    $RelatedDataEntity/moles:RelationID/moles:dgValidTermID 
    342280                }, (: </relation> :) 
    343                 f:return-stub-dataentity('dataentity', data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:repositoryIdentifier), data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:localIdentifier)) 
    344                 } (: </relateddataentity> :) 
    345     } (: </dgDataEntity> :), 
     281                let $DE := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:repositoryIdentifier 
     282                      and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelatedDataEntity/moles:RelatedDataEntityID/moles:localIdentifier] 
     283                 return 
     284                    f:return-stub-dataentity('dataentity', $DE) 
     285                } 
     286} (: </dgDataEntity> :), 
    346287    for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd, 
    347288    if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (), 
     
    351292''' 
    352293 
    353 StubBActQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles/activity';  
     294StubBActQuery = ''' 
     295declare default element namespace 'http://ndg.nerc.ac.uk/moles/activity';  
    354296declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; 
    355297declare namespace moles='http://ndg.nerc.ac.uk/moles'; 
     
    361303import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery'; 
    362304:) 
     305 
    363306declare variable $targetCollection as xs:string {'TargetCollection'}; 
    364307declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; 
     
    369312(: Security not implemented here yet :) 
    370313{ 
    371 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    372             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    373             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    374 return   
    375     if ($found = 0) then  
    376         element {$out-element-name} { 
    377             element error {'not found'}, 
    378             element repositoryIdentifier {$repid}, 
    379             element localIdentifier {$locid} 
    380         }  
    381     else ( 
    382         for $SRAct in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    383             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    384             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    385         return  
    386             element  {$out-element-name} {  
    387                 ($SRAct/moles:dgMetadataID), 
    388                 ($SRAct/moles:dgMetadataDescription), 
    389                 ($SRAct/moles:name), 
    390                 ($SRAct/moles:abbreviation), 
    391                 element dgActivity { 
    392                     if (exists($SRAct/*/moles:dgActivityDataCollection)) then  
    393                         ($SRAct/*/moles:dgActivityDataCollection) 
    394                     else if (exists($SRAct/*/moles:dgActivityDataProject)) then  
    395                         ($SRAct/*/moles:dgActivityDataProject) 
    396                     else if (exists($SRAct/*/dgActivityDataCampaign)) then 
    397                         ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
    398                     else  
    399                         ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),  
    400                     ($SRAct/moles:dgActivity/moles:dgActivityCoverage), 
    401                     ($SRAct/moles:dgActivity/moles:dgActivityDuration) 
    402                 } (: </dgActivity> :)  
    403             } (: </activity> :)  
    404     ) 
    405 } ; 
    406  
    407 declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()  
     314let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     315moles:dgMetadataID/moles:localIdentifier=$locid 
     316and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]  
     317return  
     318element  {$out-element-name} {  
     319($SRAct/moles:dgMetadataID), 
     320($SRAct/moles:dgMetadataDescription), 
     321($SRAct/moles:name), 
     322($SRAct/moles:abbreviation), 
     323($SRAct/moles:logos), 
     324element dgActivity { 
     325if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCollection)) then  
     326($SRAct/*/moles:dgActivityDataCollection) 
     327else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataProject)) then  
     328($SRAct/*/moles:dgActivityDataProject) 
     329else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)) then 
     330($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
     331else  
     332($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),  
     333($SRAct/moles:dgActivity/moles:dgActivityCoverage), 
     334($SRAct/moles:dgActivity/moles:dgActivityDuration) 
     335} (: </dgActivity> :)  
     336} (: </activity> :)  
     337} ; 
     338 
     339declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()  
    408340(: Returns a 'stubB' style observation station record to expand an data entity record :) 
    409341(: Security not implemented yet :) 
    410342{ 
    411 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    412         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    413         and moles:dgMetadataID/moles:localIdentifier=$locid]) 
     343let $SRDE := $DE 
    414344return   
    415     if ($found = 0) then  
    416         element {$out-element-name} { 
    417             element error {'not found'}, 
    418             element repositoryIdentifier {$repid}, 
    419             element localIdentifier {$locid} 
    420         }  
    421     else ( 
    422         for $SRDE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    423             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    424             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    425         return   
    426             element {$out-element-name} { 
    427                 ($SRDE/moles:dgMetadataID), 
    428                 ($SRDE/moles:dgMetadataDescription), 
    429                 ($SRDE/moles:name), 
    430                 ($SRDE/moles:abbreviation), 
    431                 element dgDataEntity { 
    432                     ($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
    433                     ($SRDE/moles:dgDataEntity/moles:dgDataGranule), 
    434                     ($SRDE/moles:dgDataEntity/moles:dgDataSummary) 
    435                 } (: </dgDataEntity> :)         
    436             } 
    437     ) 
     345element {$out-element-name} { 
     346($SRDE/moles:dgMetadataID), 
     347($SRDE/moles:dgMetadataDescription), 
     348($SRDE/moles:name), 
     349($SRDE/moles:abbreviation), 
     350($SRDE/moles:abbreviation), 
     351element dgDataEntity { 
     352($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
     353($SRDE/moles:dgDataEntity/moles:dgDataGranule), 
     354($SRDE/moles:dgDataEntity/moles:dgDataSummary) 
     355} (: </dgDataEntity> :)         
     356} 
    438357} ; 
    439358 
     
    442361(: Security not implemented yet :) 
    443362{ 
    444 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    445         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    446         and moles:dgMetadataID/moles:localIdentifier=$locid]) 
     363let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     364moles:dgMetadataID/moles:localIdentifier=$locid 
     365and 
     366moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     367] 
    447368return   
    448     if ($found = 0) then  
    449         element {$out-element-name} { 
    450             element error {'not found'}, 
    451             element repositoryIdentifier {$repid}, 
    452             element localIdentifier {$locid} 
    453         }  
    454     else ( 
    455         for $SRDPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    456                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    457                 and moles:dgMetadataID/moles:localIdentifier=$locid] 
    458         return   
    459             element {$out-element-name} { 
    460                 $SRDPT/moles:dgMetadataID, 
    461                 $SRDPT/moles:dgMetadataDescription, 
    462                 $SRDPT/moles:name, 
    463                 $SRDPT/moles:abbreviation, 
    464                 $SRDPT/moles:logos, 
    465                 element dgDataProductionTool { 
    466                     $SRDPT/moles:dgDataProductionTool/moles:contactDetails, 
    467                     if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then 
    468                         $SRDPT/moles:dgDataProductionTool/moles:dgModel 
    469                     else (), 
    470                     if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then 
    471                         $SRDPT/moles:dgDataProductionTool/moles:dgInstrument 
    472                     else () 
    473                     } (: </dgDataProductionTool> :) 
    474                 } (: </dataproductiontool> :) 
    475     ) 
     369element {$out-element-name} { 
     370$SRDPT/moles:dgMetadataID, 
     371$SRDPT/moles:dgMetadataDescription, 
     372$SRDPT/moles:name, 
     373$SRDPT/moles:abbreviation, 
     374$SRDPT/moles:logos, 
     375element dgDataProductionTool { 
     376$SRDPT/moles:dgDataProductionTool/moles:contactDetails, 
     377if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then 
     378$SRDPT/moles:dgDataProductionTool/moles:dgModel 
     379else (), 
     380if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then 
     381$SRDPT/moles:dgDataProductionTool/moles:dgInstrument 
     382else () 
     383} (: </dgDataProductionTool> :) 
     384} (: </dataproductiontool> :) 
    476385} ; 
    477386 
     
    480389(: Security not implemented here yet;  :) 
    481390{ 
    482 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    483             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    484             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    485 return   
    486     if ($found = 0) then  
    487         element {$out-element-name} { 
    488             element error {'not found'}, 
    489             element repositoryIdentifier {$repid}, 
    490             element localIdentifier {$locid} 
    491         }  
    492     else ( 
    493         for $SRObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    494             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    495             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    496         return 
    497             element {$out-element-name} { 
    498                 ($SRObsStn/moles:dgMetadataID), 
    499                 ($SRObsStn/moles:dgMetadataDescription), 
    500                 ($SRObsStn/moles:name), 
    501                 ($SRObsStn/moles:abbreviation), 
    502                 element dgObservationStation { 
    503                     ($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
    504                     if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then 
    505                         element dgStationaryPlatform { 
    506                             $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
    507                             if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} 
    508                             else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} 
    509                             else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} 
    510                             else () 
    511                             } 
    512                     else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then  
    513                         $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform 
    514                     else () 
    515                 } (: </dgObservationStation> :) 
    516             } 
    517     ) 
     391let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     392moles:dgMetadataID/moles:localIdentifier=$locid 
     393and 
     394moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     395]  
     396return 
     397element {$out-element-name} { 
     398($SRObsStn/moles:dgMetadataID), 
     399($SRObsStn/moles:dgMetadataDescription), 
     400($SRObsStn/moles:name), 
     401($SRObsStn/moles:abbreviation), 
     402($SRObsStn/moles:logos), 
     403element dgObservationStation { 
     404($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
     405if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then 
     406element dgStationaryPlatform { 
     407$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
     408if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''} 
     409else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''} 
     410else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''} 
     411else () 
     412} 
     413else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then  
     414$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform 
     415else () 
     416} (: </dgObservationStation> :) 
     417} 
    518418} ; 
    519419 
     
    522422(: Security not implemented yet :) 
    523423{ 
    524 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    525             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    526             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    527 return   
    528     if ($found = 0) then  
    529         element {$out-element-name} { 
    530             element error {'not found'}, 
    531             element repositoryIdentifier {$repid}, 
    532             element localIdentifier {$locid} 
    533         }  
    534     else ( 
    535     for $person in collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    536         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    537         and moles:dgMetadataID/moles:localIdentifier=$locid]  
    538     return  
    539         element  {$out-element-name}  
    540         { 
    541             ($person/moles:name), 
    542             ($person/moles:contactDetails), 
    543             ($person/moles:dgMetadataID) 
    544         } 
    545     ) 
     424let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
     425moles:dgMetadataID/moles:localIdentifier=$locid 
     426and 
     427moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     428]  
     429return  
     430element  {$out-element-name}  
     431{ 
     432($person/moles:name), 
     433($person/moles:contactDetails), 
     434($person/moles:dgMetadataID) 
     435} 
    546436} ; 
    547437 
     
    550440(: Security not implemented yet :) 
    551441{ 
    552     let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    553                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    554                 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    555     return   
    556         if ($found = 0) then  
    557             element {$out-element-name} { 
    558                 element error {'not found'}, 
    559                 element repositoryIdentifier {$repid}, 
    560                 element localIdentifier {$locid} 
    561             }  
    562         else ( 
    563             for $org in collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    564                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    565                 and moles:dgMetadataID/moles:localIdentifier=$locid]  
    566             return  
    567                 element  {$out-element-name} { 
    568                     $org/moles:dgMetadataID, 
    569                     $org/moles:name, 
    570                     $org/moles:abbreviation, 
    571                     $org/moles:contactDetails, 
    572                     $org/moles:logos 
    573                 } 
    574         ) 
     442let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
     443moles:dgMetadataID/moles:localIdentifier=$locid 
     444and 
     445moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     446]  
     447return  
     448element  {$out-element-name} { 
     449$org/moles:dgMetadataID, 
     450$org/moles:name, 
     451$org/moles:abbreviation, 
     452$org/moles:contactDetails, 
     453$org/moles:logos 
     454} 
    575455} ; 
    576456 
     
    717597            f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), 
    718598            f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), 
    719             for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord 
    720                 where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier 
    721                         and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier 
    722             return 
    723                 f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)) 
     599                for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier 
     600and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier] 
     601return 
     602f:return-stub-dataentity('dataentity', $DE) 
    724603        }, (: </ActivityDeployment> :) 
    725604        if (exists($Act/dgActivityCoverage)) then 
     
    755634(: Security not implemented here yet :) 
    756635{ 
    757 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    758             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    759             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    760 return   
    761     if ($found = 0) then  
    762         element {$out-element-name} { 
    763             element error {'not found'}, 
    764             element repositoryIdentifier {$repid}, 
    765             element localIdentifier {$locid} 
    766         }  
    767     else ( 
    768         for $SRAct in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    769             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    770             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    771         return  
    772             element  {$out-element-name} {  
    773                 ($SRAct/moles:dgMetadataID), 
    774                 ($SRAct/moles:dgMetadataDescription), 
    775                 ($SRAct/moles:name), 
    776                 ($SRAct/moles:abbreviation), 
    777                 element dgActivity { 
    778                     if (exists($SRAct/*/moles:dgActivityDataCollection)) then  
    779                         ($SRAct/*/moles:dgActivityDataCollection) 
    780                     else if (exists($SRAct/*/moles:dgActivityDataProject)) then  
    781                         ($SRAct/*/moles:dgActivityDataProject) 
    782                     else if (exists($SRAct/*/dgActivityDataCampaign)) then 
    783                         ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
    784                     else  
    785                         ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),  
    786                     ($SRAct/moles:dgActivity/moles:dgActivityCoverage), 
    787                     ($SRAct/moles:dgActivity/moles:dgActivityDuration) 
    788                 } (: </dgActivity> :)  
    789             } (: </activity> :)  
    790     ) 
    791 } ; 
    792  
    793 declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()  
     636let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     637moles:dgMetadataID/moles:localIdentifier=$locid 
     638and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]  
     639return  
     640element  {$out-element-name} {  
     641($SRAct/moles:dgMetadataID), 
     642($SRAct/moles:dgMetadataDescription), 
     643($SRAct/moles:name), 
     644($SRAct/moles:abbreviation), 
     645($SRAct/moles:logos), 
     646element dgActivity { 
     647if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCollection)) then  
     648($SRAct/*/moles:dgActivityDataCollection) 
     649else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataProject)) then  
     650($SRAct/*/moles:dgActivityDataProject) 
     651else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)) then 
     652($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
     653else  
     654($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),  
     655($SRAct/moles:dgActivity/moles:dgActivityCoverage), 
     656($SRAct/moles:dgActivity/moles:dgActivityDuration) 
     657} (: </dgActivity> :)  
     658} (: </activity> :)  
     659} ; 
     660 
     661declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()  
    794662(: Returns a 'stubB' style observation station record to expand an data entity record :) 
    795663(: Security not implemented yet :) 
    796664{ 
    797 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    798         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    799         and moles:dgMetadataID/moles:localIdentifier=$locid]) 
     665let $SRDE := $DE 
    800666return   
    801     if ($found = 0) then  
    802         element {$out-element-name} { 
    803             element error {'not found'}, 
    804             element repositoryIdentifier {$repid}, 
    805             element localIdentifier {$locid} 
    806         }  
    807     else ( 
    808         for $SRDE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    809             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    810             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    811         return   
    812             element {$out-element-name} { 
    813                 ($SRDE/moles:dgMetadataID), 
    814                 ($SRDE/moles:dgMetadataDescription), 
    815                 ($SRDE/moles:name), 
    816                 ($SRDE/moles:abbreviation), 
    817                 element dgDataEntity { 
    818                     ($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
    819                     ($SRDE/moles:dgDataEntity/moles:dgDataGranule), 
    820                     ($SRDE/moles:dgDataEntity/moles:dgDataSummary) 
    821                 } (: </dgDataEntity> :)         
    822             } 
    823     ) 
     667element {$out-element-name} { 
     668($SRDE/moles:dgMetadataID), 
     669($SRDE/moles:dgMetadataDescription), 
     670($SRDE/moles:name), 
     671($SRDE/moles:abbreviation), 
     672($SRDE/moles:abbreviation), 
     673element dgDataEntity { 
     674($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
     675($SRDE/moles:dgDataEntity/moles:dgDataGranule), 
     676($SRDE/moles:dgDataEntity/moles:dgDataSummary) 
     677} (: </dgDataEntity> :)         
     678} 
    824679} ; 
    825680 
     
    828683(: Security not implemented yet :) 
    829684{ 
    830 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    831         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    832         and moles:dgMetadataID/moles:localIdentifier=$locid]) 
     685let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     686moles:dgMetadataID/moles:localIdentifier=$locid 
     687and 
     688moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     689] 
    833690return   
    834     if ($found = 0) then  
    835         element {$out-element-name} { 
    836             element error {'not found'}, 
    837             element repositoryIdentifier {$repid}, 
    838             element localIdentifier {$locid} 
    839         }  
    840     else ( 
    841         for $SRDPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    842                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    843                 and moles:dgMetadataID/moles:localIdentifier=$locid] 
    844         return   
    845             element {$out-element-name} { 
    846                 $SRDPT/moles:dgMetadataID, 
    847                 $SRDPT/moles:dgMetadataDescription, 
    848                 $SRDPT/moles:name, 
    849                 $SRDPT/moles:abbreviation, 
    850                 $SRDPT/moles:logos, 
    851                 element dgDataProductionTool { 
    852                     $SRDPT/moles:dgDataProductionTool/moles:contactDetails, 
    853                     if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then 
    854                         $SRDPT/moles:dgDataProductionTool/moles:dgModel 
    855                     else (), 
    856                     if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then 
    857                         $SRDPT/moles:dgDataProductionTool/moles:dgInstrument 
    858                     else () 
    859                     } (: </dgDataProductionTool> :) 
    860                 } (: </dataproductiontool> :) 
    861     ) 
     691element {$out-element-name} { 
     692$SRDPT/moles:dgMetadataID, 
     693$SRDPT/moles:dgMetadataDescription, 
     694$SRDPT/moles:name, 
     695$SRDPT/moles:abbreviation, 
     696$SRDPT/moles:logos, 
     697element dgDataProductionTool { 
     698$SRDPT/moles:dgDataProductionTool/moles:contactDetails, 
     699if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then 
     700$SRDPT/moles:dgDataProductionTool/moles:dgModel 
     701else (), 
     702if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then 
     703$SRDPT/moles:dgDataProductionTool/moles:dgInstrument 
     704else () 
     705} (: </dgDataProductionTool> :) 
     706} (: </dataproductiontool> :) 
    862707} ; 
    863708 
     
    866711(: Security not implemented here yet;  :) 
    867712{ 
    868 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    869             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    870             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    871 return   
    872     if ($found = 0) then  
    873         element {$out-element-name} { 
    874             element error {'not found'}, 
    875             element repositoryIdentifier {$repid}, 
    876             element localIdentifier {$locid} 
    877         }  
    878     else ( 
    879         for $SRObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    880             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    881             and moles:dgMetadataID/moles:localIdentifier=$locid]  
    882         return 
    883             element {$out-element-name} { 
    884                 ($SRObsStn/moles:dgMetadataID), 
    885                 ($SRObsStn/moles:dgMetadataDescription), 
    886                 ($SRObsStn/moles:name), 
    887                 ($SRObsStn/moles:abbreviation), 
    888                 element dgObservationStation { 
    889                     ($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
    890                     if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then 
    891                         element dgStationaryPlatform { 
    892                             $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
    893                             if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} 
    894                             else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} 
    895                             else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} 
    896                             else () 
    897                             } 
    898                     else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then  
    899                         $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform 
    900                     else () 
    901                 } (: </dgObservationStation> :) 
    902             } 
    903     ) 
     713let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     714moles:dgMetadataID/moles:localIdentifier=$locid 
     715and 
     716moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     717]  
     718return 
     719element {$out-element-name} { 
     720($SRObsStn/moles:dgMetadataID), 
     721($SRObsStn/moles:dgMetadataDescription), 
     722($SRObsStn/moles:name), 
     723($SRObsStn/moles:abbreviation), 
     724($SRObsStn/moles:logos), 
     725element dgObservationStation { 
     726($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
     727if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then 
     728element dgStationaryPlatform { 
     729$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
     730if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''} 
     731else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''} 
     732else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''} 
     733else () 
     734} 
     735else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then  
     736$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform 
     737else () 
     738} (: </dgObservationStation> :) 
     739} 
    904740} ; 
    905741 
     
    908744(: Security not implemented yet :) 
    909745{ 
    910 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    911             moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    912             and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    913 return   
    914     if ($found = 0) then  
    915         element {$out-element-name} { 
    916             element error {'not found'}, 
    917             element repositoryIdentifier {$repid}, 
    918             element localIdentifier {$locid} 
    919         }  
    920     else ( 
    921     for $person in collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    922         moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    923         and moles:dgMetadataID/moles:localIdentifier=$locid]  
    924     return  
    925         element  {$out-element-name}  
    926         { 
    927             ($person/moles:name), 
    928             ($person/moles:contactDetails), 
    929             ($person/moles:dgMetadataID) 
    930         } 
    931     ) 
     746let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
     747moles:dgMetadataID/moles:localIdentifier=$locid 
     748and 
     749moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     750]  
     751return  
     752element  {$out-element-name}  
     753{ 
     754($person/moles:name), 
     755($person/moles:contactDetails), 
     756($person/moles:dgMetadataID) 
     757} 
    932758} ; 
    933759 
     
    936762(: Security not implemented yet :) 
    937763{ 
    938     let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    939                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    940                 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    941     return   
    942         if ($found = 0) then  
    943             element {$out-element-name} { 
    944                 element error {'not found'}, 
    945                 element repositoryIdentifier {$repid}, 
    946                 element localIdentifier {$locid} 
    947             }  
    948         else ( 
    949             for $org in collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    950                 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    951                 and moles:dgMetadataID/moles:localIdentifier=$locid]  
    952             return  
    953                 element  {$out-element-name} { 
    954                     $org/moles:dgMetadataID, 
    955                     $org/moles:name, 
    956                     $org/moles:abbreviation, 
    957                     $org/moles:contactDetails, 
    958                     $org/moles:logos 
    959                 } 
    960         ) 
     764let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
     765moles:dgMetadataID/moles:localIdentifier=$locid 
     766and 
     767moles:dgMetadataID/moles:repositoryIdentifier=$repid  
     768]  
     769return  
     770element  {$out-element-name} { 
     771$org/moles:dgMetadataID, 
     772$org/moles:name, 
     773$org/moles:abbreviation, 
     774$org/moles:contactDetails, 
     775$org/moles:logos 
     776} 
    961777} ; 
    962778 
     
    994810            f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)), 
    995811            f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), 
    996             for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord 
    997                 where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier 
    998                         and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier 
    999             return 
    1000                 f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)), 
     812                for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier 
     813and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier] 
     814return 
     815f:return-stub-dataentity('dataentity', $DE), 
    1001816            $RelDep/moles:Coverage 
    1002817        } (: </DPTDeployment> :)  
     
    1009824''' 
    1010825 
    1011 StubBObsStnQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';  
     826StubBObsStnQuery = ''' 
     827declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';  
    1012828import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; 
    1013829import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; 
     
    1027843(: Security not implemented here yet :) 
    1028844{ 
    1029 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1030 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1031 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    1032 return   
    1033 if ($found = 0) then  
    1034 element {$out-element-name} { 
    1035 element error {'not found'}, 
    1036 element repositoryIdentifier {$repid}, 
    1037 element localIdentifier {$locid} 
    1038 }  
    1039 else ( 
    1040 for $SRAct in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1041 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1042 and moles:dgMetadataID/moles:localIdentifier=$locid]  
     845let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     846moles:dgMetadataID/moles:localIdentifier=$locid 
     847and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]  
    1043848return  
    1044849element  {$out-element-name} {  
     
    1047852($SRAct/moles:name), 
    1048853($SRAct/moles:abbreviation), 
     854($SRAct/moles:logos), 
    1049855element dgActivity { 
    1050 if (exists($SRAct/*/moles:dgActivityDataCollection)) then  
     856if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCollection)) then  
    1051857($SRAct/*/moles:dgActivityDataCollection) 
    1052 else if (exists($SRAct/*/moles:dgActivityDataProject)) then  
     858else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataProject)) then  
    1053859($SRAct/*/moles:dgActivityDataProject) 
    1054 else if (exists($SRAct/*/dgActivityDataCampaign)) then 
     860else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)) then 
    1055861($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) 
    1056862else  
     
    1060866} (: </dgActivity> :)  
    1061867} (: </activity> :)  
    1062 ) 
    1063 } ; 
    1064  
    1065 declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()  
     868} ; 
     869 
     870declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()  
    1066871(: Returns a 'stubB' style observation station record to expand an data entity record :) 
    1067872(: Security not implemented yet :) 
    1068873{ 
    1069 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1070 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1071 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    1072 return   
    1073 if ($found = 0) then  
    1074 element {$out-element-name} { 
    1075 element error {'not found'}, 
    1076 element repositoryIdentifier {$repid}, 
    1077 element localIdentifier {$locid} 
    1078 }  
    1079 else ( 
    1080 for $SRDE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1081 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1082 and moles:dgMetadataID/moles:localIdentifier=$locid]  
     874let $SRDE := $DE 
    1083875return   
    1084876element {$out-element-name} { 
     
    1087879($SRDE/moles:name), 
    1088880($SRDE/moles:abbreviation), 
     881($SRDE/moles:abbreviation), 
    1089882element dgDataEntity { 
    1090883($SRDE/moles:dgDataEntity/moles:dgDataSetType), 
     
    1093886} (: </dgDataEntity> :)         
    1094887} 
    1095 ) 
    1096888} ; 
    1097889 
     
    1100892(: Security not implemented yet :) 
    1101893{ 
    1102 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     894let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     895moles:dgMetadataID/moles:localIdentifier=$locid 
     896and 
    1103897moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1104 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    1105 return   
    1106 if ($found = 0) then  
    1107 element {$out-element-name} { 
    1108 element error {'not found'}, 
    1109 element repositoryIdentifier {$repid}, 
    1110 element localIdentifier {$locid} 
    1111 }  
    1112 else ( 
    1113 for $SRDPT in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1114 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1115 and moles:dgMetadataID/moles:localIdentifier=$locid] 
     898] 
    1116899return   
    1117900element {$out-element-name} { 
     
    1131914} (: </dgDataProductionTool> :) 
    1132915} (: </dataproductiontool> :) 
    1133 ) 
    1134916} ; 
    1135917 
     
    1138920(: Security not implemented here yet;  :) 
    1139921{ 
    1140 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     922let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     923moles:dgMetadataID/moles:localIdentifier=$locid 
     924and 
    1141925moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1142 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    1143 return   
    1144 if ($found = 0) then  
    1145 element {$out-element-name} { 
    1146 element error {'not found'}, 
    1147 element repositoryIdentifier {$repid}, 
    1148 element localIdentifier {$locid} 
    1149 }  
    1150 else ( 
    1151 for $SRObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1152 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1153 and moles:dgMetadataID/moles:localIdentifier=$locid]  
     926]  
    1154927return 
    1155928element {$out-element-name} { 
     
    1158931($SRObsStn/moles:name), 
    1159932($SRObsStn/moles:abbreviation), 
     933($SRObsStn/moles:logos), 
    1160934element dgObservationStation { 
    1161935($SRObsStn/moles:dgObservationStation/moles:contactDetails), 
     
    1163937element dgStationaryPlatform { 
    1164938$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, 
    1165 if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} 
    1166 else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} 
    1167 else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} 
     939if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''} 
     940else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''} 
     941else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''} 
    1168942else () 
    1169943} 
     
    1173947} (: </dgObservationStation> :) 
    1174948} 
    1175 ) 
    1176949} ; 
    1177950 
     
    1180953(: Security not implemented yet :) 
    1181954{ 
    1182 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
     955let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
     956moles:dgMetadataID/moles:localIdentifier=$locid 
     957and 
    1183958moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1184 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    1185 return   
    1186 if ($found = 0) then  
    1187 element {$out-element-name} { 
    1188 element error {'not found'}, 
    1189 element repositoryIdentifier {$repid}, 
    1190 element localIdentifier {$locid} 
    1191 }  
    1192 else ( 
    1193 for $person in collection($targetCollection)/moles:dgMetadata/moles:dgPerson[ 
    1194 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1195 and moles:dgMetadataID/moles:localIdentifier=$locid]  
     959]  
    1196960return  
    1197961element  {$out-element-name}  
     
    1201965($person/moles:dgMetadataID) 
    1202966} 
    1203 ) 
    1204967} ; 
    1205968 
     
    1208971(: Security not implemented yet :) 
    1209972{ 
    1210 let $found := count(collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
     973let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
     974moles:dgMetadataID/moles:localIdentifier=$locid 
     975and 
    1211976moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1212 and moles:dgMetadataID/moles:localIdentifier=$locid]) 
    1213 return   
    1214 if ($found = 0) then  
    1215 element {$out-element-name} { 
    1216 element error {'not found'}, 
    1217 element repositoryIdentifier {$repid}, 
    1218 element localIdentifier {$locid} 
    1219 }  
    1220 else ( 
    1221 for $org in collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[ 
    1222 moles:dgMetadataID/moles:repositoryIdentifier=$repid  
    1223 and moles:dgMetadataID/moles:localIdentifier=$locid]  
     977]  
    1224978return  
    1225979element  {$out-element-name} { 
     
    1230984$org/moles:logos 
    1231985} 
    1232 ) 
    1233 } ; 
    1234  
    1235 for $ObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     986} ; 
     987 
     988let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1236989moles:dgObservationStation!=''  
    1237990and moles:dgMetadataID[ 
     
    12651018for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping  
    12661019return   
    1267 f:return-stub-obsstn('stationgrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier)) 
     1020f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier)) 
    12681021else () 
    12691022} (: End </dgMooring> :)   
     
    12881041f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)), 
    12891042f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),  
    1290 for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord 
    1291 where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier 
    1292 and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier 
     1043for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier 
     1044and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier] 
    12931045return 
    1294 f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)), 
     1046f:return-stub-dataentity('dataentity', $DE), 
    12951047$RelDep/moles:Coverage 
    12961048} (: </RelatedDeployment> :)  
Note: See TracChangeset for help on using the changeset viewer.