use of org.olat.core.logging.StartupException in project openolat by klemens.
the class UserModule method checkMandatoryUserProperty.
private void checkMandatoryUserProperty(String userPropertyIdentifyer) {
List<UserPropertyHandler> propertyHandlers = userPropertiesConfig.getAllUserPropertyHandlers();
boolean propertyDefined = false;
for (UserPropertyHandler propertyHandler : propertyHandlers) {
if (propertyHandler.getName().equals(userPropertyIdentifyer)) {
propertyDefined = true;
break;
}
}
if (!propertyDefined) {
throw new StartupException("The user property handler for the mandatory user property " + userPropertyIdentifyer + " is not defined. Check your olat_userconfig.xml file!");
}
}
use of org.olat.core.logging.StartupException in project openolat by klemens.
the class UpgradeManager method abort.
/**
* On any RuntimeExceptions during init. Abort loading of application.
* Modules should throw RuntimeExceptions if they can't live with a the
* given state of configuration.
* @param e
*/
protected void abort(Throwable e) {
if (e instanceof StartupException) {
StartupException se = (StartupException) e;
logWarn("Message: " + se.getLogMsg(), se);
Throwable cause = se.getCause();
logWarn("Cause: " + (cause != null ? cause.getMessage() : "n/a"), se);
}
throw new RuntimeException("*** CRITICAL ERROR IN UPGRADE MANAGER. Loading aborted.", e);
}
use of org.olat.core.logging.StartupException in project openolat by klemens.
the class DatabaseUpgradeManager method runAlterDbStatements.
/**
* @see org.olat.upgrade.UpgradeManager#runAlterDbStatements()
*/
public void runAlterDbStatements() {
Dialect dialect;
// only run upgrades on mysql or postgresql
if (getDbVendor().contains("mysql"))
dialect = Dialect.mysql;
else if (getDbVendor().contains("postgresql"))
dialect = Dialect.postgresql;
else
return;
Statement statement = null;
try {
logAudit("+--------------------------------------------------------------+");
logAudit("+... Pure database upgrade: starting alter DB statements ...+");
logAudit("+ If it fails, do it manually by applying the content of the alter_X_to_Y.sql files.+");
logAudit("+ For each file you upgraded to add an entry like this to the [pathToOlat]/olatdata/system/installed_database_upgrades.xml: +");
logAudit("+ <entry><string>Database update</string><boolean>true</boolean></entry>+");
logAudit("+--------------------------------------------------------------+");
statement = getDataSource().getConnection().createStatement();
Iterator<OLATUpgrade> iter = upgrades.iterator();
OLATUpgrade upgrade = null;
while (iter.hasNext()) {
upgrade = iter.next();
String alterDbStatementsFilename = upgrade.getAlterDbStatements();
if (alterDbStatementsFilename != null) {
UpgradeHistoryData uhd = getUpgradesHistory(upgrade.getVersion());
if (uhd == null) {
// has never been called, initialize
uhd = new UpgradeHistoryData();
}
if (!uhd.getBooleanDataValue(OLATUpgrade.TASK_DP_UPGRADE)) {
loadAndExecuteSqlStatements(statement, alterDbStatementsFilename, dialect);
uhd.setBooleanDataValue(OLATUpgrade.TASK_DP_UPGRADE, true);
setUpgradesHistory(uhd, upgrade.getVersion());
logAudit("Successfully executed alter DB statements for Version::" + upgrade.getVersion());
}
}
}
} catch (SQLException e) {
logError("Could not upgrade your database! Please do it manually and add ", e);
throw new StartupException("Could not execute alter db statements. Please do it manually.", e);
} catch (Throwable e) {
logWarn("Error executing alter DB statements::", e);
abort(e);
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (SQLException e2) {
logWarn("Could not close sql statement", e2);
throw new StartupException("Could not close sql statements.", e2);
}
}
}
use of org.olat.core.logging.StartupException in project openolat by klemens.
the class I18nModule method searchForBundleNamesContainingI18nFiles.
/**
* Search in all packages on the source patch for packages that contain an
* _i18n directory that can be used to store olatcore localization files
*
* @return set of bundles that contain olatcore i18n compatible localization
* files
*/
List<String> searchForBundleNamesContainingI18nFiles() {
List<String> foundBundles;
// 1) First search on normal source path of application
String srcPath = null;
File applicationDir = getTransToolApplicationLanguagesSrcDir();
if (applicationDir != null) {
srcPath = applicationDir.getAbsolutePath();
} else {
// Fall back to compiled classes
srcPath = WebappHelper.getBuildOutputFolderRoot();
}
if (StringHelper.containsNonWhitespace(srcPath)) {
I18nDirectoriesVisitor srcVisitor = new I18nDirectoriesVisitor(srcPath, getTransToolReferenceLanguages());
FileUtils.visitRecursively(new File(srcPath), srcVisitor);
foundBundles = srcVisitor.getBundlesContainingI18nFiles();
// 3) For jUnit tests, add also the I18n test dir
if (Settings.isJUnitTest()) {
Resource testres = new ClassPathResource("olat.local.properties");
String jUnitSrcPath = null;
try {
jUnitSrcPath = testres.getFile().getAbsolutePath();
} catch (IOException e) {
throw new StartupException("Could not find classpath resource for: test-classes/olat.local.property ", e);
}
I18nDirectoriesVisitor juniSrcVisitor = new I18nDirectoriesVisitor(jUnitSrcPath, getTransToolReferenceLanguages());
FileUtils.visitRecursively(new File(jUnitSrcPath), juniSrcVisitor);
foundBundles.addAll(juniSrcVisitor.getBundlesContainingI18nFiles());
}
// Sort alphabetically
Collections.sort(foundBundles);
} else {
foundBundles = new ArrayList<String>();
}
return foundBundles;
}
use of org.olat.core.logging.StartupException in project openolat by klemens.
the class WebappHelper method init.
/**
* @see Initializable
*/
public void init() {
// servletContext.getRealPath("/"); does not work with an unpacked war file we only use it for fallback for unit testing
Resource res = new ClassPathResource(CoreSpringFactory.class.getCanonicalName().replaceAll("\\.", "\\/") + ".class");
try {
String fullPath = res.getURL().toString();
if (fullPath.contains(File.separator + "WEB-INF")) {
fullPath = fullPath.substring(fullPath.indexOf("file:") + 5, fullPath.indexOf(File.separator + "WEB-INF"));
} else {
fullPath = servletContext.getRealPath("/");
}
log.info("Sucessfully extracted context root path as: " + fullPath);
contextRoot = fullPath;
} catch (Exception e) {
throw new StartupException("Error getting canonical context root.", e);
}
servletContextPath = servletContext.getContextPath();
try {
InputStream meta = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
if (meta != null) {
try {
Properties props = new Properties();
props.load(meta);
changeSet = props.getProperty("Build-Change-Set");
changeSetDate = props.getProperty("Build-Change-Set-Date");
revisionNumber = props.getProperty("Build-Revision-Number");
implementationVersion = props.getProperty("Implementation-Version");
buildJdk = props.getProperty("Build-Jdk");
} catch (IOException e) {
log.error("", e);
}
}
} catch (Exception e) {
log.warn("MANIFEST.MF not found", e);
}
File fil = new File(fullPathToSrc);
if (fil.exists()) {
log.info("Path to source set to: " + fullPathToSrc);
} else {
log.info("Path to source doesn't exist (only needed for debugging purpose): " + fullPathToSrc);
}
testUtf8FileSystem();
logStartup();
}
Aggregations