Commit afdf0f6a authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Fixed TODO in "ActionLoadProject" about i18n of migration messages

parent 29c41241
......@@ -395,4 +395,12 @@ Data.TrajectoryOrScenarioFile.NoData.text=No trajectory or scenario file found.
ImageSizeDialog.title=Image size
ImageSizeDialog.lblWidth.text=Width
ImageSizeDialog.lblHeight.text=Height
\ No newline at end of file
ImageSizeDialog.lblHeight.text=Height
MigrationAssistant.title=Migration Assistant
MigrationAssistant.Results.title=Migration to version
MigrationAssistant.Results.analyzed=Analyzed files
MigrationAssistant.Results.migrated=Migrated
MigrationAssistant.Results.upToDate=Already up to date
MigrationAssistant.Results.notMigratable=Not migratable
MigrationAssistant.Results.migratedInfo=Backed up original scenarios to folder \"legacy\"
\ No newline at end of file
......@@ -389,4 +389,12 @@ Data.TrajectoryOrScenarioFile.NoData.text=Keine Trajektorien- oder Szenario-Date
ImageSizeDialog.title=Bildgr\u00f6\u00dfe
ImageSizeDialog.lblWidth.text=Breite
ImageSizeDialog.lblHeight.text=H\u00f6he
\ No newline at end of file
ImageSizeDialog.lblHeight.text=H\u00f6he
MigrationAssistant.title=Migrations-Assistent
MigrationAssistant.Results.title=Migration zu Version
MigrationAssistant.Results.analyzed=Insgesamt analysiert
MigrationAssistant.Results.migrated=Migriert
MigrationAssistant.Results.upToDate=Bereits aktuell
MigrationAssistant.Results.notMigratable=Nicht migrierbar
MigrationAssistant.Results.migratedInfo=Original-Szenarien gesichert in Ordner \"legacy\"
\ No newline at end of file
package org.vadere.gui.projectview.control;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.gui.projectview.view.VDialogManager;
......@@ -14,6 +12,7 @@ import org.vadere.simulator.projects.migration.MigrationResult;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.nio.file.Files;
......@@ -21,11 +20,7 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.*;
public class ActionLoadProject extends AbstractAction {
......@@ -135,45 +130,47 @@ public class ActionLoadProject extends AbstractAction {
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
public Void doInBackground() {
int total = stats.total;
int migrated = stats.legacy;
int nonmigratable = stats.notmigratable;
int untouched = total - migrated - nonmigratable;
// TODO pull this text from the language files
String message =
"The migration assistant analyzed the " + total + " scenarios in the scenarios and output " +
"directories of this project and attempted to upgrade them to the latest version "
+ Version.latest().label() + ".\n" +
"Log-files have been created in legacy/scenarios and legacy/output.\n\n";
if (untouched > 0)
message += "(" + untouched + "/" + total + ") of the scenarios were already up to date.\n\n";
if (nonmigratable > 0)
message += "(" + nonmigratable + "/" + total
+ ") scenarios could not automatically be upgraded and were moved to the legacy-folder. They can't be opened unless the upgrade is done manually.\n\n";
if (migrated > 0)
message += "(" + migrated + "/" + total
+ ") scenarios were successfully upgraded. The old versions were moved to the legacy-folder.\n\n";
String migrationResult = String.format("%s %s:\n\n",
Messages.getString("MigrationAssistant.Results.title"),
Version.latest().label());
migrationResult += String.join("\n", getMigrationResult(stats));
if (stats.legacy > 0) {
migrationResult += String.format("\n\n%s", Messages.getString("MigrationAssistant.Results.migratedInfo"));
}
JOptionPane.showMessageDialog(
ProjectView.getMainWindow(),
message, "JoltMigrationAssistant assistant",
migrationResult, Messages.getString("MigrationAssistant.title"),
JOptionPane.INFORMATION_MESSAGE);
return null;
}
};
worker.execute();
} else {
logger.info("Nothing to migrate all up to date " + stats);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "JoltMigrationAssistant assistant",
JOptionPane.showMessageDialog(null, e.getMessage(), Messages.getString("MigrationAssistant.title"),
JOptionPane.ERROR_MESSAGE);
logger.error("could not loadFromFilesystem project: " + e.getMessage());
e.printStackTrace();
}
}
/**
* The "MigrationResult" class cannot access "Messages.getString(...)"
* because of avoiding cyclic dependencies between view and controller classes.
* Therefore, translate the migration results here.
*/
public static List<String> getMigrationResult(MigrationResult migrationResult) {
List<String> resultArray = new ArrayList<>();
String resultLineTemplate = "%s: %d";
resultArray.add(String.format(resultLineTemplate, Messages.getString("MigrationAssistant.Results.analyzed"), migrationResult.total));
resultArray.add(String.format(resultLineTemplate, Messages.getString("MigrationAssistant.Results.migrated"), migrationResult.legacy));
resultArray.add(String.format(resultLineTemplate, Messages.getString("MigrationAssistant.Results.upToDate"), migrationResult.upToDate));
resultArray.add(String.format(resultLineTemplate, Messages.getString("MigrationAssistant.Results.notMigratable"), migrationResult.notmigratable));
return resultArray;
}
}
package org.vadere.simulator.projects.migration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class MigrationResult {
public int total;
public int upToDate;
public int legacy;
......@@ -53,11 +56,15 @@ public class MigrationResult {
@Override
public String toString() {
return "MigrationResult{" +
"total=" + total +
", upToDate=" + upToDate +
", legacy=" + legacy +
", notmigratable=" + notmigratable +
'}';
List<String> resultArray = new ArrayList<>();
String resultLineTemplate = "%s: %d";
resultArray.add(String.format(resultLineTemplate, "analyzed", total));
resultArray.add(String.format(resultLineTemplate, "migrated", legacy));
resultArray.add(String.format(resultLineTemplate, "upToDate", upToDate));
resultArray.add(String.format(resultLineTemplate, "notMigratable", notmigratable));
return String.join(", ", resultArray);
}
}
......@@ -275,14 +275,14 @@ public class JsonMigrationAssistant extends MigrationAssistant {
// apply all transformation from current to latest version.
for (Version v : Version.listToLatest(version)) {
migrationLogger.info("<" + node.get("name").asText() + "> Start Transform to Version: " + v.label());
logger.info(migrationLogger.last());
logger.debug(migrationLogger.last());
transformedNode = transform(transformedNode, v);
}
// will always be Version.latest()
transformedNode = AbstractJsonTransformation.addNewMembersWithDefaultValues(transformedNode);
if (legacyDir != null) {
migrationLogger.info("Scenario Migrated - OK. Move copy of old version to legacllyDir");
logger.info(migrationLogger.last());
logger.debug(migrationLogger.last());
moveFileAddExtension(scenarioFilePath, legacyDir, migrationOptions.getLegacyExtension(), false);
}
IOUtils.writeTextFile(scenarioFilePath.toString(), StateJsonConverter.serializeJsonNode(transformedNode));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment