Search in sources :

Example 1 with SMPTransportProfileManagerXML

use of com.helger.phoss.smp.domain.transportprofile.SMPTransportProfileManagerXML in project phoss-smp by phax.

the class V5__MigrateTransportProfilesToDB method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all transport profiles to the DB");
        final String sFilename = "transportprofiles.xml";
        final File aFile = WebFileIO.getDataIO().getFile(sFilename);
        if (aFile.exists()) {
            final SMPTransportProfileManagerXML aMgrXML = new SMPTransportProfileManagerXML(sFilename);
            final ICommonsList<ISMPTransportProfile> aTransportProfiles = aMgrXML.getAll();
            if (aTransportProfiles.isNotEmpty()) {
                final SMPTransportProfileManagerJDBC aMgrNew = new SMPTransportProfileManagerJDBC(SMPDBExecutor::new);
                for (final ISMPTransportProfile aTransportProfile : aTransportProfiles) if (aMgrNew.createSMPTransportProfile(aTransportProfile.getID(), aTransportProfile.getName(), aTransportProfile.isDeprecated()) == null)
                    LOGGER.error("Failed to migrate " + aTransportProfile + " to DB");
            }
            // Rename to avoid later inconsistencies
            WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
            LOGGER.info("Finished migrating all " + aTransportProfiles.size() + " transport profiles to the DB");
        } else {
            LOGGER.info("No transport profile file found");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfileManagerJDBC(com.helger.phoss.smp.backend.sql.mgr.SMPTransportProfileManagerJDBC) SMPTransportProfileManagerXML(com.helger.phoss.smp.domain.transportprofile.SMPTransportProfileManagerXML) File(java.io.File) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor)

Aggregations

ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)1 SMPDBExecutor (com.helger.phoss.smp.backend.sql.SMPDBExecutor)1 SMPTransportProfileManagerJDBC (com.helger.phoss.smp.backend.sql.mgr.SMPTransportProfileManagerJDBC)1 SMPTransportProfileManagerXML (com.helger.phoss.smp.domain.transportprofile.SMPTransportProfileManagerXML)1 WebScoped (com.helger.web.scope.mgr.WebScoped)1 File (java.io.File)1