Merge branch 'module/messagebus' into dev
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
FROM alpine:3.22
|
||||
LABEL Maintainer "Stephan Richter <s.richter@srsoftware.de>"
|
||||
LABEL Maintainer "Stephan Richter"
|
||||
ARG UID=1000
|
||||
ARG GID=1000
|
||||
RUN apk add bash npm
|
||||
|
||||
@@ -64,10 +64,10 @@ public class Application {
|
||||
|
||||
var server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
try {
|
||||
new Translations().bindPath("/api/translations").on(server);
|
||||
new Translations(config).bindPath("/api/translations").on(server);
|
||||
new JournalModule(config).bindPath("/api/journal").on(server);
|
||||
new MessageApi().bindPath("/api/bus").on(server);
|
||||
new MessageSystem(config);
|
||||
new MessageSystem(config).bindPath("/api/message").on(server);
|
||||
new UserModule(config).bindPath("/api/user").on(server);
|
||||
new TagModule(config).bindPath("/api/tags").on(server);
|
||||
new BookmarkApi(config).bindPath("/api/bookmark").on(server);
|
||||
|
||||
@@ -6,17 +6,19 @@ import static java.util.Optional.*;
|
||||
|
||||
import de.srsoftware.tools.Diff;
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
public abstract class Event<Payload extends Mappable> {
|
||||
|
||||
public enum EventType {
|
||||
CREATE,
|
||||
MEMBER_ADDED,
|
||||
UPDATE,
|
||||
DELETE;
|
||||
}
|
||||
@@ -37,13 +39,15 @@ public abstract class Event<Payload extends Mappable> {
|
||||
|
||||
public Event(UmbrellaUser initiator, String module, Payload payload, Map<String, Object> oldData){
|
||||
this.initiator = initiator;
|
||||
this.module = module;
|
||||
this.payload = payload;
|
||||
this.module = module;
|
||||
this.payload = payload;
|
||||
this.eventType = EventType.UPDATE;
|
||||
this.oldData = oldData;
|
||||
this.oldData = oldData;
|
||||
}
|
||||
|
||||
public abstract String describe();
|
||||
public abstract Collection<UmbrellaUser> audience();
|
||||
|
||||
public abstract Translatable describe();
|
||||
|
||||
private Map<String, Object> dropMarkdown(Map<String, Object> map) {
|
||||
var result = new HashMap<String, Object>();
|
||||
@@ -56,15 +60,21 @@ public abstract class Event<Payload extends Mappable> {
|
||||
}
|
||||
|
||||
public Optional<String> diff(){
|
||||
return oldData == null ? empty() : of(Diff.MapDiff.diff(dropMarkdown(oldData),dropMarkdown(payload.toMap())));
|
||||
return oldData == null ? empty() : of(Diff.MapDiff.diff(filter(oldData),filter(payload.toMap())));
|
||||
}
|
||||
|
||||
|
||||
public String eventType(){
|
||||
return eventType.toString();
|
||||
public EventType eventType(){
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public abstract boolean isIntendedFor(UmbrellaUser user);
|
||||
protected Map<String,Object> filter(Map<String,Object> map){
|
||||
return dropMarkdown(map);
|
||||
}
|
||||
|
||||
public boolean isIntendedFor(UmbrellaUser user){
|
||||
return audience().contains(user);
|
||||
}
|
||||
|
||||
public UmbrellaUser initiator(){
|
||||
return initiator;
|
||||
@@ -88,7 +98,13 @@ public abstract class Event<Payload extends Mappable> {
|
||||
return module;
|
||||
}
|
||||
|
||||
protected Map<String, Object> oldData() {
|
||||
return oldData;
|
||||
}
|
||||
|
||||
public Payload payload(){
|
||||
return payload;
|
||||
}
|
||||
|
||||
public abstract Translatable subject();
|
||||
}
|
||||
|
||||
@@ -1,27 +1,69 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.projectService;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.taskService;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.PROJECT;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.MEMBER_ADDED;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.Project;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class ProjectEvent extends Event<Project>{
|
||||
|
||||
private UmbrellaUser newMember;
|
||||
public ProjectEvent(UmbrellaUser initiator, Project project, EventType type){
|
||||
super(initiator, PROJECT, project, type);
|
||||
newMember = null;
|
||||
}
|
||||
|
||||
public ProjectEvent(UmbrellaUser initiator, Project project, Map<String, Object> oldData){
|
||||
super(initiator, PROJECT, project, oldData);
|
||||
newMember = null;
|
||||
}
|
||||
|
||||
public ProjectEvent(UmbrellaUser initiator, Project project, UmbrellaUser newMember){
|
||||
super(initiator, PROJECT, project, MEMBER_ADDED);
|
||||
this.newMember = newMember;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return diff().orElse("[TODO: ProjectEvent.describe]");
|
||||
public Collection<UmbrellaUser> audience() {
|
||||
return payload().members().values().stream().map(Member::user).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate();
|
||||
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 describeMemberAdded() {
|
||||
var head = t("'{name}' has been added to '{project}' by '{user}'.",NAME,newMember.name(),Field.PROJECT,payload().name(),USER,initiator().name());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isIntendedFor(UmbrellaUser user) {
|
||||
for (var member : payload().members().values()){
|
||||
@@ -29,4 +71,14 @@ 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 Translatable subject() {
|
||||
return t("{user} edited {object}",USER,initiator(),OBJECT,payload().name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,84 @@
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.projectService;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.taskService;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.TASK;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.MEMBER_ADDED;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.Task;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class TaskEvent extends Event<Task>{
|
||||
private final UmbrellaUser newMember;
|
||||
|
||||
public TaskEvent(UmbrellaUser initiator, Task task, EventType type){
|
||||
super(initiator, TASK, task, type);
|
||||
newMember = null;
|
||||
}
|
||||
|
||||
public TaskEvent(UmbrellaUser initiator, Task task, Map<String, Object> oldData){
|
||||
super(initiator, TASK, task, oldData);
|
||||
newMember = null;
|
||||
}
|
||||
|
||||
public TaskEvent(UmbrellaUser initiator, Task task, UmbrellaUser newMember) {
|
||||
super(initiator, TASK, task, MEMBER_ADDED);
|
||||
this.newMember = newMember;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return diff().orElse("[TODO: TaskEvent.describe()]");
|
||||
public Collection<UmbrellaUser> audience() {
|
||||
return payload().members().values().stream().map(Member::user).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeCreate();
|
||||
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 describeMemberAdded() {
|
||||
var head = t("'{name}' has been added to '{task}' by '{user}'.",NAME,newMember.name(),Field.TASK,payload().name(),USER,initiator().name());
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
}
|
||||
|
||||
private Translatable describeCreate() {
|
||||
String parentName = null;
|
||||
var pid = payload().parentTaskId();
|
||||
if (pid != null) {
|
||||
var parent = taskService().load(List.of(pid)).get(pid);
|
||||
if (parent != null) parentName = parent.name();
|
||||
}
|
||||
if (parentName == null){
|
||||
var project = projectService().load(payload().projectId());
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> filter(Map<String, Object> map) {
|
||||
map.remove(MEMBERS);
|
||||
return super.filter(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,4 +89,16 @@ 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()){
|
||||
case CREATE -> t("The task '{task}' has been created", Field.TASK, payload().name());
|
||||
case DELETE -> t("The task '{task}' has been deleted",Field.TASK, payload().name());
|
||||
case MEMBER_ADDED, UPDATE -> t("Task '{task}' was edited",Field.TASK,payload().name());
|
||||
};
|
||||
}}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.OBJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.USER;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.WIKI;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.core.model.WikiPage;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -19,15 +21,18 @@ public class WikiEvent extends Event<WikiPage>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return diff().orElse("[TODO: WikiEvent.describe()]");
|
||||
public Collection<UmbrellaUser> audience() {
|
||||
return payload().members().values().stream().map(Member::user).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIntendedFor(UmbrellaUser user) {
|
||||
for (var member : payload().members().values()){
|
||||
if (member.user().equals(user)) return true;
|
||||
}
|
||||
return false;
|
||||
public Translatable describe() {
|
||||
return diff().map(UnTranslatable::new).map(Translatable.class::cast)
|
||||
.orElseGet(() -> t("[TODO: {object}.describe]",OBJECT,this.getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subject() {
|
||||
return t("{user} edited {object}",USER,initiator(),OBJECT,payload());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ package de.srsoftware.umbrella.core.constants;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Constants {
|
||||
|
||||
private Constants(){
|
||||
@@ -17,6 +19,7 @@ public class Constants {
|
||||
public static final String NO_CACHE = "no-cache";
|
||||
public static final String NONE = "none";
|
||||
public static final String TABLE_SETTINGS = "settings";
|
||||
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
|
||||
public static final String UMBRELLA = "Umbrella";
|
||||
public static final String UTF8 = UTF_8.displayName();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ public class Field {
|
||||
public static final String ATTACHMENTS = "attachments";
|
||||
public static final String AUTHORIZATION = "Authorization";
|
||||
|
||||
public static final String BASE_URL = "umbrella.base_url";
|
||||
public static final String BANK_ACCOUNT = "bank_account";
|
||||
public static final String BODY = "body";
|
||||
|
||||
@@ -67,8 +68,10 @@ public class Field {
|
||||
|
||||
public static final String HASH = "hash";
|
||||
public static final String HEAD = "head";
|
||||
public static final String HOURS = "hours";
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String INSTANTLY = "instantly";
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEM_CODE = "item_code";
|
||||
|
||||
@@ -112,6 +115,7 @@ public class Field {
|
||||
public static final String PRICE = "single_price";
|
||||
public static final String PRICE_FORMAT = "price_format";
|
||||
public static final String PRIORITY = "priority";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
public static final String PROPERTIES = "properties";
|
||||
|
||||
@@ -123,6 +127,7 @@ public class Field {
|
||||
public static final String SENDER = "sender";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String SHOW_CLOSED = "show_closed";
|
||||
public static final String SILENT = "silent";
|
||||
public static final String SOURCE = "source";
|
||||
public static final String START_DATE = "start_date";
|
||||
public static final String START_TIME = "start_time";
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Path {
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
|
||||
public static final String READ = "read";
|
||||
public static final String REDIRECT = "redirect";
|
||||
|
||||
public static final String SEARCH = "search";
|
||||
|
||||
@@ -23,6 +23,11 @@ public class EmailAddress {
|
||||
return obj instanceof EmailAddress other && Objects.equals(email,other.email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return email.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return email;
|
||||
|
||||
@@ -9,6 +9,7 @@ import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -17,8 +18,9 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Envelope {
|
||||
private Message message;
|
||||
private Set<User> receivers;
|
||||
private final Message message;
|
||||
private final Set<User> receivers;
|
||||
private final LocalDateTime time;
|
||||
|
||||
public Envelope(Message message, User receiver){
|
||||
this(message,new HashSet<>(Set.of(receiver)));
|
||||
@@ -27,6 +29,7 @@ public class Envelope {
|
||||
public Envelope(Message message, HashSet<User> receivers) {
|
||||
this.message = message;
|
||||
this.receivers = receivers;
|
||||
time = LocalDateTime.now();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +52,17 @@ public class Envelope {
|
||||
return new Envelope(message,receivers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (!(o instanceof Envelope envelope)) return false;
|
||||
return message.equals(envelope.message) && time.equals(envelope.time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * message.hashCode() + time.hashCode();
|
||||
}
|
||||
|
||||
public boolean isFor(User receiver) {
|
||||
return receivers.contains(receiver);
|
||||
}
|
||||
@@ -61,6 +75,10 @@ public class Envelope {
|
||||
return receivers;
|
||||
}
|
||||
|
||||
public LocalDateTime time(){
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format("{0} (to: {1}), subject: {2}",getClass().getSimpleName(),receivers.stream().map(User::email).map(EmailAddress::toString).collect(Collectors.joining(", ")),message.subject());
|
||||
|
||||
@@ -9,12 +9,13 @@ import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.util.*;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public record Message(UmbrellaUser sender, String subject, String body, Map<String,String> fills, List<Attachment> attachments) {
|
||||
public record Message(UmbrellaUser sender, Translatable subject, Translatable body, List<Attachment> attachments) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Message message)) return false;
|
||||
@@ -43,7 +44,7 @@ public record Message(UmbrellaUser sender, String subject, String body, Map<Stri
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Message(sender,subject,body,null, attachments);
|
||||
return new Message(sender,new UnTranslatable(subject),new UnTranslatable(body),attachments);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.*;
|
||||
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Translatable {
|
||||
private final String message;
|
||||
private Map<String, Object> fills;
|
||||
protected final String message;
|
||||
private final Map<String, Object> fills;
|
||||
private final HashMap<String,String> translated = new HashMap<>();
|
||||
|
||||
public Translatable(String message, Map<String,Object> fills){
|
||||
@@ -39,7 +41,7 @@ public class Translatable {
|
||||
}
|
||||
|
||||
public String translate(String language){
|
||||
var translation = language != null ? translated.get(language) : null;
|
||||
var translation = language == null ? null : translated.get(language);
|
||||
if (translation == null){
|
||||
var translatedFills = new HashMap<String,String>();
|
||||
if (fills != null) {
|
||||
@@ -54,7 +56,7 @@ public class Translatable {
|
||||
}
|
||||
}
|
||||
translation = ModuleRegistry.translator().translate(language,message,translatedFills);
|
||||
if (translation != null) translated.put(language,translation);
|
||||
if (allSet(language, translation)) translated.put(language,translation);
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
|
||||
|
||||
public class UnTranslatable extends Translatable{
|
||||
public UnTranslatable(String message) {
|
||||
super(message, null);
|
||||
}
|
||||
|
||||
public String translate(String language){
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,17 @@ public class User {
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof User user)) return false;
|
||||
return email.equals(user.email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return email.hashCode();
|
||||
}
|
||||
|
||||
public String language(){
|
||||
return lang;
|
||||
}
|
||||
|
||||
@@ -157,6 +157,11 @@ public class WikiPage implements Mappable {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public int version(){
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -577,7 +577,7 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
||||
LOG.log(WARNING,e);
|
||||
}
|
||||
var attachment = new Attachment(doc.number()+".pdf",rendered.mimeType(),rendered.bytes());
|
||||
var message = new Message(user,subject,content,null,List.of(attachment));
|
||||
var message = new Message(user,new UnTranslatable(subject),new UnTranslatable(content),List.of(attachment));
|
||||
var envelope = new Envelope(message,new User(doc.customer().shortName(),new EmailAddress(email),doc.customer().language()));
|
||||
postBox().send(envelope);
|
||||
db.save(doc.set(SENT));
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
import Kanban from "./routes/project/Kanban.svelte";
|
||||
import Login from "./Components/Login.svelte";
|
||||
import Messages from "./routes/message/Messages.svelte";
|
||||
import MsgSettings from "./routes/message/Settings.svelte";
|
||||
import Menu from "./Components/Menu.svelte";
|
||||
import NewPage from "./routes/wiki/AddPage.svelte";
|
||||
import Notes from "./routes/notes/Index.svelte";
|
||||
@@ -91,7 +92,8 @@
|
||||
<Route path="/document/:id/send" component={SendDoc} />
|
||||
<Route path="/document/:id/view" component={ViewDoc} />
|
||||
<Route path="/files/*" component={FileIndex} />
|
||||
<Route path="/message/settings" component={Messages} />
|
||||
<Route path="/message" component={Messages} />
|
||||
<Route path="/message/settings" component={MsgSettings} />
|
||||
<Route path="/notes" component={Notes} />
|
||||
<Route path="/project" component={ProjectList} />
|
||||
<Route path="/project/add" component={ProjectAdd} />
|
||||
|
||||
@@ -69,6 +69,7 @@ onMount(fetchModules);
|
||||
<a href="/wiki" {onclick} class="wiki">{t('wiki')}</a>
|
||||
<a href="/contact" {onclick} class="contact">{t('contacts')}</a>
|
||||
<a href="/stock" {onclick} class="stock">{t('stock')}</a>
|
||||
<a href="/message" {onclick} class="message">{t('messages')}</a>
|
||||
{#if user.id == 2}
|
||||
<a href="https://svelte.dev/tutorial/svelte/state" target="_blank">{t('tutorial')}</a>
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,95 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
import { t } from '../../translations.svelte';
|
||||
import { api, get, patch } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
|
||||
let router = useTinyRouter();
|
||||
let messages = [];
|
||||
let timer = null;
|
||||
|
||||
async function display(hash){
|
||||
const url = api(`message/${hash}`);
|
||||
const res = await get(url);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
const json = await res.json();
|
||||
if (timer) clearTimeout(timer);
|
||||
for (let i in messages){
|
||||
if (messages[i].hash == hash){
|
||||
messages[i].body = json.body;
|
||||
timer = setTimeout(() => {mark_read(hash)}, 2000);
|
||||
} else {
|
||||
delete messages[i].body;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async function load(){
|
||||
const url = api('message');
|
||||
const res = await get(url);
|
||||
if (res.ok){
|
||||
messages = await res.json();
|
||||
yikes();
|
||||
} else {
|
||||
error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async function mark_read(hash){
|
||||
timer = null;
|
||||
const url = api(`message/read/${hash}`);
|
||||
const res = await patch(url);
|
||||
if (res.ok) {
|
||||
for (let i in messages){
|
||||
if (messages[i].hash == hash) messages[i].read = true;
|
||||
}
|
||||
yikes();
|
||||
} else {
|
||||
error(res);
|
||||
}
|
||||
}
|
||||
|
||||
function showSettings(){
|
||||
router.navigate("message/settings");
|
||||
}
|
||||
|
||||
onMount(load);
|
||||
</script>
|
||||
|
||||
<fieldset>
|
||||
<legend>{t('messages')}</legend>
|
||||
<legend>{t('messages')} <button onclick={showSettings}>{t('settings')}</button></legend>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t('timestamp')}</th>
|
||||
<th>{t('initiator')}</th>
|
||||
<th>{t('subject')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each messages as message}
|
||||
<tr class="message-{message.hash}" onclick={ev => display(message.hash)}>
|
||||
<td>
|
||||
{#if message.read}→ {/if}
|
||||
{message.timestamp}
|
||||
</td>
|
||||
<td>{message.sender}</td>
|
||||
<td>{message.subject}</td>
|
||||
</tr>
|
||||
{#if message.body}
|
||||
<tr class="message-{message.hash} body">
|
||||
<td></td>
|
||||
<td colspan="2">
|
||||
<pre>{message.body.trim()}</pre>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
@@ -0,0 +1,201 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
import { api, get, patch } from '../../urls.svelte';
|
||||
import { error, warn, yikes } from '../../warn.svelte';
|
||||
|
||||
let instant = false;
|
||||
let silent = false;
|
||||
let at8 = false;
|
||||
let at9 = false;
|
||||
let at10 = false;
|
||||
let at11 = false;
|
||||
let at12 = false;
|
||||
let at13 = false;
|
||||
let at14 = true;
|
||||
let at15 = false;
|
||||
let at16 = false;
|
||||
let at17 = false;
|
||||
let at18 = false;
|
||||
let at19 = false;
|
||||
let at20 = false;
|
||||
let at21 = false;
|
||||
let at22 = false;
|
||||
|
||||
function delivery(mode){
|
||||
if (mode){
|
||||
silent = false;
|
||||
} else {
|
||||
instant = false;
|
||||
}
|
||||
at8 = at9 = at10 = at11 = at12 = at13 = at14 = at15 = at16 = at17 = at18 = at19 = at20 = at21 = at22 = false;
|
||||
saveTimes();
|
||||
}
|
||||
|
||||
async function loadSettings(){
|
||||
const url = api('message/settings');
|
||||
const res = await get(url);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
const json = await res.json();
|
||||
if (json.hours){
|
||||
at8 = json.hours.includes(8);
|
||||
at9 = json.hours.includes(9);
|
||||
at10 = json.hours.includes(10);
|
||||
at11 = json.hours.includes(11);
|
||||
at12 = json.hours.includes(12);
|
||||
at13 = json.hours.includes(13);
|
||||
at14 = json.hours.includes(14);
|
||||
at15 = json.hours.includes(15);
|
||||
at16 = json.hours.includes(16);
|
||||
at17 = json.hours.includes(17);
|
||||
at18 = json.hours.includes(18);
|
||||
at19 = json.hours.includes(19);
|
||||
at20 = json.hours.includes(20);
|
||||
at21 = json.hours.includes(21);
|
||||
at22 = json.hours.includes(22);
|
||||
instant = false;
|
||||
silent = !(at8 || at9 || at10 || at11 || at12 || at13 || at14 || at15 || at16 || at17 || at18 || at19 || at20 || at21 || at22);
|
||||
} else {
|
||||
instant = json.instantly;
|
||||
silent = !instant;
|
||||
at8 = at9 = at10 = at11 = at12 = at13 = at14 = at15 = at16 = at17 = at18 = at19 = at20 = at21 = at22 = false;
|
||||
}
|
||||
} else {
|
||||
error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveTimes(){
|
||||
let data = {
|
||||
instantly : instant,
|
||||
hours : []
|
||||
}
|
||||
if (at8) data.hours.push(8);
|
||||
if (at9) data.hours.push(9);
|
||||
if (at10) data.hours.push(10);
|
||||
if (at11) data.hours.push(11);
|
||||
if (at12) data.hours.push(12);
|
||||
if (at13) data.hours.push(13);
|
||||
if (at14) data.hours.push(14);
|
||||
if (at15) data.hours.push(15);
|
||||
if (at16) data.hours.push(16);
|
||||
if (at17) data.hours.push(17);
|
||||
if (at18) data.hours.push(18);
|
||||
if (at19) data.hours.push(19);
|
||||
if (at20) data.hours.push(20);
|
||||
if (at21) data.hours.push(21);
|
||||
if (at22) data.hours.push(22);
|
||||
let url = api('message/settings');
|
||||
let res = await patch(url,data);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
warn(t('saved'));
|
||||
setTimeout(yikes,2500);
|
||||
} else {
|
||||
error(res);
|
||||
}
|
||||
}
|
||||
|
||||
function selectTime(ev){
|
||||
instant = false;
|
||||
silent = !(at8 || at9 || at10 || at11 || at12 || at13 || at14 || at15 || at16 || at17 || at18 || at19 || at20 || at21 || at22);
|
||||
saveTimes();
|
||||
}
|
||||
|
||||
onMount(loadSettings)
|
||||
</script>
|
||||
|
||||
<fieldset class="message settings">
|
||||
<legend>{t('message settings')}</legend>
|
||||
<p>{t('When shall messages be delivered?')}</p>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<label>
|
||||
<input type="checkbox" onchange={ev => delivery(true)} bind:checked={instant} />{t('instantly')}
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{t('collect messages and send them at')}
|
||||
</td>
|
||||
<td>
|
||||
⎧<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎨<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎪<br/>
|
||||
⎩
|
||||
</td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at8} />{t('8 am')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at9} />{t('9:00 am')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at10} />{t('10:00 am')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at11} />{t('11:00 am')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at12} />{t('noon')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at13} />{t('1:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at14} />{t('2:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at15} />{t('3:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at16} />{t('4:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at17} />{t('5:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at18} />{t('6:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at19} />{t('7:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at20} />{t('8:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at21} />{t('9:00 pm')}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" onchange={selectTime} bind:checked={at22} />{t('10:00 pm')}
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<label>
|
||||
<input type="checkbox" onchange={ev => delivery(false)} bind:checked={silent} />{t('i don`t want to receive email notifications!')}
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
@@ -4,12 +4,12 @@ package de.srsoftware.umbrella.journal;
|
||||
import static de.srsoftware.tools.jdbc.Query.insertInto;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.failedToCreateTable;
|
||||
import static de.srsoftware.umbrella.journal.Constants.ERROR_WRITE_EVENT;
|
||||
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.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -43,7 +43,7 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
||||
try {
|
||||
db.prepareStatement(sql).execute();
|
||||
} catch (SQLException e) {
|
||||
throw UmbrellaException.failedToCreateTable(TABLE_JOURNAL);
|
||||
throw failedToCreateTable(TABLE_JOURNAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
description = "Umbrella : Message subsystem"
|
||||
|
||||
dependencies{
|
||||
implementation(project(":bus"))
|
||||
implementation(project(":core"))
|
||||
implementation("com.sun.mail:jakarta.mail:2.0.1")
|
||||
implementation("org.bitbucket.b_c:jose4j:0.9.6")
|
||||
|
||||
@@ -1,23 +1,39 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.message;
|
||||
|
||||
import static de.srsoftware.tools.PathHandler.CONTENT_TYPE;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.TIME_FORMATTER;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.UTF8;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.READ;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.SETTINGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.LONG;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingConfig;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static de.srsoftware.umbrella.message.Constants.*;
|
||||
import static de.srsoftware.umbrella.message.model.Schedule.schedule;
|
||||
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
|
||||
import static java.lang.System.Logger.Level.*;
|
||||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.api.PostBox;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Envelope;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.core.model.User;
|
||||
import de.srsoftware.umbrella.message.model.CombinedMessage;
|
||||
import de.srsoftware.umbrella.message.model.*;
|
||||
import de.srsoftware.umbrella.messagebus.EventListener;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
import jakarta.activation.DataHandler;
|
||||
import jakarta.mail.Message;
|
||||
import jakarta.mail.Message.RecipientType;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.Transport;
|
||||
@@ -25,11 +41,14 @@ import jakarta.mail.internet.MimeBodyPart;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
import jakarta.mail.util.ByteArrayDataSource;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class MessageSystem implements PostBox {
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class MessageSystem extends BaseHandler implements PostBox, EventListener {
|
||||
public static final System.Logger LOG = System.getLogger(MessageSystem.class.getSimpleName());
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
@@ -59,9 +78,6 @@ public class MessageSystem implements PostBox {
|
||||
timer.schedule(this,date.getTime());
|
||||
LOG.log(INFO,"Scheduled {0} at {1}",getClass().getSimpleName(),date.getTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
private final String from,host,user,pass;
|
||||
private final int port;
|
||||
@@ -77,8 +93,8 @@ public class MessageSystem implements PostBox {
|
||||
debugAddress = config.get(DEBUG_ADDREESS).map(Object::toString).orElse(null);
|
||||
port = config.get(CONFIG_SMTP_PORT,587);
|
||||
host = config.get(CONFIG_SMTP_HOST).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.host not configured!"));
|
||||
user = config.get(CONFIG_SMTP_USER).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.user not configured!"));
|
||||
pass = config.get(CONFIG_SMTP_PASS).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.pass not configured!"));
|
||||
user = config.get(CONFIG_SMTP_USER).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.user not configured!"));
|
||||
pass = config.get(CONFIG_SMTP_PASS).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.pass not configured!"));
|
||||
from = user;
|
||||
ModuleRegistry.add(this);
|
||||
new SubmissionTask(8).schedule();
|
||||
@@ -88,12 +104,110 @@ public class MessageSystem implements PostBox {
|
||||
new SubmissionTask(16).schedule();
|
||||
new SubmissionTask(18).schedule();
|
||||
new SubmissionTask(20).schedule();
|
||||
messageBus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Envelope envelope) {
|
||||
queue.add(envelope);
|
||||
new Thread(() -> processMessages(null)).start();
|
||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = ModuleRegistry.userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var head = path.pop();
|
||||
return switch (head){
|
||||
case null -> listMessages(ex,user.get());
|
||||
case SETTINGS -> getSettings(ex,user.get());
|
||||
default -> {
|
||||
try {
|
||||
yield getMessage(ex,user.get(),Integer.parseInt(head));
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
||||
}
|
||||
yield super.doGet(path, ex);
|
||||
}
|
||||
};
|
||||
} catch (NumberFormatException e){
|
||||
return sendContent(ex,HTTP_BAD_REQUEST,"Invalid project id");
|
||||
} catch (UmbrellaException e){
|
||||
return send(ex,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = ModuleRegistry.userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var head = path.pop();
|
||||
return switch (head){
|
||||
case SETTINGS -> patchSettings(ex,user.get());
|
||||
case READ -> patchState(ex,user.get(),path.pop());
|
||||
default -> super.doGet(path,ex);
|
||||
};
|
||||
} catch (NumberFormatException e){
|
||||
return sendContent(ex,HTTP_BAD_REQUEST,"Invalid project id");
|
||||
} catch (UmbrellaException e){
|
||||
return send(ex,e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getMessage(HttpExchange ex, UmbrellaUser user, int hash) throws IOException {
|
||||
var envelope = queue.stream()
|
||||
.filter(msg -> msg.isFor(user))
|
||||
.filter(msg -> msg.hashCode() == hash)
|
||||
.findFirst();
|
||||
if (envelope.isPresent()) return sendMessage(ex, user, envelope.get());
|
||||
return notFound(ex);
|
||||
}
|
||||
|
||||
private boolean getSettings(HttpExchange ex, UmbrellaUser user) throws IOException {
|
||||
return sendContent(ex,db.getSettings(user));
|
||||
}
|
||||
|
||||
private boolean listMessages(HttpExchange ex, UmbrellaUser user) throws IOException {
|
||||
var messages = queue.stream().filter(e -> e.isFor(user)).map(e -> summary(e, user.language())).toList();
|
||||
return sendContent(ex,messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(Event<?> event) {
|
||||
for (var user : event.audience()){
|
||||
if (debugAddress != null && !debugAddress.equals(user.email().toString())) continue;
|
||||
var message = new de.srsoftware.umbrella.core.model.Message(event.initiator(),event.subject(),event.describe(),null);
|
||||
var envelope = new Envelope(message,user);
|
||||
send(envelope);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean patchSettings(HttpExchange ex, UmbrellaUser user) throws IOException {
|
||||
var json = json(ex);
|
||||
Settings settings = null;
|
||||
if (json.has(INSTANTLY) && json.get(INSTANTLY) instanceof Boolean b && b){
|
||||
settings = new Instantly();
|
||||
} else {
|
||||
if (json.has(HOURS) && json.get(HOURS) instanceof JSONArray hrs){
|
||||
var hours = hrs.toList().stream().filter(v -> v instanceof Integer).map(Integer.class::cast).toList();
|
||||
settings = schedule(hours);
|
||||
} else settings = new Silent();
|
||||
}
|
||||
return sendContent(ex,db.update(user,settings));
|
||||
}
|
||||
|
||||
private boolean patchState(HttpExchange ex, UmbrellaUser user, String path) {
|
||||
try {
|
||||
var hash = Integer.parseInt(path);
|
||||
var envelope = queue.stream().filter(env -> env.hashCode() == hash).findFirst().orElse(null);
|
||||
if (envelope != null){
|
||||
envelope.receivers().remove(user);
|
||||
return sendMessage(ex,user,envelope);
|
||||
}
|
||||
return notFound(ex);
|
||||
} catch (NumberFormatException | IOException e) {
|
||||
throw invalidField(HASH,LONG);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void processMessages(Integer scheduledHour) {
|
||||
@@ -116,14 +230,12 @@ public class MessageSystem implements PostBox {
|
||||
var date = new Date();
|
||||
|
||||
for (var receiver : dueRecipients){
|
||||
BiFunction<String,Map<String,String>,String> translateFunction = (text,fills) -> ModuleRegistry.translator().translate(receiver.language(),text,fills);
|
||||
|
||||
var combined = new CombinedMessage("Collected messages",translateFunction);
|
||||
var combined = new CombinedMessage(t("Collected messages"),receiver);
|
||||
var envelopes = queue.stream().filter(env -> env.isFor(receiver)).toList();
|
||||
for (var envelope : envelopes) combined.merge(envelope.message());
|
||||
|
||||
try {
|
||||
send(combined,receiver,date);
|
||||
send(combined,date);
|
||||
for (var envelope : envelopes){
|
||||
var audience = envelope.receivers();
|
||||
audience.remove(receiver);
|
||||
@@ -139,6 +251,69 @@ public class MessageSystem implements PostBox {
|
||||
if (scheduledHour != null) new SubmissionTask(scheduledHour).schedule();
|
||||
}
|
||||
|
||||
private boolean sendMessage(HttpExchange ex, UmbrellaUser user, Envelope envelope) throws IOException {
|
||||
var message = envelope.message();
|
||||
var sender = message.sender().name();
|
||||
var subject = message.subject().translate(user.language());
|
||||
var body = message.body().translate(user.language());
|
||||
return sendContent(ex,Map.of(
|
||||
SENDER,sender,
|
||||
SUBJECT,subject,
|
||||
BODY,body
|
||||
));
|
||||
}
|
||||
|
||||
private static JSONObject summary(Envelope envelope, String lang) {
|
||||
var sender = envelope.message().sender().name();
|
||||
var subject = envelope.message().subject().translate(lang);
|
||||
var time = envelope.time().format(TIME_FORMATTER);
|
||||
var hash = envelope.hashCode();
|
||||
return new JSONObject(Map.of(SENDER,sender,SUBJECT,subject,TIMESTAMP,time,HASH,hash));
|
||||
}
|
||||
|
||||
|
||||
private void send(CombinedMessage message, Date date) throws MessagingException {
|
||||
var receiver = message.receiver();
|
||||
LOG.log(TRACE,"Sending combined message to {0}…",receiver);
|
||||
session = session();
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
msg.addHeader(CONTENT_TYPE, "text/markdown; charset=UTF-8");
|
||||
msg.addHeader("format", "flowed");
|
||||
msg.addHeader("Content-Transfer-Encoding", "8bit");
|
||||
msg.setFrom(message.sender().email().toString());
|
||||
msg.setSubject(message.subject(), UTF8);
|
||||
msg.setSentDate(date);
|
||||
var toEmail = debugAddress != null ? debugAddress : receiver.email().toString();
|
||||
msg.setRecipients(RecipientType.TO, toEmail);
|
||||
|
||||
if (message.attachments().isEmpty()){
|
||||
msg.setText(message.body(), UTF8);
|
||||
} else {
|
||||
var multipart = new MimeMultipart();
|
||||
var body = new MimeBodyPart();
|
||||
body.setText(message.body(),UTF8);
|
||||
|
||||
multipart.addBodyPart(body);
|
||||
for (var attachment : message.attachments()){
|
||||
var part = new MimeBodyPart();
|
||||
part.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment.content(),attachment.mime())));
|
||||
part.setFileName(attachment.name());
|
||||
multipart.addBodyPart(part);
|
||||
msg.setContent(multipart);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.log(TRACE, "Message to {0} is ready…", receiver);
|
||||
Transport.send(msg,user,pass);
|
||||
LOG.log(DEBUG, "Sent message to {0}.", receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Envelope envelope) {
|
||||
queue.add(envelope);
|
||||
new Thread(() -> processMessages(null)).start();
|
||||
}
|
||||
|
||||
private Session session() {
|
||||
if (session == null){
|
||||
Properties props = new Properties();
|
||||
@@ -156,41 +331,4 @@ public class MessageSystem implements PostBox {
|
||||
this.debugAddress = newVal;
|
||||
}
|
||||
|
||||
|
||||
private void send(CombinedMessage message, User receiver, Date date) throws MessagingException {
|
||||
LOG.log(TRACE,"Sending combined message to {0}…",receiver);
|
||||
session = session();
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
msg.addHeader(CONTENT_TYPE, "text/markdown; charset=UTF-8");
|
||||
msg.addHeader("format", "flowed");
|
||||
msg.addHeader("Content-Transfer-Encoding", "8bit");
|
||||
msg.setFrom(message.sender().email().toString());
|
||||
msg.setSubject(message.subject(), UTF8);
|
||||
msg.setSentDate(date);
|
||||
var toEmail = debugAddress != null ? debugAddress : receiver.email().toString();
|
||||
msg.setRecipients(Message.RecipientType.TO, toEmail);
|
||||
|
||||
if (message.attachments().isEmpty()){
|
||||
msg.setText(message.body(), UTF8);
|
||||
} else {
|
||||
var multipart = new MimeMultipart();
|
||||
var body = new MimeBodyPart();
|
||||
body.setText(message.body(),UTF8);
|
||||
|
||||
multipart.addBodyPart(body);
|
||||
for (var attachment : message.attachments()){
|
||||
var part = new MimeBodyPart();
|
||||
part.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment.content(),attachment.mime())));
|
||||
part.setFileName(attachment.name());
|
||||
multipart.addBodyPart(part);
|
||||
msg.setContent(multipart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOG.log(TRACE, "Message to {0} is ready…", receiver);
|
||||
Transport.send(msg,user,pass);
|
||||
LOG.log(DEBUG, "Sent message to {0}.", receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@ import static de.srsoftware.umbrella.core.constants.Constants.TABLE_SETTINGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static de.srsoftware.umbrella.message.model.Settings.Times;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
import static de.srsoftware.umbrella.message.model.Schedule.schedule;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.message.model.Instantly;
|
||||
import de.srsoftware.umbrella.message.model.Settings;
|
||||
import de.srsoftware.umbrella.message.model.Silent;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SqliteMessageDb implements MessageDb{
|
||||
private static final System.Logger LOG = System.getLogger(SqliteMessageDb.class.getSimpleName());
|
||||
@@ -100,21 +100,19 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
|
||||
private Settings toSettings(ResultSet rs) throws SQLException {
|
||||
var submission = rs.getString(VALUE);
|
||||
var parts = submission.split(",");
|
||||
var times = new HashSet<Times>();
|
||||
for (var part : parts) try {
|
||||
times.add(Times.valueOf(part));
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.log(WARNING,"encountered {0}, which is not a valid Times enumeration value!",part);
|
||||
if (submission.trim().equalsIgnoreCase(INSTANTLY)) return new Instantly();
|
||||
try {
|
||||
var times = Arrays.stream(submission.split(",")).map(Integer::parseInt).toList();
|
||||
return schedule(times);
|
||||
} catch (NumberFormatException nfe){
|
||||
return new Silent();
|
||||
}
|
||||
return new Settings(times);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings update(UmbrellaUser user, Settings settings) throws UmbrellaException {
|
||||
var times = settings.times().stream().map(Times::toString).collect(Collectors.joining(","));
|
||||
try {
|
||||
replaceInto(TABLE_SUBMISSIONS, USER_ID, VALUE).values(user.id(),times).execute(db).close();
|
||||
replaceInto(TABLE_SUBMISSIONS, USER_ID, VALUE).values(user.id(),settings.toString()).execute(db).close();
|
||||
return settings;
|
||||
} catch (SQLException e) {
|
||||
throw failedToStoreObject("submission data").causedBy(e);
|
||||
|
||||
@@ -5,33 +5,31 @@ import static java.lang.System.Logger.Level.DEBUG;
|
||||
import static java.lang.System.Logger.Level.TRACE;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.Attachment;
|
||||
import de.srsoftware.umbrella.core.model.Message;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CombinedMessage {
|
||||
private static final System.Logger LOG = System.getLogger(CombinedMessage.class.getSimpleName());
|
||||
|
||||
private final Set<Attachment> attachments = new HashSet<>();
|
||||
private final StringBuilder combinedBody = new StringBuilder();
|
||||
private final User receiver;
|
||||
private String combinedSubject = null;
|
||||
private final List<Message> mergedMessages = new ArrayList<>();
|
||||
private final String subjectForCombinedMessage;
|
||||
private final BiFunction<String,Map<String,String>,String> translate;
|
||||
private final Translatable subjectForCombinedMessage;
|
||||
private UmbrellaUser sender = null;
|
||||
|
||||
public CombinedMessage(String subjectForCombinedMessage, BiFunction<String, Map<String,String>,String> translateFunction){
|
||||
public CombinedMessage(Translatable subjectForCombinedMessage, User receiver){
|
||||
LOG.log(DEBUG,"Creating combined message…");
|
||||
this.subjectForCombinedMessage = subjectForCombinedMessage;
|
||||
translate = translateFunction;
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
public void merge(Message message) {
|
||||
LOG.log(TRACE,"Merging {0} into combined message…",message);
|
||||
var body = translate.apply(message.body(),message.fills());
|
||||
var subject = translate.apply(message.subject(),message.fills());
|
||||
var lang = receiver.language();
|
||||
var body = message.body().translate(lang);
|
||||
var subject = message.subject().translate(lang);
|
||||
switch (mergedMessages.size()){
|
||||
case 0:
|
||||
combinedBody.append(body);
|
||||
@@ -40,7 +38,7 @@ public class CombinedMessage {
|
||||
break;
|
||||
case 1:
|
||||
combinedBody.insert(0,format("# {0}:\n# {1}:\n\n",sender,subject)); // insert sender and subject of first message right before the body of the first message
|
||||
combinedSubject = subjectForCombinedMessage;
|
||||
combinedSubject = subjectForCombinedMessage.translate(lang);
|
||||
// no break here, we need to append the subject and content
|
||||
default:
|
||||
combinedBody.append("\n\n# ").append(message.sender()).append(":\n");
|
||||
@@ -59,6 +57,14 @@ public class CombinedMessage {
|
||||
return combinedBody.toString();
|
||||
}
|
||||
|
||||
public List<Message> messages() {
|
||||
return mergedMessages;
|
||||
}
|
||||
|
||||
public User receiver(){
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public UmbrellaUser sender() {
|
||||
return sender;
|
||||
}
|
||||
@@ -67,7 +73,10 @@ public class CombinedMessage {
|
||||
return combinedSubject;
|
||||
}
|
||||
|
||||
public List<Message> messages() {
|
||||
return mergedMessages;
|
||||
@Override
|
||||
public String toString() {
|
||||
var body = body();
|
||||
if (body.length()>100) body = body.substring(0,99)+"…";
|
||||
return format("{0} for {1} ({2}): {3}",getClass().getSimpleName(),receiver.email(),subject(),body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.message.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.INSTANTLY;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Instantly implements Settings{
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(INSTANTLY,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendAt(Integer scheduledHour) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return INSTANTLY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.message.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.HOURS;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class Schedule implements Settings{
|
||||
|
||||
private final HashSet<Integer> hours;
|
||||
|
||||
private Schedule(Collection<Integer> hours){
|
||||
this.hours = new HashSet<>(hours);
|
||||
}
|
||||
|
||||
public static Settings schedule(Collection<Integer> hours){
|
||||
return hours == null || hours.isEmpty() ? new Silent() : new Schedule(hours);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendAt(Integer scheduledHour) {
|
||||
return scheduledHour != null && hours.contains(scheduledHour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(HOURS,hours);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return hours.stream().map(Object::toString).collect(joining(","));
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,10 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.message.model;
|
||||
|
||||
import static de.srsoftware.umbrella.message.Constants.SUBMISSION;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public record Settings(Set<Times> times) implements Mappable {
|
||||
|
||||
public enum Times{
|
||||
INSTANTLY,
|
||||
AT8,
|
||||
AT10,
|
||||
AT12,
|
||||
AT14,
|
||||
AT16,
|
||||
AT18,
|
||||
AT20;
|
||||
|
||||
public boolean matches(int hour){
|
||||
if (this == INSTANTLY) return false;
|
||||
return Integer.parseInt(toString().substring(2)) == hour;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean sendAt(Integer scheduledHour) {
|
||||
return times.contains(Times.INSTANTLY) || (scheduledHour != null && times.stream().anyMatch(time -> time.matches(scheduledHour)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(SUBMISSION,times);
|
||||
}
|
||||
|
||||
public interface Settings extends Mappable {
|
||||
boolean sendAt(Integer scheduledHour);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.message.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.SILENT;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Silent implements Settings{
|
||||
@Override
|
||||
public boolean sendAt(Integer scheduledHour) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(SILENT,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "silent";
|
||||
}
|
||||
}
|
||||
@@ -49,11 +49,12 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
||||
ModuleRegistry.add(this);
|
||||
}
|
||||
|
||||
private void addMember(Project project, long userId) {
|
||||
private UmbrellaUser addMember(Project project, long userId) {
|
||||
var user = userService().loadUser(userId);
|
||||
var member = new Member(user,READ_ONLY);
|
||||
project.members().put(userId,member);
|
||||
project.dirty(MEMBERS);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,15 +214,16 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
||||
|
||||
private boolean patchProject(HttpExchange ex, long projectId, UmbrellaUser user) throws IOException, UmbrellaException {
|
||||
var project = loadMembers(projectDb.load(projectId));
|
||||
var old = project.toMap();
|
||||
if (!project.hasMember(user)) throw notAmember(t(PROJECT_WITH_ID,ID,project.name()));
|
||||
var old = project.toMap();
|
||||
var json = json(ex);
|
||||
UmbrellaUser newMember = null;
|
||||
if (json.has(DROP_MEMBER) && json.get(DROP_MEMBER) instanceof Number id) dropMember(project,id.longValue());
|
||||
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(project,memberJson);
|
||||
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) addMember(project,num.longValue());
|
||||
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) newMember = addMember(project,num.longValue());
|
||||
|
||||
project = projectDb.save(project.patch(json), user);
|
||||
messageBus().dispatch(new ProjectEvent(user,project, old));
|
||||
messageBus().dispatch(newMember != null ? new ProjectEvent(user,project,newMember) : new ProjectEvent(user,project, old));
|
||||
return sendContent(ex,project.toMap());
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.core.Errors.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.TABLE_SETTINGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.PROJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TYPE;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
|
||||
@@ -7,6 +7,7 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.*;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.PROJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TAGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TASKS;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.TASK;
|
||||
@@ -56,11 +57,12 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
ModuleRegistry.add(this);
|
||||
}
|
||||
|
||||
private void addMember(Task task, long userId) {
|
||||
private UmbrellaUser addMember(Task task, long userId) {
|
||||
var user = userService().loadUser(userId);
|
||||
var member = new Member(user, READ_ONLY);
|
||||
task.members().put(userId, member);
|
||||
task.dirty(MEMBERS);
|
||||
return user;
|
||||
}
|
||||
|
||||
private boolean deleteTask(HttpExchange ex, long taskId, UmbrellaUser user) throws IOException {
|
||||
@@ -328,12 +330,15 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
var member = task.members().get(user.id());
|
||||
if (member == null || member.permission() == READ_ONLY) throw forbidden("You are not a allowed to edit {object}!", OBJECT, task.name());
|
||||
var json = json(ex);
|
||||
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.");
|
||||
|
||||
UmbrellaUser newMember = null;
|
||||
if (json.has(DROP_MEMBER) && json.get(DROP_MEMBER) instanceof Number id) dropMember(task, id.longValue());
|
||||
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.");
|
||||
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) newMember = addMember(task, num.longValue());
|
||||
|
||||
task = taskDb.save(task.patch(json)).tags(tagService().getTags(TASK, taskId, user));
|
||||
messageBus().dispatch(new TaskEvent(user, task, old));
|
||||
messageBus().dispatch(newMember != null ? new TaskEvent(user, task, newMember) : new TaskEvent(user, task, old));
|
||||
return sendContent(ex, task);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.translations;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.BASE_URL;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingField;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.PathHandler;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
@@ -14,15 +17,21 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Translations extends PathHandler implements Translator {
|
||||
private static final System.Logger LOG = System.getLogger("Translations");
|
||||
private final String baseUrl;
|
||||
|
||||
private HashMap<String, JSONObject> translations = new HashMap<>();
|
||||
|
||||
public Translations() {
|
||||
public Translations(Configuration config) {
|
||||
ModuleRegistry.add(this);
|
||||
Optional<String> baseUrl = config.get(BASE_URL);
|
||||
if (baseUrl.isEmpty()) throw missingField(BASE_URL);
|
||||
this.baseUrl = baseUrl.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +79,7 @@ public class Translations extends PathHandler implements Translator {
|
||||
if (fills != null) for (var entry : fills.entrySet()) {
|
||||
translated = translated.replaceAll("\\{"+entry.getKey()+"}",entry.getValue());
|
||||
}
|
||||
return translated;
|
||||
return translated.replaceAll("\\{base_url}",baseUrl);
|
||||
} catch (IOException e) {
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"by": "von",
|
||||
|
||||
"cancel": "abbrechen",
|
||||
"Changes in task '{task}':\n\n{body}": "Änderungen an Aufgabe '{task}':\n\n{body}",
|
||||
"choose_type": "Typ wählen",
|
||||
"click_to_edit": "Anklicken zum Bearbeiten",
|
||||
"client_id": "Client-ID",
|
||||
@@ -143,7 +144,6 @@
|
||||
|
||||
"given_name": "Vorname",
|
||||
"go": "los!",
|
||||
"go_to_url_to_reset_password": "Um ein neues Passwort zu erhalten, öffnen Sie bitte den folgenden Link: {url}",
|
||||
"gross_sum": "Brutto-Summe",
|
||||
|
||||
"head": "Kopf-Text",
|
||||
@@ -189,6 +189,7 @@
|
||||
"members": "Mitarbeiter",
|
||||
"message": "Nachricht",
|
||||
"messages": "Benachrichtigungen",
|
||||
"message settings": "Benachrichtigungs-Einstellungen",
|
||||
"miscellaneous_settings": "sonstige Einstellungen",
|
||||
"missing_new_item_id": "Alter Artikel-ID ({0}) wurde keine neue ID zugeordnet!",
|
||||
"mismatch": "ungleich",
|
||||
@@ -218,6 +219,7 @@
|
||||
"my files": "Meine Dateien",
|
||||
|
||||
"name": "Name",
|
||||
"'{name}' has been added to '{task}' by '{user}'.": "'{name}' wurde von {user} zu '{task}' hinzugefügt.",
|
||||
"net_price": "Nettopreis",
|
||||
"net_sum": "Netto-Summe",
|
||||
"new_contact": "neuer Kontakt",
|
||||
@@ -332,6 +334,8 @@
|
||||
"tags": "Tags",
|
||||
"task": "Aufgabe",
|
||||
"task_list": "Aufgabenliste",
|
||||
"'{task}' has been added to '{object}':\n\n{body}": "'{task}' wurde zu '{object}' hinzugefügt:\n\n{body}",
|
||||
"Task '{task}' was edited": "Aufgabe '{task}' wurde bearbeitet",
|
||||
"tasks": "Aufgaben",
|
||||
"tasks_for_tag": "Aufgaben mit Tag „{tag}“",
|
||||
"tax_id": "Steuernummer",
|
||||
@@ -339,12 +343,16 @@
|
||||
"tax_rate": "Steuersatz",
|
||||
"template": "Vorlage",
|
||||
"theme": "Design",
|
||||
"The task '{task}' has been created": "Die Aufgabe '{task}' wurde angelegt",
|
||||
"The task '{task}' has been deleted": "Die Aufgabe '{task}' wurde gelöscht",
|
||||
"The task '{task}' has been deleted by {user}": "Die Aufgabe '{task}' wurde von {user} bearbeitet",
|
||||
"time ({id})": "Zeit ({id})",
|
||||
"times": "Zeiten",
|
||||
"timetracking": "Zeiterfassung",
|
||||
"title_not_available": "„{title}“ ist als Seitenname nicht mehr verfügbar!",
|
||||
"title_or_desc": "Titel/Beschreibung",
|
||||
"toggle_objects": "{objects} an/ausschalten",
|
||||
"To receive a new password, open the following link: {url}": "Um ein neues Passwort zu erhalten, öffnen Sie bitte den folgenden Link: {url}",
|
||||
"tutorial": "Tutorial",
|
||||
"type": "Dokumententyp",
|
||||
"type_confirmation": "Bestätigung",
|
||||
@@ -384,6 +392,7 @@
|
||||
"visible_to_guests": "Für Besucher sichtbar",
|
||||
|
||||
"year": "Jahr",
|
||||
"your_password_reset_token" : "Ihr Token zum Erstellen eines neuen Passworts",
|
||||
"You can view/edit this task at {base_url}/task/{id}/view": "Du kannst diese Aufgabe unter {base_url}/task/{id}/view ansehen/bearbeiten.",
|
||||
"Your token to create a new password" : "Ihr Token zum Erstellen eines neuen Passworts",
|
||||
"your_profile": "dein Profil"
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"by": "by",
|
||||
|
||||
"cancel": "cancel",
|
||||
"Changes in task '{task}':\n\n{body}": "Changes in task '{task}':\n\n{body}",
|
||||
"choose_type": "choose type",
|
||||
"click_to_edit": "click to edit",
|
||||
"client_id": "client ID",
|
||||
@@ -143,7 +144,6 @@
|
||||
|
||||
"given_name": "given name",
|
||||
"go": "go!",
|
||||
"go_to_url_to_reset_password": "To receive a new password, open the following link: {url}",
|
||||
"gross_sum": "gross sum",
|
||||
|
||||
"head": "header text",
|
||||
@@ -189,6 +189,7 @@
|
||||
"members": "members",
|
||||
"message": "message",
|
||||
"messages": "messages",
|
||||
"message settings": "message settings",
|
||||
"miscellaneous_settings": "miscellaneous settings",
|
||||
"missing_new_item_id": "Old item id ({0}) has no new counterpart!",
|
||||
"mismatch": "mismatch",
|
||||
@@ -218,6 +219,7 @@
|
||||
"my files": "my files",
|
||||
|
||||
"name": "Name",
|
||||
"'{name}' has been added to '{task}' by '{user}'.": "'{name}' has been added to '{task}' by '{user}'.",
|
||||
"net_price": "net price",
|
||||
"net_sum": "net sum",
|
||||
"new_contact": "new contact",
|
||||
@@ -332,6 +334,8 @@
|
||||
"tags": "tags",
|
||||
"task": "task",
|
||||
"task_list": "task list",
|
||||
"'{task}' has been added to '{object}':\n\n{body}": "'{task}' has been added to '{object}':\n\n{body}",
|
||||
"Task '{task}' was edited": "Task '{task}' was edited",
|
||||
"tasks": "tasks",
|
||||
"tasks_for_tag": "tasks with tag „{tag}“",
|
||||
"tax_id": "tax ID",
|
||||
@@ -339,12 +343,16 @@
|
||||
"tax_rate": "tax rate",
|
||||
"template": "template",
|
||||
"theme": "design",
|
||||
"The task '{task}' has been created": "The task '{task}' has been created",
|
||||
"The task '{task}' has been deleted": "The task '{task}' has been deleted",
|
||||
"The task '{task}' has been deleted by {user}": "The task '{task}' has been deleted by {user}",
|
||||
"time ({id})": "time ({id})",
|
||||
"times": "times",
|
||||
"timetracking": "time tracking",
|
||||
"title_not_available": "„{title}“ is not available as page name!",
|
||||
"title_or_desc": "title/description",
|
||||
"toggle_objects": "toggle {objects}",
|
||||
"To receive a new password, open the following link: {url}": "To receive a new password, open the following link: {url}",
|
||||
"tutorial": "tutorial",
|
||||
"type": "type",
|
||||
"type_confirmation": "confirmation",
|
||||
@@ -384,6 +392,7 @@
|
||||
"visible_to_guests": "visible to guests",
|
||||
|
||||
"year": "year",
|
||||
"your_password_reset_token" : "Your token to create a new password",
|
||||
"You can view/edit this task at {base_url}/task/{id}/view": "You can view/edit this task at {base_url}/task/{id}/view",
|
||||
"Your token to create a new password" : "Your token to create a new password",
|
||||
"your_profile": "your profile"
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import static de.srsoftware.umbrella.core.constants.Field.STATE;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.USER;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static de.srsoftware.umbrella.user.Constants.*;
|
||||
import static de.srsoftware.umbrella.user.Paths.*;
|
||||
import static de.srsoftware.umbrella.user.Paths.IMPERSONATE;
|
||||
@@ -502,11 +503,10 @@ public class UserModule extends BaseHandler implements UserService {
|
||||
if (oldToken != null) tokenMap.remove(oldToken);
|
||||
tokenMap.put(token,email);
|
||||
tokenMap.put(email,token);
|
||||
var subject = "user.your_password_reset_token";
|
||||
var content = "user.go_to_url_to_reset_password";
|
||||
var url = url(ex).replace("/api/user/reset_pw","/user/reset/pw")+"?token="+token;
|
||||
var fills = Map.of("url",url);
|
||||
var message = new Message(user,subject,content,fills,null);
|
||||
var subject = t("Your token to create a new password");
|
||||
var content = t("To receive a new password, open the following link: {url}",URL,url);
|
||||
var message = new Message(user,subject,content,null);
|
||||
var envelope = new Envelope(message,user);
|
||||
postBox().send(envelope);
|
||||
} catch (UmbrellaException e){
|
||||
|
||||
@@ -100,6 +100,10 @@ nav a.mark::before {
|
||||
content: " ";
|
||||
}
|
||||
|
||||
nav a.message::before {
|
||||
content: " ";
|
||||
}
|
||||
|
||||
nav a.note::before {
|
||||
content: " ";
|
||||
}
|
||||
@@ -133,6 +137,7 @@ nav a.contact,
|
||||
nav a.doc,
|
||||
nav a.file,
|
||||
nav a.mark,
|
||||
nav a.message,
|
||||
nav a.note,
|
||||
nav a.project,
|
||||
nav a.stock,
|
||||
@@ -318,6 +323,13 @@ textarea{
|
||||
max-height: unset;
|
||||
}
|
||||
|
||||
.message.settings label{
|
||||
display: block;
|
||||
}
|
||||
.message.settings td{
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.project th,
|
||||
.task th{
|
||||
text-align: right;
|
||||
|
||||
Reference in New Issue
Block a user