Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f0dced606 | ||
|
|
d4feda141e | ||
|
|
b0096ad5f4 | ||
|
|
6fe8cb4b1d |
@@ -5,6 +5,7 @@ import static de.srsoftware.umbrella.core.constants.Module.BOOKMARK;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.model.Bookmark;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
@@ -22,19 +23,42 @@ public class BookmarkEvent extends Event<Bookmark> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
return switch (eventType()){
|
||||
case CREATE -> t("New bookmark created");
|
||||
case DELETE -> t("The bookmark '{url}' has been deleted", Field.URL, payload().url());
|
||||
case UPDATE -> t("Bookmark updated");
|
||||
default -> null;
|
||||
};
|
||||
public Translatable describeCreate(boolean verbose) {
|
||||
return t(Text.CREATE_BOOKMARK_DESCRIPTION,Field.URL,payload().url(),Field.DESCRIPTION,payload().comment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subject() {
|
||||
return describe();
|
||||
public Translatable describeDelete(boolean verbose) {
|
||||
return t(Text.DELETE_BOOKMARK_DESCRIPTION, Field.DESCRIPTION, payload().comment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describeMemberAdded(boolean verbose) {
|
||||
return t(Text.MEMBER_ADDED_TO_BM_DESC,Field.DESCRIPTION,payload().comment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describeUpdate(boolean verbose) {
|
||||
return t(Text.UPDATE_BM_DESCRIPTION, Field.USER, initiator().name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subjectCreate() {
|
||||
return t(Text.CREATE_BOOKMARK_SUBJECT,Field.USER,initiator().name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subjectDelete() {
|
||||
return t(Text.DELETE_BOOKMARK_SUBJECT, Field.USER, initiator().name(), Field.URL, payload().url());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subjectMemberAdded() {
|
||||
return t(Text.MEMBER_ADDED_TO_BM_SUBJ,Field.USER, initiator().name(), Field.URL, payload().url());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subjectUpdate() {
|
||||
return t(Text.UPDATE_BM_SUBJECT,Field.URL, payload().url(), Field.DESCRIPTION, diff().orElse(""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static java.util.Optional.*;
|
||||
|
||||
import de.srsoftware.tools.Diff;
|
||||
import de.srsoftware.umbrella.core.model.ObjectWithId;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaObject;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -14,7 +16,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public abstract class Event<Payload extends ObjectWithId> {
|
||||
public abstract class Event<Payload extends UmbrellaObject> {
|
||||
|
||||
public enum EventType {
|
||||
CREATE,
|
||||
@@ -47,7 +49,19 @@ public abstract class Event<Payload extends ObjectWithId> {
|
||||
|
||||
public abstract Collection<UmbrellaUser> audience();
|
||||
|
||||
public abstract Translatable describe();
|
||||
public Translatable describe(boolean verbose) {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate(verbose);
|
||||
case DELETE -> describeDelete(verbose);
|
||||
case MEMBER_ADDED -> describeMemberAdded(verbose);
|
||||
case UPDATE -> describeUpdate(verbose);
|
||||
};
|
||||
}
|
||||
|
||||
public abstract Translatable describeCreate(boolean verbose);
|
||||
public abstract Translatable describeDelete(boolean verbose);
|
||||
public abstract Translatable describeMemberAdded(boolean verbose);
|
||||
public abstract Translatable describeUpdate(boolean verbose);
|
||||
|
||||
private Map<String, Object> dropMarkdown(Map<String, Object> map) {
|
||||
var result = new HashMap<String, Object>();
|
||||
@@ -110,5 +124,18 @@ public abstract class Event<Payload extends ObjectWithId> {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public abstract Translatable subject();
|
||||
public Translatable subject() {
|
||||
return switch (eventType()){
|
||||
case CREATE -> subjectCreate();
|
||||
case DELETE -> subjectDelete();
|
||||
case MEMBER_ADDED -> subjectMemberAdded();
|
||||
case UPDATE -> subjectUpdate();
|
||||
};
|
||||
}
|
||||
|
||||
public abstract Translatable subjectCreate();
|
||||
public abstract Translatable subjectDelete();
|
||||
public abstract Translatable subjectMemberAdded();
|
||||
public abstract Translatable subjectUpdate();
|
||||
|
||||
}
|
||||
|
||||
@@ -23,30 +23,9 @@ public class ItemEvent extends Event<Item>{
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate();
|
||||
case null, default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private Translatable describeCreate() {
|
||||
var loc = payload().location().resolve().name();
|
||||
return t("{user} added \"{item}\" to \"{location}\"", USER,initiator().name(), ITEM, payload().name(), LOCATION, loc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long objectId() {
|
||||
return payload().id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subject() {
|
||||
var loc = payload().location().resolve().name();
|
||||
return switch (eventType()){
|
||||
case CREATE -> t("A new item has been added to \"{location}\":",LOCATION,loc);
|
||||
case null, default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.time.ZoneOffset.UTC;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaObject;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class JournalEntry extends UmbrellaObject {
|
||||
|
||||
LocalDateTime timestamp;
|
||||
long userId, entityId;
|
||||
String action, module;
|
||||
Translatable description;
|
||||
|
||||
public JournalEntry(long id, LocalDateTime timestamp, long userId, String module, long entityId, String action, Translatable 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 json = new JSONObject(rs.getString(DESCRIPTION));
|
||||
var message = json.getString(TEXT);
|
||||
var fills = json.getJSONObject(DATA).toMap();
|
||||
|
||||
return new JournalEntry(id, timestamp, userId, module, entityId, action, new Translatable(message,fills));
|
||||
}
|
||||
|
||||
public long userId(){
|
||||
return userId;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap(String lang){
|
||||
return map(
|
||||
TIMESTAMP, timestamp,
|
||||
USER_ID, userId,
|
||||
MODULE, module,
|
||||
ENTITY_ID, entityId,
|
||||
ACTION, action,
|
||||
DESCRIPTION, description.translate(lang)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return toMap(null);
|
||||
}
|
||||
}
|
||||
@@ -36,28 +36,27 @@ public class ProjectEvent extends Event<Project>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
public Translatable describe(boolean verbose) {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate();
|
||||
case CREATE -> describeCreate(verbose);
|
||||
case DELETE -> t("The project '{project}' has been deleted by {user}", Field.PROJECT, payload().name(), USER, initiator().name());
|
||||
case MEMBER_ADDED -> describeMemberAdded();
|
||||
case UPDATE -> describeUpdate();
|
||||
};
|
||||
}
|
||||
|
||||
private Translatable describeCreate() {
|
||||
var head = t("You have been added to the new project '{project}', created by {user}:\n\n{body}", Field.PROJECT, payload().name(), BODY, payload().description(), USER, initiator().name());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
private Translatable describeCreate(boolean verbose) {
|
||||
var description = t("{user} created a new project \"{project}\"",USER,initiator().name(),Field.PROJECT,payload().name());
|
||||
if (verbose) description = t("{title}:\n\n{description}", TITLE,description, DESCRIPTION, payload().description());
|
||||
return description;
|
||||
}
|
||||
|
||||
private Translatable describeMemberAdded() {
|
||||
var head = t("'{name}' has been added to '{object}' by '{user}'.",NAME,newMember.name(),Field.OBJECT,payload().name(),USER,initiator().name());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
return t("\"{name}\" has been added to \"{object}\" by \"{user}\"",NAME,newMember.name(),Field.OBJECT,payload().name(),USER,initiator().name());
|
||||
}
|
||||
|
||||
private Translatable describeUpdate() {
|
||||
var head = t("Changes in project '{project}':\n\n{body}",Field.PROJECT,payload().name(),BODY,diff().orElse(""));
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
return t("Changes in project '{project}':\n\n{body}",Field.PROJECT,payload().name(),BODY,diff().orElse(""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,10 +73,6 @@ public class ProjectEvent extends Event<Project>{
|
||||
return false;
|
||||
}
|
||||
|
||||
private Translatable link() {
|
||||
return t("You can view/edit this project at {base_url}/project/{id}/view",ID,payload().id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long objectId() {
|
||||
return payload().id();
|
||||
|
||||
@@ -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.model.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -42,16 +39,16 @@ public class TaskEvent extends Event<Task>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
public Translatable describe(boolean verbose) {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate();
|
||||
case CREATE -> describeCreate(verbose);
|
||||
case DELETE -> t("The task '{task}' has been deleted by {user}",Field.TASK, payload().name(), USER, initiator().name());
|
||||
case MEMBER_ADDED -> describeMemberAdded();
|
||||
case UPDATE -> describeUpdate();
|
||||
};
|
||||
}
|
||||
|
||||
private Translatable describeCreate() {
|
||||
private Translatable describeCreate(boolean verbose) {
|
||||
String parentName = null;
|
||||
var pid = payload().parentTaskId();
|
||||
if (pid != null) {
|
||||
@@ -63,18 +60,17 @@ public class TaskEvent extends Event<Task>{
|
||||
if (project != null) parentName = project.name();
|
||||
}
|
||||
if (parentName == null) parentName = "?";
|
||||
var head = t("'{task}' has been added to '{object}':\n\n{body}", Field.TASK, payload().name(), OBJECT, parentName, BODY, payload().description());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
var description = t("\"{name}\" has been added to \"{object}\" by \"{user}\"", NAME,payload().name(), OBJECT, parentName, USER, initiator().name());
|
||||
if (verbose) description = t("{title}:\n\n{description}", TITLE,description, DESCRIPTION,payload().description());
|
||||
return description;
|
||||
}
|
||||
|
||||
private Translatable describeMemberAdded() {
|
||||
var head = t("'{name}' has been added to '{object}' by '{user}'.",NAME,newMember.name(), OBJECT,payload().name(),USER,initiator().name());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
return t("\"{name}\" has been added to \"{object}\" by \"{user}\"",NAME,newMember.name(), OBJECT,payload().name(),USER,initiator().name());
|
||||
}
|
||||
|
||||
private Translatable describeUpdate() {
|
||||
var head = t("Changes in task '{task}':\n\n{body}",Field.TASK,payload().name(),BODY,diff().orElse(""));
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
return t("Changes in task '{task}':\n\n{body}",Field.TASK,payload().name(),BODY,diff().orElse(""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,11 +91,6 @@ public class TaskEvent extends Event<Task>{
|
||||
return false;
|
||||
}
|
||||
|
||||
private Translatable link() {
|
||||
return t("You can view/edit this task at {base_url}/task/{id}/view",ID,payload().id());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Translatable subject() {
|
||||
return switch (eventType()){
|
||||
|
||||
@@ -34,32 +34,33 @@ public class TransactionEvent extends Event<Transaction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
public Translatable describe(boolean verbose) {
|
||||
var user = initiator().name();
|
||||
var type = t(Text.TRANSACTION);
|
||||
var entity = payload().purpose();
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeDetail();
|
||||
case DELETE -> describeDetail();
|
||||
case CREATE, DELETE -> describeDetail();
|
||||
case UPDATE -> describeUpdate();
|
||||
case null, default -> t("TODO"); // TODO
|
||||
};
|
||||
}
|
||||
|
||||
private Translatable describeUpdate() {
|
||||
var head = t("Changes in {type} '{entity}':\n\n{body}",Field.TYPE,t(Text.TRANSACTION),Field.ENTITY,oldData().get(PURPOSE),BODY,diff().orElse(""));
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
return t("Changes in {type} '{entity}':\n\n{body}",Field.TYPE,t(Text.TRANSACTION),Field.ENTITY,oldData().get(PURPOSE),BODY,diff().orElse(""));
|
||||
}
|
||||
|
||||
private Translatable describeDetail(){
|
||||
var tr = payload();
|
||||
var transaction = payload();
|
||||
|
||||
var message = "{source}: {source_name}\n{destination}: {dest_name}\n{amount}: {value}\n{purpose}: {purpose_val}\n\n{link}";
|
||||
return t(message,SOURCE,t(Text.SOURCE), "source_name",tr.source(), DESTINATION,t(Text.DESTINATION),"dest_name",tr.destination(), AMOUNT,t(Text.AMOUNT), VALUE,tr.amount(), PURPOSE,t(Text.PURPOSE),"purpose_val",tr.purpose(),"link",link());
|
||||
}
|
||||
|
||||
private Translatable link() {
|
||||
return t("You can view/edit this transaction at {base_url}/account/{id}", ID, payload().accountId());
|
||||
return t("{source}: {source_name}\n{destination}: {dest_name}\n{amount}: {value}\n{purpose}: {purpose_val}",
|
||||
SOURCE,t(Text.SOURCE),
|
||||
"source_name",transaction.source(),
|
||||
DESTINATION, t(Text.DESTINATION),
|
||||
"dest_name", transaction.destination(),
|
||||
AMOUNT, t(Text.AMOUNT),
|
||||
VALUE, transaction.amount(),
|
||||
PURPOSE, t(Text.PURPOSE),
|
||||
"purpose_val",transaction.purpose());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ public class WikiEvent extends Event<WikiPage>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
public Translatable describe(boolean verbose) {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate();
|
||||
case DELETE -> describeDelete();
|
||||
@@ -46,8 +46,7 @@ public class WikiEvent extends Event<WikiPage>{
|
||||
}
|
||||
|
||||
public Translatable describeCreate(){
|
||||
var head = t("New wiki page {name} has been created");
|
||||
return t("{head}:\n\n{object}\n\n{link}","head",head,OBJECT,payload().content(),"link",link());
|
||||
return t("New wiki page {name} has been created");
|
||||
}
|
||||
|
||||
public Translatable describeDelete(){
|
||||
@@ -55,17 +54,11 @@ public class WikiEvent extends Event<WikiPage>{
|
||||
}
|
||||
|
||||
public Translatable describeMemberAdded(){
|
||||
var head = t("'{name}' has been added to '{object}' by '{user}'.",NAME,newMember.name(), OBJECT,payload().title(),USER,initiator().name());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
return t("\"{name}\" has been added to \"{object}\" by \"{user}\"",NAME,newMember.name(), OBJECT,payload().title(),USER,initiator().name());
|
||||
}
|
||||
|
||||
private Translatable describeUpdate() {
|
||||
var head = t("Changes in wiki page '{id}':\n\n{body}",Field.ID,payload().title(),BODY,diff().orElse(""));
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
}
|
||||
|
||||
private Translatable link() {
|
||||
return t("You can view/edit this wiki page at {base_url}/wiki/{id}/view",ID,payload().id());
|
||||
return t("Changes in wiki page '{id}':\n\n{body}",Field.ID,payload().title(),BODY,diff().orElse(""));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,6 +83,8 @@ public class Field {
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEM_CODE = "item_code";
|
||||
|
||||
public static final String JOURNAL = "journal";
|
||||
|
||||
public static final String KEY = "key";
|
||||
|
||||
public static final String LANGUAGE = "language";
|
||||
|
||||
@@ -19,10 +19,14 @@ public class Text {
|
||||
public static final String CONTACT = "Contact";
|
||||
public static final String CONTACTS = "contacts";
|
||||
public static final String CONTACT_WITH_ID = "contact ({id})";
|
||||
public static final String CREATE_BOOKMARK_SUBJECT = "create_bookmark_subject";
|
||||
public static final String CREATE_BOOKMARK_DESCRIPTION = "create_bookmark_description";
|
||||
public static final String CUSTOMER = "customer";
|
||||
public static final String CUSTOMER_SETTINGS = "customer settings";
|
||||
|
||||
public static final String DESTINATION = "destination";
|
||||
public static final String DELETE_BOOKMARK_DESCRIPTION = "The deleted bookmark was described as:\n{description}";
|
||||
public static final String DELETE_BOOKMARK_SUBJECT = "{user} deleted {url}";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String DOCUMENTS = "documents";
|
||||
public static final String DOCUMENT_TYPE_ID = "document type id";
|
||||
@@ -43,6 +47,8 @@ public class Text {
|
||||
public static final String LOGIN_SERVICE = "login service";
|
||||
public static final String LONG = "Long";
|
||||
|
||||
public static final String MEMBER_ADDED_TO_BM_DESC = "Description:\n{description}";
|
||||
public static final String MEMBER_ADDED_TO_BM_SUBJ = "{user} shared {url}";
|
||||
public static final String MESSAGE = "message";
|
||||
public static final String MESSAGES = "messages";
|
||||
|
||||
@@ -96,6 +102,8 @@ public class Text {
|
||||
|
||||
public static final String UNIT_PRICE = "unit price";
|
||||
public static final String UNKNOWN_FIELD = "unknown field: {id}";
|
||||
public static final String UPDATE_BM_DESCRIPTION = "{user} updated bookmark";
|
||||
public static final String UPDATE_BM_SUBJECT = "{url} was changed:\n{description}";
|
||||
public static final String USER = "user";
|
||||
public static final String USERS = "users";
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Bookmark extends ObjectWithId {
|
||||
public final class Bookmark extends UmbrellaObject {
|
||||
private final String url;
|
||||
private final String comment;
|
||||
private final LocalDateTime timestamp;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Item extends ObjectWithId {
|
||||
public class Item extends UmbrellaObject {
|
||||
private long ownerNumber; // id is the database key, number the owner-relative id
|
||||
private final Owner owner;
|
||||
private String code, description, name;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Project extends ObjectWithId {
|
||||
public class Project extends UmbrellaObject {
|
||||
private final Map<Long,Member> members;
|
||||
private final Collection<Status> allowedStates;
|
||||
private boolean showClosed;
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Task extends ObjectWithId {
|
||||
public class Task extends UmbrellaObject {
|
||||
public static final System.Logger LOG = System.getLogger(Task.class.getSimpleName());
|
||||
private final long projectId;
|
||||
private Long parentTaskId;
|
||||
|
||||
@@ -3,7 +3,6 @@ package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -14,7 +13,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Transaction extends ObjectWithId {
|
||||
public class Transaction extends UmbrellaObject {
|
||||
private final long accountId;
|
||||
private LocalDateTime date;
|
||||
private IdOrString source, destination;
|
||||
|
||||
@@ -3,11 +3,13 @@ package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Translatable {
|
||||
public class Translatable implements Mappable {
|
||||
protected final String message;
|
||||
private final Map<String, Object> fills;
|
||||
private final HashMap<String,String> translated = new HashMap<>();
|
||||
@@ -40,6 +42,11 @@ public class Translatable {
|
||||
return new Translatable(message,args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(Field.TEXT,message,Field.DATA,fills);
|
||||
}
|
||||
|
||||
public String translate(String language){
|
||||
var translation = language == null ? null : translated.get(language);
|
||||
if (translation == null){
|
||||
|
||||
+12
-8
@@ -1,16 +1,16 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ObjectWithId implements Mappable {
|
||||
public abstract class UmbrellaObject implements Mappable {
|
||||
private long id;
|
||||
|
||||
public ObjectWithId(long id){
|
||||
public UmbrellaObject(long id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,6 @@ public abstract class ObjectWithId implements Mappable {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ObjectWithId setId(long newValue){
|
||||
id = newValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Map<String, Object> map(Object ... keysAndValues) {
|
||||
if (keysAndValues.length % 2 != 0) throw new InvalidParameterException("Expected even number of keys and parameters!");
|
||||
var map = new HashMap<String, Object>();
|
||||
@@ -30,4 +25,13 @@ public abstract class ObjectWithId implements Mappable {
|
||||
for (var idx = 0; idx<keysAndValues.length; idx+=2) map.put(keysAndValues[idx].toString(),keysAndValues[idx+1]);
|
||||
return map;
|
||||
}
|
||||
|
||||
public String path(){
|
||||
return getClass().getSimpleName().toLowerCase()+"/"+id()+"/view";
|
||||
}
|
||||
|
||||
public UmbrellaObject setId(long newValue){
|
||||
id = newValue;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class WikiPage extends ObjectWithId {
|
||||
public class WikiPage extends UmbrellaObject {
|
||||
|
||||
private String title;
|
||||
private int version;
|
||||
|
||||
@@ -4,14 +4,26 @@
|
||||
import { t } from '../../translations.svelte';
|
||||
let { module, entityId } = $props();
|
||||
|
||||
let data = $state({journal:[]});
|
||||
|
||||
async function loadJournal(){
|
||||
const url = api(`journal/${module}/${entityId}`);
|
||||
const res = await get(url);
|
||||
if (res.ok) {
|
||||
data = await res.json();
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
$effect(loadJournal);
|
||||
</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>
|
||||
<pre>{entry.description}</pre>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
@@ -364,14 +364,15 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<h3>{t('Journal')}</h3>
|
||||
<div>
|
||||
<Journal module="task" entityId={id} />
|
||||
</div>
|
||||
<h3>{t('notes')}</h3>
|
||||
<div>
|
||||
<Notes module="task" entity_id={id} />
|
||||
</div>
|
||||
<h3>{t('Journal')}</h3>
|
||||
<div>
|
||||
<Journal module="task" entityId={id} />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.journal;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
|
||||
import java.util.HashMap;
|
||||
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||
import java.util.List;
|
||||
|
||||
public interface JournalDb {
|
||||
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.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.missingField;
|
||||
import static de.srsoftware.umbrella.journal.Constants.CONFIG_DATABASE;
|
||||
@@ -21,12 +19,11 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
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.events.Event;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@@ -55,7 +52,14 @@ public class JournalModule extends BaseHandler implements EventListener {
|
||||
if (head == null) throw missingField(Field.ENTITY_ID);
|
||||
try {
|
||||
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(entry -> entry.toMap(user.get().language())).toList()
|
||||
));
|
||||
} catch (NumberFormatException e) {
|
||||
throw invalidField(Field.ENTITY_ID, Text.NUMBER);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* © SRSoftware 2025 */
|
||||
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.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.tools.jdbc.Query.insertInto;
|
||||
@@ -13,20 +12,16 @@ import static de.srsoftware.umbrella.journal.Constants.TABLE_JOURNAL;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
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.model.UmbrellaUser;
|
||||
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.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SqliteDb extends BaseDb implements JournalDb{
|
||||
public SqliteDb(Connection connection) {
|
||||
@@ -64,38 +59,25 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Event<?>> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader) {
|
||||
public List<JournalEntry> list(String module, long entityId) {
|
||||
try {
|
||||
var rs = select(ALL).from(TABLE_JOURNAL).where(MODULE, equal(module)).where(ENTITY_ID,equal(entityId)).exec(db);
|
||||
var list = new ArrayList<Event<?>>();
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
var list = new ArrayList<JournalEntry>();
|
||||
while (rs.next()) list.add(JournalEntry.of(rs));
|
||||
rs.close();
|
||||
return list;
|
||||
} catch (SQLException e) {
|
||||
throw failedToLoadObject(Text.EVENT_LIST);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logEvent(Event<?> event) {
|
||||
try {
|
||||
var timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
|
||||
var description = new JSONObject(event.describe(false).toMap()).toString(2);
|
||||
insertInto(TABLE_JOURNAL,TIMESTAMP,USER_ID,MODULE,ENTITY_ID,ACTION,DESCRIPTION)
|
||||
.values(timestamp,event.initiator().id(), event.module(), event.objectId(), event.eventType(), event.describe())
|
||||
.values(timestamp,event.initiator().id(), event.module(), event.objectId(), event.eventType(), description)
|
||||
.execute(db).close();
|
||||
} catch (SQLException e) {
|
||||
throw databaseException(ERROR_WRITE_EVENT,event.eventType(),event.initiator().name());
|
||||
|
||||
@@ -172,8 +172,12 @@ public class MessageSystem extends BaseHandler implements PostBox, EventListener
|
||||
|
||||
@Override
|
||||
public void onEvent(Event<?> event) {
|
||||
var message = new TranslatableMessage(event.initiator(),event.subject(),event.describe(),null);
|
||||
var audience = new HashSet<>(event.audience());
|
||||
var description = event.describe(true);
|
||||
var payload = event.payload();
|
||||
var location = t("You can view/edit this {object} at {base_url}/{path}", OBJECT,t(payload.getClass().getSimpleName()), PATH,payload.path());
|
||||
var body = t("{description}\n\n{location}", DESCRIPTION,description, LOCATION,location);
|
||||
var message = new TranslatableMessage(event.initiator(),event.subject(),body,null);
|
||||
var audience = new HashSet<>(event.audience());
|
||||
audience.remove(event.initiator());
|
||||
send(new Envelope<>(0,message,audience));
|
||||
}
|
||||
|
||||
@@ -72,7 +72,10 @@
|
||||
"CUSTOMER-NUMBER": "Kundennummer",
|
||||
"customer_number_prefix": "Präfix für Kundennummer",
|
||||
"create": "anlegen",
|
||||
"create_bookmark_description": "{url} was annotated with:\n{description}",
|
||||
"create_bookmark_subject": "{user} created new bookmark",
|
||||
"create_new_object": "{object} neu anlegen",
|
||||
"created_wiki_page":
|
||||
"CREATE_USERS": "Nutzer anlegen",
|
||||
"create_pdf": "PDF erzeugen",
|
||||
"created_with": "erzeugt mit {tool} von {producer}",
|
||||
@@ -87,12 +90,14 @@
|
||||
"data_sent": "Daten übermittelt",
|
||||
"date": "Datum",
|
||||
"delete": "löschen",
|
||||
"delete_bookmark_subject": "{user} deleted {url}",
|
||||
"delete_object": "{object} löschen",
|
||||
"DELETE_USERS": "Nutzer löschen",
|
||||
"deletes_nested": "Das wird auch alle enthaltenen Dateien löschen!",
|
||||
"delivery_date": "Lieferdatum",
|
||||
"depends_on": "hängt ab von",
|
||||
"description": "Beschreibung",
|
||||
"Description:\n{description}": "Beschreibung:\n{description}",
|
||||
"destination": "Ziel",
|
||||
"detail": "Details",
|
||||
"directory": "Verzeichnis",
|
||||
@@ -257,7 +262,7 @@
|
||||
"my files": "Meine Dateien",
|
||||
|
||||
"name": "Name",
|
||||
"'{name}' has been added to '{object}' by '{user}'.": "'{name}' wurde von {user} zu '{object}' hinzugefügt.",
|
||||
"\"{name}\" has been added to \"{object}\" by \"{user}\"": "„{name}“ wurde von „{user}“ zu „{object}“ hinzugefügt",
|
||||
"net_price": "Nettopreis",
|
||||
"net_sum": "Netto-Summe",
|
||||
"new_contact": "neuer Kontakt",
|
||||
@@ -438,9 +443,11 @@
|
||||
"update": "aktualisieren",
|
||||
"UPDATE_USERS" : "Nutzer aktualisieren",
|
||||
"upload_file": "Datei hochladen",
|
||||
"{url} was changed:\n{description}": "{url} wurde geändert:\n{description}",
|
||||
"user": "Benutzer",
|
||||
"user ({id})": "Benutzer ({id})",
|
||||
"{user} added a new transaction: {entity}": "{user} hat einen neuen Umsatz hinzugefügt: {entity}",
|
||||
"{user} shared {url}": "{user} teilte {url}",
|
||||
"{user} updated the transaction '{entity}'": "{user} hat den Umsatz „{entity}“ aktualisiert",
|
||||
"user_list": "Benutzer-Liste",
|
||||
"user_module" : "Umbrella User-Verwaltung",
|
||||
|
||||
@@ -257,7 +257,7 @@
|
||||
"my files": "my files",
|
||||
|
||||
"name": "Name",
|
||||
"'{name}' has been added to '{object}' by '{user}'.": "'{name}' has been added to '{object}' by '{user}'.",
|
||||
"\"{name}\" has been added to \"{object}\" by \"{user}\"": "\"{name}\" has been added to \"{object}\" by \"{user}\"",
|
||||
"net_price": "net price",
|
||||
"net_sum": "net sum",
|
||||
"new_contact": "new contact",
|
||||
|
||||
@@ -6,7 +6,6 @@ import static de.srsoftware.tools.Optionals.*;
|
||||
import static de.srsoftware.tools.Strings.uuid;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
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.HTTP_SERVER_ERROR;
|
||||
import static de.srsoftware.umbrella.core.Util.*;
|
||||
@@ -165,10 +164,14 @@ public class UserModule extends BaseHandler implements UserService {
|
||||
@Override
|
||||
public HashMap<Long, UmbrellaUser> loader() {
|
||||
return new HashMap<Long, UmbrellaUser>(){
|
||||
public UmbrellaUser get(long id) {
|
||||
var user = super.get(id);
|
||||
if (user == null) put(id, user = loadUser(id));
|
||||
return user;
|
||||
@Override
|
||||
public UmbrellaUser get(Object key) {
|
||||
if (key instanceof Long id){
|
||||
var user = super.get(id);
|
||||
if (user == null) put(id, user = loadUser(id));
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user