implemented loading and display of journal.

Nächste Schritte:

der Hinweis "you can view/edit xxx at https://…" sollte zwar in der Mail auftauchen, nicht aber im Journal – hier muss also nochmal nachgearbeitet werden

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-07-31 09:20:55 +02:00
parent 6fe8cb4b1d
commit b0096ad5f4
11 changed files with 58 additions and 42 deletions
@@ -1,21 +1,23 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.messagebus.events; package de.srsoftware.umbrella.messagebus.events;
import de.srsoftware.tools.Mappable; import static de.srsoftware.umbrella.core.Util.mapMarkdown;
import de.srsoftware.umbrella.core.constants.Field; import static de.srsoftware.umbrella.core.constants.Field.*;
import de.srsoftware.umbrella.core.model.ObjectWithId; import static java.time.ZoneOffset.UTC;
import de.srsoftware.umbrella.core.model.ObjectWithId;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Map; import java.util.Map;
import static de.srsoftware.umbrella.core.constants.Field.*;
public class JournalEntry extends ObjectWithId { public class JournalEntry extends ObjectWithId {
long timestamp, userId, entityId; LocalDateTime timestamp;
long userId, entityId;
String action, description, module; String action, description, module;
public JournalEntry(long id, long timestamp, long userId, String module, long entityId, String action, String description){ public JournalEntry(long id, LocalDateTime timestamp, long userId, String module, long entityId, String action, String description){
super(id); super(id);
this.timestamp = timestamp; this.timestamp = timestamp;
this.userId = userId; this.userId = userId;
@@ -26,7 +28,7 @@ public class JournalEntry extends ObjectWithId {
} }
public static JournalEntry of(ResultSet rs) throws SQLException { public static JournalEntry of(ResultSet rs) throws SQLException {
var id = rs.getLong(ID); var id = rs.getLong(ID);
var timestamp = rs.getLong(TIMESTAMP); var timestamp = LocalDateTime.ofEpochSecond(rs.getLong(TIMESTAMP),0, UTC);
var userId = rs.getLong(USER_ID); var userId = rs.getLong(USER_ID);
var module = rs.getString(MODULE); var module = rs.getString(MODULE);
var entityId = rs.getLong(ENTITY_ID); var entityId = rs.getLong(ENTITY_ID);
@@ -36,6 +38,10 @@ public class JournalEntry extends ObjectWithId {
return new JournalEntry(id, timestamp, userId, module, entityId, action, description); return new JournalEntry(id, timestamp, userId, module, entityId, action, description);
} }
public long userId(){
return userId;
}
@Override @Override
public Map<String, Object> toMap() { public Map<String, Object> toMap() {
return map( return map(
@@ -44,7 +50,7 @@ public class JournalEntry extends ObjectWithId {
MODULE, module, MODULE, module,
ENTITY_ID, entityId, ENTITY_ID, entityId,
ACTION, action, ACTION, action,
DESCRIPTION, description DESCRIPTION, mapMarkdown(description)
); );
} }
} }
@@ -10,9 +10,6 @@ import static de.srsoftware.umbrella.messagebus.events.Event.EventType.MEMBER_AD
import de.srsoftware.umbrella.core.constants.Field; import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.model.*; import de.srsoftware.umbrella.core.model.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -83,6 +83,8 @@ public class Field {
public static final String ITEM = "item"; public static final String ITEM = "item";
public static final String ITEM_CODE = "item_code"; public static final String ITEM_CODE = "item_code";
public static final String JOURNAL = "journal";
public static final String KEY = "key"; public static final String KEY = "key";
public static final String LANGUAGE = "language"; public static final String LANGUAGE = "language";
@@ -1,8 +1,8 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model; package de.srsoftware.umbrella.core.model;
import de.srsoftware.tools.Mappable; import de.srsoftware.tools.Mappable;
import de.srsoftware.umbrella.core.constants.Field; import de.srsoftware.umbrella.core.constants.Field;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -3,7 +3,6 @@ package de.srsoftware.umbrella.core.model;
import static java.text.MessageFormat.format; import static java.text.MessageFormat.format;
import de.srsoftware.tools.Mappable;
import de.srsoftware.umbrella.core.constants.Field; import de.srsoftware.umbrella.core.constants.Field;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
+15 -1
View File
@@ -4,14 +4,28 @@
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
let { module, entityId } = $props(); let { module, entityId } = $props();
let data = $state({journal:[]});
async function loadJournal(){ async function loadJournal(){
const url = api(`journal/${module}/${entityId}`); const url = api(`journal/${module}/${entityId}`);
const res = await get(url); const res = await get(url);
if (res.ok) { if (res.ok) {
data = await res.json();
} else error(res); } else error(res);
} }
$effect(loadJournal); $effect(loadJournal);
</script> </script>
... <ul>
{#each data.journal as entry (entry.id)}
<li>
<span class="date">{entry.timestamp.replace('T',' ')}</span>
<span class="actor">{data.user_list[entry.user_id].name}</span>:
<span class="action">{t(entry.action)}</span>
<div>
{@html entry.description.rendered}
</div>
</li>
{/each}
</ul>
+5 -4
View File
@@ -364,14 +364,15 @@
{/if} {/if}
</div> </div>
<h3>{t('Journal')}</h3>
<div>
<Journal module="task" entityId={id} />
</div>
<h3>{t('notes')}</h3> <h3>{t('notes')}</h3>
<div> <div>
<Notes module="task" entity_id={id} /> <Notes module="task" entity_id={id} />
</div> </div>
<h3>{t('Journal')}</h3>
<div>
<Journal module="task" entityId={id} />
</div>
</div> </div>
{/if} {/if}
@@ -1,15 +1,12 @@
/* © SRSoftware 2025 */ /* © SRSoftware 2025 */
package de.srsoftware.umbrella.journal; package de.srsoftware.umbrella.journal;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import de.srsoftware.umbrella.messagebus.events.Event; import de.srsoftware.umbrella.messagebus.events.Event;
import de.srsoftware.umbrella.messagebus.events.JournalEntry; import de.srsoftware.umbrella.messagebus.events.JournalEntry;
import java.util.HashMap;
import java.util.List; import java.util.List;
public interface JournalDb { public interface JournalDb {
void logEvent(Event<?> event); void logEvent(Event<?> event);
List<JournalEntry> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader); List<JournalEntry> list(String module, long entityId);
} }
@@ -3,8 +3,6 @@ package de.srsoftware.umbrella.journal;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.constants.Path.PARENT_CANDIDATES;
import static de.srsoftware.umbrella.core.constants.Path.TAGGED;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingField; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingField;
import static de.srsoftware.umbrella.journal.Constants.CONFIG_DATABASE; import static de.srsoftware.umbrella.journal.Constants.CONFIG_DATABASE;
@@ -21,12 +19,12 @@ import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.constants.Text; import de.srsoftware.umbrella.core.constants.Text;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Token; import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import de.srsoftware.umbrella.messagebus.EventListener; import de.srsoftware.umbrella.messagebus.EventListener;
import de.srsoftware.umbrella.messagebus.events.Event; import de.srsoftware.umbrella.messagebus.events.Event;
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
@@ -55,8 +53,14 @@ public class JournalModule extends BaseHandler implements EventListener {
if (head == null) throw missingField(Field.ENTITY_ID); if (head == null) throw missingField(Field.ENTITY_ID);
try { try {
var entityId = Long.parseLong(head); var entityId = Long.parseLong(head);
var entries = journalDb.list(module, entityId, userService().loader()); var entries = journalDb.list(module, entityId);
return sendContent(ex,entries); // TODO: map entries var loader = userService().loader();
var userMap = new HashMap<Long,Object>();
for (var entry : entries) userMap.put(entry.userId(),loader.get(entry.userId()).toMap());
return sendContent(ex,Map.of(
Field.USER_LIST,userMap,
Field.JOURNAL,entries.stream().map(JournalEntry::toMap).toList()
));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw invalidField(Field.ENTITY_ID, Text.NUMBER); throw invalidField(Field.ENTITY_ID, Text.NUMBER);
} }
@@ -1,7 +1,6 @@
/* © SRSoftware 2025 */ /* © SRSoftware 2025 */
package de.srsoftware.umbrella.journal; package de.srsoftware.umbrella.journal;
import static de.srsoftware.tools.NotImplemented.notImplemented;
import static de.srsoftware.tools.jdbc.Condition.equal; 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.insertInto; import static de.srsoftware.tools.jdbc.Query.insertInto;
@@ -13,20 +12,14 @@ import static de.srsoftware.umbrella.journal.Constants.TABLE_JOURNAL;
import static java.text.MessageFormat.format; import static java.text.MessageFormat.format;
import de.srsoftware.umbrella.core.BaseDb; import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.constants.Module;
import de.srsoftware.umbrella.core.constants.Text; import de.srsoftware.umbrella.core.constants.Text;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import de.srsoftware.umbrella.messagebus.events.Event; import de.srsoftware.umbrella.messagebus.events.Event;
import de.srsoftware.umbrella.messagebus.events.JournalEntry; import de.srsoftware.umbrella.messagebus.events.JournalEntry;
import de.srsoftware.umbrella.messagebus.events.TaskEvent;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class SqliteDb extends BaseDb implements JournalDb{ public class SqliteDb extends BaseDb implements JournalDb{
@@ -65,7 +58,7 @@ public class SqliteDb extends BaseDb implements JournalDb{
} }
@Override @Override
public List<JournalEntry> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader) { public List<JournalEntry> list(String module, long entityId) {
try { try {
var rs = select(ALL).from(TABLE_JOURNAL).where(MODULE, equal(module)).where(ENTITY_ID,equal(entityId)).exec(db); var rs = select(ALL).from(TABLE_JOURNAL).where(MODULE, equal(module)).where(ENTITY_ID,equal(entityId)).exec(db);
var list = new ArrayList<JournalEntry>(); var list = new ArrayList<JournalEntry>();
@@ -6,7 +6,6 @@ import static de.srsoftware.tools.Optionals.*;
import static de.srsoftware.tools.Strings.uuid; import static de.srsoftware.tools.Strings.uuid;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.ModuleRegistry.postBox; import static de.srsoftware.umbrella.core.ModuleRegistry.postBox;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.ResponseCode.*; import static de.srsoftware.umbrella.core.ResponseCode.*;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR;
import static de.srsoftware.umbrella.core.Util.*; import static de.srsoftware.umbrella.core.Util.*;
@@ -165,11 +164,15 @@ public class UserModule extends BaseHandler implements UserService {
@Override @Override
public HashMap<Long, UmbrellaUser> loader() { public HashMap<Long, UmbrellaUser> loader() {
return new HashMap<Long, UmbrellaUser>(){ return new HashMap<Long, UmbrellaUser>(){
public UmbrellaUser get(long id) { @Override
public UmbrellaUser get(Object key) {
if (key instanceof Long id){
var user = super.get(id); var user = super.get(id);
if (user == null) put(id, user = loadUser(id)); if (user == null) put(id, user = loadUser(id));
return user; return user;
} }
return null;
}
}; };
} }