working on implementatin of MessageQueue by SqliteMessageDb
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -11,6 +11,8 @@ public class Constants {
|
||||
private Constants(){
|
||||
// prevent instantiation
|
||||
}
|
||||
|
||||
public static final String COUNT = "COUNT(*)";
|
||||
public static final String FALLBACK_LANG = "de";
|
||||
public static final String HOME = "home";
|
||||
public static final String JSONARRAY = "json array";
|
||||
|
||||
@@ -33,6 +33,8 @@ public class Text {
|
||||
public static final String LOGIN_SERVICE = "login service";
|
||||
public static final String LONG = "Long";
|
||||
|
||||
public static final String MESSAGE = "message";
|
||||
|
||||
public static final String NOTE = "note";
|
||||
public static final String NOTE_WITH_ID = "note ({id})";
|
||||
public static final String NUMBER = "number";
|
||||
@@ -43,6 +45,7 @@ public class Text {
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
|
||||
public static final String RECEIVER = "receiver";
|
||||
public static final String RECEIVERS = "receivers";
|
||||
|
||||
public static final String SENDER = "sender";
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.JSONARRAY;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.JSONOBJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.ID;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.RECEIVERS;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
@@ -22,15 +23,17 @@ public class Envelope<T extends Message<?>> {
|
||||
private final T message;
|
||||
private final Set<User> receivers;
|
||||
private final LocalDateTime time;
|
||||
private final long id;
|
||||
|
||||
public Envelope(T message, User receiver){
|
||||
this(message,new HashSet<>(Set.of(receiver)));
|
||||
public Envelope(long id, T message, User receiver){
|
||||
this(id, message,new HashSet<>(Set.of(receiver)));
|
||||
}
|
||||
|
||||
public Envelope(T message, Collection<? extends User> receivers) {
|
||||
public Envelope(long id, T message, Collection<? extends User> receivers) {
|
||||
this.message = message;
|
||||
this.receivers = new HashSet<>(receivers);
|
||||
time = LocalDateTime.now();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,7 @@ public class Envelope<T extends Message<?>> {
|
||||
*/
|
||||
public static Envelope<TranslatedMessage> from(JSONObject json) throws UmbrellaException {
|
||||
if (!json.has(RECEIVERS)) throw missingField(RECEIVERS);
|
||||
var id = json.has(ID) && json.get(ID) instanceof Number n ? n.longValue() : 0;
|
||||
var message = TranslatedMessage.from(json);
|
||||
var obj = json.get(RECEIVERS);
|
||||
if (obj instanceof JSONObject) obj = new JSONArray(List.of(obj));
|
||||
@@ -50,7 +54,7 @@ public class Envelope<T extends Message<?>> {
|
||||
if (!(o instanceof JSONObject receiverData)) throw invalidField("entries of "+ RECEIVERS, t(JSONOBJECT));
|
||||
receivers.add(User.of(receiverData));
|
||||
}
|
||||
return new Envelope<>(message,receivers);
|
||||
return new Envelope<>(id, message, receivers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +68,10 @@ public class Envelope<T extends Message<?>> {
|
||||
return 31 * message.hashCode() + time.hashCode();
|
||||
}
|
||||
|
||||
public long id(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isFor(User receiver) {
|
||||
return receivers.contains(receiver);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user