Search in sources :

Example 6 with SMPDBExecutor

use of com.helger.phoss.smp.backend.sql.SMPDBExecutor in project phoss-smp by phax.

the class V10__MigrateRolesToDB method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all roles to the DB");
        final String sFilename = PhotonSecurityManager.FactoryXML.DIRECTORY_SECURITY + PhotonSecurityManager.FactoryXML.FILENAME_ROLES_XML;
        final File aFile = WebFileIO.getDataIO().getFile(sFilename);
        if (aFile.exists()) {
            final RoleManager aMgrXML = new RoleManager(sFilename);
            final ICommonsList<IRole> aRoles = aMgrXML.getAll();
            if (aRoles.isNotEmpty()) {
                final RoleManagerJDBC aMgrNew = new RoleManagerJDBC(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER);
                for (final IRole aRole : aRoles) {
                    // Don't run the callback here
                    if (aMgrNew.internalCreateNewRole((Role) aRole, false, false) == null)
                        LOGGER.error("Failed to migrate role " + aRole + " to DB");
                }
            }
            // Rename to avoid later inconsistencies
            WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
            LOGGER.info("Finished migrating all " + aRoles.size() + " roles to the DB");
        } else {
            LOGGER.warn("No role file found");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IRole(com.helger.photon.security.role.IRole) Role(com.helger.photon.security.role.Role) IRole(com.helger.photon.security.role.IRole) RoleManager(com.helger.photon.security.role.RoleManager) RoleManagerJDBC(com.helger.photon.jdbc.security.RoleManagerJDBC) File(java.io.File) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor)

Example 7 with SMPDBExecutor

use of com.helger.phoss.smp.backend.sql.SMPDBExecutor in project phoss-smp by phax.

the class V11__MigrateUsersToDB method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all users to the DB");
        final String sFilename = PhotonSecurityManager.FactoryXML.DIRECTORY_SECURITY + PhotonSecurityManager.FactoryXML.FILENAME_USERS_XML;
        final File aFile = WebFileIO.getDataIO().getFile(sFilename);
        if (aFile.exists()) {
            // Read the XML file
            final UserManager aMgrXML = new UserManager(sFilename);
            final ICommonsList<IUser> aUsers = aMgrXML.getAll();
            if (aUsers.isNotEmpty()) {
                // Create a new JDBC manager
                final UserManagerJDBC aMgrNew = new UserManagerJDBC(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER);
                for (final IUser aUser : aUsers) {
                    // Don't run the callback here
                    if (aMgrNew.internalCreateNewUser((User) aUser, false, false) == null)
                        LOGGER.error("Failed to migrate user " + aUser + " to DB");
                }
            }
            // Rename to avoid later inconsistencies
            WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
            LOGGER.info("Finished migrating all " + aUsers.size() + " users to the DB");
        } else {
            LOGGER.warn("No user file found");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IUser(com.helger.photon.security.user.IUser) User(com.helger.photon.security.user.User) UserManager(com.helger.photon.security.user.UserManager) IUser(com.helger.photon.security.user.IUser) UserManagerJDBC(com.helger.photon.jdbc.security.UserManagerJDBC) File(java.io.File) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor)

Example 8 with SMPDBExecutor

use of com.helger.phoss.smp.backend.sql.SMPDBExecutor 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)8 WebScoped (com.helger.web.scope.mgr.WebScoped)6 File (java.io.File)5 RoleManagerJDBC (com.helger.photon.jdbc.security.RoleManagerJDBC)2 UserManagerJDBC (com.helger.photon.jdbc.security.UserManagerJDBC)2 IUser (com.helger.photon.security.user.IUser)2 IUserManager (com.helger.photon.security.user.IUserManager)2 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)1 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)1 MutableLong (com.helger.commons.mutable.MutableLong)1 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)1 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)1 EDatabaseType (com.helger.phoss.smp.backend.sql.EDatabaseType)1 DBUser (com.helger.phoss.smp.backend.sql.domain.DBUser)1 SMPSettingsManagerJDBC (com.helger.phoss.smp.backend.sql.mgr.SMPSettingsManagerJDBC)1 SMPTransportProfileManagerJDBC (com.helger.phoss.smp.backend.sql.mgr.SMPTransportProfileManagerJDBC)1 SMPTransportProfileManagerXML (com.helger.phoss.smp.domain.transportprofile.SMPTransportProfileManagerXML)1 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)1 SMPSettingsManagerXML (com.helger.phoss.smp.settings.SMPSettingsManagerXML)1 UserGroupManagerJDBC (com.helger.photon.jdbc.security.UserGroupManagerJDBC)1