Search in sources :

Example 11 with Version

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

the class VersionedDataUpdaterImpl method postUpdateDatabase.

@Override
@PortalTransactional
public void postUpdateDatabase(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 postUpdate", product);
    } else {
        // updaters that apply
        for (final IVersionedDatabaseUpdateHelper updateHelper : updateHelpers) {
            final Version updateVersion = updateHelper.getVersion();
            if (dbVersion.equals(updateVersion) || dbVersion.isBefore(updateVersion)) {
                logger.info("PostUpdate {} from {} to {}", product, dbVersion, updateVersion);
                updateHelper.postUpdate();
                logger.info("PostUpdate {} from {} to {} complete", product, dbVersion, updateVersion);
            }
        }
    }
    // Update the db version number
    final Version codeVersion = this.requiredProductVersions.get(product);
    logger.info("PostUpdate - Set {} version to {}", product, codeVersion);
    this.versionDao.setVersion(product, codeVersion);
}
Also used : Version(org.apereo.portal.version.om.Version) PortalTransactional(org.apereo.portal.jpa.BasePortalJpaDao.PortalTransactional)

Example 12 with Version

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

the class JpaVersionDaoTest method testVersionLifecycle.

@Test
public void testVersionLifecycle() {
    final String productName = "TEST_VERSION";
    // Doesn't exist
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final Version version = versionDao.getVersion(productName);
            assertNull(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());
        }
    });
    // Update
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            Version version = versionDao.getVersion(productName);
            assertNotNull(version);
            assertEquals(1, version.getMajor());
            assertEquals(2, version.getMinor());
            assertEquals(3, version.getPatch());
            assertNull(version.getLocal());
            version = versionDao.setVersion(productName, 4, 5, 6, null);
            assertNotNull(version);
            assertEquals(4, version.getMajor());
            assertEquals(5, version.getMinor());
            assertEquals(6, version.getPatch());
            assertNull(version.getLocal());
        }
    });
    // verify
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            Version version = versionDao.getVersion(productName);
            assertNotNull(version);
            assertEquals(4, version.getMajor());
            assertEquals(5, version.getMinor());
            assertEquals(6, version.getPatch());
            assertNull(version.getLocal());
        }
    });
}
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)

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