working on backend-side translations

This commit is contained in:
2025-12-14 20:45:55 +01:00
parent 9fd540ba3c
commit 878365a83d
7 changed files with 85 additions and 71 deletions

View File

@@ -9,6 +9,7 @@ import static de.srsoftware.umbrella.bookmarks.Constants.*;
import static de.srsoftware.umbrella.core.Constants.*; import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Errors.*; import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
import static java.text.MessageFormat.format; import static java.text.MessageFormat.format;
import static java.time.ZoneOffset.UTC; import static java.time.ZoneOffset.UTC;
@@ -52,7 +53,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_URL_COMMENTS); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_URL_COMMENTS).causedBy(e);
} }
} }
@@ -63,7 +64,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_URLS); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_URLS).causedBy(e);
} }
} }
@@ -76,7 +77,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();; rs.close();;
return map; return map;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark list"); throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark list").causedBy(e);
} }
} }
@@ -95,7 +96,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();; rs.close();;
return map; return map;
} catch (SQLException e) { } catch (SQLException e) {
throw new UmbrellaException("Failed to load bookmark list"); throw databaseException(FAILED_TO_DROP_ENTITY,"bookmark list").causedBy(e);
} }
} }
@@ -111,7 +112,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();; rs.close();;
return map; return map;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark list"); throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark list").causedBy(e);
} }
} }
@@ -123,9 +124,9 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) result = Bookmark.of(rs); if (rs.next()) result = Bookmark.of(rs);
rs.close(); rs.close();
if (result != null) return result; if (result != null) return result;
throw UmbrellaException.notFound("no_bookmark_for_urlid",id); throw notFound(NO_BOOKMARK_FOR_URLID,id);
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark"); throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark").causedBy(e);
} }
} }
@@ -148,7 +149,7 @@ CREATE TABLE IF NOT EXISTS {0} (
query.execute(db).close(); query.execute(db).close();
return Bookmark.of(urlId,url,comment,timestamp); return Bookmark.of(urlId,url,comment,timestamp);
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_STORE_ENTITY,"url"); throw databaseException(FAILED_TO_STORE_ENTITY,"url").causedBy(e);
} }
} }
} }

View File

@@ -12,8 +12,7 @@ import static de.srsoftware.umbrella.core.Constants.COMPANY;
import static de.srsoftware.umbrella.core.Errors.*; import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.Field.*; import static de.srsoftware.umbrella.core.Field.*;
import static de.srsoftware.umbrella.core.Field.COMPANY_ID; import static de.srsoftware.umbrella.core.Field.COMPANY_ID;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
import static java.text.MessageFormat.format; import static java.text.MessageFormat.format;
import de.srsoftware.umbrella.company.api.CompanyDb; import de.srsoftware.umbrella.company.api.CompanyDb;
@@ -68,7 +67,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_COMPANIES); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_COMPANIES).causedBy(e);
} }
} }
@@ -79,7 +78,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_COMPANIES); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_COMPANIES).causedBy(e);
} }
} }
@@ -92,7 +91,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
.execute(db) .execute(db)
.close(); .close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_ASSIGN_USER_TO_COMPANY); throw databaseException(FAILED_TO_ASSIGN_USER_TO_COMPANY).causedBy(e);
} }
} }
@@ -103,7 +102,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
delete().from(TABLE_COMPANIES).where(ID,equal(companyId)).execute(db); delete().from(TABLE_COMPANIES).where(ID,equal(companyId)).execute(db);
return companyId; return companyId;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY,"company",companyId); throw databaseException(FAILED_TO_DROP_ENTITY,"company",companyId).causedBy(e);
} }
} }
@@ -112,7 +111,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
try { try {
delete().from(TABLE_COMPANIES_USERS).where(COMPANY_ID,equal(companyId)).where(USER_ID,equal(userId)).execute(db); delete().from(TABLE_COMPANIES_USERS).where(COMPANY_ID,equal(companyId)).where(USER_ID,equal(userId)).execute(db);
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"user",userId,"company",companyId); throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"user",userId,"company",companyId).causedBy(e);
} }
} }
@@ -125,7 +124,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
rs.close(); rs.close();
return ids; return ids;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_COMPANY_MEMBERS,companyId); throw databaseException(FAILED_TO_LOAD_COMPANY_MEMBERS,companyId).causedBy(e);
} }
} }
@@ -143,7 +142,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
var next = last+1; var next = last+1;
return prefix+next; // TODO: currently not taking growing number lengths into account, this should be resolved! return prefix+next; // TODO: currently not taking growing number lengths into account, this should be resolved!
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_CUSTOMER_NUM_SETTINGS,companyId); throw databaseException(FAILED_TO_LOAD_CUSTOMER_NUM_SETTINGS,companyId).causedBy(e);
} }
} }
@@ -163,8 +162,8 @@ CREATE TABLE IF NOT EXISTS "companies" (
} }
rs.close(); rs.close();
return companies; return companies;
} catch (SQLException ex){ } catch (SQLException e){
throw databaseException(FAILED_TO_SEARCH_DB, ModuleRegistry.translator().translate(user.language(),COMPANY)); throw databaseException(FAILED_TO_SEARCH_DB, ModuleRegistry.translator().translate(user.language(),COMPANY)).causedBy(e);
} }
} }
@@ -180,7 +179,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
rs.close(); rs.close();
return companies; return companies;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_USER_COMPANIES,userId); throw databaseException(FAILED_TO_LOAD_USER_COMPANIES,userId).causedBy(e);
} }
} }
@@ -191,10 +190,10 @@ CREATE TABLE IF NOT EXISTS "companies" (
Company company = null; Company company = null;
if (rs.next()) company = Company.of(rs); if (rs.next()) company = Company.of(rs);
rs.close(); rs.close();
if (company == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"company",companyId); if (company == null) throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID,"company",companyId);
return company; return company;
} catch (SQLException e){ } catch (SQLException e){
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"company",companyId); throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"company",companyId).causedBy(e);
} }
} }
@@ -226,7 +225,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
return company; return company;
} }
} catch (SQLException e){ } catch (SQLException e){
throw databaseException(FAILED_TO_STORE_ENTITY,company.name()); throw databaseException(FAILED_TO_STORE_ENTITY,company.name()).causedBy(e);
} }
} }
@@ -240,7 +239,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
try { try {
update(TABLE_COMPANIES).set(LAST_CUSTOMER_NUMBER,CUSTOMER_NUMBER_PREFIX).where(ID,equal(companyId)).prepare(db).apply(number,prefix).close(); update(TABLE_COMPANIES).set(LAST_CUSTOMER_NUMBER,CUSTOMER_NUMBER_PREFIX).where(ID,equal(companyId)).prepare(db).apply(number,prefix).close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_UPDATE_ENTITY, LAST_CUSTOMER_NUMBER); throw databaseException(FAILED_TO_UPDATE_ENTITY, LAST_CUSTOMER_NUMBER).causedBy(e);
} }
} }
} }

View File

@@ -45,7 +45,7 @@ public class SqliteDb extends BaseDb implements ContactDb{
try { try {
db.prepareStatement(sql).execute(); db.prepareStatement(sql).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(ERROR_FAILED_CREATE_TABLE,TABLE_CONTACTS); throw databaseException(ERROR_FAILED_CREATE_TABLE,TABLE_CONTACTS).causedBy(e);
} }
} }
@@ -55,7 +55,7 @@ public class SqliteDb extends BaseDb implements ContactDb{
try { try {
db.prepareStatement(sql).execute(); db.prepareStatement(sql).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(ERROR_FAILED_CREATE_TABLE,TABLE_CONTACTS_USERS); throw databaseException(ERROR_FAILED_CREATE_TABLE,TABLE_CONTACTS_USERS).causedBy(e);
} }
} }
@@ -67,7 +67,7 @@ public class SqliteDb extends BaseDb implements ContactDb{
Query.delete().from(TABLE_CONTACTS_USERS).where(CONTACT_ID,equal(contact.id())).execute(db); Query.delete().from(TABLE_CONTACTS_USERS).where(CONTACT_ID,equal(contact.id())).execute(db);
db.setAutoCommit(true); db.setAutoCommit(true);
} catch (SQLException e){ } catch (SQLException e){
throw databaseException(FAILED_TO_DROP_ENTITY,"contact",contact.id()); throw databaseException(FAILED_TO_DROP_ENTITY,"contact",contact.id()).causedBy(e);
} }
} }
@@ -83,7 +83,7 @@ public class SqliteDb extends BaseDb implements ContactDb{
rs.close(); rs.close();
return contacts; return contacts;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException("Failed to load contacts of user {0}",userId); throw databaseException(FAILED_TO_LOAD_CONTACTS_OF_USER,userId).causedBy(e);
} }
} }
@@ -97,7 +97,7 @@ public class SqliteDb extends BaseDb implements ContactDb{
if (contact != null) return contact; if (contact != null) return contact;
throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID, "contact", contactId); throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID, "contact", contactId);
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_CONTACTS_OF_USER,userId); throw databaseException(FAILED_TO_LOAD_CONTACTS_OF_USER,userId).causedBy(e);
} }
} }
@@ -110,14 +110,14 @@ public class SqliteDb extends BaseDb implements ContactDb{
if (rs.next()) id = rs.getLong(1); if (rs.next()) id = rs.getLong(1);
rs.close(); rs.close();
if (id != null) return new Contact(id,contact.vcard()); if (id != null) return new Contact(id,contact.vcard());
throw databaseException("Failed to store new vcard"); throw databaseException(FAILED_TO_STORE_ENTITY,"vcard");
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException("Failed to store new vcard",e); throw databaseException(FAILED_TO_STORE_ENTITY,"vcard").causedBy(e);
} }
} else try { // update } else try { // update
Query.update(TABLE_CONTACTS).set(DATA).where(ID,equal(contact.id())).prepare(db).apply(contact.vcard()).execute(); Query.update(TABLE_CONTACTS).set(DATA).where(ID,equal(contact.id())).prepare(db).apply(contact.vcard()).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException("Failed to update vcard {0}",contact.id()); throw databaseException(FAILED_TO_UPDATE_ENTITY,"vcard").causedBy(e);
} }
return contact; return contact;
} }
@@ -127,7 +127,7 @@ public class SqliteDb extends BaseDb implements ContactDb{
try { try {
Query.replaceInto(TABLE_CONTACTS_USERS,USER_ID,CONTACT_ID,ASSIGNED).values(userId,contact.id(),false).execute(db).close(); Query.replaceInto(TABLE_CONTACTS_USERS,USER_ID,CONTACT_ID,ASSIGNED).values(userId,contact.id(),false).execute(db).close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException("Failed to assign contact {0} to user {1]",contact.id(),userId); throw databaseException(FAILED_TO_ASSIGN_CONTACT_TO_USER,contact.id(),userId).causedBy(e);
} }
} }
} }

View File

@@ -3,6 +3,8 @@ package de.srsoftware.umbrella.core;
public class Errors { public class Errors {
public static final String FAILED_TO_ASSIGN_USER_TO_COMPANY = "failed_to_assign_user_to_company"; public static final String FAILED_TO_ASSIGN_USER_TO_COMPANY = "failed_to_assign_user_to_company";
public static final String FAILED_TO_ASSIGN_CONTACT_TO_USER = "failed_to_assign_contact_to_user";
public static final String FAILED_TO_CHECK_FILE_PERMISSIONS = "failed_to_check_file_permissions";
public static final String FAILED_TO_CREATE_STATE = "failed_to_create_state"; public static final String FAILED_TO_CREATE_STATE = "failed_to_create_state";
public static final String FAILED_TO_CREATE_TABLE = "failed_to_create_table"; public static final String FAILED_TO_CREATE_TABLE = "failed_to_create_table";
public static final String FAILED_TO_DROP_ENTITY = "failed_to_drop_entity"; public static final String FAILED_TO_DROP_ENTITY = "failed_to_drop_entity";
@@ -12,6 +14,8 @@ public class Errors {
public static final String FAILED_TO_LOAD_COMPANY_MEMBERS = "failed_to_load_company_members"; public static final String FAILED_TO_LOAD_COMPANY_MEMBERS = "failed_to_load_company_members";
public static final String FAILED_TO_LOAD_CONTACTS_OF_USER = "failed_to_load_contacts_of_user"; public static final String FAILED_TO_LOAD_CONTACTS_OF_USER = "failed_to_load_contacts_of_user";
public static final String FAILED_TO_LOAD_CUSTOMER_NUM_SETTINGS = "failed_to_load_customer_number_settings"; public static final String FAILED_TO_LOAD_CUSTOMER_NUM_SETTINGS = "failed_to_load_customer_number_settings";
public static final String FAILED_TO_LOAD_CUSTOMER_PRICE = "failed_to_load_customer_price";
public static final String FAILED_TO_LOAD_CUSTOMER_SETTINGS = "failed_to_load_customer_settings";
public static final String FAILED_TO_LOAD_ENTITY = "failed_to_load_entity"; public static final String FAILED_TO_LOAD_ENTITY = "failed_to_load_entity";
public static final String FAILED_TO_LOAD_ENTITY_BY_ID = "failed_to_load_entity_by_id"; public static final String FAILED_TO_LOAD_ENTITY_BY_ID = "failed_to_load_entity_by_id";
public static final String FAILED_TO_LOAD_PROJECT_MEMBERS = "failed_to_load_project_members"; public static final String FAILED_TO_LOAD_PROJECT_MEMBERS = "failed_to_load_project_members";
@@ -20,6 +24,8 @@ public class Errors {
public static final String FAILED_TO_READ_LAST_DOCID = "failed_to_read_last_docId"; public static final String FAILED_TO_READ_LAST_DOCID = "failed_to_read_last_docId";
public static final String FAILED_TO_SEARCH_DB = "failed_to_search_db"; public static final String FAILED_TO_SEARCH_DB = "failed_to_search_db";
public static final String FAILED_TO_STORE_ENTITY = "failed_to_store_entity"; public static final String FAILED_TO_STORE_ENTITY = "failed_to_store_entity";
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_COLUMN = "failed_to_update_column";
public static final String FAILED_TO_UPDATE_ENTITY = "failed_to_update_entity"; public static final String FAILED_TO_UPDATE_ENTITY = "failed_to_update_entity";
public static final String NO_BOOKMARK_FOR_URLID = "no_bookmark_for_urlid";
} }

View File

@@ -13,6 +13,7 @@ import static de.srsoftware.umbrella.core.Field.TAX;
import static de.srsoftware.umbrella.core.Field.UNIT; import static de.srsoftware.umbrella.core.Field.UNIT;
import static de.srsoftware.umbrella.core.ModuleRegistry.translator; import static de.srsoftware.umbrella.core.ModuleRegistry.translator;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
import static de.srsoftware.umbrella.core.model.Document.DEFAULT_THOUSANDS_SEPARATOR; import static de.srsoftware.umbrella.core.model.Document.DEFAULT_THOUSANDS_SEPARATOR;
import static de.srsoftware.umbrella.core.model.Document.State; import static de.srsoftware.umbrella.core.model.Document.State;
import static de.srsoftware.umbrella.documents.Constants.*; import static de.srsoftware.umbrella.documents.Constants.*;
@@ -48,7 +49,7 @@ public class SqliteDb extends BaseDb implements DocumentDb{
var sql = format("ALTER TABLE {0} ADD COLUMN {1} VARCHAR(255)",TABLE_DOCUMENTS,TEMPLATE); var sql = format("ALTER TABLE {0} ADD COLUMN {1} VARCHAR(255)",TABLE_DOCUMENTS,TEMPLATE);
db.prepareStatement(sql).execute(); db.prepareStatement(sql).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_UPDATE_COLUMN,TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS); throw databaseException(FAILED_TO_UPDATE_COLUMN,TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS).causedBy(e);
} }
} }
@@ -78,7 +79,7 @@ public class SqliteDb extends BaseDb implements DocumentDb{
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PRICES); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PRICES).causedBy(e);
} }
} }
@@ -89,7 +90,7 @@ public class SqliteDb extends BaseDb implements DocumentDb{
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_CUSTOMER_SETTINGS); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_CUSTOMER_SETTINGS).causedBy(e);
} }
} }
@@ -123,7 +124,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_DOCUMENTS); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_DOCUMENTS).causedBy(e);
} }
} }
@@ -140,7 +141,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.values(4,4,TYPE_REMINDER) .values(4,4,TYPE_REMINDER)
.execute(db); .execute(db);
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_DOCUMENT_TYPES); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_DOCUMENT_TYPES).causedBy(e);
} }
} }
@@ -166,7 +167,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_POSITIONS); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_POSITIONS).causedBy(e);
} }
} }
@@ -177,7 +178,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TEMPLATES); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TEMPLATES).causedBy(e);
} }
} }
@@ -193,10 +194,10 @@ CREATE TABLE IF NOT EXISTS {0} (
delete().from(TABLE_DOCUMENTS).where(ID,equal(docId)).execute(db); delete().from(TABLE_DOCUMENTS).where(ID,equal(docId)).execute(db);
db.setAutoCommit(true); db.setAutoCommit(true);
if (number != null) return number; if (number != null) return number;
} catch (SQLException e){
LOG.log(WARNING,"Failed to delete document {0}",docId);
}
throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId); throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId);
} catch (SQLException e){
throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId).causedBy(e);
}
} }
@Override @Override
@@ -213,8 +214,7 @@ CREATE TABLE IF NOT EXISTS {0} (
db.setAutoCommit(true); db.setAutoCommit(true);
return pos; return pos;
} catch (SQLException e) { } catch (SQLException e) {
LOG.log(WARNING,"Failed to delete position {0} of document {1}",pos,docId); throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"position",pos,"document",docId).causedBy(e);
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"position",pos,"document",docId);
} }
} }
@@ -224,7 +224,7 @@ CREATE TABLE IF NOT EXISTS {0} (
var sql = format("ALTER TABLE {0} DROP COLUMN {1}",TABLE_DOCUMENTS,TEMPLATE_ID); var sql = format("ALTER TABLE {0} DROP COLUMN {1}",TABLE_DOCUMENTS,TEMPLATE_ID);
db.prepareStatement(sql).execute(); db.prepareStatement(sql).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_UPDATE_COLUMN,TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS); throw databaseException(FAILED_TO_UPDATE_COLUMN,TEMPLATE_ID,TEMPLATE,TABLE_DOCUMENTS).causedBy(e);
} }
} }
@@ -233,7 +233,7 @@ CREATE TABLE IF NOT EXISTS {0} (
var sql = format("DROP TABLE IF EXISTS {0};",TABLE_TEMPLATES); var sql = format("DROP TABLE IF EXISTS {0};",TABLE_TEMPLATES);
db.prepareStatement(sql).execute(); db.prepareStatement(sql).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY,"table",TABLE_TEMPLATES); throw databaseException(FAILED_TO_DROP_ENTITY,"table",TABLE_TEMPLATES).causedBy(e);
} }
} }
@@ -245,10 +245,10 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) price = rs.getLong(PRICE); if (rs.next()) price = rs.getLong(PRICE);
rs.close(); rs.close();
if (price != null) return price; if (price != null) return price;
throw notFound(FAILED_TO_LOAD_CUSTOMER_PRICE,company,customer,itemCode);
} catch (SQLException e) { } catch (SQLException e) {
LOG.log(WARNING,"Failed to load customer price (company: {0}, customer: {1}, item: {2}",company,customer,itemCode,e); throw databaseException(FAILED_TO_LOAD_CUSTOMER_PRICE,company,customer,itemCode).causedBy(e);
} }
throw new UmbrellaException(500,"Failed to load customer price (company: {0}, customer: {1}, item: {2}",company,customer,itemCode);
} }
@Override @Override
@@ -260,8 +260,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close(); rs.close();
return settings; return settings;
} catch (SQLException e) { } catch (SQLException e) {
LOG.log(WARNING,"Failed to load customer settings (company: {0}, document type: {1})",companyId, docType.name(),e); throw databaseException(FAILED_TO_LOAD_CUSTOMER_SETTINGS,companyId, docType.name()).causedBy(e);
throw new UmbrellaException(500,"Failed to load customer settings (company: {0}, document type: {1})",companyId, docType.name());
} }
} }
@@ -273,10 +272,11 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) type = toType(rs); if (rs.next()) type = toType(rs);
rs.close(); rs.close();
if (type != null) return type; if (type != null) return type;
throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID,"type",typeId);
} catch (SQLException e) { } catch (SQLException e) {
LOG.log(WARNING,"Failed to read document type ({0})!",typeId); throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"type",typeId).causedBy(e);
} }
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"type",typeId);
} }
@Override @Override
@@ -293,7 +293,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close(); rs.close();
return map; return map;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LIST_ENTITIES,"documents"); throw databaseException(FAILED_TO_LIST_ENTITIES,"documents").causedBy(e);
} }
} }
@@ -342,7 +342,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close(); rs.close();
return map; return map;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_SEARCH_DB,"documents"); throw databaseException(FAILED_TO_SEARCH_DB,"documents").causedBy(e);
} }
} }
@@ -369,7 +369,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close(); rs.close();
return map; return map;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LIST_ENTITIES,"documents"); throw databaseException(FAILED_TO_LIST_ENTITIES,"documents").causedBy(e);
} }
} }
@@ -382,7 +382,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close(); rs.close();
return types; return types;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_LIST_ENTITIES,"document types"); throw databaseException(FAILED_TO_LIST_ENTITIES,"document types").causedBy(e);
} }
} }
@@ -410,9 +410,11 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close(); rs.close();
return doc; return doc;
} }
} catch (SQLException ignored) { throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID,"document",docId);
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"document",docId).causedBy(e);
} }
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"document",docId);
} }
private void moveTemplateNames() { private void moveTemplateNames() {
@@ -420,7 +422,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); var sql = format("UPDATE {0} SET template = (SELECT name FROM templates WHERE templates.id = documents.template_id);",TABLE_DOCUMENTS);
db.prepareStatement(sql).execute(); db.prepareStatement(sql).execute();
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_MOVE,"template.names","document.templates"); throw databaseException(FAILED_TO_MOVE,"template.names","document.templates").causedBy(e);
} }
} }
@@ -446,7 +448,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} }
return lastId; return lastId;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_READ_LAST_DOCID); throw databaseException(FAILED_TO_READ_LAST_DOCID).causedBy(e);
} }
} }
@@ -461,7 +463,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db); .execute(db);
return settings; return settings;
} catch (SQLException e){ } catch (SQLException e){
throw new UmbrellaException("Failed to update customer settings"); throw databaseException(FAILED_TO_UPDATE_ENTITY,"customer settings").causedBy(e);
} }
} }
@@ -483,10 +485,10 @@ CREATE TABLE IF NOT EXISTS {0} (
sender.clean(); sender.clean();
custom.clean(); custom.clean();
doc.clean(); doc.clean();
if (newId == null) throw new UmbrellaException(500,"Failed to save new document"); if (newId == null) throw databaseException(FAILED_TO_STORE_ENTITY,"document");
return loadDoc(newId); return loadDoc(newId);
} catch (Exception e) { } catch (Exception e) {
throw new UmbrellaException(500,"Failed to update document ({0}) in database",doc.number()).causedBy(e); throw databaseException(FAILED_TO_UPDATE_ENTITY,"document",doc.number()).causedBy(e);
} }
if (doc.isDirty()) try { if (doc.isDirty()) try {
@@ -503,7 +505,7 @@ CREATE TABLE IF NOT EXISTS {0} (
custom.clean(); custom.clean();
doc.clean(); doc.clean();
} catch (Exception e) { } catch (Exception e) {
throw new UmbrellaException(500,"Failed to update document ({0}) in database",doc.number()).causedBy(e); throw databaseException(FAILED_TO_UPDATE_ENTITY,"document").causedBy(e);
} }
if (doc.positions().isDirty()) try { if (doc.positions().isDirty()) try {
@@ -530,7 +532,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw new UmbrellaException(500,"Failed to save positions of document ({0}) in database",doc.number()).causedBy(e); throw databaseException(FAILED_TO_STORE_ENTITY,"positions of document").causedBy(e);
} }
return doc; return doc;
} }
@@ -545,7 +547,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.close(); .close();
return settings; return settings;
} catch (SQLException e){ } catch (SQLException e){
throw new UmbrellaException(500,"Failed to update customer settings!").causedBy(e); throw databaseException(FAILED_TO_UPDATE_ENTITY,"customer settings").causedBy(e);
} }
} }
@@ -563,7 +565,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.set(PRICE).prepare(db).apply(price).close(); .set(PRICE).prepare(db).apply(price).close();
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw databaseException(FAILED_TO_STORE_ENTITY,"customer_price").causedBy(e);
} }
} }
@@ -576,8 +578,7 @@ CREATE TABLE IF NOT EXISTS {0} (
update(TABLE_POSITIONS).set(POS).where(DOCUMENT_ID,equal(docId)).where(POS,equal(-pair.right())).prepare(db).apply(pair.right()).close(); update(TABLE_POSITIONS).set(POS).where(DOCUMENT_ID,equal(docId)).where(POS,equal(-pair.right())).prepare(db).apply(pair.right()).close();
db.setAutoCommit(true); db.setAutoCommit(true);
} catch (SQLException e) { } catch (SQLException e) {
LOG.log(ERROR,"Failed to switch positions {0} and {1} of document {2}",pair.left(),pair.right(),docId); throw databaseException(FAILED_TO_SWITCH_POSITIONS,pair.left(),pair.right(),docId).causedBy(e);
throw new UmbrellaException(500,"Failed to switch positions {0} and {1} of document {2}",pair.left(),pair.right(),docId).causedBy(e);
} }
return pair; return pair;
} }

View File

@@ -5,6 +5,8 @@ import static de.srsoftware.tools.jdbc.Condition.equal;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.tools.jdbc.Query.select; import static de.srsoftware.tools.jdbc.Query.select;
import static de.srsoftware.umbrella.core.Constants.USER_ID; import static de.srsoftware.umbrella.core.Constants.USER_ID;
import static de.srsoftware.umbrella.core.Errors.FAILED_TO_CHECK_FILE_PERMISSIONS;
import static de.srsoftware.umbrella.core.Errors.FAILED_TO_CREATE_TABLE;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.files.Constants.FILE; import static de.srsoftware.umbrella.files.Constants.FILE;
import static de.srsoftware.umbrella.files.Constants.TABLE_FILE_SHARES; import static de.srsoftware.umbrella.files.Constants.TABLE_FILE_SHARES;
@@ -37,7 +39,7 @@ public class SqliteDb extends BaseDb implements FileDb {
try { try {
db.prepareStatement(format(sql, TABLE_FILE_SHARES,FILE,USER_ID)).execute(); db.prepareStatement(format(sql, TABLE_FILE_SHARES,FILE,USER_ID)).execute();
} catch (SQLException e){ } catch (SQLException e){
throw databaseException(e.getMessage()).causedBy(e); throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_FILE_SHARES).causedBy(e);
} }
} }
@@ -49,7 +51,7 @@ public class SqliteDb extends BaseDb implements FileDb {
rs.close(); rs.close();
return result; return result;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException("Failed to check file permissions"); throw databaseException(FAILED_TO_CHECK_FILE_PERMISSIONS);
} }
} }
} }

View File

@@ -95,7 +95,9 @@
"failed": "fehlgeschlagen", "failed": "fehlgeschlagen",
"failed_login_attempts" : "Account nach {attempts} fehlgeschlagenen Logins gesperrt bis {release_time}", "failed_login_attempts" : "Account nach {attempts} fehlgeschlagenen Logins gesperrt bis {release_time}",
"failed_to_assign_contact_to_user": "Failed to assign contact {0} to user {1]",
"failed_to_assign_user_to_company": "Failed to assign user {0} to company {1}", "failed_to_assign_user_to_company": "Failed to assign user {0} to company {1}",
"failed_to_check_file_permissions": "Failed to check file permissions!",
"failed_to_create_state": "Failed to create custom state!", "failed_to_create_state": "Failed to create custom state!",
"failed_to_create_table": "Failed to create table `{0}`", "failed_to_create_table": "Failed to create table `{0}`",
"failed_to_drop_entity": "Failed to remove {0} {1}", "failed_to_drop_entity": "Failed to remove {0} {1}",
@@ -106,6 +108,8 @@
"failed_to_load_company_members": "Failed to load members of company {0}", "failed_to_load_company_members": "Failed to load members of company {0}",
"failed_to_load_contacts_of_user": "Failed to load contacts of user {0}", "failed_to_load_contacts_of_user": "Failed to load contacts of user {0}",
"failed_to_load_customer_number_settings": "Failed to load customer number settings for company {0}", "failed_to_load_customer_number_settings": "Failed to load customer number settings for company {0}",
"failed_to_load_customer_price": "Failed to load customer price (company: {0}, customer: {1}, item: {2})",
"failed_to_load_customer_settings": "Failed to load customer settings (company: {0}, document type: {1})",
"failed_to_load_entity": "Failed to load {0}", "failed_to_load_entity": "Failed to load {0}",
"failed_to_load_entity_by_id": "Failed to load {0} with id = {1}", "failed_to_load_entity_by_id": "Failed to load {0} with id = {1}",
"failed_to_load_project_members": "Failed to load members of project", "failed_to_load_project_members": "Failed to load members of project",
@@ -115,6 +119,7 @@
"failed_to_remove_user_from_company": "Failed to remove user {0} from company {1}", "failed_to_remove_user_from_company": "Failed to remove user {0} from company {1}",
"failed_to_search_db": "Failed to search in {0} database!", "failed_to_search_db": "Failed to search in {0} database!",
"failed_to_store_entity": "Failed to store {0}", "failed_to_store_entity": "Failed to store {0}",
"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_column": "Failed to update column {0} → {1} of {2}",
"failed_to_update_entity": "Failed to update {0} in database", "failed_to_update_entity": "Failed to update {0} in database",
"family_name": "Familenname", "family_name": "Familenname",