working on backend-side translations

This commit is contained in:
2025-12-15 22:07:26 +01:00
parent a275b5065d
commit c7b5b11f4c
9 changed files with 86 additions and 119 deletions

View File

@@ -124,7 +124,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
rs.close();
return ids;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_COMPANY_MEMBERS,companyId).causedBy(e);
throw databaseException(FAILED_TO_LOAD_ENTITY_MEMBERS,COMPANY,companyId).causedBy(e);
}
}

View File

@@ -6,23 +6,24 @@ public class Errors {
public static final String FAILED_TO_ADD_PROPERTY_TO_ITEM = "failed_to_add_prop_to_item";
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_ENTITY_AVAILABLE = "failed_to_check_entity_available";
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_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_OF_ENTITY = "failed_to_drop_entity_from_entity";
public static final String FAILED_TO_DROP_NOTES = "failed_to_drop_notes";
public static final String FAILED_TO_GET_FREE_ID = "failed_to_get_free_id";
public static final String FAILED_TO_INSERT_PROJECT = "failed_to_insert_project";
public static final String FAILED_TO_LIST_ENTITIES = "failed_to_list_entities";
public static final String FAILED_TO_LOAD_CHILD_LOCATIONS = "failed_to_load_child_locations";
public static final String FAILED_TO_LOAD_COMPANY_MEMBERS = "failed_to_load_company_members";
public static final String FAILED_TO_LOAD_ENTITY_MEMBERS = "failed_to_load_entity_members";
public static final String FAILED_TO_LOAD_ENTITIES_OF_OWNER = "failed_to_load_entities_of_owner";
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_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_USER_COMPANIES = "failed_to_load_user_companies";
public static final String FAILED_TO_LOAD_USER_SETTINGS = "failed_to_load_user_settings";
public static final String FAILED_TO_MOVE = "failed_to_move";

View File

@@ -124,7 +124,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return result;
} catch (SQLException e){
throw databaseException(FAILED_TO_LOAD_PROJECT_MEMBERS).causedBy(e);
throw databaseException(FAILED_TO_LOAD_ENTITY_MEMBERS,PROJECT,project.name()).causedBy(e);
}
}

View File

@@ -9,7 +9,6 @@ import static de.srsoftware.tools.jdbc.Query.Dialect.SQLITE;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
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;
@@ -22,7 +21,6 @@ import de.srsoftware.tools.Tuple;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.bookmarks.BookmarkDb;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.LocalDateTime;

View File

@@ -6,12 +6,13 @@ 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.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
import static de.srsoftware.umbrella.core.model.Status.*;
import static de.srsoftware.umbrella.project.Constants.*;
import static de.srsoftware.umbrella.task.Constants.*;
import static java.lang.System.Logger.Level.*;
import static java.lang.System.Logger.Level.ERROR;
import static java.text.MessageFormat.format;
import de.srsoftware.tools.jdbc.Query;
@@ -55,8 +56,7 @@ public class SqliteDb extends BaseDb implements TaskDb {
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_TASK_DEPENDENCIES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TASK_DEPENDENCIES).causedBy(e);
}
}
@@ -65,7 +65,7 @@ public class SqliteDb extends BaseDb implements TaskDb {
try {
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw databaseException("Failed to add {0} column to {1}",PRIORITY,TABLE_TASKS);
throw databaseException(FAILED_TO_ADD_COLUMN,PRIORITY,TABLE_TASKS).causedBy(e);
}
}
@@ -89,8 +89,7 @@ public class SqliteDb extends BaseDb implements TaskDb {
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_PROJECTS, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PROJECTS).causedBy(e);
}
}
@@ -107,8 +106,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_PROJECT_USERS,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PROJECT_USERS).causedBy(e);
}
}
@@ -123,7 +121,7 @@ CREATE TABLE IF NOT EXISTS {0} (
Query.delete().from(TABLE_TASKS).where(ID,equal(task.id())).execute(db);
Query.delete().from(TABLE_TASKS_USERS).where(TASK_ID,equal(task.id())).execute(db);
} catch (SQLException e) {
throw new UmbrellaException("Failed to delete task");
throw databaseException(FAILED_TO_DROP_ENTITY,"task").causedBy(e);
}
}
@@ -135,7 +133,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.where(USER_ID,equal(userId))
.execute(db);
} catch (SQLException e) {
throw new UmbrellaException("Failed to delete member (userId = {0} from project {1}",userId,projectId);
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,USER_ID,userId,PROJECT,projectId).causedBy(e);
}
}
@@ -158,8 +156,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return tasks;
} catch (SQLException e){
LOG.log(WARNING,"Failed to load tasks for user (user_id: {0}",userId,e);
throw new UmbrellaException("Failed to load tasks for project id");
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,TASKS,USER).causedBy(e);
}
}
@@ -172,7 +169,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return result;
} catch (SQLException e){
throw new UmbrellaException("Faailed to load task members");
throw databaseException(FAILED_TO_LIST_ENTITIES,"task members").causedBy(e);
}
}
@@ -187,7 +184,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return loadDependencies(tasks);
} catch (SQLException e) {
throw databaseException("Failed to load tasks for project ids");
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,TASKS,"project_ids").causedBy(e);
}
}
@@ -207,8 +204,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return loadDependencies(tasks);
} catch (SQLException e){
LOG.log(WARNING,"Failed to load tasks for project (pid: {0}, user_id: {1}",projectId,user.id(),e);
throw databaseException("Failed to load tasks for project id");
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,TASKS,"project "+projectId).causedBy(e);
}
}
@@ -227,8 +223,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return loadDependencies(tasks);
} catch (SQLException e){
LOG.log(WARNING,"Failed to load child tasks (parentTaskId: {0}, user_id: {1}",parentTaskId,user.id(),e);
throw databaseException("Failed to load tasks for project id");
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"child tasks",parentTaskId).causedBy(e);
}
}
@@ -247,7 +242,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return loadDependencies(tasks);
} catch (SQLException e){
throw databaseException("Failed to load tasks for project {0}",projectId);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"project "+projectId).causedBy(e);
}
}
@@ -262,7 +257,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return map;
} catch (SQLException e) {
throw databaseException("Failed to load tasks of user {0}",userId);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"user "+userId).causedBy(e);
}
}
@@ -270,7 +265,7 @@ CREATE TABLE IF NOT EXISTS {0} (
public Task load(long taskId) throws UmbrellaException {
var map = load(List.of(taskId));
var task = map.get(taskId);
if (task == null) throw UmbrellaException.notFound("no_task_for_id",taskId);
if (task == null) throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID,TASK,taskId);
return task;
}
@@ -286,7 +281,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return loadDependencies(map);
} catch (SQLException e) {
throw new UmbrellaException("Failed to load task from database");
throw databaseException(FAILED_TO_LOAD_ENTITY,TASK).causedBy(e);
}
}
@@ -301,7 +296,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return tasks;
} catch (SQLException e) {
throw databaseException("Failed to load task dependencies");
throw databaseException(FAILED_TO_LOAD_ENTITY,"task dependencies").causedBy(e);
}
}
@@ -350,7 +345,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
return task;
} catch (SQLException e){
throw new UmbrellaException("Failed to save task {0}",task.name());
throw databaseException(FAILED_TO_STORE_ENTITY,task.name()).causedBy(e);
}
}
@@ -359,7 +354,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
replaceInto(TABLE_TASKS_USERS,TASK_ID,USER_ID,PERMISSIONS).values(taskId,userId,permission.code()).execute(db).close();
} catch (SQLException e) {
throw new UmbrellaException("Failed to store permissions");
throw databaseException(FAILED_TO_STORE_ENTITY,PERMISSIONS).causedBy(e);
}
}
}

View File

@@ -5,10 +5,10 @@ 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.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.model.Time.State.Complete;
import static de.srsoftware.umbrella.time.Constants.*;
import static java.lang.System.Logger.Level.ERROR;
import static java.text.MessageFormat.format;
import de.srsoftware.tools.jdbc.Query;
@@ -50,8 +50,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_TASK_TIMES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TASK_TIMES).causedBy(e);
}
}
@@ -72,8 +71,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_TIMES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TIMES).causedBy(e);
}
}
@@ -86,7 +84,7 @@ CREATE TABLE IF NOT EXISTS {0} (
db.setAutoCommit(false);
return timeId;
} catch (SQLException e) {
throw databaseException("Failed to delete time with id = {0}",timeId);
throw databaseException(FAILED_TO_DROP_ENTITY,"time "+timeId).causedBy(e);
}
}
@@ -108,7 +106,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return times;
} catch (Exception e) {
throw new UmbrellaException("Failed to search for times");
throw databaseException(FAILED_TO_SEARCH_DB,TABLE_TIMES).causedBy(e);
}
}
@@ -135,8 +133,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return times;
} catch (Exception e) {
throw new UmbrellaException("Failed to load times for task list");
throw databaseException(FAILED_TO_LIST_ENTITIES,TIMES).causedBy(e);
}
}
@@ -160,7 +157,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return times;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load times for task list");
throw databaseException(FAILED_TO_LIST_ENTITIES,TIMES).causedBy(e);
}
}
@@ -178,7 +175,7 @@ CREATE TABLE IF NOT EXISTS {0} (
if (time == null) throw UmbrellaException.notFound("No time found with id = {0}",timeId);
return time;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load times for task list");
throw databaseException(FAILED_TO_LIST_ENTITIES,TIMES).causedBy(e);
}
}
@@ -202,8 +199,7 @@ CREATE TABLE IF NOT EXISTS {0} (
query.execute(db).close();
return track;
} catch (SQLException e){
LOG.log(ERROR,"Failed to write time to DB",e);
throw databaseException("Failed to write time to DB");
throw databaseException(FAILED_TO_STORE_ENTITY,"time").causedBy(e);
}
}
@@ -217,7 +213,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.apply(timeState.code())
.close();
} catch (SQLException e) {
throw databaseException("Failed to update state of several times");
throw databaseException(FAILED_TO_UPDATE_ENTITY,TIMES).causedBy(e);
}
}
}

View File

@@ -99,17 +99,19 @@
"failed_to_add_prop_to_item": "Failed to add new property to item {0}",
"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_check_entity_available": "Failed to check availability of {0}",
"failed_to_check_file_permissions": "Failed to check file permissions!",
"failed_to_create_state": "Failed to create custom state!",
"failed_to_create_table": "Failed to create table `{0}`",
"failed_to_drop_entity": "Failed to remove {0} {1}",
"failed_to_drop_entity_from_entity": "Failed to remove {0} {1} from {2} {3}",
"failed_to_drop_notes": "Failed to delete notes of ({0} {1})",
"failed_to_get_free_id": "Failed to query free ID",
"failed_to_insert_project": "Failed to insert project into database",
"failed_to_list_entities": "Failed to list {0}",
"failed_to_load_child_locations": "Failed to load child locations for {0}",
"failed_to_load_companies": "Could not load company {0}",
"failed_to_load_company_members": "Failed to load members of company {0}",
"failed_to_load_entity_members": "Failed to load members of {0} {1}",
"failed_to_load_entities_of_owner": "Failed to load {0} of {1}",
"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})",

View File

@@ -5,6 +5,8 @@ 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.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.user.Constants.*;
import static de.srsoftware.umbrella.user.model.DbUser.ADMIN_PERMISSIONS;
import static java.lang.System.Logger.Level.*;
@@ -53,8 +55,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_LOGIN_SERVICES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_LOGIN_SERVICES).causedBy(e);
}
createTable = """
@@ -67,8 +68,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_SERVICE_IDS_USERS,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_SERVICE_IDS_USERS).causedBy(e);
}
createTable = """
@@ -81,8 +81,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TOKEN_USES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TOKEN_USES).causedBy(e);
}
}
@@ -110,8 +109,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed to create column {1} in {0}",TABLE_USERS, LANGUAGE,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_ADD_COLUMN,LANGUAGE,TABLE_USERS).causedBy(e);
}
}
@@ -157,8 +155,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
if (count<1) insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
} catch (SQLException e) {
LOG.log(ERROR,"Failed to create first user");
throw new RuntimeException(e);
throw databaseException(FAILED_TO_STORE_ENTITY,"first user");
}
createTable = """
@@ -172,8 +169,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_USERS,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_USERS).causedBy(e);
}
}
@@ -182,8 +178,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
Query.delete().from(TABLE_USERS).where(ID,equal(userId)).execute(db);
} catch (SQLException e) {
LOG.log(WARNING,"Failed to delete user with id = {0}!",userId,e);
throw new UmbrellaException(500,"Failed to delete user with id = {0}!",userId).causedBy(e);
throw databaseException(FAILED_TO_DROP_ENTITY,"user "+userId).causedBy(e);
}
return userId;
}
@@ -194,8 +189,7 @@ CREATE TABLE IF NOT EXISTS {0} (
Query.delete().from(TABLE_LOGIN_SERVICES).where(NAME,equal(serviceName)).execute(db);
Query.delete().from(TABLE_SERVICE_IDS_USERS).where(SERVICE_ID,like(serviceName+":%")).execute(db);
} catch (SQLException e) {
LOG.log(WARNING,"Failed to delete login service {0}!",serviceName,e);
throw new UmbrellaException(500,"Failed to delete login service {0}!",serviceName).causedBy(e);
throw databaseException(FAILED_TO_DROP_ENTITY,serviceName).causedBy(e);
}
return serviceName;
}
@@ -220,7 +214,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
return Query.delete().from(TABLE_TOKENS).where(TOKEN, equal(token)).execute(db);
} catch (SQLException e){
throw new UmbrellaException(500,"Failed to drop session token").causedBy(e);
throw databaseException(FAILED_TO_DROP_ENTITY,"session token").causedBy(e);
}
}
@@ -232,8 +226,7 @@ CREATE TABLE IF NOT EXISTS {0} (
LOG.log(DEBUG,"Extended session of user {0} until {1}",session.user().name(),then());
return session.extended(newExpiration);
} catch (SQLException e) {
LOG.log(WARNING,"Failed to extend session {0}",session.token());
throw new UmbrellaException(500,"Failed to extend session {0}",session.token()).causedBy(e);
throw databaseException(FAILED_TO_UPDATE_ENTITY,session.token()).causedBy(e);
}
}
@@ -252,8 +245,7 @@ CREATE TABLE IF NOT EXISTS {0} (
insertInto(TABLE_TOKENS, USER_ID, TOKEN, EXPIRATION).values(session.user().id(),session.token(),session.expiration().getEpochSecond()).execute(db);
return session;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to request session for \"{0}\" from database",user.name());
throw new UmbrellaException(500,"Failed to request session for \"{0}\" from database",user.name()).causedBy(e);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"session",user.name()).causedBy(e);
}
}
@@ -267,7 +259,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException sqle){
LOG.log(WARNING,"Failed to load user_id for '{0}' @ '{1}'!",foreignUserId,loginService);
}
if (userId == null) throw new UmbrellaException(500,"Failed to load user_id for \"{0}\" @ \"{1}\"!",foreignUserId,loginService);
if (userId == null) throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,foreignUserId,loginService);
return userId;
}
@@ -286,8 +278,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
rs.close();
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user list from database!",e);
throw new UmbrellaException(500,"Failed to load user list from database!").causedBy(e);
throw databaseException(FAILED_TO_LIST_ENTITIES,USERS).causedBy(e);
}
return list;
}
@@ -301,8 +292,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return list;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to fetch {0} for user {1}",TABLE_SERVICE_IDS_USERS,userId,e);
throw new UmbrellaException(500,"Failed to fetch {0} for user {1}",TABLE_SERVICE_IDS_USERS,userId).causedBy(e);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"service ids","user "+userId).causedBy(e);
}
}
@@ -314,8 +304,7 @@ CREATE TABLE IF NOT EXISTS {0} (
while (rs.next()) list.add(toLoginService(rs));
rs.close();
} catch (SQLException e){
LOG.log(WARNING,"Failed to load login service list from database!",e);
throw new UmbrellaException(500,"Failed to load login service list from database!");
throw databaseException(FAILED_TO_LIST_ENTITIES,TABLE_LOGIN_SERVICES).causedBy(e);
}
return list;
}
@@ -328,7 +317,7 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) loginService = toLoginService(rs);
rs.close();
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load login service \"{0}\"!",name);
throw databaseException(FAILED_TO_LOAD_ENTITY,"login service").causedBy(e);
}
if (loginService == null) throw new UmbrellaException(500,"Failed to load login service \"{0}\"!",name);
return loginService;
@@ -345,7 +334,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user for \"{0}\"!",email);
}
if (user == null) throw new UmbrellaException(500,"Failed to load user for \"{0}\"!",email);
if (user == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,USER,email);
return user;
}
@@ -360,7 +349,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user \"{0}\"!",id);
}
if (user == null) throw new UmbrellaException(500,"Failed to load user \"{0}\"!",id);
if (user == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,USER,id);
return user;
}
@@ -375,7 +364,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user for session {0}!",session.token());
}
if (user == null) throw new UmbrellaException(500,"Failed to load user for session {0}!",session.token());
if (user == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,USER,session.token());
return user;
}
@@ -401,7 +390,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user \"{0}\"!",key,e);
}
if (user == null) throw new UmbrellaException(HTTP_UNAUTHORIZED,"Failed to load user \"{0}\"!",key);
if (user == null) throw new UmbrellaException(HTTP_UNAUTHORIZED,FAILED_TO_LOAD_ENTITY_BY_ID,USER,key);
return user;
}
@@ -418,7 +407,7 @@ CREATE TABLE IF NOT EXISTS {0} (
LOG.log(WARNING,"Failed to request session ({0}) from database",token);
throw new UmbrellaException(500,"Failed to request session ({0}) from database",token);
}
if (session == null) throw new UmbrellaException(500,"Failed to request session ({0}) from database",token);
if (session == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"session",token);
return session;
}
@@ -431,8 +420,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
insertInto(TABLE_SERVICE_IDS_USERS, SERVICE_ID, USER_ID).values(assignment.loginService()+":"+assignment.foreingId(),assignment.userId()).execute(db).close();
} catch (SQLException e) {
LOG.log(WARNING,"Failed to insert assignment into table {0}!",TABLE_SERVICE_IDS_USERS,e);
throw new UmbrellaException(500,"Failed to insert assignment into table {0}!",TABLE_SERVICE_IDS_USERS).causedBy(e);
throw databaseException(FAILED_TO_STORE_ENTITY,"user assignment").causedBy(e);
}
return assignment;
}
@@ -446,9 +434,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db)
.close();
} catch (SQLException e){
LOG.log(WARNING,"Failed to store login service data for {0}!",service.name(),e);
throw new UmbrellaException(500,"Failed to store login service for {0}!",service.name()).causedBy(e);
throw databaseException(FAILED_TO_STORE_ENTITY,"login service data").causedBy(e);
}
return service;
}
@@ -470,8 +456,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.close();
}
} catch (SQLException e) {
LOG.log(WARNING,"Failed to store user data for {0}!",user.name(),e);
throw new UmbrellaException(500,"Failed to store user data for {0}!",user.name()).causedBy(e);
throw databaseException(FAILED_TO_STORE_ENTITY,"user data").causedBy(e);
}
return user;
}
@@ -488,7 +473,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return users;
} catch (SQLException e){
throw new UmbrellaException("Failed to search for user by key = {0}",key);
throw databaseException(FAILED_TO_SEARCH_DB,USERS).causedBy(e);
}
}
@@ -539,8 +524,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db);
return assignment;
} catch (SQLException e) {
LOG.log(WARNING,"Failed to drop foreign login assignment: {0} - {1}",assignment.loginService(),assignment.foreingId(),e);
throw new UmbrellaException(500,"Failed to drop foreign login assignment: {0} - {1}",assignment.loginService(),assignment.foreingId()).causedBy(e);
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"foreign id",assignment.foreingId(),"service",assignment.loginService()).causedBy(e);
}
}
}

View File

@@ -6,7 +6,7 @@ import static de.srsoftware.tools.jdbc.Condition.like;
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.Constants.ERROR_FAILED_CREATE_TABLE;
import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.ModuleRegistry.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
@@ -85,8 +85,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, newPages, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,newPages).causedBy(e);
}
}
@@ -97,8 +96,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_PAGES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PAGES).causedBy(e);
}
}
@@ -109,8 +107,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_PAGES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_PAGES_USERS).causedBy(e);
}
}
@@ -120,7 +117,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
delete().from(TABLE_PAGES).where(ID,equal(page.id())).where(VERSION,equal(page.version())).execute(db);
return page;
} catch (SQLException e) {
throw databaseException("Failed to delete page version!");
throw databaseException(FAILED_TO_DROP_ENTITY,"page version").causedBy(e);
}
}
@@ -128,14 +125,12 @@ public class SqliteDb extends BaseDb implements WikiDb {
try {
db.prepareStatement(format("DROP TABLE {0}",TABLE_PAGES)).execute();
} catch (SQLException e) {
LOG.log(ERROR, "Failed to drop table {0}", TABLE_PAGES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_DROP_ENTITY,TABLE_PAGES).causedBy(e);
}
try {
db.prepareStatement(format("DROP TABLE {0}",TABLE_PAGES_USERS)).execute();
} catch (SQLException e) {
LOG.log(ERROR, "Failed to drop table {0}", TABLE_PAGES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_DROP_ENTITY,TABLE_PAGES_USERS).causedBy(e);
}
}
@@ -148,7 +143,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
rs.close();
return id+1;
} catch (SQLException e) {
throw databaseException("Failed to query next free page id!");
throw databaseException(FAILED_TO_GET_FREE_ID).causedBy(e);
}
}
@@ -166,7 +161,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
rs.close();
return map;
} catch (SQLException e) {
throw databaseException("Failed to search \"{0}\" in wiki pages",String.join(" "+keys));
throw databaseException(FAILED_TO_SEARCH_DB,"wiki pages").causedBy(e);
}
}
@@ -180,7 +175,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
rs.close();
return count < 1;
} catch (SQLException e) {
throw databaseException("Failed to query availability of {0}!",title);
throw databaseException(FAILED_TO_CHECK_ENTITY_AVAILABLE,title).causedBy(e);
}
}
@@ -193,7 +188,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
rs.close();
return set;
} catch (SQLException e) {
throw databaseException("Failed to list wiki articles for user {0}",userId);
throw databaseException(FAILED_TO_LIST_ENTITIES,"wiki pages").causedBy(e);
}
}
@@ -214,7 +209,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
} catch (NumberFormatException ignored){
// title is not an id, go on…
} catch (SQLException e) {
throw databaseException("Failed to load wiki page \"{0}\" from database!",title);
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"wiki page",title).causedBy(e);
}
if (page == null) try { // page was not loaded by ID
var query = select(ALL).from(TABLE_PAGES).where(TITLE, equal(title));
@@ -227,9 +222,9 @@ public class SqliteDb extends BaseDb implements WikiDb {
if (rs.next()) page = WikiPage.of(rs);
rs.close();
} catch (SQLException e) {
throw databaseException("Failed to load wiki page \"{0}\" from database!",title);
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"wiki page",title).causedBy(e);
}
if (page == null) throw notFound("Failed to load wiki page \"{0}\" from database!",title);
if (page == null) throw notFound(FAILED_TO_LOAD_ENTITY_BY_ID,"wiki page",title);
try {
var rs = select(VERSION).from(TABLE_PAGES).where(ID, equal(page.id())).sort(VERSION).exec(db);
var versions = page.versions();
@@ -237,7 +232,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
rs.close();
return page;
} catch (SQLException e) {
throw databaseException("Failed to load wiki page \"{0}\" from database!",title);
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"wiki page",title).causedBy(e);
}
}
@@ -253,7 +248,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
rs.close();
return map;
} catch (SQLException e) {
throw databaseException("Failed to load members of \"{0}\" from database!",page.title());
throw databaseException(FAILED_TO_LOAD_ENTITY_MEMBERS,"wiki page",page.title()).causedBy(e);
}
}
@@ -261,14 +256,12 @@ public class SqliteDb extends BaseDb implements WikiDb {
try {
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}",newPages,TABLE_PAGES)).execute();
} catch (SQLException e) {
LOG.log(ERROR, "Failed to rename table {0} → {1}", newPages, TABLE_PAGES, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_UPDATE_TABLE,format("{0} → {1}", newPages, TABLE_PAGES)).causedBy(e);
}
try {
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}",newUsers,TABLE_PAGES_USERS)).execute();
} catch (SQLException e) {
LOG.log(ERROR, "Failed to rename table {0} → {1}", newUsers, TABLE_PAGES_USERS, e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_UPDATE_TABLE,format("{0} → {1}", newPages, TABLE_PAGES_USERS)).causedBy(e);
}
}
@@ -292,7 +285,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
}
return page;
} catch (SQLException e) {
throw databaseException("Failed to write wiki page \"{0}\" to database",page.title(),e);
throw databaseException(FAILED_TO_STORE_ENTITY,page.title()).causedBy(e);
}
}
@@ -334,9 +327,7 @@ public class SqliteDb extends BaseDb implements WikiDb {
}
rs.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed to transfer entries from {0} → {0}_new!",TABLE_PAGES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_MOVE,TABLE_PAGES,TABLE_PAGES+"_new").causedBy(e);
}
var notes = noteService();
var tags = tagService();