Ignore:
Timestamp:
19/05/06 16:11:06 (14 years ago)
Author:
ko23
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/JavaCode/bulkdestubbxmldb/ndg/services/bulkdestubb/Main.java

    r681 r967  
    3434        static String IDIssuesDoc = "http://bscw.badc.rl.ac.uk/bscw.bscw.cgi/d83706/IDIssuesinNDG.doc"; 
    3535 
    36         static String DefaulteXistService = "xmldb:exist://localhost:8080/exist/xmlrpc"; 
     36        static String DefaulteXistService = "xmldb:exist://localhost:8080/exist/xmlrpc";  
    3737    static String defaultXMLDBDriver = "org.exist.xmldb.DatabaseImpl"; 
     38    static String DefaultUserID = "guest"; 
     39    static String DefaultUserPW = "guest"; 
    3840 
    3941        static String ListDEQuery = "for $DE in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[exists(dgDataEntity)] return <dgMetadataRecord>{$DE/dgMetadataID/repositoryIdentifier}{$DE/dgMetadataID/localIdentifier}<fileName>{util:document-name($DE)}</fileName></dgMetadataRecord>"; 
     
    4244        static String RawDEMoles = "for $DE in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID[schemeIdentifier='NDG-B0' and repositoryIdentifier='RepositoryID' and localIdentifier='LocalID']] return $DE"; 
    4345        static String DublinCoreDEQuery = "xquery version '1.0'; declare default element namespace ''; declare namespace dc='http://purl.org/dc/elements/1.1/'; declare namespace oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc'; for $DE in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID'] return <oai_dc:dc> <dc:title>{string($DE/name)}</dc:title> <dc:type>Dataset</dc:type> <dc:identifier>{concat($DE/dgMetadataID/repositoryIdentifier, ':DC:', $DE/dgMetadataID/localIdentifier)}</dc:identifier> <dc:description>{string($DE/dgMetadataDescription/abstract/abstractText)}</dc:description> {for $StructuredKeyword in distinct-values($DE//(dgStructuredKeyword | dgStdParameterMeasured)/dgValidTerm) where ($DE//(dgStructuredKeyword | dgStdParameterMeasured)/dgValidTermID/ParentListID='http://www.cgd.ucar.edu/cms/eaton/cf-metadata/standard_name.html' or $DE//(dgStructuredKeyword | dgStdParameterMeasured)/dgValidTermID/ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html' or $DE//(dgStructuredKeyword | dgStdParameterMeasured)/dgValidTermID/ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/projects.html') return <dc:subject> {string($StructuredKeyword)} </dc:subject> } {for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder return <dc:creator> {if (exists($DataCreatorRole/dgPersonID)) then for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/dgPerson[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCreatorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCreatorRole/*/localIdentifier)] return string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName))) else if (exists($DataCreatorRole/dgOrganisationID)) then for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/dgOrganisation[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCreatorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCreatorRole/*/localIdentifier)] return string($DataCreatorRoleHolder/name) else (string('Not known')) } </dc:creator> } {for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate=''] return <dc:publisher> {if (exists($DataCuratorRole/dgPersonID)) then for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/dgPerson[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/*/localIdentifier)] return string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))) else if (exists($DataCuratorRole/dgOrganisationID)) then for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/dgOrganisation[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/*/localIdentifier)] return string($DataCuratorRoleHolder/name) else (string('Not known')) } </dc:publisher> } </oai_dc:dc>"; 
    44         static String DIFQuery = "for $DE in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID'] return <DIF> <Entry_ID>{concat($DE/dgMetadataID/repositoryIdentifier, ':DIF:', $DE/dgMetadataID/localIdentifier)}</Entry_ID> <Entry_Title>{string($DE/name)}</Entry_Title> <Parameters> {for $StructuredKeyword in ($DE//(dgStructuredKeyword | dgStdParameterMeasured)) where (($DE//(dgStructuredKeyword | dgStdParameterMeasured)/dgValidTermID/ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html' or $DE//(dgStructuredKeyword | dgStdParameterMeasured)/dgValidTermID/ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/projects.html') and ($DE//(dgStructuredKeyword | dgStdParameterMeasured)/ListLevel = 0)) return if (exists($StructuredKeyword/*/dgValidTerm)) then ( <Parameter> {string($StructuredKeyword/*/dgValidTerm)} {if (exists($StructuredKeyword//dgValidSubterm) and $StructuredKeyword//dgValidSubterm != '' and $StructuredKeyword//dgValidSubterm != ' ') then ( for $Subterm in $StructuredKeyword//dgValidSubterm[exists(dgValidTerm)] where exists($Subterm/dgValidSubterm) order by $Subterm/ListLevel return concat(' &gt; ', string($Subterm/dgValidSubterm/dgValidTerm)) ) else()} </Parameter> ) else() } </Parameters> <ISO_Topic_Category> </ISO_Topic_Category> {for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate=''] return <Data_Center> {if (exists($DataCuratorRole/dgPersonID)) then for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/dgPerson[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/*/localIdentifier)] return string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))) else if (exists($DataCuratorRole/dgOrganisationID)) then for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/dgOrganisation[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/*/localIdentifier)] return string($DataCuratorRoleHolder/name) else () } </Data_Center> } <Summary>{string($DE/dgMetadataDescription/abstract/abstractText)}</Summary> <Metadata_Name>[CEOS IDN DIF]</Metadata_Name> <Metadata_Version>9.4</Metadata_Version> </DIF>"; 
     46        static String DIFQuery = "for $DE in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[exists('dgDataEntity') and dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID'] return <DIF> <Entry_ID>{concat($DE/dgMetadataID/repositoryIdentifier, ':DIF:', $DE/dgMetadataID/localIdentifier)}</Entry_ID> <Entry_Title>{string($DE/name)}</Entry_Title> {for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder[not(exists(endDate)) or endDate=''] return  for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/*[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCreatorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCreatorRole/*/localIdentifier)] return  <Dataset_Citation> {element Data_Creator {if (exists($DataCreatorRoleHolder/name/initials)) then ( string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName))) ) else ( string($DataCreatorRoleHolder/abbreviation) )} }  <Dataset_Title>{string($DE/name)}</Dataset_Title>  </Dataset_Citation> } <Personnel/> <Discipline/>  <Parameters> {for $StructuredKeyword in ($DE//(dgStructuredKeyword | dgStdParameterMeasured)[dgValidTermID/ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html' and ListLevel = 0]) return if (exists($StructuredKeyword/*/dgValidTerm)) then ( <Parameter> {element Category {string($StructuredKeyword/*/dgValidTerm)}} {if (exists($StructuredKeyword//dgValidSubterm)  and $StructuredKeyword//dgValidSubterm != ''  and $StructuredKeyword//dgValidSubterm != ' ') then ( for $Subterm in $StructuredKeyword//dgValidSubterm[exists(dgValidTerm)] where exists($Subterm/dgValidSubterm) order by $Subterm/ListLevel return  if ($Subterm/ListLevel=1) then (<Topic>{string($Subterm/dgValidSubterm/dgValidTerm)}</Topic>)  else ( if ($Subterm/ListLevel=2) then (<Term>{string($Subterm/dgValidSubterm/dgValidTerm)}</Term>)  else ( if ($Subterm/ListLevel=3) then (<Variable>{string($Subterm/dgValidSubterm/dgValidTerm)}</Variable>)  else ( if ($Subterm/ListLevel=4) then (<Detailed_Variable>{string($Subterm/dgValidSubterm/dgValidTerm)}</Detailed_Variable>)  else (<GCMD_Science_Valid>{string($Subterm/dgValidSubterm/dgValidTerm)}</GCMD_Science_Valid>)))) )  else()} </Parameter> ) else() } </Parameters> {for $ISOTopicCategory in ($DE/dgStructuredKeyword[dgValidTermID/ParentListID='ISO 19115 Topic Category']) return  <ISO_Topic_Category>{$ISOTopicCategory/dgValidTerm}</ISO_Topic_Category> }  <ISO_Topic_Category/> <Keyword/> <Sensor_Name/> <Source_Name/> <Temporal_Coverage/> <Paleo_Temporal_Coverage/> <Data_Set_Progress/> <Spatial_Coverage/> <Location/> <Data_Resolution/> <Project/> <Quality/> <Access_Constraints/> <Use_Constraints/> <Data_Set_Language/> <Originating_Center/>  {for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate=''] return  for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/*[(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/*/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/*/localIdentifier)] return  <Data_Center> <Data_Center_Name> {element Short_Name {if (exists($DataCuratorRoleHolder/name/initials)) then ( string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))) ) else ( string($DataCuratorRoleHolder/abbreviation) )} } {element Long_Name {if (exists($DataCuratorRoleHolder/name/initials)) then ( string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))) ) else (string($DataCuratorRoleHolder/name))} } </Data_Center_Name> {if (exists($DataCuratorRoleHolder/contactDetails/URI)) then ( element Data_Center_URL {data($DataCuratorRoleHolder/contactDetails/URI)} ) else ()} {for $DGID in $DE/dgDataEntity/dgDataGranule/dataModelID return element Data_Set_ID {concat($DGID/repositoryIdentifier, ':', $DGID/schemeIdentifier, ':', $DGID/localIdentifier)} } <Personnel> {element Role {'Data Center Contact'}} {if (exists($DataCuratorRoleHolder/name/knownAs)) then ( element First_Name {string($DataCuratorRoleHolder/name/knownAs)} ) else if (exists($DataCuratorRoleHolder/name/initials)) then ( element First_Name {string($DataCuratorRoleHolder/name/initials)} ) else ()}  {element Last_Name {if (exists($DataCuratorRoleHolder/name/familyName)) then ( string($DataCuratorRoleHolder/name/familyName) ) else (string($DataCuratorRoleHolder/name))} } {if (exists($DataCuratorRole/contactDetails/eMail)) then ( element Email {string($DataCuratorRole/contactDetails/eMail)} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then ( element Email {string($DataCuratorRoleHolder/contactDetails/eMail)} ) else () )} {if (exists($DataCuratorRole/contactDetails/telephone)) then ( element Phone {string($DataCuratorRole/contactDetails/telephone)} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/telephone)) then ( element Phone {string($DataCuratorRoleHolder/contactDetails/telephone)} ) else () )} {if (exists($DataCuratorRole/contactDetails/fax)) then ( element Fax {string($DataCuratorRole/contactDetails/fax)} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/fax)) then ( element Fax {string($DataCuratorRoleHolder/contactDetails/fax)} ) else () )} {if (exists($DataCuratorRole/contactDetails/address/addressline)) then ( for $addressline in $DataCuratorRole/contactDetails/address/addressline return element address {$addressline} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/addressline)) then ( for $addressline in $DataCuratorRoleHolder/contactDetails/address/addressline return element address {$addressline} ) else () )} {if (exists($DataCuratorRole/contactDetails/address/city)) then ( element City {string($DataCuratorRole/contactDetails/city)} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/city)) then ( element Cityl {string($DataCuratorRoleHolder/contactDetails/city)} ) else () )} {if (exists($DataCuratorRole/contactDetails/address/postcode)) then ( element Postal_Code {string($DataCuratorRole/contactDetails/postcode)} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/postcode)) then ( element email {string($DataCuratorRoleHolder/contactDetails/postcode)} ) else () )} {if (exists($DataCuratorRole/contactDetails/address/country)) then ( element Postal_Code {string($DataCuratorRole/contactDetails/country)} ) else ( if (exists($DataCuratorRoleHolder/contactDetails/postcode)) then ( element Postal_Code {string($DataCuratorRoleHolder/contactDetails/eMail)} ) else () )} </Personnel> </Data_Center> } <Summary>{string($DE/dgMetadataDescription/abstract/abstractText)}</Summary> <Metadata_Name>[CEOS IDN DIF]</Metadata_Name> <Metadata_Version>9.4</Metadata_Version> </DIF>"; 
    4547   
    4648 
     49        private static String getNamedParam(String paramName, String[] args) { 
     50                // pass in args and get named parameter 
     51                String namedArg = "";  
     52 
     53        for (int x = 0; x < args.length; x=x+2) { 
     54                String paramValue = args[x]; 
     55            if (debug) {System.out.println("  Arg=" + args[x]);} 
     56            if (debug) {System.out.println("Value=" + args[x+1]);} 
     57                if (paramValue.compareTo(paramName) == 0) { 
     58                        namedArg = args[x+1]; 
     59                        x = args.length; 
     60                } 
     61        } 
     62        if (debug) {System.out.println("returned namedArg=" + namedArg + "\n\n");} 
     63                 
     64                return namedArg; 
     65                 
     66        } 
     67         
    4768        public static void main(String[] args) { 
    4869 
     
    7293            String targetDirectory = null; 
    7394 
    74                 boolean outputDirectoryCreated = false; 
     95            String user = null; 
     96            String userpw = null; 
     97 
     98            boolean outputDirectoryCreated = false; 
    7599                Writer writer = null; 
    76100 
     
    87111                 * Check args 
    88112                 */ 
    89                 if (args.length != 1 && args.length != 2) { 
    90                         System.out.println("Usage:java -jar bulkdestubb.jar output-filetype [xmldb:exist://<host-name>:<port>/exist/xmlrpc]"); 
    91                         if (debug) {System.out.println("Arg length " + args.length);} 
    92                         System.exit(0); 
    93                         } 
     113        outputType = getNamedParam("format", args); 
     114        if (outputType == "") { 
     115                user = DefaultUserID; 
     116            } 
     117        eXistService = getNamedParam("repository", args); 
     118        if (eXistService == "") { 
     119                eXistService = DefaulteXistService; 
     120            } 
     121        userpw = getNamedParam("userpw", args); 
     122        if (userpw == "") { 
     123                userpw = DefaultUserPW; 
     124            } 
     125        user = getNamedParam("user", args); 
     126        if (user == "") { 
     127                user = DefaultUserID; 
     128            } 
     129        if (debug) { 
     130                System.out.println("format=" + outputType); 
     131                System.out.println("eXistService=" + eXistService); 
     132                System.out.println("user=" + user); 
     133                System.out.println("userpw=" + userpw + "\n"); 
     134                } 
     135         
     136        if(outputType.compareTo("")== 0) { 
     137            System.out.println("Missing repository and/or local ID.\n"); 
     138            System.out.println("Correct execution syntax: java -jar returnstubb.jar [parametername parametervalue]"); 
     139            System.out.println("Mandatory parameters are:\n"); 
     140            System.out.println("\tformat - see " + IDIssuesDoc + " for legal values\n"); 
     141            System.out.println("Optional parameters are:\n"); 
     142            System.out.println("\trepository\n\t\t in the format xmldb:exist://<host-name>:<port>/exist/xmlrpc\n"); 
     143            System.out.println("\tuser - default = \"guest\"\n"); 
     144            System.out.println("\tpassword - default = \"guest\"\n"); 
     145            System.out.println("\nNote that everything is case-sensitive, but parameters can be in any order.\n"); 
     146            System.exit(0); 
     147        } 
    94148                /*  
    95149                 * Check that the outputType is legal according to IDIssuesDoc  
    96150                 */ 
    97                 if (debug) {System.out.println("Format: =" + args[0] + "=");} 
    98151                 
    99                 if (args[0].equals("NDG-B1")) { 
    100                         outputType="StubB"; 
    101                         } 
    102                 else if (args[0].equals("NDG-B0")) { 
    103                         outputType="MOLES"; 
    104                         } 
    105                 else if (args[0].equals("TEST")) { 
    106                         outputType="test"; 
    107                         } 
    108                 else if (args[0].equals("DC")) { 
    109                         outputType="DC"; 
    110                         } 
    111                 else if (args[0].equals("DIF")) { 
    112                         outputType="DIF"; 
    113                         } 
    114                 else if (args[0].equals("ISO19115")) { 
     152                if (outputType.equals("NDG-B1") || 
     153                                outputType.equals("NDG-B0") || 
     154                                outputType.equals("test") || 
     155                                outputType.equals("DC") || 
     156                                outputType.equals("DIF")) {;} 
     157                else if (outputType.equals("ISO19115")) { 
    115158                        outputType="ISO19115"; 
    116159                        System.out.println("Curse you Green Dragon! This format isn't supported yet..."); 
     
    125168                if (args.length == 2) {eXistService = args[1];} 
    126169        else {eXistService = DefaulteXistService;} 
     170                if (debug) { 
     171                        System.out.println("eXist service = " + eXistService); 
     172                } 
    127173                 
    128174                // Set output directory 
     
    165211                     
    166212            // get root-collection 
    167             rootCollection = DatabaseManager.getCollection(eXistService + DBBroker.ROOT_COLLECTION); 
     213            rootCollection = DatabaseManager.getCollection(eXistService + DBBroker.ROOT_COLLECTION, user, userpw); 
    168214            // get query-service 
    169215                if (trace) {System.out.println("Set query-service");} 
     
    172218            service.setProperty( OutputKeys.INDENT, "no" ); 
    173219            service.setProperty( OutputKeys.ENCODING, "UTF-8" ); 
     220 
    174221                        // Compile the query 
    175222                if (trace) {System.out.println("Compile query");} 
     
    242289                                         
    243290                                        // Select and setup XQuery 
    244                                         if (outputType.equals("StubB")) { 
     291                                        if (outputType.equals("NDG-B1")) { 
    245292                                                xquery = StubBDEQuery; 
    246293                                                } 
    247                                         else if (outputType.equals("MOLES")) { 
     294                                        else if (outputType.equals("NDG-B0")) { 
    248295                                                xquery = RawDEMoles; 
    249296                                                } 
Note: See TracChangeset for help on using the changeset viewer.