working on backend-side translations
This commit is contained in:
@@ -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.ModuleRegistry.translator;
|
||||
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.State;
|
||||
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);
|
||||
db.prepareStatement(sql).execute();
|
||||
} 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.close();
|
||||
} 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.close();
|
||||
} 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.close();
|
||||
} 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)
|
||||
.execute(db);
|
||||
} 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.close();
|
||||
} 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.close();
|
||||
} 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);
|
||||
db.setAutoCommit(true);
|
||||
if (number != null) return number;
|
||||
throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId);
|
||||
} catch (SQLException e){
|
||||
LOG.log(WARNING,"Failed to delete document {0}",docId);
|
||||
throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId).causedBy(e);
|
||||
}
|
||||
throw databaseException(FAILED_TO_DROP_ENTITY,"document",docId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,8 +214,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
db.setAutoCommit(true);
|
||||
return pos;
|
||||
} 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);
|
||||
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"position",pos,"document",docId).causedBy(e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -224,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,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);
|
||||
db.prepareStatement(sql).execute();
|
||||
} 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);
|
||||
rs.close();
|
||||
if (price != null) return price;
|
||||
throw notFound(FAILED_TO_LOAD_CUSTOMER_PRICE,company,customer,itemCode);
|
||||
} 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
|
||||
@@ -260,8 +260,7 @@ 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());
|
||||
throw databaseException(FAILED_TO_LOAD_CUSTOMER_SETTINGS,companyId, docType.name()).causedBy(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,10 +272,11 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
if (rs.next()) type = toType(rs);
|
||||
rs.close();
|
||||
if (type != null) return type;
|
||||
throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID,"type",typeId);
|
||||
} 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
|
||||
@@ -293,7 +293,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.close();
|
||||
return map;
|
||||
} 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();
|
||||
return map;
|
||||
} 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();
|
||||
return map;
|
||||
} 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();
|
||||
return types;
|
||||
} 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();
|
||||
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() {
|
||||
@@ -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);
|
||||
db.prepareStatement(sql).execute();
|
||||
} 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;
|
||||
} 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);
|
||||
return settings;
|
||||
} 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();
|
||||
custom.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);
|
||||
} 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 {
|
||||
@@ -503,7 +505,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
custom.clean();
|
||||
doc.clean();
|
||||
} 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 {
|
||||
@@ -530,7 +532,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
@@ -545,7 +547,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
.close();
|
||||
return settings;
|
||||
} 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();
|
||||
}
|
||||
} 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();
|
||||
db.setAutoCommit(true);
|
||||
} catch (SQLException e) {
|
||||
LOG.log(ERROR,"Failed to switch positions {0} and {1} of document {2}",pair.left(),pair.right(),docId);
|
||||
throw new UmbrellaException(500,"Failed to switch positions {0} and {1} of document {2}",pair.left(),pair.right(),docId).causedBy(e);
|
||||
throw databaseException(FAILED_TO_SWITCH_POSITIONS,pair.left(),pair.right(),docId).causedBy(e);
|
||||
}
|
||||
return pair;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user