working on backend-side translations

This commit is contained in:
2025-12-15 21:17:45 +01:00
parent 0c909d6d7c
commit a275b5065d
4 changed files with 35 additions and 37 deletions

View File

@@ -32,5 +32,9 @@ public class Errors {
public static final String FAILED_TO_SWITCH_POSITIONS = "failed_to_switch_positions";
public static final String FAILED_TO_UPDATE_COLUMN = "failed_to_update_column";
public static final String FAILED_TO_UPDATE_ENTITY = "failed_to_update_entity";
public static final String FAILED_TO_UPDATE_TABLE = "failed_to_update_table";
public static final String MISSING_NEW_ITEM_ID = "missing_new_item_id";
public static final String NO_BOOKMARK_FOR_URLID = "no_bookmark_for_urlid";
public static final String UNEXPECTED_ITEM_ID_FORMAT = "unexpected_item_id_format";
public static final String UNKNOWN_ITEM_LOCATION = "unknown_item_location";
}

View File

@@ -516,18 +516,18 @@ public class SqliteDb extends BaseDb implements StockDb {
while (rs.next()){
var oldId = rs.getString(ID);
var parts = oldId.split(":");
if (parts.length != 3) throw databaseException("Expected old item id to be of the form ss:dd:dd, encountered {0}!",oldId);
if (parts.length != 3) throw databaseException(UNEXPECTED_ITEM_ID_FORMAT,oldId);
var owner = String.join(":",parts[0], parts[1]);
long ownerNumber;
try {
ownerNumber = Long.parseLong(parts[2]);
} catch (NumberFormatException e) {
throw databaseException("Expected old item id to be of the form ss:dd:dd, encountered {0}!",oldId);
throw databaseException(UNEXPECTED_ITEM_ID_FORMAT,oldId).causedBy(e);
}
var oldLocationId = rs.getString(LOCATION_ID);
var locationId = oldLocationIdsToNew.get(oldLocationId);
if (locationId == null) throw databaseException("Item {0} of {1} {2} refers to location {3}, which is unknown!",oldId,parts[0],parts[1],oldLocationId);
if (locationId == null) throw databaseException(UNKNOWN_ITEM_LOCATION,oldId,parts[0],parts[1],oldLocationId);
var rs2 = insert.values(owner, ownerNumber, locationId, rs.getString(CODE), rs.getString(NAME)).execute(db).getGeneratedKeys();
oldToNew.put(oldId,rs2.getLong(1));
rs2.close();
@@ -572,9 +572,7 @@ public class SqliteDb extends BaseDb implements StockDb {
while (rs.next()){
var oldItemId = rs.getString(ITEM_ID);
var itemId = oldItemIdsToNew.get(oldItemId);
if (itemId == null) {
throw databaseException("Old item id ({0}) has no new counterpart!",oldItemId);
}
if (itemId == null) throw databaseException(MISSING_NEW_ITEM_ID,oldItemId);
insert.values(itemId, rs.getLong(PROPERTY_ID), rs.getString(VALUE));
}
rs.close();
@@ -600,8 +598,7 @@ public class SqliteDb extends BaseDb implements StockDb {
db.rollback();
} catch (SQLException ignored) {
}
LOG.log(ERROR,"Failed to transform {0} table!",TABLE_LOCATIONS,e);
throw databaseException("Failed to transform {0} table!",TABLE_LOCATIONS);
throw databaseException(FAILED_TO_UPDATE_TABLE,TABLE_LOCATIONS).causedBy(e);
}
}
@@ -612,11 +609,7 @@ public class SqliteDb extends BaseDb implements StockDb {
var note = entry.getValue();
var oldEntityId = note.entityId();
var newEntityId = oldItemIdsToNew.get(oldEntityId);
if (newEntityId != null){
noteService.save(note.entityId(""+newEntityId));
}
if (newEntityId != null) noteService.save(note.entityId(""+newEntityId));
}
}
}

View File

@@ -11,6 +11,7 @@ import static de.srsoftware.umbrella.bookmarks.Constants.*;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
import static de.srsoftware.umbrella.core.Constants.USER_ID;
import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.tags.Constants.*;
import static java.lang.System.Logger.Level.*;
@@ -104,7 +105,7 @@ public class SqliteDb extends BaseDb implements TagDB{
}
commentedURLS.close();
} catch (SQLException e) {
throw new RuntimeException(e);
throw databaseException(FAILED_TO_UPDATE_TABLE,TABLE_URLS).causedBy(e);
}
}
@@ -115,8 +116,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "Comments (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"Comments (legacy)").causedBy(e);
}
}
@@ -127,8 +127,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "Tags (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"Tags (legacy)").causedBy(e);
}
}
@@ -139,8 +138,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "URLs (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"URLs (legacy)").causedBy(e);
}
}
@@ -151,8 +149,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "URL_comments (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"URL_comments (legacy)").causedBy(e);
}
}
@@ -171,20 +168,20 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TAGS_NEW,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TAGS_NEW).causedBy(e);
}
}
private void dropOldTables(){
var sql = "DROP TABLE IF EXISTS {0}";
for (var table : List.of(TABLE_TAGS,TABLE_COMMENTS,TABLE_TOKENS,TABLE_URL_COMMENTS,TABLE_URLS)) try {
String table = null;
for (var t : List.of(TABLE_TAGS,TABLE_COMMENTS,TABLE_TOKENS,TABLE_URL_COMMENTS,TABLE_URLS)) try {
table = t;
var stmt = db.prepareStatement(format(sql,table));
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TAGS_NEW,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_DROP_ENTITY,table).causedBy(e);
}
}
@@ -195,8 +192,8 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TAGS_NEW,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TAGS).causedBy(e);
}
}
@@ -211,7 +208,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db);
return tag;
} catch (SQLException e){
throw new UmbrellaException("Failed to delete tag {0}",tag);
throw databaseException(FAILED_TO_DROP_ENTITY,tag);
}
}
@@ -222,7 +219,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.where(MODULE,iEqual(module)).where(ENTITY_ID,equal(entityId))
.execute(db);
} catch (SQLException e){
throw new UmbrellaException("Failed to save tags ({0} {1})",module,entityId);
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,entityId,module).causedBy(e);
}
}
@@ -246,7 +243,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return result;
} catch (SQLException e){
throw new UmbrellaException("Failed to load uses of tag \"{0}\"!",tag);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"uses",tag).causedBy(e);
}
}
@@ -266,7 +263,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return tags;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load tags");
throw databaseException(FAILED_TO_LIST_ENTITIES,"tags").causedBy(e);
}
}
@@ -284,7 +281,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return list;
} catch (SQLException e) {
throw databaseException("Failed to load tags for user {0}",userId);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"tags",userId).causedBy(e);
}
}
@@ -304,7 +301,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return tags;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load tags");
throw databaseException(FAILED_TO_LIST_ENTITIES,"tags").causedBy(e);
}
}
@@ -321,7 +318,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
query.execute(db).close();
} catch (SQLException e){
throw new UmbrellaException("Failed to save tags: {0}",String.join(", ",tags));
throw databaseException(FAILED_TO_STORE_ENTITY,String.join(", ",tags)).causedBy(e);
}
}
@@ -331,7 +328,7 @@ CREATE TABLE IF NOT EXISTS {0} (
update(TABLE_TAGS).set(ENTITY_ID).where(MODULE,iEqual(module)).where(ENTITY_ID,equal(oldId)).prepare(db).apply(newId).close();
LOG.log(DEBUG,"Updated tag @ {0}.{1} → {0}.{2}",module,oldId,newId);
} catch (SQLException e) {
throw databaseException("Failed to update {0}.{1} → {0}.{2}",module,oldId,newId);
throw databaseException(FAILED_TO_UPDATE_ENTITY,format("{0}.{1} → {0}.{2}",module,oldId,newId)).causedBy(e);
}
}
}

View File

@@ -127,6 +127,7 @@
"failed_to_switch_positions": "Failed to switch positions {0} and {1} of document {2}",
"failed_to_update_column": "Failed to update column {0} → {1} of {2}",
"failed_to_update_entity": "Failed to update {0} in database",
"failed_to_update_table": "Failed to update {0} table!",
"family_name": "Familenname",
"file": "Datei",
"files": "Dateien",
@@ -182,6 +183,7 @@
"message": "Nachricht",
"messages": "Benachrichtigungen",
"miscellaneous_settings": "sonstige Einstellungen",
"missing_new_item_id": "Old item id ({0}) has no new counterpart!",
"mismatch": "ungleich",
"model": "Modell",
"models": "Modelle",
@@ -332,8 +334,10 @@
"type_offer": "Angebot",
"type_reminder": "Erinnerung",
"unexpected_item_id_format": "Expected old item ID to be of the form ss:dd:dd, encountered {0}!",
"unit": "Einheit",
"unit_price": "Preis/Einheit",
"unknown_item_location": "Item {0} of {1} {2} refers to location {3}, which is unknown!",
"unlink": "Trennen",
"update": "aktualisieren",
"UPDATE_USERS" : "Nutzer aktualisieren",