Compare commits
2
Commits
51a9f9272e
...
b0096ad5f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0096ad5f4 | ||
|
|
6fe8cb4b1d |
@@ -0,0 +1,56 @@
|
|||||||
|
/* © SRSoftware 2025 */
|
||||||
|
package de.srsoftware.umbrella.messagebus.events;
|
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||||
|
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||||
|
import static java.time.ZoneOffset.UTC;
|
||||||
|
|
||||||
|
import de.srsoftware.umbrella.core.model.ObjectWithId;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class JournalEntry extends ObjectWithId {
|
||||||
|
|
||||||
|
LocalDateTime timestamp;
|
||||||
|
long userId, entityId;
|
||||||
|
String action, description, module;
|
||||||
|
|
||||||
|
public JournalEntry(long id, LocalDateTime timestamp, long userId, String module, long entityId, String action, String description){
|
||||||
|
super(id);
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.userId = userId;
|
||||||
|
this.module = module;
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.action = action;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public static JournalEntry of(ResultSet rs) throws SQLException {
|
||||||
|
var id = rs.getLong(ID);
|
||||||
|
var timestamp = LocalDateTime.ofEpochSecond(rs.getLong(TIMESTAMP),0, UTC);
|
||||||
|
var userId = rs.getLong(USER_ID);
|
||||||
|
var module = rs.getString(MODULE);
|
||||||
|
var entityId = rs.getLong(ENTITY_ID);
|
||||||
|
var action = rs.getString(ACTION);
|
||||||
|
var description = rs.getString(DESCRIPTION);
|
||||||
|
|
||||||
|
return new JournalEntry(id, timestamp, userId, module, entityId, action, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long userId(){
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> toMap() {
|
||||||
|
return map(
|
||||||
|
TIMESTAMP, timestamp,
|
||||||
|
USER_ID, userId,
|
||||||
|
MODULE, module,
|
||||||
|
ENTITY_ID, entityId,
|
||||||
|
ACTION, action,
|
||||||
|
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;
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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,14 +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 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<Event<?>> 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,7 +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);
|
||||||
journalDb.list(module, entityId, userService().loader());
|
var entries = journalDb.list(module, entityId);
|
||||||
|
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,19 +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.TaskEvent;
|
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||||
|
|
||||||
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{
|
||||||
@@ -64,30 +58,16 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Event<?>> 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<Event<?>>();
|
var list = new ArrayList<JournalEntry>();
|
||||||
|
while (rs.next()) list.add(JournalEntry.of(rs));
|
||||||
|
|
||||||
while (rs.next()){
|
|
||||||
var user = userLoader.get(rs.getLong(USER_ID));
|
|
||||||
var id = rs.getLong(Field.ID);
|
|
||||||
var timestamp = rs.getLong(TIMESTAMP);
|
|
||||||
var action = rs.getString(ACTION);
|
|
||||||
var descr = rs.getString(DESCRIPTION);
|
|
||||||
|
|
||||||
var event = switch (module){
|
|
||||||
case Module.TASK -> new TaskEvent(user,)
|
|
||||||
default -> throw notImplemented("No handler for "+module+" events!");
|
|
||||||
};
|
|
||||||
list.add(event);
|
|
||||||
}
|
|
||||||
rs.close();
|
rs.close();
|
||||||
return list;
|
return list;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw failedToLoadObject(Text.EVENT_LIST);
|
throw failedToLoadObject(Text.EVENT_LIST);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user