Search in sources :

Example 1 with SMPSettingsManagerXML

use of com.helger.phoss.smp.settings.SMPSettingsManagerXML in project phoss-smp by phax.

the class V14__MigrateSettingsToDB method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all settings to the DB");
        final String sFilename = "smp-settings.xml";
        final File aFile = WebFileIO.getDataIO().getFile(sFilename);
        if (aFile.exists()) {
            final SMPSettingsManagerXML aMgrXML = new SMPSettingsManagerXML(sFilename);
            final ISMPSettings aSettings = aMgrXML.getSettings();
            final SMPSettingsManagerJDBC aMgrNew = new SMPSettingsManagerJDBC(SMPDBExecutor::new);
            if (aMgrNew.updateSettings(aSettings.isRESTWritableAPIDisabled(), aSettings.isDirectoryIntegrationEnabled(), aSettings.isDirectoryIntegrationRequired(), aSettings.isDirectoryIntegrationAutoUpdate(), aSettings.getDirectoryHostName(), aSettings.isSMLEnabled(), aSettings.isSMLRequired(), aSettings.getSMLInfoID()).isUnchanged())
                throw new IllegalStateException("Failed to migrate SMP settings to DB");
            // Rename to avoid later inconsistencies
            WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
            LOGGER.info("Finished migrating all SMP settings to the DB");
        } else {
            LOGGER.info("No SMP settings file found");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) SMPSettingsManagerJDBC(com.helger.phoss.smp.backend.sql.mgr.SMPSettingsManagerJDBC) File(java.io.File) SMPSettingsManagerXML(com.helger.phoss.smp.settings.SMPSettingsManagerXML) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor)

Aggregations

SMPDBExecutor (com.helger.phoss.smp.backend.sql.SMPDBExecutor)1 SMPSettingsManagerJDBC (com.helger.phoss.smp.backend.sql.mgr.SMPSettingsManagerJDBC)1 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)1 SMPSettingsManagerXML (com.helger.phoss.smp.settings.SMPSettingsManagerXML)1 WebScoped (com.helger.web.scope.mgr.WebScoped)1 File (java.io.File)1