overhauling constants, working on translations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-15 13:58:50 +01:00
parent 669853352e
commit 0d1cdd35d1
103 changed files with 2161 additions and 1207 deletions

View File

@@ -2,12 +2,11 @@
package de.srsoftware.umbrella.notes;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.FULLTEXT;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.Paths.SEARCH;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
import static de.srsoftware.umbrella.core.Util.mapValues;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.constants.Path.SEARCH;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.notes.Constants.CONFIG_DATABASE;
@@ -34,7 +33,7 @@ public class NoteModule extends BaseHandler implements NoteService {
public NoteModule(Configuration config) {
super();
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingField(CONFIG_DATABASE));
notesDb = new SqliteDb(connect(dbFile));
ModuleRegistry.add(this);
}
@@ -122,7 +121,7 @@ public class NoteModule extends BaseHandler implements NoteService {
var head = path.pop();
long noteId = Long.parseLong(head);
String text = body(ex);
if (text.isBlank()) throw missingFieldException("Note text");
if (text.isBlank()) throw missingField("Note text");
var note = notesDb.load(noteId);
if (note.authorId() != user.get().id()) throw forbidden("You are not allowed to edit notes of another user!");
note = new Note(note.id(),note.module(),note.entityId(),note.authorId(),text,LocalDateTime.now());
@@ -146,9 +145,9 @@ public class NoteModule extends BaseHandler implements NoteService {
if (SEARCH.equals(module)) return postSearch(ex,user.get());
if (module == null) throw unprocessable("Module missing in path.");
var entityId = path.pop();
if (entityId == null || entityId.isBlank()) throw missingFieldException(ENTITY_ID);
if (entityId == null || entityId.isBlank()) throw missingField(ENTITY_ID);
String text = body(ex);
if (text.isBlank()) throw missingFieldException("Note text");
if (text.isBlank()) throw missingField("Note text");
var note = new Note(0,module,entityId,user.get().id(),text, LocalDateTime.now());
note = save(note);
return sendContent(ex, note);
@@ -170,7 +169,7 @@ public class NoteModule extends BaseHandler implements NoteService {
private boolean postSearch(HttpExchange ex, UmbrellaUser user) throws IOException {
var json = json(ex);
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY);
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingField(KEY);
var keys = Arrays.asList(key.split(" "));
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
var notes = notesDb.find(user.id(),keys,fulltext);

View File

@@ -5,9 +5,12 @@ import static de.srsoftware.tools.jdbc.Condition.equal;
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.Errors.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.constants.Text.NOTE;
import static de.srsoftware.umbrella.core.constants.Text.NOTE_WITH_ID;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.core.model.Translatable.t;
import static de.srsoftware.umbrella.notes.Constants.*;
import static java.lang.System.Logger.Level.*;
import static java.text.MessageFormat.format;
@@ -15,6 +18,7 @@ import static java.time.ZoneOffset.UTC;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.constants.Text;
import de.srsoftware.umbrella.core.model.Note;
import java.sql.Connection;
import java.sql.SQLException;
@@ -55,7 +59,7 @@ ADD COLUMN entity_id VARCHAR(255);
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_UPDATE_COLUMN,"(not existing)",ENTITY_ID,TABLE_NOTES).causedBy(e);
throw databaseException(FAILED_TO_UPDATE_COLUMN,"old","(not existing)","new", ENTITY_ID, TABLE,TABLE_NOTES).causedBy(e);
}
}
@@ -69,7 +73,7 @@ ADD COLUMN module VARCHAR(20);
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_UPDATE_COLUMN,"(not existing)",MODULE,TABLE_NOTES).causedBy(e);
throw databaseException(FAILED_TO_UPDATE_COLUMN,"old","(not existing)","new", MODULE, TABLE,TABLE_NOTES).causedBy(e);
}
}
@@ -84,7 +88,7 @@ SET module = SUBSTR(uri, 1, INSTR(uri, ':') - 1),
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException("Failed to fill \"{0}\" and \"{1}\" columns",MODULE,ENTITY_ID).causedBy(e);
throw databaseException("Failed to fill \"{a}\" and \"{b}\" columns","a", MODULE,"b", ENTITY_ID).causedBy(e);
}
}
@@ -101,7 +105,7 @@ CREATE TABLE IF NOT EXISTS notes (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_NOTES).causedBy(e);
throw failedToCreateTable(TABLE_NOTES).causedBy(e);
}
}
@@ -120,7 +124,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_NOTES).causedBy(e);
throw failedToCreateTable(TABLE_NOTES).causedBy(e);
}
}
@@ -132,7 +136,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
.execute(db);
return noteId;
} catch (SQLException e){
throw databaseException(FAILED_TO_DROP_ENTITY,"note",noteId);
throw failedToDropObject(t(NOTE_WITH_ID, ID,noteId)).causedBy(e);
}
}
@@ -143,7 +147,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
.where(MODULE,equal(module)).where(ENTITY_ID,equal(entityId))
.execute(db);
} catch (SQLException e){
throw databaseException(FAILED_TO_DROP_NOTES,module,entityId).causedBy(e);
throw databaseException(FAILED_TO_DROP_NOTES,MODULE,module, ID,entityId).causedBy(e);
}
}
@@ -154,7 +158,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY,"uri","column").causedBy(e);
throw databaseException(FAILED_TO_DROP_OBJECT, t("uri column")).causedBy(e);
}
}
@@ -172,7 +176,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return notes;
} catch (SQLException e) {
throw databaseException(FAILED_TO_SEARCH_DB,TABLE_NOTES).causedBy(e);
throw failedToSearchDb(t(TABLE_NOTES)).causedBy(e);
}
}
@@ -181,7 +185,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
try {
var notes = new HashMap<Long, Note>();
var rs = select(ALL).from(TABLE_NOTES).where(USER_ID,equal(authorId))
.sort(format("{0} DESC",ID)).skip(offset).limit(limit).exec(db);
.sort(format("{0} DESC", ID)).skip(offset).limit(limit).exec(db);
while (rs.next()) {
var note = Note.of(rs);
notes.put(note.id(),note);
@@ -189,7 +193,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return notes;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,TABLE_NOTES).causedBy(e);
throw failedToLoadObject(TABLE_NOTES).causedBy(e);
}
}
@@ -207,7 +211,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return notes;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,TABLE_NOTES).causedBy(e);
throw failedToLoadObject(TABLE_NOTES).causedBy(e);
}
}
@@ -220,7 +224,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return note;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"note",noteId).causedBy(e);
throw failedToLoadObject(t(Text.NOTE),noteId).causedBy(e);
}
}
@@ -244,7 +248,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
return note;
} catch (SQLException e){
throw databaseException(FAILED_TO_STORE_ENTITY,"note").causedBy(e);
throw failedToStoreObject(t(Text.NOTE)).causedBy(e);
}
}
@@ -254,7 +258,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
update(TABLE_NOTES).set(ENTITY_ID).where(MODULE,equal(module)).where(ENTITY_ID,equal(oldId)).prepare(db).apply(newId).close();
LOG.log(DEBUG,"Updated note @ {0}.{1} → {0}.{2}",module,oldId,newId);
} catch (SQLException e) {
throw databaseException("Failed to update {0}.{1} → {0}.{2}",module,oldId,newId).causedBy(e);
throw databaseException("Failed to update {module}.{a} → {module}.{b}", MODULE,module,"a",oldId,"b",newId).causedBy(e);
}
}
}