Ignore:
Timestamp:
07/06/07 15:20:43 (12 years ago)
Author:
ko23
Message:

Update of ndg_xqueries.py to include time-out capability and optimised DIF output

File:
1 edited

Legend:

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

    r2553 r2554  
    11281128    return $Moles ''' 
    11291129             
    1130 DIFQuery = '''import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; 
     1130DIFQuery = ''' 
     1131import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; 
    11311132import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; 
    11321133declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'; 
     
    11341135declare namespace moles='http://ndg.nerc.ac.uk/moles'; 
    11351136declare option exist:timeout '24500';  
    1136  
    11371137declare variable $targetCollection as xs:string {'TargetCollection'}; 
    11381138declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; 
    11391139declare variable $localIdentifier as xs:string {'LocalID'}; 
    11401140 
    1141 for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     1141let $DE := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    11421142    exists('moles:dgDataEntity')  
    1143     and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'  
    11441143    and moles:dgMetadataID/moles:repositoryIdentifier=$repositoryIdentifier 
    11451144    and moles:dgMetadataID/moles:localIdentifier=$localIdentifier] 
     
    11521151            for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1] 
    11531152        return  
    1154             for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
    1155                    and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
    1156                    and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
     1153            for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[( 
     1154                   moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
     1155                   and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
    11571156            return  
    11581157                    element Dataset_Creator { 
     
    11691168            element Parameters { 
    11701169            element Category {string($StructuredKeyword/*/moles:dgValidTerm)}, 
    1171             if (exists($StructuredKeyword//moles:dgValidSubterm)  
    1172                 and $StructuredKeyword//moles:dgValidSubterm != ''  
    1173                 and $StructuredKeyword//moles:dgValidSubterm != ' ') then  
     1170            if (exists($StructuredKeyword/*/moles:dgValidSubterm)  
     1171                and $StructuredKeyword/*/moles:dgValidSubterm != ''  
     1172                and $StructuredKeyword/*/moles:dgValidSubterm != ' ') then  
    11741173            for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)] 
    11751174                where exists($Subterm/moles:dgValidSubterm) 
     
    11801179                    else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
    11811180                    else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
    1182                     else element GCMD_Science_Valid {$Subterm/moles:ListLevel,($Subterm/moles:dgValidSubterm/moles:dgValidTerm)} 
     1181                    else element GCMD_Science_Valid {data($Subterm/moles:dgValidSubterm/moles:dgValidTerm)} 
    11831182            else() 
    11841183                } 
    11851184        else(), 
    1186     for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | moles:dgDataEntity/moles:dgDataSummary/moles:dgParameterSummary/moles:dgStdParameterMeasured)[voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_deprecated, moles:dgValidTermID/moles:ParentListID) and (not(exists(moles:ListLevel)) or moles:ListLevel=0)]) 
     1185    for $StructuredKeyword in ($DE/(moles:dgStructuredKeyword | moles:dgDataEntity/moles:dgDataSummary/moles:dgParameterSummary/moles:dgStdParameterMeasured)[voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_deprecated, moles:dgValidTermID/moles:ParentListID) and (not(exists(moles:ListLevel)) or moles:ListLevel=0)]) 
    11871186    return 
    11881187        element Parameters {data($StructuredKeyword/moles:dgValidTerm)}, 
     
    11901189        return  
    11911190            element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)}, 
    1192     for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[ 
     1191    for $Keyword in distinct-values($DE/moles:dgStructuredKeyword[ 
    11931192    not (voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID) 
    11941193    or voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) 
    11951194    or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) 
     1195    or voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID) 
    11961196    )]/moles:dgValidTerm) 
    11971197    return element Keyword {string($Keyword)},  
    1198     for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID 
    1199     return  
    1200         element Sensor_Name { 
    1201             for $DepDPTAbbrev in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:abbreviation)) 
    1202                 return element Short_Name {data($DepDPTAbbrev)}, 
    1203             for $DepDPTName in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:name)) 
    1204                 return element Long_Name {data($DepDPTName)} 
     1198    for $DepDPTRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID/moles:repositoryIdentifier 
     1199    for $DepDPTLocal in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID[moles:repositoryIdentifier=$DepDPTRepository]/moles:localIdentifier)  
     1200    let $DepDPTRecord := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPTRepository  and moles:localIdentifier=$DepDPTLocal]] 
     1201                return 
     1202                        element Sensor_Name { 
     1203                element Short_Name {data($DepDPTRecord/moles:abbreviation)}, 
     1204                element Long_Name {data($DepDPTRecord/moles:name)} 
    12051205            }, 
    1206     for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID) 
    1207     return  
    1208         element Source_Name { 
    1209             for $DepObsStnAbbrev in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:abbreviation)) 
    1210                 return element Short_Name {data($DepObsStnAbbrev)}, 
    1211             for $DepObsStnName in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:name)) 
    1212                 return element Long_Name {data($DepObsStnName)} 
     1206    for $DepObsStnRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID/moles:repositoryIdentifier) 
     1207    for $DepObsStnLocal in distinct-values(($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID[moles:repositoryIdentifier=$DepObsStnRepository]/moles:localIdentifier)) 
     1208    let $DepObsStnRecord := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:repositoryIdentifier=$DepObsStnRepository  and moles:localIdentifier=$DepObsStnLocal]] 
     1209                return element Source_Name { 
     1210                element Short_Name {data($DepObsStnRecord/moles:abbreviation)}, 
     1211                element Long_Name {data($DepObsStnRecord/moles:name)} 
    12131212            }, 
    1214     for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:DateRange) 
     1213    for $TemporalRange in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage/(moles:dgTemporalCoverage | moles:dgSpatioTemporalCoverage/moles:dgSpatioTemporalRange/moles:dgTemporalCoverage)/moles:DateRange 
    12151214        return  
    12161215            element Temporal_Coverage 
     
    12191218                element End_Date {data($TemporalRange/moles:DateRangeEnd)} 
    12201219                }, 
    1221     for $TemporalTerm in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_chronostratigraphic_valids, moles:dgValidTermID/moles:ParentListID)]/moles:dgValidTerm) 
     1220    for $TemporalTerm in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage/(moles:dgTemporalCoverage | moles:dgSpatioTemporalCoverage/moles:dgSpatioTemporalRange/moles:dgTemporalCoverage)/moles:dgChronostratigraphicTerm[voclib:spot-vocab($voclib:gcmd_chronostratigraphic_valids, moles:dgValidTermID/moles:ParentListID)]/moles:dgValidTerm 
    12221221        return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},  
    12231222    for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure) 
    12241223        return element Data_Set_Progress {data($Data_Set_Progress)}, 
    1225     for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox) 
     1224    for $BoundingBox in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage/(moles:dgSpatialCoverage | moles:dgSpatioTemporalCoverage/moles:dgSpatioTemporalRange/moles:dgSpatialCoverage)/moles:BoundingBox 
    12261225    return  
    12271226        element Spatial_Coverage { 
     
    12311230                element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)} 
    12321231            }, 
    1233     for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)]) 
     1232    for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage/(moles:dgSpatialCoverage | moles:dgSpatioTemporalCoverage/moles:dgSpatioTemporalRange/moles:dgSpatialCoverage)/moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)]) 
    12341233        return element Location {data($Location/moles:dgValidTerm)},  
    1235     for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID) 
     1234    for $DepActRepository in distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID/moles:repositoryIdentifer) 
     1235    for $DepActLocal in  distinct-values($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID[moles:repositoryIdentifer=$DepActRepository]/moles:localIdentifer)   
     1236    let $DepActRecord := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:repositoryIdentifier=$DepActRepository and moles:localIdentifier=$DepActLocal]] 
    12361237    return  
    12371238        element Project { 
    1238             for $DepActAbbrev in (collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:abbreviation) 
    1239                 return  
    1240                     element Short_Name {data($DepActAbbrev)}, 
    1241             for $DepActName in (collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:name) 
    1242                 return  
    1243                     element Long_Name {data($DepActName)} 
     1239                    element Short_Name {data($DepActRecord/abbreviation)}, 
     1240                    element Long_Name {data($DepActRecord/name)} 
    12441241            }, 
    12451242    if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then  
     
    14351432            element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)} 
    14361433    else () 
    1437         }''' 
     1434        } 
     1435''' 
    14381436         
    14391437DublinCoreDEQuery='''import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; 
Note: See TracChangeset for help on using the changeset viewer.