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

@@ -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);
}
}
}