diff --git a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationController.java b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationController.java index 2c4da4a00043b4dfa9f6795e9aafdc622ac30c0b..3cbb822c2bca58d4214404a2fbd5117f0694531b 100644 --- a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationController.java +++ b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationController.java @@ -58,7 +58,7 @@ public class MigrationController extends BaseController @GetMapping public String migrate(Model model) { - model.addAttribute(ModelAttributes.MIGRATION_SETTINGS, new MigrationSettings(null, null, null, null, null)); + model.addAttribute(ModelAttributes.MIGRATION_SETTINGS, migrationService.getPrefilledMigrationSettings()); return ReturnValues.MIGRATION_SETTINGS; } diff --git a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java index 32507fb555aa3bc8739c212ed397b10dfaf7f0b9..bd72fa24019622b6cda814e039749a037dfa6a09 100644 --- a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java +++ b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java @@ -6,6 +6,7 @@ import de.deadlocker8.budgetmaster.categories.CategoryType; import de.deadlocker8.budgetmaster.settings.SettingsService; import de.deadlocker8.budgetmaster.templates.TemplateRepository; import de.deadlocker8.budgetmaster.transactions.TransactionRepository; +import de.deadlocker8.budgetmaster.utils.DatabaseConfigurationProperties; import de.deadlocker8.budgetmaster.utils.Mappings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,9 +36,10 @@ public class MigrationService private final CategoryRepository categoryRepository; private final TransactionRepository transactionRepository; private final TemplateRepository templateRepository; + private final DatabaseConfigurationProperties databaseConfig; @Autowired - public MigrationService(SettingsService settingsService, Path applicationSupportFolder, AccountRepository accountRepository, CategoryRepository categoryRepository, TransactionRepository transactionRepository, TemplateRepository templateRepository) + public MigrationService(SettingsService settingsService, Path applicationSupportFolder, AccountRepository accountRepository, CategoryRepository categoryRepository, TransactionRepository transactionRepository, TemplateRepository templateRepository, DatabaseConfigurationProperties databaseConfig) { this.settingsService = settingsService; this.applicationSupportFolder = applicationSupportFolder; @@ -45,6 +47,12 @@ public class MigrationService this.categoryRepository = categoryRepository; this.transactionRepository = transactionRepository; this.templateRepository = templateRepository; + this.databaseConfig = databaseConfig; + } + + public MigrationSettings getPrefilledMigrationSettings() + { + return new MigrationSettings(databaseConfig.getHostname(), databaseConfig.getPort(), databaseConfig.getDatabaseName(), databaseConfig.getUsername(), databaseConfig.getPassword()); } public boolean needToShowMigrationDialog(String loadedPage) diff --git a/BudgetMasterServer/src/main/resources/languages/base_de.properties b/BudgetMasterServer/src/main/resources/languages/base_de.properties index ed8465f8ad2b4078b9a9386c8bba70f8b7aaa2e4..b8de58e0677550f56b1f4ccbe7285a3c83514285 100644 --- a/BudgetMasterServer/src/main/resources/languages/base_de.properties +++ b/BudgetMasterServer/src/main/resources/languages/base_de.properties @@ -640,6 +640,7 @@ copied=Kopiert! migration.settings.description=Alle Daten aus deiner bestehenden BudgetMaster Datenbank werden in die neue Datenbank migriert.<br> Bitte gib die Einstellungen für das neue Datenbank-Backend (z.B. postgresql) ein. migration.settings.description.warning=Alle vorhandenen Daten der Zieldatenbank werden unwiderruflich gelöscht! +migration.settings.description.info=Die Einstellungen werden mit der aktuell verwendeten Datenbank vorbefüllt. migration.settings.hostname=Hostname migration.settings.port=Port migration.settings.databaseName=Datenbankname diff --git a/BudgetMasterServer/src/main/resources/languages/base_en.properties b/BudgetMasterServer/src/main/resources/languages/base_en.properties index 6e81d84b5d0e089dd6a4a8861141e2ed6c43ccb5..ff69f2097e9df3df1f0f3e42670114ca6e2a31c3 100644 --- a/BudgetMasterServer/src/main/resources/languages/base_en.properties +++ b/BudgetMasterServer/src/main/resources/languages/base_en.properties @@ -637,8 +637,9 @@ import.entity.chart=Only user-defined charts will be imported.<br>The import of copied=Copied! -migration.settings.description=All data from your existing BudgetMaster database will be migrated to the new database.<br> Please enter the settings for the new database backend (e.g. postgresql). +migration.settings.description=All data from your existing BudgetMaster database will be migrated to the new database.<br>Please enter the settings for the new database backend (e.g. postgresql). migration.settings.description.warning=All existing data of the target database will be permanently deleted! +migration.settings.description.info=The settings are prefilled with the currently used database. migration.settings.hostname=Hostname migration.settings.port=Port migration.settings.databaseName=Database name diff --git a/BudgetMasterServer/src/main/resources/templates/migration.ftl b/BudgetMasterServer/src/main/resources/templates/migration.ftl index 08aab2420e7ce6301be67589ddd7732b7bb31056..b24a95ba00f945b24b38a726d05a55e1a3e79b62 100644 --- a/BudgetMasterServer/src/main/resources/templates/migration.ftl +++ b/BudgetMasterServer/src/main/resources/templates/migration.ftl @@ -40,6 +40,17 @@ </div> </div> + <div class="row notification-row"> + <div class="col s12 center-align"> + <div class="notification-wrapper"> + <div class="notification background-grey text-black"> + <i class="fas fa-info notification-item"></i> + <span class="notification-item left-align">${locale.getString("migration.settings.description.info")}</span> + </div> + </div> + </div> + </div> + <div class="row"> <div class="input-field col s12 m12 l8 offset-l2"> <i class="material-icons prefix">public</i> diff --git a/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/unit/MigrationServiceTest.java b/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/unit/MigrationServiceTest.java index 693d94920fa1c2a4e8d6ac5a898c3921e87aa014..e6aa9c4ef30d7f6c37a4995368322fee97a94ad3 100644 --- a/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/unit/MigrationServiceTest.java +++ b/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/unit/MigrationServiceTest.java @@ -10,6 +10,7 @@ import de.deadlocker8.budgetmaster.settings.SettingsService; import de.deadlocker8.budgetmaster.templates.TemplateRepository; import de.deadlocker8.budgetmaster.transactions.TransactionRepository; import de.deadlocker8.budgetmaster.unit.helpers.LocalizedTest; +import de.deadlocker8.budgetmaster.utils.DatabaseConfigurationProperties; import de.deadlocker8.budgetmaster.utils.Mappings; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -44,6 +45,9 @@ class MigrationServiceTest @Mock private TemplateRepository templateRepository; + @Mock + private DatabaseConfigurationProperties databaseConfig; + @TempDir public Path tempFolder; @@ -57,7 +61,7 @@ class MigrationServiceTest Mockito.when(settingsService.getSettings()).thenReturn(settings); - final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository); + final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository, databaseConfig); assertThat(migrationService.needToShowMigrationDialog("migration")).isFalse(); } @@ -72,7 +76,7 @@ class MigrationServiceTest Mockito.when(settingsService.getSettings()).thenReturn(settings); - final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository); + final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository, databaseConfig); assertThat(migrationService.needToShowMigrationDialog(Mappings.TRANSACTIONS)).isFalse(); } @@ -87,7 +91,7 @@ class MigrationServiceTest Mockito.when(settingsService.getSettings()).thenReturn(settings); Mockito.when(categoryRepository.findAllByTypeOrderByNameAsc(CategoryType.CUSTOM)).thenReturn(List.of(new Category("custom category", "ff0000", CategoryType.CUSTOM))); - final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository); + final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository, databaseConfig); assertThat(migrationService.needToShowMigrationDialog(Mappings.TRANSACTIONS)).isFalse(); } @@ -98,7 +102,7 @@ class MigrationServiceTest Mockito.when(settingsService.getSettings()).thenReturn(settings); - final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository); + final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository, databaseConfig); assertThat(migrationService.needToShowMigrationDialog(Mappings.TRANSACTIONS)).isFalse(); } @@ -112,7 +116,7 @@ class MigrationServiceTest Mockito.when(settingsService.getSettings()).thenReturn(settings); - final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository); + final MigrationService migrationService = new MigrationService(settingsService, tempFolder, accountRepository, categoryRepository, transactionRepository, templateRepository, databaseConfig); assertThat(migrationService.needToShowMigrationDialog(Mappings.TRANSACTIONS)).isTrue(); } }