Changeset 2268 for TI01-discovery/trunk


Ignore:
Timestamp:
13/03/07 13:51:10 (13 years ago)
Author:
mpritcha
Message:

Uses new xqueries for MOLES-to-DC, MOLES-to-MDIP present

File:
1 edited

Legend:

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

    r2264 r2268  
    174174                                        //1. Check to see if a dc-format document exists for this name 
    175175                                        Vector queryParams = new Vector(); 
    176                                         String xqueryStr = "declare default element namespace 'http://ndg.nerc.ac.uk/moles'; declare namespace dummy='http://ndg.nerc.ac.uk/dummy'; declare namespace dc='http://purl.org/dc/elements/1.1/'; declare namespace oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc'; declare variable $gcmd_science_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html'}; declare variable $gcmd_project_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/projects.html'}; declare variable $cf_standard_names as xs:string {'http://www.cgd.ucar.edu/cms/eaton/cf-metadata/standard_name.html'}; declare variable $iso_topic_list as xs:string {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'}; 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  $i  return $matches  }; let $i := local:docExists('/db/discovery/original/"+this.format+"', '"+thisdoc+"')return if ( fn:empty($i) ) then ( for $DE in collection('/db/discovery/moles')/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID/schemeIdentifier='NDG-B0'] where util:document-name($DE)='"+thisdoc+"' return element dummy:container { <oai_dc:dc xmlns:oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'> { element dc:title {string($DE/name)}, element dc:type {'Dataset'}, element dc:identifier {concat($DE/dgMetadataID/repositoryIdentifier, ':DC:', $DE/dgMetadataID/localIdentifier)}, element dc:description {string($DE/dgMetadataDescription/abstract/abstractText)}, element dc:date { if (exists($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)) then for $updatedate in $DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate order by xs:dateTime($updatedate) descending return xs:dateTime($updatedate[1]) else string($DE/(dgMetadataProvenance | DataProvenance)/RecordCreation/CreatedDate) }, for $StructuredKeyword in distinct-values($DE/dgStructuredKeyword [dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids or dgValidTermID/ParentListID=$iso_topic_list ]//dgValidTerm) order by $StructuredKeyword return element dc:subject {string($StructuredKeyword)}, for $StructuredKeyword1 in distinct-values($DE/dgDataEntity/dgDataSummary/dgParameterSummary/dgStdParameterMeasured[dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids]//dgValidTerm) order by $StructuredKeyword1 return element dc:subject {string($StructuredKeyword1)}, for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder order by $DataCreatorRole/startDate empty least return for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/(dgOrganisation | dgPerson) [(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/localIdentifier)] return element dc:creator { if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then (string($DataCreatorRoleHolder/name)) else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then (string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName)))) else ('empty content') }, for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate=''] order by $DataCuratorRole/startDate empty least return for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/(dgOrganisation | dgPerson) [(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/localIdentifier)] return element dc:publisher { if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then (string($DataCuratorRoleHolder/name)) else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then (string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName)))) else ('empty content') } } </oai_dc:dc> } ) else ( element dummy:container { fn:item-at($i, 1) } ) "; 
     176                                        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://ndg.nerc.ac.uk/moles'; declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  declare namespace dc='http://purl.org/dc/elements/1.1/'; declare namespace oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/'; 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)/dgMetadata/dgMetadataRecord[ exists('dgDataEntity')  and dgMetadataID/schemeIdentifier='NDG-B0'  ] where util:document-name($DE)='"+thisdoc+"' return  element dummy:container { element oai_dc:dc {   attribute xsi:schemaLocation {'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'},    element dc:title {string($DE/name)},    element dc:type {'Dataset'},    element dc:identifier {concat($DE/dgMetadataID/repositoryIdentifier, $utillib:moles_id_separator, 'DC', $utillib:moles_id_separator, $DE/dgMetadataID/localIdentifier)},        element dc:description {string($DE/dgMetadataDescription/abstract/abstractText)},       element dc:date                 {               if (exists($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)) then                   for $updatedate in ($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)                                order by xs:dateTime($updatedate)                       return data($updatedate[1])             else                    string($DE/(dgMetadataProvenance | DataProvenance)/RecordCreation/CreatedDate)                  },      for $StructuredKeyword in distinct-values($DE/dgStructuredKeyword[      voclib:spot-vocab($voclib:cf_standard_names, dgValidTermID/ParentListID)        or voclib:spot-vocab($voclib:gcmd_science_valids, dgValidTermID/ParentListID)   or voclib:spot-vocab($voclib:gcmd_project_valids, dgValidTermID/ParentListID)   or voclib:spot-vocab($voclib:iso_topic_list, 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)          order by $StructuredKeyword     return                  element dc:subject {string($StructuredKeyword)},                for $StructuredKeyword1 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)                  order by $StructuredKeyword1    return                  element dc:subject  {string($StructuredKeyword1)},      for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder                 order by $DataCreatorRole/startDate empty least         return                  for $DataCreatorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)                      [(dgMetadataID/schemeIdentifier='NDG-B0'                        and dgMetadataID/repositoryIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier                     and dgMetadataID/localIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]             return                          element dc:creator {                            if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then                                   (string($DataCreatorRoleHolder/name))                           else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then                                    (string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName))))                             else ('empty content')                  },      for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate='']             order by $DataCuratorRole/startDate empty least         return                  for $DataCuratorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)                      [(dgMetadataID/schemeIdentifier='NDG-B0'                        and dgMetadataID/repositoryIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier                     and dgMetadataID/localIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]             return                          element dc:publisher {                          if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then                                   (string($DataCuratorRoleHolder/name))                           else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then                                    (string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))))                             else ('empty content')                  } }  (: </oai_dc:dc> :) } (: dummy:container :) ) else (        element dummy:container { doc(fn:item-at($i, 1)) } )"; 
    177177 
    178178                                        queryParams.addElement( xqueryStr.getBytes("UTF-8") );  
     
    187187 
    188188                                        byte[] resultByteArray = (byte[])xmlrpc.execute( "query", queryParams ); 
     189                                        //System.out.println( new String(resultByteArray) ); 
    189190                                        ByteArrayInputStream resultStream = new ByteArrayInputStream( resultByteArray ); 
    190191 
     
    193194                                        org.jdom.Element root = doc.getRootElement(); 
    194195                                        org.jdom.Element container = root.getChild("container", Namespace.getNamespace("dummy","http://ndg.nerc.ac.uk/dummy")); 
    195                                         org.jdom.Element elem = container.getChild("dc", Namespace.getNamespace("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/") ); 
     196                                        org.jdom.Element elem = container.getChild(properties.getProperty("rootElement.DC"), Namespace.getNamespace(properties.getProperty("namespacePrefix.DC"), "http://www.openarchives.org/OAI/2.0/oai_dc/") ); 
    196197 
    197198                                        //  Use XMLOutputter 
     
    232233                                        org.jdom.Element root = doc.getRootElement(); 
    233234                                        org.jdom.Element container = root.getChild("container", Namespace.getNamespace("dummy","http://ndg.nerc.ac.uk/dummy")); 
    234                                         org.jdom.Element elem = container.getChild("DIF", Namespace.getNamespace("http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/") ); 
     235                                        org.jdom.Element elem = container.getChild(properties.getProperty("rootElement.DIF"), Namespace.getNamespace(properties.getProperty("namespace.DIF")) ); 
    235236 
    236237                                        //  Use XMLOutputter 
     
    253254                                        //1. Check to see if a dc-format document exists for this name 
    254255                                        Vector queryParams = new Vector(); 
    255                                         String xqueryStr = "declare default element namespace 'http://www.dassh.ac.uk';declare namespace dummy='http://ndg.nerc.ac.uk/dummy';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 f='http://ndg.nerc.ac.uk/moles/localfunctions';declare variable $ISO_639-2_ns as xs:string{'UKGemini_Langauge_Categories'};declare variable $ISO_3166_ns as xs:string{'UKGemini_Land_Area_Categories'}; 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('/db/discovery/moles')/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 $DE/moles:dgDataEntity/moles:dgParameterSummary/moles:dgStdParameterMeasured[moles:dgValidTermID/moles:ParentListID=''] return element Subject {},      element Date {          element DatasetStartDate {},            element DatasetEndDate {}       }} } ) else ( element dummy:container { doc(fn:item-at($i, 1)) } )"; 
    256  
     256                                         
     257                                        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)) } ) "; 
    257258                                        queryParams.addElement( xqueryStr.getBytes("UTF-8") );  
    258259                                        queryParams.addElement( 1 ); 
     
    267268                                        byte[] resultByteArray = (byte[])xmlrpc.execute( "query", queryParams ); 
    268269                                        ByteArrayInputStream resultStream = new ByteArrayInputStream( resultByteArray ); 
    269  
     270                                        //System.out.println( new String(resultByteArray) ); 
    270271                                        //  Use XMLOutputter 
    271272                                        XMLOutputter out = new XMLOutputter (); 
     
    276277                                        org.jdom.Element root = doc.getRootElement(); 
    277278                                        org.jdom.Element container = root.getChild("container", Namespace.getNamespace("dummy","http://ndg.nerc.ac.uk/dummy")); 
    278                                         org.jdom.Element elem = container.getChild("Metadata", Namespace.getNamespace("http://www.oceannet.org/mdip/xml")); 
     279                                        org.jdom.Element elem = container.getChild(properties.getProperty("rootElement.MDIP"), Namespace.getNamespace(properties.getProperty("namespace.MDIP"))); 
    279280 
    280281                                        returnDoc = out.outputString( elem ); 
Note: See TracChangeset for help on using the changeset viewer.