working on backend-side translations

This commit is contained in:
2025-12-14 12:36:26 +01:00
parent 00d05bfaff
commit 9fd540ba3c
12 changed files with 59 additions and 81 deletions

View File

@@ -6,6 +6,7 @@ import static de.srsoftware.tools.jdbc.Condition.*;
import static de.srsoftware.tools.jdbc.Query.*;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.Field.*;
import static de.srsoftware.umbrella.core.Field.COMPANY_ID;
import static de.srsoftware.umbrella.core.Field.TAX;
@@ -47,7 +48,7 @@ public class SqliteDb extends BaseDb implements DocumentDb{
var sql = format("ALTER TABLE {0} ADD COLUMN {1} VARCHAR(255)",TABLE_DOCUMENTS,TEMPLATE);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw databaseException("Failed to update column {0} → {1} of {2}",TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS);
throw databaseException(FAILED_TO_UPDATE_COLUMN,TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS);
}
}
@@ -77,8 +78,7 @@ public class SqliteDb extends BaseDb implements DocumentDb{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_PRICES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PRICES);
}
}
@@ -89,8 +89,7 @@ public class SqliteDb extends BaseDb implements DocumentDb{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_CUSTOMER_SETTINGS,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_CUSTOMER_SETTINGS);
}
}
@@ -124,8 +123,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_DOCUMENTS,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_DOCUMENTS);
}
}
@@ -142,8 +140,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.values(4,4,TYPE_REMINDER)
.execute(db);
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_DOCUMENT_TYPES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_DOCUMENT_TYPES);
}
}
@@ -169,8 +166,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_POSITIONS,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_POSITIONS);
}
}
@@ -181,8 +177,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TEMPLATES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TEMPLATES);
}
}
@@ -201,7 +196,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e){
LOG.log(WARNING,"Failed to delete document {0}",docId);
}
throw new UmbrellaException(500,"Failed to delete document with id {0}",docId);
throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId);
}
@Override
@@ -210,18 +205,18 @@ CREATE TABLE IF NOT EXISTS {0} (
db.setAutoCommit(false);
delete().from(TABLE_POSITIONS).where(DOCUMENT_ID,equal(docId)).where(POS,equal(pos)).execute(db);
var sql = format("UPDATE {0} SET {1} = {1}-1 WHERE {2} = ? AND {1} > ?",TABLE_POSITIONS,POS,DOCUMENT_ID);
LOG.log(DEBUG,sql.replaceFirst("\\?",docId+"").replace("?",pos+""));
var stmt = db.prepareStatement(sql);
stmt.setLong(1,docId);
stmt.setLong(2,pos);
stmt.execute();
stmt.close();
db.setAutoCommit(true);
return pos;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to delete position {0} of document {1}",pos,docId);
throw new UmbrellaException(500,"Failed to delete position {0} of document {1}",pos,docId);
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"position",pos,"document",docId);
}
return pos;
}
private void dropTemplateIdColumn() {
@@ -229,7 +224,7 @@ CREATE TABLE IF NOT EXISTS {0} (
var sql = format("ALTER TABLE {0} DROP COLUMN {1}",TABLE_DOCUMENTS,TEMPLATE_ID);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw databaseException("Failed to update column {0} → {1} of {2}",TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS);
throw databaseException(FAILED_TO_UPDATE_COLUMN,TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS);
}
}
@@ -238,7 +233,7 @@ CREATE TABLE IF NOT EXISTS {0} (
var sql = format("DROP TABLE IF EXISTS {0};",TABLE_TEMPLATES);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw databaseException("Failed to drop table {0}",TABLE_TEMPLATES);
throw databaseException(FAILED_TO_DROP_ENTITY,"table",TABLE_TEMPLATES);
}
}
@@ -265,8 +260,8 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return settings;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load customer settings (company: {0}, document type: {1}",companyId, docType.name(),e);
throw new UmbrellaException(500,"Failed to load customer settings (company: {0}, document type: {1}",companyId, docType.name());
LOG.log(WARNING,"Failed to load customer settings (company: {0}, document type: {1})",companyId, docType.name(),e);
throw new UmbrellaException(500,"Failed to load customer settings (company: {0}, document type: {1})",companyId, docType.name());
}
}
@@ -281,7 +276,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to read document type ({0})!",typeId);
}
throw new UmbrellaException(500,"No type with id = {0}",typeId);
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"type",typeId);
}
@Override
@@ -298,7 +293,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return map;
} catch (SQLException e) {
throw databaseException("Failed to list Documents for list of times");
throw databaseException(FAILED_TO_LIST_ENTITIES,"documents");
}
}
@@ -347,8 +342,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return map;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to search list of documents.");
throw new UmbrellaException(500,"Failed to search list of documents.").causedBy(e);
throw databaseException(FAILED_TO_SEARCH_DB,"documents");
}
}
@@ -375,8 +369,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return map;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to read list of documents for company {0}.",companyId,e);
throw new UmbrellaException(500,"Failed to read list of documents for company {0}.",companyId).causedBy(e);
throw databaseException(FAILED_TO_LIST_ENTITIES,"documents");
}
}
@@ -389,8 +382,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return types;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to read list of document types.",e);
throw new UmbrellaException(500,"Failed to read list of document types.").causedBy(e);
throw databaseException(FAILED_TO_LIST_ENTITIES,"document types");
}
}
@@ -418,10 +410,9 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return doc;
}
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load document {0}.",docId,e);
} catch (SQLException ignored) {
}
throw new UmbrellaException(500,"Failed to load document {0}.",docId);
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"document",docId);
}
private void moveTemplateNames() {
@@ -429,7 +420,7 @@ CREATE TABLE IF NOT EXISTS {0} (
var sql = format("UPDATE {0} SET template = (SELECT name FROM templates WHERE templates.id = documents.template_id);",TABLE_DOCUMENTS);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw databaseException("Failed to move template.names to document.templates!");
throw databaseException(FAILED_TO_MOVE,"template.names","document.templates");
}
}
@@ -455,7 +446,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
return lastId;
} catch (SQLException e) {
throw databaseException("Failed to read last document id");
throw databaseException(FAILED_TO_READ_LAST_DOCID);
}
}