//------------------------------------------------------------------------
//--- initialize settings subsystem
logger.info(" - Setting manager...");
SettingManager settingMan = this._applicationContext.getBean(SettingManager.class);
//--- initialize ThreadUtils with setting manager and rm props
final DataSource dataSource = context.getBean(DataSource.class);
Connection conn = null;
try {
conn = dataSource.getConnection();
ThreadUtils.init(conn.getMetaData().getURL(), settingMan);
} finally {
if (conn != null) {
conn.close();
}
}
//------------------------------------------------------------------------
//--- initialize Z39.50
logger.info(" - Z39.50...");
boolean z3950Enable = settingMan.getValueAsBool("system/z3950/enable", false);
String z3950port = settingMan.getValue("system/z3950/port");
logger.info(" - Z39.50 is enabled: " + z3950Enable);
if (z3950Enable) {
// build Z3950 repositories file first from template
URL url = getClass().getClassLoader().getResource(Geonet.File.JZKITCONFIG_TEMPLATE);
if (Repositories.build(url, context)) {
logger.info(" Repositories file built from template.");
try {
ConfigurableApplicationContext appContext = context.getApplicationContext();
// to have access to the GN context in spring-managed objects
ContextContainer cc = (ContextContainer) appContext.getBean("ContextGateway");
cc.setSrvctx(context);
if (!z3950Enable) {
logger.info(" Server is Disabled.");
} else {
logger.info(" Server is Enabled.");
Server.init(z3950port, appContext);
}
} catch (Exception e) {
logger.error(" Repositories file init FAILED - Z3950 server disabled and Z3950 client services (remote search, " +
"harvesting) may not work. Error is:" + e.getMessage());
e.printStackTrace();
}
} else {
logger.error(" Repositories file builder FAILED - Z3950 server disabled and Z3950 client services (remote search, " +
"harvesting) may not work.");
}
}
//------------------------------------------------------------------------
//--- initialize SchemaManager
logger.info(" - Schema manager...");
String schemaPluginsDir = dataDirectory.getSchemaPluginsDir().getAbsolutePath();
String schemaCatalogueFile = dataDirectory.getConfigDir()+File.separator+Geonet.File.SCHEMA_PLUGINS_CATALOG;
boolean createOrUpdateSchemaCatalog = handlerConfig.getMandatoryValue(Geonet.Config.SCHEMA_PLUGINS_CATALOG_UPDATE).equals("true");
logger.info(" - Schema plugins directory: " + schemaPluginsDir);
logger.info(" - Schema Catalog File : " + schemaCatalogueFile);
SchemaManager schemaMan = _applicationContext.getBean(SchemaManager.class);
schemaMan.configure(_applicationContext, appPath, Resources.locateResourcesDir(context), schemaCatalogueFile,
schemaPluginsDir, context.getLanguage(), handlerConfig.getMandatoryValue(Geonet.Config.PREFERRED_SCHEMA),
createOrUpdateSchemaCatalog);
//------------------------------------------------------------------------
//--- initialize search and editing
logger.info(" - Search...");
boolean logSpatialObject = "true".equalsIgnoreCase(handlerConfig.getMandatoryValue(Geonet.Config.STAT_LOG_SPATIAL_OBJECTS));
boolean logAsynch = "true".equalsIgnoreCase(handlerConfig.getMandatoryValue(Geonet.Config.STAT_LOG_ASYNCH));
logger.info(" - Log spatial object: " + logSpatialObject);
logger.info(" - Log in asynch mode: " + logAsynch);
String luceneTermsToExclude = "";
luceneTermsToExclude = handlerConfig.getMandatoryValue(Geonet.Config.STAT_LUCENE_TERMS_EXCLUDE);
LuceneConfig lc = _applicationContext.getBean(LuceneConfig.class);
lc.configure(luceneConfigXmlFile);
logger.info(" - Lucene configuration is:");
logger.info(lc.toString());
try {
_applicationContext.getBean(DataStore.class);
} catch (NoSuchBeanDefinitionException e) {
DataStore dataStore = createShapefileDatastore(luceneDir);
_applicationContext.getBeanFactory().registerSingleton("dataStore", dataStore);
//--- no datastore for spatial indexing means that we can't continue
if (dataStore == null) {
throw new IllegalArgumentException("GeoTools datastore creation failed - check logs for more info/exceptions");
}
}
String maxWritesInTransactionStr = handlerConfig.getMandatoryValue(Geonet.Config.MAX_WRITES_IN_TRANSACTION);
int maxWritesInTransaction = SpatialIndexWriter.MAX_WRITES_IN_TRANSACTION;
try {
maxWritesInTransaction = Integer.parseInt(maxWritesInTransactionStr);
} catch (NumberFormatException nfe) {
logger.error("Invalid config parameter: maximum number of writes to spatial index in a transaction (maxWritesInTransaction)"
+ ", Using " + maxWritesInTransaction + " instead.");
nfe.printStackTrace();
}
SettingInfo settingInfo = context.getBean(SettingInfo.class);
searchMan = _applicationContext.getBean(SearchManager.class);
searchMan.init(logAsynch,
logSpatialObject, luceneTermsToExclude,
maxWritesInTransaction);
// if the validator exists the proxyCallbackURL needs to have the external host and
// servlet name added so that the cas knows where to send the validation notice
ServerBeanPropertyUpdater.updateURL(settingInfo.getSiteUrl(true) + baseURL, _applicationContext);
//------------------------------------------------------------------------
//--- extract intranet ip/mask and initialize AccessManager
logger.info(" - Access manager...");
//------------------------------------------------------------------------
//--- get edit params and initialize DataManager
logger.info(" - Xml serializer and Data manager...");
SvnManager svnManager = _applicationContext.getBean(SvnManager.class);
XmlSerializer xmlSerializer = _applicationContext.getBean(XmlSerializer.class);
if (xmlSerializer instanceof XmlSerializerSvn && svnManager != null) {
svnManager.setContext(context);
String subversionPath = dataDirectory.getMetadataRevisionDir().getCanonicalPath();
svnManager.setSubversionPath(subversionPath);
svnManager.init();
}
/**
* Initialize language detector
*/
LanguageDetector.init(appPath + _applicationContext.getBean(Geonet.Config.LANGUAGE_PROFILES_DIR, String.class));
//------------------------------------------------------------------------
//--- Initialize thesaurus
logger.info(" - Thesaurus...");
_applicationContext.getBean(ThesaurusManager.class).init(context, appPath, thesauriDir);
//------------------------------------------------------------------------
//--- initialize catalogue services for the web
logger.info(" - Open Archive Initiative (OAI-PMH) server...");
OaiPmhDispatcher oaipmhDis = new OaiPmhDispatcher(settingMan, schemaMan);
GeonetContext gnContext = new GeonetContext(_applicationContext, false, statusActionsClass, threadPool);
//------------------------------------------------------------------------
//--- return application context
beanFactory.registerSingleton("serviceHandlerConfig", handlerConfig);
beanFactory.registerSingleton("oaipmhDisatcher", oaipmhDis);
_applicationContext.getBean(DataManager.class).init(context, false);
_applicationContext.getBean(HarvestManager.class).init(context, gnContext.isReadOnly());
_applicationContext.getBean(ThumbnailMaker.class).init(context);
logger.info("Site ID is : " + settingMan.getSiteId());
// Creates a default site logo, only if the logo image doesn't exists
// This can happen if the application has been updated with a new version preserving the database and
// images/logos folder is not copied from old application
createSiteLogo(settingMan.getSiteId(), context, context.getAppPath());
// Notify unregistered metadata at startup. Needed, for example, when the user enables the notifier config
// to notify the existing metadata in database
// TODO: Fix DataManager.getUnregisteredMetadata and uncomment next lines
metadataNotifierControl = new MetadataNotifierControl(context);
metadataNotifierControl.runOnce();
//--- load proxy information from settings into Jeeves for observers such
//--- as jeeves.utils.XmlResolver to use
ProxyInfo pi = JeevesProxyInfo.getInstance();
boolean useProxy = settingMan.getValueAsBool("system/proxy/use", false);
if (useProxy) {
String proxyHost = settingMan.getValue("system/proxy/host");
String proxyPort = settingMan.getValue("system/proxy/port");
String username = settingMan.getValue("system/proxy/username");
String password = settingMan.getValue("system/proxy/password");
pi.setProxyInfo(proxyHost, Integer.valueOf(proxyPort), username, password);
}
//
// db heartbeat configuration -- for failover to readonly database