* Loads harvester configuration.
* @param appConfig application configuration
*/
private void loadHarvesterConfiguration(ApplicationConfiguration appConfig, Document dom, Node root) throws XPathExpressionException {
StringAttributeMap parameters = appConfig.getCatalogConfiguration().getParameters();
HarvesterConfiguration cfg = appConfig.getHarvesterConfiguration();
String active = Val.chkStr(parameters.getValue("webharvester.active"));
String suspended = Val.chkStr(parameters.getValue("webharvester.suspended"));
String queueEnabled = Val.chkStr(parameters.getValue("webharvester.queueEnabled"));
String poolsize = Val.chkStr(parameters.getValue("webharvester.poolSize"));
String autoselectfrequency = Val.chkStr(parameters.getValue("webharvester.autoSelectFrequency"));
String watchdogfrequency = Val.chkStr(parameters.getValue("webharvester.watchDogFrequency"));
String basecontextpath = Val.chkStr(parameters.getValue("webharvester.baseContextPath"));
String maxRepRecords = Val.chkStr(parameters.getValue("webharvester.maxRepRecords"));
String maxRepErrors = Val.chkStr(parameters.getValue("webharvester.maxRepErrors"));
String resourceAutoApprove = Val.chkStr(parameters.getValue("webharvester.resource.autoApprove"));
Logger logger = getLogger();
if (Val.chkBool(active, true)) {
cfg.setActive(true);
cfg.setQueueEnabled(true);
} else {
cfg.setActive(false);
cfg.setQueueEnabled(false);
}
if (Val.chkBool(suspended, false)) {
cfg.setSuspended(true);
} else {
cfg.setSuspended(false);
}
if (queueEnabled.length()>0) {
cfg.setQueueEnabled(Val.chkBool(queueEnabled, cfg.getQueueEnabled()) || cfg.getActive());
}
if (poolsize.length() > 0) {
try {
int num = Integer.parseInt(poolsize);
if (num <= 0) {
logger.info("[SYNCHRONIZER] Parameter \"webharvester.poolSize\" less or equal to zero. No harvestig will be performed.");
}
cfg.setPoolSize(num);
} catch (NumberFormatException ex) {
logger.log(Level.INFO, "[SYNCHRONIZER] Invalid \"webharvester.poolSize\" parameter. Default {0} will be used instead.", HarvesterConfiguration.DEFAULT_POOL_SIZE);
cfg.setPoolSize(HarvesterConfiguration.DEFAULT_POOL_SIZE);
}
} else {
logger.log(Level.INFO, "[SYNCHRONIZER] Missing \"webharvester.poolSize\" parameter. Default {0} will be used instead.", HarvesterConfiguration.DEFAULT_POOL_SIZE);
cfg.setPoolSize(HarvesterConfiguration.DEFAULT_POOL_SIZE);
}
if (autoselectfrequency.length() > 0) {
try {
TimePeriod tp = TimePeriod.parseValue(autoselectfrequency);
cfg.setAutoSelectFrequency(tp);
} catch (NumberFormatException ex) {
logger.log(Level.INFO, "[SYNCHRONIZER] Invalid \"webharvester.autoSelectFrequency\" parameter. Default {0} will be used instead.", HarvesterConfiguration.AUTOSELECT_FREQUENCY);
cfg.setAutoSelectFrequency(new TimePeriod(HarvesterConfiguration.AUTOSELECT_FREQUENCY));
}
} else {
logger.log(Level.INFO, "[SYNCHRONIZER] Missing \"webharvester.autoSelectFrequency\" parameter. Default {0} will be used instead.", HarvesterConfiguration.AUTOSELECT_FREQUENCY);
cfg.setAutoSelectFrequency(new TimePeriod(HarvesterConfiguration.AUTOSELECT_FREQUENCY));
}
if (watchdogfrequency.length() > 0) {
try {
TimePeriod tp = TimePeriod.parseValue(watchdogfrequency);
cfg.setWatchDogFrequency(tp);
} catch (NumberFormatException ex) {
logger.log(Level.INFO, "[SYNCHRONIZER] Invalid \"webharvester.watchDogFrequency\" parameter. Default {0} will be used instead.", HarvesterConfiguration.WATCHDOG_FREQUENCY);
cfg.setWatchDogFrequency(new TimePeriod(HarvesterConfiguration.WATCHDOG_FREQUENCY));
}
} else {
logger.log(Level.INFO, "[SYNCHRONIZER] Missing \"webharvester.watchDogFrequency\" parameter. Default {0} will be used instead.", HarvesterConfiguration.WATCHDOG_FREQUENCY);
cfg.setWatchDogFrequency(new TimePeriod(HarvesterConfiguration.WATCHDOG_FREQUENCY));
}
if (basecontextpath.length() > 0) {
cfg.setBaseContextPath(basecontextpath);
} else {
String reverseProxyPath = Val.chkStr(parameters.getValue("reverseProxy.baseContextPath"));
if (reverseProxyPath.length() > 0) {
logger.info("[SYNCHRONIZER] Missing \"webharvester.baseContextPath\" parameter. Value of \"reverseProxy.baseContextPath\" will be used instead.");
} else {
logger.info("[SYNCHRONIZER] Missing \"webharvester.baseContextPath\" parameter. Harvest notification messages will be sent without information about harvest report.");
}
}
if (maxRepRecords.length() > 0) {
try {
long num = Long.parseLong(maxRepRecords);
if (num < 0) {
logger.info("[SYNCHRONIZER] Parameter \"webharvester.maxRepRecords\" less than zero. No limits will be set.");
}
cfg.setMaxRepRecords(num);
} catch (NumberFormatException ex) {
logger.log(Level.INFO, "[SYNCHRONIZER] Invalid \"webharvester.maxRepRecords\" parameter. Default {0} will be used instead.", HarvesterConfiguration.MAX_REP_RECORDS);
cfg.setMaxRepRecords(HarvesterConfiguration.MAX_REP_RECORDS);
}
} else {
logger.log(Level.INFO, "[SYNCHRONIZER] Missing \"webharvester.maxRepRecords\" parameter. Default {0} will be used instead.", HarvesterConfiguration.MAX_REP_RECORDS);
cfg.setMaxRepRecords(HarvesterConfiguration.MAX_REP_RECORDS);
}
if (maxRepErrors.length() > 0) {
try {
long num = Long.parseLong(maxRepErrors);
if (num < 0) {
logger.info("[SYNCHRONIZER] Parameter \"webharvester.maxRepErrors\" less than zero. No limits will be set.");
}
cfg.setMaxRepErrors(num);
} catch (NumberFormatException ex) {
logger.log(Level.INFO, "[SYNCHRONIZER] Invalid \"webharvester.maxRepErrors\" parameter. Default {0} will be used instead.", HarvesterConfiguration.MAX_REP_ERRORS);
cfg.setMaxRepErrors(HarvesterConfiguration.MAX_REP_ERRORS);
}
} else {
logger.log(Level.INFO, "[SYNCHRONIZER] Missing \"webharvester.maxRepErrors\" parameter. Default {0} will be used instead.", HarvesterConfiguration.MAX_REP_ERRORS);
cfg.setMaxRepErrors(HarvesterConfiguration.MAX_REP_ERRORS);
}
if (resourceAutoApprove.length() > 0) {
boolean bool = Val.chkBool(resourceAutoApprove,HarvesterConfiguration.RESOURCE_AUTOAPPROVE);
cfg.setResourceAutoApprove(bool);
} else {
logger.log(Level.INFO, "[SYNCHRONIZER] Missing \"webharvester.resource.autoApprove\" parameter. Default {0} will be used instead.", HarvesterConfiguration.RESOURCE_AUTOAPPROVE);
cfg.setResourceAutoApprove(HarvesterConfiguration.RESOURCE_AUTOAPPROVE);
}
// load data processor factories
XPath xpath = XPathFactory.newInstance().newXPath();
// add local data processor factory by default
cfg.getDataProcessorFactories().add(new LocalDataProcessorFactory());
// get root of webharvester configuration
Node ndWebHarvester = (Node) xpath.evaluate("webharvester", root, XPathConstants.NODE);
if (ndWebHarvester!=null) {
// create and initialize data processor for each netry in configuration
NodeList ndDataProcessorFactories = (NodeList) xpath.evaluate("dataProcessorFactory", ndWebHarvester, XPathConstants.NODESET);
for (Node ndDataProcessorFactory : new NodeListAdapter(ndDataProcessorFactories)) {
String className = Val.chkStr((String) xpath.evaluate("@className", ndDataProcessorFactory, XPathConstants.STRING));
String name = Val.chkStr((String) xpath.evaluate("@name", ndDataProcessorFactory, XPathConstants.STRING));
boolean enabled = Val.chkBool(Val.chkStr((String) xpath.evaluate("@enabled", ndDataProcessorFactory, XPathConstants.STRING)), true);
if (enabled) {
try {
Class factoryClass = Class.forName(className);
DataProcessorFactory processorFactory = (DataProcessorFactory) factoryClass.newInstance();
processorFactory.setName(name);
processorFactory.init(ndDataProcessorFactory);
cfg.getDataProcessorFactories().add(processorFactory);
} catch (Exception ex) {
getLogger().log(Level.SEVERE, "Error creating processor factory: "+className, ex);
}
} else {
if (LocalDataProcessorFactory.class.getCanonicalName().equals(className)) {
removeDataProcessorFactory(cfg.getDataProcessorFactories(), className);
}
}
}
}
}