preparing message bus
This commit is contained in:
@@ -1,4 +1,23 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
|
||||
public class Event {
|
||||
public enum Type{
|
||||
CREATE,
|
||||
UPDATE,
|
||||
DELETE
|
||||
}
|
||||
|
||||
private UmbrellaUser initiator;
|
||||
private String realm;
|
||||
private Object payload;
|
||||
private Type type;
|
||||
|
||||
public Event(UmbrellaUser initiator, String realm, Object payload, Type type){
|
||||
this.initiator = initiator;
|
||||
this.realm = realm;
|
||||
this.payload = payload;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
public interface EventListener {
|
||||
public void onEvent(Event event);
|
||||
void onEvent(Event event);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MessageApi implements EventListener{
|
||||
|
||||
private static final System.Logger LOG = System.getLogger(MessageApi.class.getSimpleName());
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
LOG.log(System.Logger.Level.DEBUG,"received {0}",event.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,13 @@ public class MessageBus {
|
||||
private MessageBus(){}
|
||||
|
||||
public void dispatch(Event event){
|
||||
listeners.parallelStream().forEach(l -> l.onEvent(event));
|
||||
new Thread(() -> { // TODO: use thread pool
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
listeners.parallelStream().forEach(l -> l.onEvent(event));
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void drop(EventListener listener){
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.TASK;
|
||||
|
||||
public class TaskEvent extends Event{
|
||||
public TaskEvent(UmbrellaUser initiator,Object payload, Type type){
|
||||
super(initiator,TASK,payload, type);
|
||||
}
|
||||
}
|
||||
@@ -123,13 +123,14 @@ public class Constants {
|
||||
public static final String SUBJECT = "subject";
|
||||
|
||||
public static final String TABLE_SETTINGS = "settings";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TAG_COLORS = "tag_colors";
|
||||
public static final String TASK_IDS = "task_ids";
|
||||
public static final String TAX = "tax";
|
||||
public static final String TAX_RATE = "tax_rate";
|
||||
public static final String TEMPLATE = "template";
|
||||
public static final String TEXT = "text";
|
||||
public static final String TASK = "task";
|
||||
public static final String TASK_IDS = "task_ids";
|
||||
public static final String TAX = "tax";
|
||||
public static final String TAX_RATE = "tax_rate";
|
||||
public static final String TEMPLATE = "template";
|
||||
public static final String TEXT = "text";
|
||||
public static final String THOUSANDS_SEPARATOR = "thousands_separator";
|
||||
public static final String THEME = "theme";
|
||||
public static final String TITLE = "title";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
description = "Umbrella : Tasks"
|
||||
|
||||
dependencies{
|
||||
implementation(project(":bus"))
|
||||
implementation(project(":core"))
|
||||
implementation(project(":project"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.*;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.OWNER;
|
||||
import static de.srsoftware.umbrella.messagebus.Event.Type.UPDATE;
|
||||
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
|
||||
import static de.srsoftware.umbrella.project.Constants.PERMISSIONS;
|
||||
import static de.srsoftware.umbrella.task.Constants.*;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
@@ -32,6 +34,9 @@ import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.srsoftware.umbrella.messagebus.Event;
|
||||
import de.srsoftware.umbrella.messagebus.TaskEvent;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -311,7 +316,7 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
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.");
|
||||
taskDb.save(task.patch(json));
|
||||
|
||||
messageBus().dispatch(new TaskEvent(user,task, UPDATE));
|
||||
return sendContent(ex, task);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user