use of org.apereo.portal.version.om.Version.Field in project uPortal by Jasig.
the class VersionVerifier method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
for (final Map.Entry<String, Version> productVersionEntry : this.requiredProductVersions.entrySet()) {
final String product = productVersionEntry.getKey();
final Version dbVersion = this.versionDao.getVersion(product);
if (dbVersion == null) {
throw new ApplicationContextException("No Version exists for " + product + " in the database. Please check the upgrade instructions for this release.");
}
final Version codeVersion = productVersionEntry.getValue();
final Field mostSpecificMatchingField = VersionUtils.getMostSpecificMatchingField(dbVersion, codeVersion);
switch(mostSpecificMatchingField) {
//Versions completely match
case LOCAL:
{
logger.info("Software and Database versions are both {} for {}", dbVersion, product);
continue;
}
//Versions match except for local part
case PATCH:
//Versions match except for patch.local part
case MINOR:
{
//If db is before code and auto-update is enabled run hibernate-update
final Field upgradeField = mostSpecificMatchingField.getLessImportant();
if (dbVersion.isBefore(codeVersion) && this.updatePolicy != null && (upgradeField.equals(this.updatePolicy) || upgradeField.isLessImportantThan(this.updatePolicy))) {
logger.info("Automatically updating database from {} to {} for {}", dbVersion, codeVersion, product);
this.portalShellBuildHelper.hibernateUpdate("automated-hibernate-update", product, true, null);
continue;
} else if (codeVersion.isBefore(dbVersion)) {
//It is ok to run older code on a newer DB within the local/patch range
continue;
}
}
//Versions match except for minor.patch.local part
case MAJOR:
//Versions do not match at all
default:
{
if (dbVersion.isBefore(codeVersion)) {
throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". Please check the upgrade instructions for this release");
} else {
throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". It is not possible to run ");
}
}
}
}
}
Aggregations