Changeset 2373 for TI01-discovery


Ignore:
Timestamp:
03/04/07 15:15:44 (13 years ago)
Author:
mpritcha
Message:

Updated with latest xqueries (now labelled).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/PresentAgent.java

    r2321 r2373  
    221221                                { 
    222222                                        Vector queryParams = new Vector(); 
    223                                         String xqueryStr = "import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'; declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace dummy='http://ndg.nerc.ac.uk/dummy';  declare variable $targetCollection as xs:string {'/db/discovery/moles'}; declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; declare variable $localIdentifier as xs:string {'LocalID'}; declare function local:docExists($coll as xs:string, $doc as xs:string) as item()* {      let $testset := collection($coll)//root()       let $matches :=                 for $i in $testset              where util:document-name($i) = $doc             return  document-uri($i)        return $matches };  let $i := local:docExists('/db/discovery/original/"+this.format+"', '"+thisdoc+"') return if ( fn:empty($i) ) then ( for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[      exists('moles:dgDataEntity')    and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'  ]       where util:document-name($DE)='"+thisdoc+"' return element dummy:container { element DIF {      attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'},     element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'DIF', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)},    element Entry_Title {string($DE/moles:name)},   element Data_Set_Citation {         for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1]          return              for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'                         and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier                         and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)]                  return                      element Dataset_Creator {                           if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then                                  string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))                           else                               string($DataCreatorRoleHolder/moles:abbreviation)                            },          element Dataset_Title {string($DE/moles:name)}      },      for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | 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_categories, moles:dgValidTermID/moles:ParentListID))]     )               return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then                     element Parameters {                        element Category {string($StructuredKeyword/*/moles:dgValidTerm)},                      if (exists($StructuredKeyword//moles:dgValidSubterm)                            and $StructuredKeyword//moles:dgValidSubterm != ''                              and $StructuredKeyword//moles:dgValidSubterm != ' ') then                       for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)]                         where exists($Subterm/moles:dgValidSubterm)                     order by $Subterm/moles:ListLevel                           return                                  if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                    else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                        else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                    else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                   else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                       else()                      }           else(), 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)])      return          element Parameters {data($StructuredKeyword/moles:dgValidTerm)},        for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)])         return              element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)},       for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[ not (voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)  or voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID)       or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID)       )]/moles:dgValidTerm)   return element Keyword {string($Keyword)},      for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID)      return      element Sensor_Name {               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))                    return element Short_Name {data($DepDPTAbbrev)},            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))              return element Long_Name {data($DepDPTName)}                },      for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID)   return      element Source_Name {               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))                   return element Short_Name {data($DepObsStnAbbrev)},         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))             return element Long_Name {data($DepObsStnName)}             },      for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange)              return              element Temporal_Coverage                   {                       element Start_Date {data($TemporalRange/moles:DateRangeStart)},                 element End_Date {data($TemporalRange/moles:DateRangeEnd)}                      },      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)              return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},        for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure)                return element Data_Set_Progress {data($Data_Set_Progress)},    for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox)        return      element Spatial_Coverage {              element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)},                    element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)},                    element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)},             element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)}          },      for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)])               return element Location {data($Location/moles:dgValidTerm)},    for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID)        return      element Project {           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)              return                      element Short_Name {data($DepActAbbrev)},               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)                return                      element Long_Name {data($DepActName)}           },      if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then          for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule               return                              element Access_Constraints {                            if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then                                    concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ')                           else (),                                if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then                                concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true()))                             else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then                                  data($DG/moles:accessControlPolicy/moles:accessControlPolicyText)                            else                                for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition                               return                                      if (exists($securityCondition/moles:conditionExplanationText)) then                                         concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText))                                   else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority))                        }                else (),   if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then               for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder                     order by $DataCreatorRole/moles:startDate empty least                           return                              for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson)                                                    [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'                                                    and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:repositoryIdentifier                                               and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:localIdentifier)]                               return                                  element Originating_Center {                                    if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then                                           (string($DataCreatorRoleHolder/moles:name))                                     else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then                                            (string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))))                                     else ('empty content')                          }       else (),        for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate='']     return              for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'                 and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier                 and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)]                  return                      element Data_Center {                   element Data_Center_Name {                              element Short_Name {                                if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then                              string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))                       else                                string($DataCuratorRoleHolder/moles:abbreviation)                           },                  element Long_Name {                             if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then                                  string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))                           else string($DataCuratorRoleHolder/moles:name)                      }                   },                      if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then                                 element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)}                   else (),                        for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID                       return                      element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, '__', $DGID/moles:schemeIdentifier, '__', $DGID/moles:localIdentifier)},                      element  Personnel {                            element Role {'Data Center Contact'},                           if (exists($DataCuratorRoleHolder/name/knownAs)) then                               element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)}                                else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then                                     element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)}                                else (),                                                                        element Last_Name {                                      if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then                                        string($DataCuratorRoleHolder/moles:name/moles:familyName)                                    else string($DataCuratorRoleHolder/moles:name)                                  },                          if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then                                 element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)}                           else                                if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then                                           (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)})                                   else (),                                if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then                                     element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)}                               else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then                                          element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)}                          else (),                               if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then                                   element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)}                               else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then                                        element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}                                 else (),                                if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then                               element Contact_Address {                                   for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline                                           return element Address {data($addressline)},                                                        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then                                        element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)}                               else (),                                if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then                                        element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)}                                    else (),                                 if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then                                         element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)}                                 else ()                                 }                          else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then                                    element Contact_Address {                                   for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline                                     return element Address {data($addressline)},                                                            if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then                                          element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)}                                 else (),                                        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then                                          element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:postcode)}                                  else (),                                         if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then                                           element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)}                                   else ()                                     }                          else ()                          }                        },    element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)},    element Related_URL  {      element URL_Content_Type {'NDG_B_SERVICE'},     element URL {data($DE/moles:dgMetadataID/moles:repositoryIdentifier)},          element Description {'The NDG service for browsing metadata.'}          },  for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule       return              if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then                     (element Related_URL {                                  element URL_Content_Type {'NDG_A_SERVICE'},                             if (exists($DG/instance/URI)) then                                  element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())}                             else ($DG/moles:dataModelID/moles:repositoryIdentifier),                                element Description {'The NDG service delivering data via NDG A metadata.'}                         },                         element Related_URL {                            element URL_Content_Type {'GET DATA > CSML'},                                   if (exists($DG/instance)) then                                      element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())}                             else (),                                element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'}                            })              else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then                            (element Related_URL {                                    element URL_Content_Type {'NDG_A_SERVICE'},                               if (exists($DG/instance)) then                                      element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}                              else (),                                element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}                                },                          element Related_URL {                               element URL_Content_Type {'GET DATA > DX'},                             if (exists($DG/instance)) then                                      element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}                              else (),                                element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}                                })          else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then                           element Related_URL {                           element URL {data($DG/moles:instance/moles:URI)},                               if (exists($DG/moles:instance/moles:instanceComment)) then                                      element Description {data($DG/moles:instance/moles:instanceComment)}                                            else                                    element Description {'URL to aid in delivering data. Note that this may point directly to the data or, more likely, point to the web site of the curator.'}                             }       else (),        for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)         return                          element Related_URL {                           element URL {data($RelURL_Desc)},                       element Description {concat(data($RelURL_Desc/moles:name), ' - ', data($RelURL_Desc/moles:notes))}                                   },     element Metadata_Name {'[CEOS IDN DIF]'},       element Metadata_Version {'9.4'},       if  (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then          element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)} else (),        for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate        return              element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))},      if  (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then            element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)}       else ()        } } ) else (     element dummy:container { doc(fn:item-at($i, 1)) } )"; 
     223                                        // Implements revision #2358 of TI07-MOLES/trunk/DIF/XQuery/NDG-MDIP.xquery 
     224                                        String xqueryStr = "import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'; declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace dummy='http://ndg.nerc.ac.uk/dummy';  declare variable $targetCollection as xs:string {'/db/discovery/moles'}; declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; declare variable $localIdentifier as xs:string {'LocalID'}; declare function local:docExists($coll as xs:string, $doc as xs:string) as item()* {      let $testset := collection($coll)//root()       let $matches :=                 for $i in $testset              where util:document-name($i) = $doc             return  document-uri($i)        return $matches };  let $i := local:docExists('/db/discovery/original/"+this.format+"', '"+thisdoc+"') return if ( fn:empty($i) ) then ( for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[      exists('moles:dgDataEntity')    and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'  ]       where util:document-name($DE)='"+thisdoc+"' return element dummy:container { element DIF {      attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'},     element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'DIF', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)},    element Entry_Title {string($DE/moles:name)},   element Data_Set_Citation {                 for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1]          return                      for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'                         and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier                         and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)]                  return                              element Dataset_Creator {                           if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then                                  string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))                           else                               string($DataCreatorRoleHolder/moles:abbreviation)                            },          element Dataset_Title {string($DE/moles:name)}      },      for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | 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_categories, moles:dgValidTermID/moles:ParentListID))]     )               return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then                     element Parameters {                        element Category {string($StructuredKeyword/*/moles:dgValidTerm)},                      if (exists($StructuredKeyword//moles:dgValidSubterm)                            and $StructuredKeyword//moles:dgValidSubterm != ''                              and $StructuredKeyword//moles:dgValidSubterm != ' ') then                       for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)]                         where exists($Subterm/moles:dgValidSubterm)                             order by $Subterm/moles:ListLevel                           return                                          if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                    else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                        else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                    else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                                   else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}                       else()                      }           else(),         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)])      return          element Parameters {data($StructuredKeyword/moles:dgValidTerm)},        for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)])         return              element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)},       for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[         not (voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)  or voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID)       or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID)       )]/moles:dgValidTerm)   return element Keyword {string($Keyword)},      for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID)      return              element Sensor_Name {               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))                    return element Short_Name {data($DepDPTAbbrev)},            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))              return element Long_Name {data($DepDPTName)}                },      for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID)   return              element Source_Name {               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))                   return element Short_Name {data($DepObsStnAbbrev)},                 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))                     return element Long_Name {data($DepObsStnName)}             },      for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange)              return                      element Temporal_Coverage                   {                       element Start_Date {data($TemporalRange/moles:DateRangeStart)},                         element End_Date {data($TemporalRange/moles:DateRangeEnd)}                      },      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)              return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},        for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure)                return element Data_Set_Progress {data($Data_Set_Progress)},    for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox)        return              element Spatial_Coverage {              element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)},                    element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)},                    element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)},                     element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)}          },      for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)])               return element Location {data($Location/moles:dgValidTerm)},    for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID)        return              element Project {           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)              return                      element Short_Name {data($DepActAbbrev)},               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)                return                      element Long_Name {data($DepActName)}           },      if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then                  for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule               return                                      element Access_Constraints {                            if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then                                    concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ')                           else (),                                if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then                                concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true()))                             else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then                                  data($DG/moles:accessControlPolicy/moles:accessControlPolicyText)                            else                                for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition                               return                                      if (exists($securityCondition/moles:conditionExplanationText)) then                                         concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText))                                   else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority))                        }                 else (),  if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then               for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder                     order by $DataCreatorRole/moles:startDate empty least                           return                              for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson)                                                    [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'                                                    and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier                                                 and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)]                                 return                                          element Originating_Center {                                    if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then                                           (string($DataCreatorRoleHolder/moles:name))                                     else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then                                            (string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))))                                     else ('empty content')                          }       else (),        for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder         [not(exists(moles:endDate)) or moles:endDate='']        return          for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson)    [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'    and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier         and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)]         return          element Data_Center {   element Data_Center_Name {      element Short_Name {    if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then      string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))       else    string($DataCuratorRoleHolder/moles:abbreviation)       },      element Long_Name {     if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then      string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))       else string($DataCuratorRoleHolder/moles:name)  }       },      if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then         element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)}   else (),        for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID       return          element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, $utillib:moles_id_separator, $DGID/moles:schemeIdentifier, $utillib:moles_id_separator, $DGID/moles:localIdentifier)},    element  Personnel {    element Role {'Data Center Contact'},   if (exists($DataCuratorRoleHolder/name/knownAs)) then   element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)}    else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then         element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)}   else (),                                                element Last_Name {     if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then    string($DataCuratorRoleHolder/moles:name/moles:familyName)      else string($DataCuratorRoleHolder/moles:name)  },      if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then     element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)}       else    if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then   (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)})       else (),        if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then         element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)}   else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then      element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)}     else (),        if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then       element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)}   else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then    element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}     else (),        if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then   element Contact_Address {       for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline       return element Address {data($addressline)},    if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then        element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)}   else (),        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then    element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)}        else (),        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then     element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)}     else ()         }       else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then        element Contact_Address {       for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline         return element Address {data($addressline)},    if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then          element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)}     else (),        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then      element Postal_Code {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)}  else (),        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then       element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)}       else ()         }       else ()         }       },      element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)},    for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule       return              if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then                             (element Related_URL {                                  element URL_Content_Type {'NDG_A_SERVICE'},                             if (exists($DG/instance/URI)) then                                  element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())}                             else ($DG/moles:dataModelID/moles:repositoryIdentifier),                                element Description {'The NDG service delivering data via NDG A metadata.'}                         },                         element Related_URL {                                    element URL_Content_Type {'GET DATA > CSML'},                                   if (exists($DG/instance)) then                                      element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())}                             else (),                                element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'}                            })              else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then                            (element Related_URL {                                     element URL_Content_Type {'NDG_A_SERVICE'},                              if (exists($DG/instance)) then                                      element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}                              else (),                                element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}                                },                          element Related_URL {                               element URL_Content_Type {'GET DATA > DX'},                             if (exists($DG/instance)) then                                      element URL {escape-uri($DG/instance/URI, true())}                                  else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then                                   element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}                              else (),                                element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}                                })          else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then                           element Related_URL {                           element URL {data($DG/moles:instance/moles:URI)},                               if (exists($DG/moles:instance/moles:instanceComment)) then                                      element Description {data($DG/moles:instance/moles:instanceComment)}                                            else                                    element Description {'URL to aid in delivering data. Note that this may point directly to the data or, more likely, point to the web site of the curator.'}                             }       else (),        for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)         return                          if (exists($RelURL_Desc/moles:dgSimpleLink)) then                       element Related_URL {                           element URL {data($RelURL_Desc/moles:dgSimpleLink/URI)},                        element Description {concat(data($RelURL_Desc/dgSimpleLink/moles:name), ' - ', data($RelURL_Desc/dgSimpleLink/moles:notes))}                            }                       else (),    element Metadata_Name {'[CEOS IDN DIF]'},       element Metadata_Version {'9.4'},       if  (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then                  element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)}         else (),        for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate        return              element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))},      if  (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then            element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)}       else ()         } } ) else (    element dummy:container { doc(fn:item-at($i, 1)) } )"; 
    224225                                        queryParams.addElement( xqueryStr.getBytes("UTF-8") );  
    225226                                        queryParams.addElement( 1 ); 
     
    266267                                        //1. Check to see if a dc-format document exists for this name 
    267268                                        Vector queryParams = new Vector(); 
    268                                          
    269                                         String xqueryStr = "import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; declare default element namespace 'http://www.oceannet.org/mdip/xml'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace gco='http://www.isotc211.org/2005/gco'; declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  declare namespace dummy='http://ndg.nerc.ac.uk/dummy';  declare variable $targetCollection as xs:string {'/db/discovery/moles'}; declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; declare variable $localIdentifier as xs:string {'LocalID'}; declare function local:docExists($coll as xs:string, $doc as xs:string) as item()* {      let $testset := collection($coll)//root()       let $matches :=                 for $i in $testset              where util:document-name($i) = $doc             return  document-uri($i)        return $matches };  declare variable $ISO_639-2_ns as xs:string{$voclib:ISO_639-2_ns}; declare variable $ISO_3166_ns as xs:string{$voclib:ISO_3166_ns};  let $i := local:docExists('/db/discovery/original/"+this.format+"', '"+thisdoc+"') return if ( fn:empty($i) ) then ( for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[         exists('moles:dgDataEntity')    and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'          ]       where util:document-name($DE)='"+thisdoc+"' return element dummy:container { element Metadata {         element Title {data($DE/moles:name)},   if (exists($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDatasetLanguage)) then            for $lang in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDatasetLanguage                 return                  element Language{                               element LanguageName {data($lang/dgValidTerm)},                                 element LanguageVocab {data($lang/dgValidTermID/ParentListID)},                                 element LanguageCode {data($lang/dgValidTermID/TermID)}                         }                                       else (),        element Abstract {},    for $isoTopic in $DE/moles:dgStructuredKeyword[moles:dgValidTermID/moles:ParentListID='']       return element TopicCategory {},        for $subject in distinct-values($DE/dgDataEntity/dgDataSummary/dgParameterSummary/dgStdParameterMeasured[       voclib:spot-vocab($voclib:gcmd_science_valids, dgValidTermID/ParentListID)      or voclib:spot-vocab($voclib:gcmd_project_valids, dgValidTermID/ParentListID)   or voclib:spot-vocab($voclib:bodc_parameter_usage_vocab, dgValidTermID/ParentListID)    or voclib:spot-vocab($voclib:bodc_parameter_discovery_vocab, dgValidTermID/ParentListID)        ]/dgValidTerm)          return element Subject {$subject},      element Date {          element DatasetStartDate {},            element DatasetEndDate {}       } } } ) else (  element dummy:container { doc(fn:item-at($i, 1)) } ) "; 
     269                                        // Implements revision #2372 of TI07-MOLES/trunk/MDIP/XQueries/NDG-MDIP.xquery 
     270                                        String xqueryStr = "import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; declare default element namespace 'http://www.oceannet.org/mdip/xml'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace gco='http://www.isotc211.org/2005/gco'; declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  declare namespace dummy='http://ndg.nerc.ac.uk/dummy';  declare variable $targetCollection as xs:string {'/db/discovery/moles'}; declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; declare variable $localIdentifier as xs:string {'LocalID'}; declare function local:docExists($coll as xs:string, $doc as xs:string) as item()* {      let $testset := collection($coll)//root()       let $matches :=                 for $i in $testset              where util:document-name($i) = $doc             return  document-uri($i)        return $matches };  declare variable $ISO_639-2_ns as xs:string{$voclib:ISO_639-2_ns}; declare variable $ISO_3166_ns as xs:string{$voclib:ISO_3166_ns};  let $i := local:docExists('/db/discovery/original/"+this.format+"', '"+thisdoc+"') return if ( fn:empty($i) ) then ( for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[         exists('moles:dgDataEntity')    and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'          ]       where util:document-name($DE)='"+thisdoc+"' return element dummy:container { element Metadata { element Title {data($DE/moles:name)}, if (exists($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDatasetLanguage)) then for $lang in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDatasetLanguage return element Language{ element LanguageName {data($lang/moles:dgValidTerm)}, element LanguageVocab {data($lang/moles:dgValidTermID/moles:ParentListID)}, element LanguageCode {data($lang/moles:dgValidTermID/moles:TermID)} }  else (),  element Abstract {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}, for $isoTopic in $DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)]  return element TopicCategory { element TopicCategoryName {data($isoTopic/moles:dgValidTerm)}, element TopicCategoryVocab {data($isoTopic/moles:dgValidTermID/moles:ParentListID)}, element TopicCategoryCode {data($isoTopic/moles:dgValidTermID/moles:TermID)} }, for $subject in ($DE/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_project_valids, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_categories, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:bodc_parameter_usage_vocab, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:bodc_parameter_discovery_vocab, moles:dgValidTermID/moles:ParentListID) ])  return (element Subject { element SubjectName {data($subject/moles:dgValidTerm)}, element SubjectVocab {data($subject/moles:dgValidTermID/moles:ParentListID)}, element SubjectCode {data($subject/moles:dgValidTermID/moles:TermID)} }, for $subterm in $subject//moles:dgValidSubterm return (element Subject { element SubjectName {data($subterm/moles:dgValidTerm)}, element SubjectVocab {data($subterm/moles:dgValidTermID/moles:ParentListID)}, element SubjectCode {data($subterm/moles:dgValidTermID/moles:TermID)} } ) ), if (exists($DE//moles:dgTemporalCoverage/(moles:DateSingle | moles:DateRange))) then  element Date { element DatasetStartDate { let $dateStart:=min($DE//moles:dgTemporalCoverage/(moles:DateSingle | moles:DateRange/moles:DateRangeStart) cast as xs:date) return  if (empty($dateStart)) then ()  else data($dateStart) }, element DatasetEndDate { let $dateEnd:=max($DE//moles:dgTemporalCoverage/(moles:DateSingle | moles:DateRange/moles:DateRangeEnd) cast as xs:date) return if (empty($dateEnd)) then ()  else data($dateEnd) } } else (), let $west := min($DE/moles:dgDataEntity/moles:dgDataSummary//moles:BoundingBox/moles:LimitWest cast as xs:decimal) return element WestCoOrdinate {data($west)}, let $east := max($DE/moles:dgDataEntity/moles:dgDataSummary//moles:BoundingBox/moles:LimitEast cast as xs:decimal) return element EastCoOrdinate {data($east)}, let $north := max($DE/moles:dgDataEntity/moles:dgDataSummary//moles:BoundingBox/moles:LimitNorth cast as xs:decimal) return element NorthCoOrdinate {data($north)}, let $south := min($DE/moles:dgDataEntity/moles:dgDataSummary//moles:BoundingBox/moles:LimitSouth cast as xs:decimal) return element SouthCoOrdinate {data($south)}, element DatasetIdentifier {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'MDIP', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)}, for $target in $DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:ndg_data_provider_vocab, moles:dgValidTermID/moles:ParentListID) ] return element Target { element TargetName {data($target/moles:dgValidTerm)}, element TargetVocab {data($target/moles:dgValidTermID/moles:ParentListID)}, element TargetCode {data($target/moles:dgValidTermID/moles:TermID)} } } } ) else (         element dummy:container { doc(fn:item-at($i, 1)) } ) "; 
    270271                                        queryParams.addElement( xqueryStr.getBytes("UTF-8") );  
    271272                                        queryParams.addElement( 1 ); 
Note: See TracChangeset for help on using the changeset viewer.