use of org.apereo.portal.version.om.Version 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 ");
}
}
}
}
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionUtilsTest method testGetMostSpecificMatchingField.
@Test
public void testGetMostSpecificMatchingField() {
Version v1 = VersionUtils.parseVersion("4.0.5");
Version v2 = VersionUtils.parseVersion("4.0.5");
assertEquals(Version.Field.LOCAL, VersionUtils.getMostSpecificMatchingField(v1, v2));
assertEquals(Version.Field.LOCAL, VersionUtils.getMostSpecificMatchingField(v2, v1));
v2 = VersionUtils.parseVersion("4.0.5.1");
assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v1, v2));
assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v2, v1));
v1 = VersionUtils.parseVersion("4.0.5.2");
v2 = VersionUtils.parseVersion("4.0.5.3");
assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v1, v2));
assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v2, v1));
v2 = VersionUtils.parseVersion("4.0.6");
assertEquals(Version.Field.MINOR, VersionUtils.getMostSpecificMatchingField(v1, v2));
assertEquals(Version.Field.MINOR, VersionUtils.getMostSpecificMatchingField(v2, v1));
v2 = VersionUtils.parseVersion("4.1.0.0");
assertEquals(Version.Field.MAJOR, VersionUtils.getMostSpecificMatchingField(v1, v2));
assertEquals(Version.Field.MAJOR, VersionUtils.getMostSpecificMatchingField(v2, v1));
v2 = VersionUtils.parseVersion("5.6.7");
assertNull(VersionUtils.getMostSpecificMatchingField(v1, v2));
assertNull(VersionUtils.getMostSpecificMatchingField(v2, v1));
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionUtilsTest method testVersionParsing.
@Test
public void testVersionParsing() {
Version version = VersionUtils.parseVersion("4.0.5");
assertNotNull(version);
assertEquals(4, version.getMajor());
assertEquals(0, version.getMinor());
assertEquals(5, version.getPatch());
assertNull(version.getLocal());
version = VersionUtils.parseVersion("4.0.5.3");
assertNotNull(version);
assertEquals(4, version.getMajor());
assertEquals(0, version.getMinor());
assertEquals(5, version.getPatch());
assertEquals(Integer.valueOf(3), version.getLocal());
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionUtilsTest method testVersionUpgrade.
@Test
public void testVersionUpgrade() {
Version v1 = VersionUtils.parseVersion("4.0.5");
Version v2 = VersionUtils.parseVersion("4.0.5");
assertTrue(VersionUtils.canUpdate(v1, v2));
assertTrue(VersionUtils.canUpdate(v2, v1));
v2 = VersionUtils.parseVersion("4.0.5.1");
assertTrue(VersionUtils.canUpdate(v1, v2));
assertFalse(VersionUtils.canUpdate(v2, v1));
v1 = VersionUtils.parseVersion("4.0.5.2");
v2 = VersionUtils.parseVersion("4.0.5.3");
assertTrue(VersionUtils.canUpdate(v1, v2));
assertFalse(VersionUtils.canUpdate(v2, v1));
v2 = VersionUtils.parseVersion("4.0.6");
assertTrue(VersionUtils.canUpdate(v1, v2));
assertFalse(VersionUtils.canUpdate(v2, v1));
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionedDataUpdaterImpl method preUpdateDatabase.
@Override
@OpenEntityManager(unitName = BasePortalJpaDao.PERSISTENCE_UNIT_NAME)
public void preUpdateDatabase(String product) {
//This happens first because even if there are no updaters we need to make sure the attempted update is valid
final Version dbVersion = getAndVerifyDatabaseVersionForUpdate(product);
final SortedSet<IVersionedDatabaseUpdateHelper> updateHelpers = this.databaseUpdateHelpers.get(product);
if (updateHelpers == null || updateHelpers.isEmpty()) {
logger.info("No IVersionedDatabaseUpdateHelpers configured for database {}, nothing will be done in preUpdate", product);
} else {
//updateHelpers is sorted oldest to newest by version so iterate through and run the updaters that apply
for (final IVersionedDatabaseUpdateHelper updateHelper : updateHelpers) {
final Version updateVersion = updateHelper.getVersion();
if (dbVersion.equals(updateVersion) || dbVersion.isBefore(updateVersion)) {
logger.info("PreUpdate {} from {} to {}", product, dbVersion, updateVersion);
updateHelper.preUpdate();
logger.info("PreUpdate {} from {} to {} complete", product, dbVersion, updateVersion);
}
}
}
}
Aggregations