Changeset 6356
- Timestamp:
- 07/06/15 11:05:51 (9 years ago)
- Location:
- vlo/trunk/vlo-importer/src/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/trunk/vlo-importer/src/main/bin/vlo_solr_importer.sh
r6235 r6356 12 12 fi 13 13 14 # try to get the configuration file name from the command line options 15 if [ 1 -eq $# ]; then 16 CONFIG=$1 17 else 18 # fall back to default location 19 echo No configuration location specified, using default 20 CONFIG=${DIR}/"../config/VloConfig.xml" 21 fi 14 #default configuration file 15 DFLT_CONFIG=${DIR}/"../config/VloConfig.xml" 22 16 23 17 LOGDIR=${DIR}/../log/ … … 35 29 # to the JAVA command. Please note the a specification on the command line will 36 30 # take preference over a specification as a property. 31 # 32 # to process only subset of data roots from configuration file pass the list via command line: 33 # -l path OR -l "path1 path2 ..." 34 # 37 35 38 36 $JAVA -Xmx3G \ 39 37 -cp "${DIR}:${DIR}/vlo-importer-${project.version}-importer.jar" \ 38 -DconfigFile=${DFLT_CONFIG} \ 40 39 -DIMPORTER_LOG_DIR=${LOGDIR} \ 41 eu.clarin.cmdi.vlo.importer.MetadataImporter -c "$CONFIG"40 eu.clarin.cmdi.vlo.importer.MetadataImporter "$@" 42 41 -
vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java
r6319 r6356 1 1 package 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;9 2 10 3 import java.io.File; … … 14 7 import java.text.SimpleDateFormat; 15 8 import java.util.ArrayList; 9 import java.util.Arrays; 16 10 import java.util.Date; 17 11 import java.util.HashMap; 18 12 import java.util.HashSet; 19 13 import java.util.Iterator; 14 import java.util.LinkedList; 20 15 import java.util.List; 21 16 import java.util.Map; … … 38 33 import org.slf4j.LoggerFactory; 39 34 35 import eu.clarin.cmdi.vlo.CommonUtils; 36 import eu.clarin.cmdi.vlo.FacetConstants; 37 import eu.clarin.cmdi.vlo.LanguageCodeUtils; 38 import eu.clarin.cmdi.vlo.config.DataRoot; 39 import eu.clarin.cmdi.vlo.config.VloConfig; 40 import eu.clarin.cmdi.vlo.config.XmlVloConfigFactory; 41 40 42 /** 41 43 * The main metadataImporter class. Also contains the main function. … … 93 95 */ 94 96 public MetadataImporter() {} 97 98 public MetadataImporter(String clDatarootsList) { 99 this.clDatarootsList = clDatarootsList; 100 } 95 101 96 102 /** … … 121 127 initSolrServer(); 122 128 List<DataRoot> dataRoots = checkDataRoots(); 129 130 dataRoots = filterDataRootsWithCLArgs(dataRoots); 131 123 132 long start = System.currentTimeMillis(); 124 133 try { … … 202 211 protected List<DataRoot> checkDataRoots() { 203 212 List<DataRoot> dataRoots = config.getDataRoots(); 213 List<DataRoot> existingDataRoots = new LinkedList<DataRoot>(); 204 214 for (DataRoot dataRoot : dataRoots) { 205 215 if (!dataRoot.getRootFile().exists()) { 206 LOG.error("Root file " + dataRoot.getRootFile() + " does not exist. Probable configuration error so stopping import."); 207 System.exit(1); 208 } 209 } 210 return dataRoots; 216 LOG.warn("Root file " + dataRoot.getRootFile() + " does not exist. It could be configuration error! Proceeding with next ..."); 217 } else{ 218 existingDataRoots.add(dataRoot); 219 } 220 221 } 222 return existingDataRoots; 223 } 224 225 /** 226 * if user specified which data roots should be imported, 227 * list of existing data roots will be filtered with the list from user 228 * 229 * @return 230 */ 231 protected List<DataRoot> filterDataRootsWithCLArgs(List<DataRoot> dataRoots){ 232 if(clDatarootsList == null) 233 return dataRoots; 234 235 236 LOG.info("Filtering configured data root files with command line arguments: \"" + clDatarootsList + "\"" ) ; 237 238 LinkedList<File> fsDataRoots = new LinkedList<File>(); 239 240 List<String> paths = Arrays.asList((clDatarootsList.split("\\s+"))); 241 242 //Convert String paths to File objects for comparison 243 for(String path: paths) 244 fsDataRoots.add(new File(path)); 245 246 List<DataRoot> filteredDataRoots = new LinkedList<DataRoot>(); 247 try{ 248 //filter data 249 dr: for(DataRoot dataRoot: dataRoots){ 250 for(File fsDataRoot: fsDataRoots){ 251 if(fsDataRoot.getCanonicalPath().equals(dataRoot.getRootFile().getCanonicalPath())){ 252 filteredDataRoots.add(dataRoot); 253 fsDataRoots.remove(fsDataRoot); 254 continue dr; 255 } 256 } 257 LOG.info("Root file " + dataRoot.getRootFile() + " will be omitted from processing"); 258 } 259 }catch (IOException e){ 260 filteredDataRoots = dataRoots; 261 } 262 263 264 return filteredDataRoots; 211 265 } 212 266 … … 529 583 public static LanguageCodeUtils languageCodeUtils; 530 584 585 //data roots passed from command line 586 private String clDatarootsList = null; 587 531 588 /** 532 589 * @param args … … 541 598 // use the Apache cli framework for getting command line parameters 542 599 Options options = new Options(); 600 601 // Data root list passed from command line with -l option 602 String cldrList = null; 543 603 544 604 /** 545 605 * Add a "c" option, the option indicating the specification of an XML 546 606 * configuration file 607 * 608 * "l" option - to specify which data roots (from config file) to import 609 * imports all by default 547 610 */ 548 611 options.addOption("c", true, "-c <file> : use parameters specified in <file>"); 612 options.addOption("l", true, "-l <dataroot> [ ' ' <dataroot> ]* : space separated list of dataroots to be processed.\n" 613 + "If dataroot is not specified in config file it will be ignored."); 614 options.getOption("l").setOptionalArg(true); 549 615 550 616 CommandLineParser parser = new PosixParser(); … … 557 623 // the "c" option was specified, now get its value 558 624 configFile = cmd.getOptionValue("c"); 625 } 626 627 if(cmd.hasOption("l")){ 628 cldrList = cmd.getOptionValue("l"); 559 629 } 560 630 … … 599 669 } 600 670 System.out.println("Reading configuration from " + configUrl.toString()); 671 LOG.info("Reading configuration from " + configUrl.toString()); 601 672 final XmlVloConfigFactory configFactory = new XmlVloConfigFactory(configUrl); 602 673 MetadataImporter.config = configFactory.newConfig(); … … 605 676 // optionally, modify the configuration here 606 677 // create and start the importer 607 MetadataImporter importer = new MetadataImporter( );678 MetadataImporter importer = new MetadataImporter(cldrList); 608 679 importer.startImport(); 609 680
Note: See TracChangeset
for help on using the changeset viewer.