Changeset 6321


Ignore:
Timestamp:
06/23/15 14:36:16 (9 years ago)
Author:
davor.ostojic@oeaw.ac.at
Message:

Issue #768
https://trac.clarin.eu/ticket/768

"Maybe also add a command line option to specify which data roots to (try to) import (import all by default)"

the option is added: -l <list_of_dataroot_paths> (space separated)
program compares canonical paths

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java

    r6317 r6321  
    11package eu.clarin.cmdi.vlo.importer;
    2 
    3 import eu.clarin.cmdi.vlo.LanguageCodeUtils;
    4 import eu.clarin.cmdi.vlo.CommonUtils;
    5 import eu.clarin.cmdi.vlo.FacetConstants;
    6 import eu.clarin.cmdi.vlo.config.DataRoot;
    7 import eu.clarin.cmdi.vlo.config.VloConfig;
    8 import eu.clarin.cmdi.vlo.config.XmlVloConfigFactory;
    92
    103import java.io.File;
     
    3831import org.slf4j.LoggerFactory;
    3932
     33import eu.clarin.cmdi.vlo.CommonUtils;
     34import eu.clarin.cmdi.vlo.FacetConstants;
     35import eu.clarin.cmdi.vlo.LanguageCodeUtils;
     36import eu.clarin.cmdi.vlo.config.DataRoot;
     37import eu.clarin.cmdi.vlo.config.VloConfig;
     38import eu.clarin.cmdi.vlo.config.XmlVloConfigFactory;
     39
    4040/**
    4141 * The main metadataImporter class. Also contains the main function.
     
    121121        initSolrServer();
    122122        List<DataRoot> dataRoots = checkDataRoots();
     123       
     124        dataRoots = filterDataRootsWithCLArgs(dataRoots);
     125       
    123126        long start = System.currentTimeMillis();
    124127        try {
     
    204207        for (DataRoot dataRoot : dataRoots) {
    205208            if (!dataRoot.getRootFile().exists()) {
    206                 LOG.error("Root file " + dataRoot.getRootFile() + " does not exist. Could be configuration error (see VLOConfig.xml)! Proceeding with next ...");
    207 //              LOG.error("Root file " + dataRoot.getRootFile() + " does not exist. Probable configuration error so stopping import.");
    208 //                System.exit(1);
     209                LOG.error("Root file " + dataRoot.getRootFile() + " does not exist. It could be configuration error! Proceeding with next ...");
    209210            } else{
    210211                existingDataRoots.add(dataRoot);
    211212            }
     213           
    212214        }
    213215        return existingDataRoots;
     216    }
     217   
     218    /**
     219     * if user specified which data roots should be imported,
     220     * list of existing data roots will be filtered with the list from user
     221     *
     222     * @return
     223     */
     224    protected List<DataRoot> filterDataRootsWithCLArgs(List<DataRoot> dataRoots){
     225        if(CL_DATAROOTS_LIST == null)
     226                return dataRoots;
     227       
     228        //filter data
     229       
     230        LOG.info("Filtering configured data root files with command line arguments: " + CL_DATAROOTS_LIST) ;
     231       
     232        LinkedList<File> cl_dataroots = new LinkedList<File>();
     233       
     234        List<String> paths = Arrays.asList((CL_DATAROOTS_LIST.split("\\s+")));
     235       
     236        for(String path: paths)
     237                cl_dataroots.add(new File(path));
     238       
     239        List<DataRoot> filteredDataRoots = new LinkedList<DataRoot>();
     240        try{
     241        dr: for(DataRoot dataRoot: dataRoots){
     242                        for(File cldr: cl_dataroots){
     243                        if(cldr.getCanonicalPath().equals(dataRoot.getRootFile().getCanonicalPath())){
     244                                filteredDataRoots.add(dataRoot);
     245                                cl_dataroots.remove(cldr);
     246                                continue dr;
     247                        }
     248                        }
     249                        LOG.info("Root file " + dataRoot.getRootFile() + " will be omitted from processing");
     250                }
     251        }catch (IOException e){
     252                filteredDataRoots = dataRoots;
     253        }
     254
     255       
     256                return filteredDataRoots;
    214257    }
    215258
     
    522565    public static LanguageCodeUtils languageCodeUtils;
    523566   
     567    //data roots passed from command line   
     568    public static String CL_DATAROOTS_LIST = null;
     569   
    524570    /**
    525571     * @param args
     
    540586         */
    541587        options.addOption("c", true, "-c <file> : use parameters specified in <file>");
     588        options.addOption("l", true, "-l <dataroot> [ ' ' <dataroot> ]* :  space separated list of dataroots to be processed.\n"
     589                        + "If dataroot is not specified in config file it will be ignored.");
     590        options.getOption("l").setOptionalArg(true);
    542591       
    543592        CommandLineParser parser = new PosixParser();
     
    550599                // the "c" option was specified, now get its value
    551600                configFile = cmd.getOptionValue("c");
     601            }
     602           
     603            if(cmd.hasOption("l")){
     604                CL_DATAROOTS_LIST = cmd.getOptionValue("l");
    552605            }
    553606           
Note: See TracChangeset for help on using the changeset viewer.