refactoring Events for better journal

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-10 01:10:24 +01:00
parent 0dd640de30
commit 10ea200a2e
9 changed files with 89 additions and 55 deletions

View File

@@ -13,7 +13,6 @@ import static de.srsoftware.umbrella.core.model.Permission.*;
import static de.srsoftware.umbrella.core.model.Permission.OWNER;
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.CREATE;
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.UPDATE;
import static de.srsoftware.umbrella.project.Constants.PERMISSIONS;
import static de.srsoftware.umbrella.task.Constants.*;
import static java.lang.System.Logger.Level.WARNING;
@@ -42,22 +41,6 @@ import org.json.JSONObject;
public class TaskModule extends BaseHandler implements TaskService {
private static class TaggedTask extends Task{
private final Collection<String> tags;
public TaggedTask(Task task, Collection<String> tags) {
super(task.id(), task.projectId(), task.parentTaskId(), task.name(), task.description(), task.status(), task.estimatedTime(), task.start(), task.dueDate(), task.showClosed(), task.noIndex(), task.members(), task.priority());
this.tags = tags;
}
@Override
public Map<String, Object> toMap() {
var map = super.toMap();
map.put(TAGS,tags);
return map;
}
}
private final TaskDb taskDb;
public TaskModule(Configuration config) throws UmbrellaException {
@@ -343,10 +326,8 @@ public class TaskModule extends BaseHandler implements TaskService {
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(task, memberJson);
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) addMember(task, num.longValue());
if (json.has(PARENT_TASK_ID) && json.get(PARENT_TASK_ID) instanceof Number ptid && newParentIsSubtask(task, ptid.longValue())) throw forbidden("Task must not be sub-task of itself.");
var curr = taskDb.save(task.patch(json)).toMap();
var diff = diff(old,curr);
var tagList = tagService().getTags(TASK, taskId, user);
messageBus().dispatch(new TaskEvent(user,new TaggedTask(task,tagList), UPDATE));
task = taskDb.save(task.patch(json)).tags(tagService().getTags(TASK, taskId, user));
messageBus().dispatch(new TaskEvent(user, task, old));
return sendContent(ex, task);
}
@@ -407,8 +388,8 @@ public class TaskModule extends BaseHandler implements TaskService {
if ((tagList == null || tagList.isEmpty())) tagList = tagService().getTags(PROJECT, projectId, user);
if (tagList != null && !tagList.isEmpty()) tagService().save(TASK, task.id(), null, tagList);
task = loadMembers(task);
messageBus().dispatch(new TaskEvent(user,new TaggedTask(task,tagList), CREATE));
task.tags(tagList);
messageBus().dispatch(new TaskEvent(user, task, CREATE));
return sendContent(ex, task);
}
@@ -449,6 +430,6 @@ public class TaskModule extends BaseHandler implements TaskService {
}
private Map<Long, Task> addTags(Map<Long, Task> taskList, Map<Long, ? extends Collection<String>> tags) {
return taskList.values().stream().map(task -> new TaggedTask(task, tags.get(task.id()))).collect(Collectors.toMap(Task::id, t -> t));
return taskList.values().stream().map(task -> task.tags(tags.get(task.id()))).collect(Collectors.toMap(Task::id, t -> t));
}
}