Search in sources :

Example 6 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionVerifier method afterPropertiesSet.

@SuppressWarnings("FallThrough")
@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 ");
                    }
                }
        }
    }
}
Also used : Field(org.apereo.portal.version.om.Version.Field) Version(org.apereo.portal.version.om.Version) ApplicationContextException(org.springframework.context.ApplicationContextException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 7 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class JpaVersionDaoTest method testVersionBadSql.

@Test
public void testVersionBadSql() {
    final String productName = "TEST_VERSION";
    // Create
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            Version version = versionDao.getVersion(productName);
            assertNull(version);
            version = versionDao.setVersion(productName, 1, 2, 3, null);
            assertNotNull(version);
            assertEquals(1, version.getMajor());
            assertEquals(2, version.getMinor());
            assertEquals(3, version.getPatch());
            assertNull(version.getLocal());
        }
    });
    jdbcOperations.execute("ALTER TABLE UP_VERSION DROP LOCAL_VER");
    try {
        // Doesn't exist
        this.execute(new CallableWithoutResult() {

            @Override
            protected void callWithoutResult() {
                final Version version = versionDao.getVersion(productName);
                assertNotNull(version);
                assertEquals(1, version.getMajor());
                assertEquals(2, version.getMinor());
                assertEquals(3, version.getPatch());
                assertNull(version.getLocal());
            }
        });
    } finally {
        jdbcOperations.execute("ALTER TABLE UP_VERSION ADD COLUMN LOCAL_VER INTEGER");
    }
}
Also used : Version(org.apereo.portal.version.om.Version) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 8 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class AbstractVersion method equals.

@Override
public final boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null || obj.hashCode() != this.hashCode())
        return false;
    if (!(obj instanceof Version))
        return false;
    Version other = (Version) obj;
    if (getMajor() != other.getMajor())
        return false;
    if (getMinor() != other.getMinor())
        return false;
    if (getPatch() != other.getPatch())
        return false;
    final Integer local = getLocal();
    final Integer oLocal = other.getLocal();
    if (local == null) {
        if (oLocal != null)
            return false;
    } else if (!local.equals(oLocal))
        return false;
    return true;
}
Also used : Version(org.apereo.portal.version.om.Version)

Example 9 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionedDataUpdaterImpl method postInitDatabase.

@Override
@PortalTransactional
public void postInitDatabase(String product) {
    final Version version = this.requiredProductVersions.get(product);
    if (version == null) {
        throw new IllegalArgumentException("No Version is configured for: " + product);
    }
    logger.info("PostInit - Set {} version to {}", product, version);
    this.versionDao.setVersion(product, version);
}
Also used : Version(org.apereo.portal.version.om.Version) PortalTransactional(org.apereo.portal.jpa.BasePortalJpaDao.PortalTransactional)

Example 10 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionedDataUpdaterImpl method getAndVerifyDatabaseVersionForUpdate.

protected Version getAndVerifyDatabaseVersionForUpdate(String product) {
    final Version codeVersion = this.requiredProductVersions.get(product);
    if (codeVersion == null) {
        throw new IllegalStateException("No code version configured for " + product);
    }
    Version dbVersion = this.versionDao.getVersion(product);
    if (dbVersion == null) {
        // If null assume version 4.0.0
        dbVersion = VersionUtils.parseVersion("4.0.0");
    }
    if (!VersionUtils.canUpdate(dbVersion, codeVersion)) {
        throw new IllegalStateException("Cannot update " + product + " db from " + dbVersion + " to " + codeVersion);
    }
    if (codeVersion.equals(dbVersion)) {
        logger.info("{} code version matches database version. No update needed.", product);
    }
    return dbVersion;
}
Also used : Version(org.apereo.portal.version.om.Version)

Aggregations

Version (org.apereo.portal.version.om.Version)12 Test (org.junit.Test)5 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)2 PortalTransactional (org.apereo.portal.jpa.BasePortalJpaDao.PortalTransactional)2 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Field (org.apereo.portal.version.om.Version.Field)1 ApplicationContextException (org.springframework.context.ApplicationContextException)1