diff --git a/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java b/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java index 3e59a18..1a490ad 100644 --- a/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java +++ b/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java @@ -10,7 +10,6 @@ import de.srsoftware.configuration.JsonConfig; import de.srsoftware.tools.ColorLogger; import de.srsoftware.umbrella.bookmarks.BookmarkApi; import de.srsoftware.umbrella.company.CompanyModule; -import de.srsoftware.umbrella.core.ModuleRegistry; import de.srsoftware.umbrella.core.Util; import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.documents.DocumentApi; @@ -59,26 +58,25 @@ public class Application { var server = HttpServer.create(new InetSocketAddress(port), 0); - var registry = new ModuleRegistry(); - new Translations(registry).bindPath("/api/translations").on(server); - new MessageSystem(registry,config); - new UserModule(registry,config).bindPath("/api/user").on(server); - new TagModule(registry,config).bindPath("/api/tags").on(server); - new BookmarkApi(registry,config).bindPath("/api/bookmark").on(server); - new CompanyModule(registry, config).bindPath("/api/company").on(server); - new CompanyLegacy(registry, config).bindPath("/legacy/company").on(server); - new DocumentApi(registry, config).bindPath("/api/document").on(server); - new ItemApi(registry, config).bindPath("/api/items").on(server); - new UserLegacy(registry,config).bindPath("/legacy/user").on(server); - new NotesLegacy(registry,config).bindPath("/legacy/notes").on(server); - new MarkdownApi(registry).bindPath("/api/markdown").on(server); - new NoteModule(registry,config).bindPath("/api/notes").on(server); - new ProjectModule(registry, config).bindPath("/api/project").on(server); - new ProjectLegacy(registry,config).bindPath("/legacy/project").on(server); - new TaskModule(registry, config).bindPath("/api/task").on(server); - new TaskLegacy(registry, config).bindPath("/legacy/task").on(server); - new TimeModule(registry, config).bindPath("/api/time").on(server); - new WebHandler(registry).bindPath("/").on(server); + new Translations().bindPath("/api/translations").on(server); + new MessageSystem(config); + new UserModule(config).bindPath("/api/user").on(server); + new TagModule(config).bindPath("/api/tags").on(server); + new BookmarkApi(config).bindPath("/api/bookmark").on(server); + new CompanyModule(config).bindPath("/api/company").on(server); + new CompanyLegacy(config).bindPath("/legacy/company").on(server); + new DocumentApi(config).bindPath("/api/document").on(server); + new ItemApi(config).bindPath("/api/items").on(server); + new UserLegacy(config).bindPath("/legacy/user").on(server); + new NotesLegacy(config).bindPath("/legacy/notes").on(server); + new MarkdownApi().bindPath("/api/markdown").on(server); + new NoteModule(config).bindPath("/api/notes").on(server); + new ProjectModule(config).bindPath("/api/project").on(server); + new ProjectLegacy(config).bindPath("/legacy/project").on(server); + new TaskModule(config).bindPath("/api/task").on(server); + new TaskLegacy().bindPath("/legacy/task").on(server); + new TimeModule(config).bindPath("/api/time").on(server); + new WebHandler().bindPath("/").on(server); server.setExecutor(Executors.newFixedThreadPool(threads)); server.start(); diff --git a/bookmark/src/main/java/de/srsoftware/umbrella/bookmarks/BookmarkApi.java b/bookmark/src/main/java/de/srsoftware/umbrella/bookmarks/BookmarkApi.java index 311d58f..6be917a 100644 --- a/bookmark/src/main/java/de/srsoftware/umbrella/bookmarks/BookmarkApi.java +++ b/bookmark/src/main/java/de/srsoftware/umbrella/bookmarks/BookmarkApi.java @@ -29,10 +29,11 @@ import org.json.JSONArray; public class BookmarkApi extends BaseHandler implements BookmarkService { private final BookmarkDb db; - public BookmarkApi(ModuleRegistry registry, Configuration config) { - super(registry); + public BookmarkApi(Configuration config) { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); db = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } @Override @@ -40,7 +41,7 @@ public class BookmarkApi extends BaseHandler implements BookmarkService { addCors(ex); try { Optional token = SessionToken.from(ex).map(Token::of); - var user = userService().loadUser(token); + var user = ModuleRegistry.userService().loadUser(token); if (user.isEmpty()) return unauthorized(ex); var head = path.pop(); return switch (head) { @@ -60,7 +61,7 @@ public class BookmarkApi extends BaseHandler implements BookmarkService { private boolean getBookmark(UmbrellaUser user, long id, HttpExchange ex) throws IOException { var bookmark = db.load(id,user.id()); - tagService().getTags(BOOKMARK, id, user).forEach(bookmark.tags()::add); + ModuleRegistry.tagService().getTags(BOOKMARK, id, user).forEach(bookmark.tags()::add); return sendContent(ex,bookmark); } @@ -69,7 +70,7 @@ public class BookmarkApi extends BaseHandler implements BookmarkService { addCors(ex); try { Optional token = SessionToken.from(ex).map(Token::of); - var user = userService().loadUser(token); + var user = ModuleRegistry.userService().loadUser(token); if (user.isEmpty()) return unauthorized(ex); var head = path.pop(); return switch (head) { @@ -117,7 +118,7 @@ public class BookmarkApi extends BaseHandler implements BookmarkService { if (json.has(TAGS) && json.get(TAGS) instanceof JSONArray tagList){ var list = tagList.toList().stream().map(Object::toString).toList(); - tagService().save(BOOKMARK,bookmark.urlId(), userList, list); + ModuleRegistry.tagService().save(BOOKMARK,bookmark.urlId(), userList, list); } return sendContent(ex,bookmark); } diff --git a/company/src/main/java/de/srsoftware/umbrella/company/CompanyModule.java b/company/src/main/java/de/srsoftware/umbrella/company/CompanyModule.java index fdccf89..b70f76e 100644 --- a/company/src/main/java/de/srsoftware/umbrella/company/CompanyModule.java +++ b/company/src/main/java/de/srsoftware/umbrella/company/CompanyModule.java @@ -4,6 +4,7 @@ package de.srsoftware.umbrella.company; import static de.srsoftware.umbrella.company.Constants.CONFIG_DATABASE; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.*; import static de.srsoftware.umbrella.core.Paths.LIST; import static de.srsoftware.umbrella.core.Paths.SEARCH; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -26,10 +27,11 @@ public class CompanyModule extends BaseHandler implements CompanyService { private final CompanyDb companyDb; - public CompanyModule(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public CompanyModule(Configuration config) throws UmbrellaException { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); companyDb = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } private boolean deleteCompany(long companyId, UmbrellaUser user, HttpExchange ex) throws IOException { diff --git a/core/src/main/java/de/srsoftware/umbrella/core/BaseHandler.java b/core/src/main/java/de/srsoftware/umbrella/core/BaseHandler.java index 10124a8..bfd43b9 100644 --- a/core/src/main/java/de/srsoftware/umbrella/core/BaseHandler.java +++ b/core/src/main/java/de/srsoftware/umbrella/core/BaseHandler.java @@ -17,13 +17,8 @@ import java.util.List; public abstract class BaseHandler extends PathHandler { - private final ModuleRegistry registry; - public record Page(String mime, byte[] bytes){} - public BaseHandler(ModuleRegistry registry){ - this.registry = registry.add(this); - } public HttpExchange addCors(HttpExchange ex){ var headers = ex.getRequestHeaders(); @@ -41,23 +36,11 @@ public abstract class BaseHandler extends PathHandler { return ex; } - public CompanyService companyService(){ - return registry.companyService(); - } - - public DocumentService documentService(){ - return registry.documentService(); - } - @Override public boolean doOptions(Path path, HttpExchange ex) throws IOException { return ok(addCors(ex)); } - public ItemService itemService(){ - return registry.itemService(); - } - public boolean load(Path path, HttpExchange ex) throws IOException { try { var doc = load(path.toString()); @@ -84,43 +67,15 @@ public abstract class BaseHandler extends PathHandler { } } - public NoteService noteService(){ - return registry.noteService(); - } - public boolean ok(HttpExchange ex) throws IOException { return sendEmptyResponse(HTTP_OK,ex); } - public PostBox postBox() { - return registry.postBox(); - } - - public ProjectService projectService(){ - return registry.projectService(); - } - public boolean send(HttpExchange ex, UmbrellaException e) throws IOException { return sendContent(ex,e.statusCode(),e.getMessage()); } - public TagService tagService(){ - return registry.tagService(); - } - - public TaskService taskService(){ - return registry.taskService(); - } - - public Translator translator(){ - return registry.translator(); - } - public boolean unauthorized(HttpExchange ex) throws IOException { return sendEmptyResponse(HTTP_UNAUTHORIZED,ex); } - - public UserService userService(){ - return registry.userService(); - } } diff --git a/core/src/main/java/de/srsoftware/umbrella/core/ModuleRegistry.java b/core/src/main/java/de/srsoftware/umbrella/core/ModuleRegistry.java index 723e516..7329433 100644 --- a/core/src/main/java/de/srsoftware/umbrella/core/ModuleRegistry.java +++ b/core/src/main/java/de/srsoftware/umbrella/core/ModuleRegistry.java @@ -19,78 +19,79 @@ public class ModuleRegistry { private Translator translator; private UserService userService; + private static final ModuleRegistry singleton = new ModuleRegistry(); + private ModuleRegistry(){} - public ModuleRegistry add(Object service) { + public static void add(Object service) { switch (service) { - case BookmarkService bs: bookmarkService = bs; break; - case CompanyService cs: companyService = cs; break; - case DocumentService ds: documentService = ds; break; - case ItemService is: itemService = is; break; - case MarkdownService ms: markdownService = ms; break; - case NoteService ns: noteService = ns; break; - case PostBox pb: postBox = pb; break; - case ProjectService ps: projectService = ps; break; - case TagService ts: tagService = ts; break; - case TaskService ts: taskService = ts; break; - case TimeService ts: timeService = ts; break; - case Translator tr: translator = tr; break; - case UserService us: userService = us; break; + case BookmarkService bs: singleton.bookmarkService = bs; break; + case CompanyService cs: singleton.companyService = cs; break; + case DocumentService ds: singleton.documentService = ds; break; + case ItemService is: singleton.itemService = is; break; + case MarkdownService ms: singleton.markdownService = ms; break; + case NoteService ns: singleton.noteService = ns; break; + case PostBox pb: singleton.postBox = pb; break; + case ProjectService ps: singleton.projectService = ps; break; + case TagService ts: singleton.tagService = ts; break; + case TaskService ts: singleton.taskService = ts; break; + case TimeService ts: singleton.timeService = ts; break; + case Translator tr: singleton.translator = tr; break; + case UserService us: singleton.userService = us; break; case null: break; - default: System.getLogger(getClass().getSimpleName()).log(System.Logger.Level.WARNING,"Trying to add untracked class {0} to {1}",service.getClass().getSimpleName(),getClass().getSimpleName()); + default: System.getLogger(ModuleRegistry.class.getSimpleName()).log(System.Logger.Level.WARNING,"Trying to add untracked class {0}",service.getClass().getSimpleName()); } - return this; } - public BookmarkService bookmarkService(){ - return bookmarkService; + public static BookmarkService bookmarkService(){ + return singleton.bookmarkService; } - public CompanyService companyService(){ - return companyService; + public static CompanyService companyService(){ + return singleton.companyService; } - public DocumentService documentService(){ - return documentService; + public static DocumentService documentService(){ + return singleton.documentService; } - public ItemService itemService(){ - return itemService; + public static ItemService itemService(){ + return singleton.itemService; } - public MarkdownService markdownService(){ - return markdownService; + public static MarkdownService markdownService(){ + return singleton.markdownService; } - public NoteService noteService(){ - return noteService; + public static NoteService noteService(){ + return singleton.noteService; } - public PostBox postBox() { - return postBox; + public static PostBox postBox() { + return singleton.postBox; } - public ProjectService projectService(){ - return projectService; + public static ProjectService projectService(){ + return singleton.projectService; } - public TagService tagService(){ - return tagService; + public static TagService tagService(){ + return singleton.tagService; } - public TaskService taskService(){ - return taskService; + public static TaskService taskService(){ + return singleton.taskService; } - public TimeService timeService(){ - return timeService; + public static TimeService timeService(){ + return singleton.timeService; } - public Translator translator(){ - return translator; + public static Translator translator(){ + return singleton.translator; } - public UserService userService(){ - return userService; + public static UserService userService(){ + return singleton.userService; } } diff --git a/documents/src/main/java/de/srsoftware/umbrella/documents/DocumentApi.java b/documents/src/main/java/de/srsoftware/umbrella/documents/DocumentApi.java index f4e617d..71f3812 100644 --- a/documents/src/main/java/de/srsoftware/umbrella/documents/DocumentApi.java +++ b/documents/src/main/java/de/srsoftware/umbrella/documents/DocumentApi.java @@ -22,6 +22,7 @@ import static de.srsoftware.umbrella.core.Constants.FIELD_PRICE_FORMAT; import static de.srsoftware.umbrella.core.Constants.FIELD_TIME_ID; import static de.srsoftware.umbrella.core.Constants.FIELD_TYPE; import static de.srsoftware.umbrella.core.Constants.FIELD_UNIT; +import static de.srsoftware.umbrella.core.ModuleRegistry.*; import static de.srsoftware.umbrella.core.Paths.*; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -76,11 +77,12 @@ public class DocumentApi extends BaseHandler implements DocumentService { private final Configuration config; private final DocumentDb db; - public DocumentApi(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public DocumentApi(Configuration config) throws UmbrellaException { + super(); this.config = config; var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); db = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); Optional templates = config.get(CONFIG_TEMPLATES); if (templates.isEmpty()) throw missingFieldException(CONFIG_TEMPLATES); diff --git a/items/src/main/java/de/srsoftware/umbrella/items/ItemApi.java b/items/src/main/java/de/srsoftware/umbrella/items/ItemApi.java index a6e585c..db07ef5 100644 --- a/items/src/main/java/de/srsoftware/umbrella/items/ItemApi.java +++ b/items/src/main/java/de/srsoftware/umbrella/items/ItemApi.java @@ -3,6 +3,8 @@ package de.srsoftware.umbrella.items; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.companyService; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Paths.LIST; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; @@ -28,10 +30,11 @@ public class ItemApi extends BaseHandler implements ItemService { private final ItemDb itemDb; - public ItemApi(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public ItemApi(Configuration config) throws UmbrellaException { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); itemDb = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } @Override diff --git a/legacy/src/main/java/de/srsoftware/umbrella/legacy/CompanyLegacy.java b/legacy/src/main/java/de/srsoftware/umbrella/legacy/CompanyLegacy.java index 7ec04f8..f649efd 100644 --- a/legacy/src/main/java/de/srsoftware/umbrella/legacy/CompanyLegacy.java +++ b/legacy/src/main/java/de/srsoftware/umbrella/legacy/CompanyLegacy.java @@ -4,6 +4,8 @@ package de.srsoftware.umbrella.legacy; import static de.srsoftware.tools.Optionals.nullable; import static de.srsoftware.umbrella.core.Constants.TOKEN; +import static de.srsoftware.umbrella.core.ModuleRegistry.companyService; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Paths.JSON; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -20,11 +22,10 @@ import java.util.Map; import java.util.Optional; public class CompanyLegacy extends BaseHandler { - private final Configuration config; - public CompanyLegacy(ModuleRegistry registry, Configuration config) { - super(registry); - this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules")); + public CompanyLegacy(Configuration config) { + super(); + ModuleRegistry.add(this); } @Override diff --git a/legacy/src/main/java/de/srsoftware/umbrella/legacy/NotesLegacy.java b/legacy/src/main/java/de/srsoftware/umbrella/legacy/NotesLegacy.java index 388ceef..17b7958 100644 --- a/legacy/src/main/java/de/srsoftware/umbrella/legacy/NotesLegacy.java +++ b/legacy/src/main/java/de/srsoftware/umbrella/legacy/NotesLegacy.java @@ -5,6 +5,8 @@ package de.srsoftware.umbrella.legacy; import static de.srsoftware.tools.Optionals.nullable; import static de.srsoftware.umbrella.core.Constants.TOKEN; import static de.srsoftware.umbrella.core.Constants.URI; +import static de.srsoftware.umbrella.core.ModuleRegistry.noteService; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Util.markdown; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException; @@ -24,11 +26,9 @@ import java.util.Map; import java.util.Optional; public class NotesLegacy extends BaseHandler { - private final Configuration config; - public NotesLegacy(ModuleRegistry registry, Configuration config) { - super(registry); - this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules")); + public NotesLegacy(Configuration config) { + super(); } @Override diff --git a/legacy/src/main/java/de/srsoftware/umbrella/legacy/ProjectLegacy.java b/legacy/src/main/java/de/srsoftware/umbrella/legacy/ProjectLegacy.java index 95ef120..2534758 100644 --- a/legacy/src/main/java/de/srsoftware/umbrella/legacy/ProjectLegacy.java +++ b/legacy/src/main/java/de/srsoftware/umbrella/legacy/ProjectLegacy.java @@ -4,6 +4,8 @@ package de.srsoftware.umbrella.legacy; import static de.srsoftware.tools.Optionals.nullable; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.projectService; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Paths.JSON; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -20,11 +22,9 @@ import java.util.Map; import java.util.Optional; public class ProjectLegacy extends BaseHandler { - private final Configuration config; - public ProjectLegacy(ModuleRegistry registry, Configuration config) { - super(registry); - this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules")); + public ProjectLegacy(Configuration config) { + super(); } @Override diff --git a/legacy/src/main/java/de/srsoftware/umbrella/legacy/TaskLegacy.java b/legacy/src/main/java/de/srsoftware/umbrella/legacy/TaskLegacy.java index 12e3709..7fab484 100644 --- a/legacy/src/main/java/de/srsoftware/umbrella/legacy/TaskLegacy.java +++ b/legacy/src/main/java/de/srsoftware/umbrella/legacy/TaskLegacy.java @@ -6,12 +6,13 @@ package de.srsoftware.umbrella.legacy; import static de.srsoftware.tools.Optionals.nullable; import static de.srsoftware.umbrella.core.Constants.DESCRIPTION; import static de.srsoftware.umbrella.core.Constants.TOKEN; +import static de.srsoftware.umbrella.core.ModuleRegistry.taskService; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Paths.JSON; import static de.srsoftware.umbrella.core.Util.mapValues; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable; 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; @@ -24,11 +25,9 @@ import java.util.Map; import java.util.Optional; public class TaskLegacy extends BaseHandler { - private final Configuration config; - public TaskLegacy(ModuleRegistry registry, Configuration config) { - super(registry); - this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules")); + public TaskLegacy() { + super(); } @Override diff --git a/legacy/src/main/java/de/srsoftware/umbrella/legacy/UserLegacy.java b/legacy/src/main/java/de/srsoftware/umbrella/legacy/UserLegacy.java index 734bb8b..02c9bc8 100644 --- a/legacy/src/main/java/de/srsoftware/umbrella/legacy/UserLegacy.java +++ b/legacy/src/main/java/de/srsoftware/umbrella/legacy/UserLegacy.java @@ -5,6 +5,7 @@ import static de.srsoftware.tools.MimeType.MIME_FORM_URL; import static de.srsoftware.tools.Query.decode; import static de.srsoftware.umbrella.core.Constants.*; import static de.srsoftware.umbrella.core.Constants.TOKEN; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Paths.*; import static de.srsoftware.umbrella.core.Util.request; import static de.srsoftware.umbrella.user.Paths.*; @@ -34,8 +35,8 @@ public class UserLegacy extends BaseHandler { private final Configuration config; private final String messageUrl; - public UserLegacy(ModuleRegistry registry, Configuration config) { - super(registry); + public UserLegacy(Configuration config) { + super(); this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules")); this.messageUrl = null; } diff --git a/markdown/src/main/java/de/srsoftware/umbrella/markdown/MarkdownApi.java b/markdown/src/main/java/de/srsoftware/umbrella/markdown/MarkdownApi.java index 9dbea31..b0d3ced 100644 --- a/markdown/src/main/java/de/srsoftware/umbrella/markdown/MarkdownApi.java +++ b/markdown/src/main/java/de/srsoftware/umbrella/markdown/MarkdownApi.java @@ -2,6 +2,7 @@ package de.srsoftware.umbrella.markdown; import static de.srsoftware.tools.MimeType.MIME_HTML; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import com.sun.net.httpserver.HttpExchange; import de.srsoftware.tools.Path; @@ -18,8 +19,9 @@ import java.util.Optional; public class MarkdownApi extends BaseHandler implements MarkdownService { - public MarkdownApi(ModuleRegistry registry) { - super(registry); + public MarkdownApi() { + super(); + ModuleRegistry.add(this); } @Override diff --git a/messages/src/main/java/de/srsoftware/umbrella/message/MessageSystem.java b/messages/src/main/java/de/srsoftware/umbrella/message/MessageSystem.java index 8c86b35..6df9e4e 100644 --- a/messages/src/main/java/de/srsoftware/umbrella/message/MessageSystem.java +++ b/messages/src/main/java/de/srsoftware/umbrella/message/MessageSystem.java @@ -32,7 +32,6 @@ import java.util.function.BiFunction; public class MessageSystem implements PostBox { public static final System.Logger LOG = System.getLogger(MessageSystem.class.getSimpleName()); private final Timer timer = new Timer(); - private final ModuleRegistry registry; private record Receiver(User user, de.srsoftware.umbrella.core.model.Message message){} @@ -72,7 +71,7 @@ public class MessageSystem implements PostBox { private String debugAddress; private final HashMap> exceptions = new HashMap<>(); - public MessageSystem(ModuleRegistry moduleRegistry, Configuration config) throws UmbrellaException { + public MessageSystem(Configuration config) throws UmbrellaException { var dbFile = config.get(CONFIG_DB).orElseThrow(() -> missingConfigException(CONFIG_DB)); db = new SqliteMessageDb(connect(dbFile)); debugAddress = config.get(DEBUG_ADDREESS).map(Object::toString).orElse(null); @@ -81,7 +80,7 @@ public class MessageSystem implements PostBox { 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; - registry = moduleRegistry.add(this); + ModuleRegistry.add(this); new SubmissionTask(8).schedule(); new SubmissionTask(10).schedule(); new SubmissionTask(12).schedule(); @@ -117,7 +116,7 @@ public class MessageSystem implements PostBox { var date = new Date(); for (var receiver : dueRecipients){ - BiFunction,String> translateFunction = (text,fills) -> registry.translator().translate(receiver.language(),text,fills); + BiFunction,String> translateFunction = (text,fills) -> ModuleRegistry.translator().translate(receiver.language(),text,fills); var combined = new CombinedMessage("Collected messages",translateFunction); var envelopes = queue.stream().filter(env -> env.isFor(receiver)).toList(); diff --git a/notes/src/main/java/de/srsoftware/umbrella/notes/NoteModule.java b/notes/src/main/java/de/srsoftware/umbrella/notes/NoteModule.java index 0b7fe59..6425dc5 100644 --- a/notes/src/main/java/de/srsoftware/umbrella/notes/NoteModule.java +++ b/notes/src/main/java/de/srsoftware/umbrella/notes/NoteModule.java @@ -4,6 +4,7 @@ package de.srsoftware.umbrella.notes; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; import static de.srsoftware.umbrella.core.Constants.FULLTEXT; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.Paths.SEARCH; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -31,10 +32,11 @@ import java.util.stream.Collectors; public class NoteModule extends BaseHandler implements NoteService { private final NotesDb notesDb; - public NoteModule(ModuleRegistry registry, Configuration config) { - super(registry); + public NoteModule(Configuration config) { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); notesDb = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } @Override diff --git a/project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java b/project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java index 3973ff7..94972e3 100644 --- a/project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java +++ b/project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java @@ -3,6 +3,7 @@ package de.srsoftware.umbrella.project; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.*; import static de.srsoftware.umbrella.core.Paths.LIST; import static de.srsoftware.umbrella.core.Paths.SEARCH; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -32,10 +33,11 @@ public class ProjectModule extends BaseHandler implements ProjectService { private final ProjectDb projectDb; - public ProjectModule(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public ProjectModule(Configuration config) throws UmbrellaException { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); projectDb = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } private void addMember(Project project, long userId) { diff --git a/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java b/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java index bac3108..b1e4b57 100644 --- a/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java +++ b/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java @@ -3,6 +3,7 @@ package de.srsoftware.umbrella.tags; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable; @@ -26,11 +27,12 @@ import org.json.JSONArray; public class TagModule extends BaseHandler implements TagService { private final SqliteDb tagDb; - public TagModule(ModuleRegistry registry, Configuration config) { - super(registry); + public TagModule(Configuration config) { + super(); var tagDbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); var bmDbFile = config.get(de.srsoftware.umbrella.bookmarks.Constants.CONFIG_DATABASE).orElseThrow(() -> missingFieldException(de.srsoftware.umbrella.bookmarks.Constants.CONFIG_DATABASE)); tagDb = new SqliteDb(connect(tagDbFile),connect(bmDbFile)); + ModuleRegistry.add(this); } @Override diff --git a/task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java b/task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java index eb42bd8..5b1e4eb 100644 --- a/task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java +++ b/task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java @@ -5,6 +5,7 @@ import static de.srsoftware.tools.Optionals.is0; import static de.srsoftware.tools.Optionals.isSet; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.*; import static de.srsoftware.umbrella.core.Paths.*; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED; import static de.srsoftware.umbrella.core.Util.mapValues; @@ -37,10 +38,11 @@ public class TaskModule extends BaseHandler implements TaskService { private final TaskDb taskDb; - public TaskModule(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public TaskModule(Configuration config) throws UmbrellaException { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); taskDb = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } private void addMember(Task task, long userId) { diff --git a/time/src/main/java/de/srsoftware/umbrella/time/TimeModule.java b/time/src/main/java/de/srsoftware/umbrella/time/TimeModule.java index e852fc3..71f20ea 100644 --- a/time/src/main/java/de/srsoftware/umbrella/time/TimeModule.java +++ b/time/src/main/java/de/srsoftware/umbrella/time/TimeModule.java @@ -3,6 +3,7 @@ package de.srsoftware.umbrella.time; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.*; import static de.srsoftware.umbrella.core.Paths.*; import static de.srsoftware.umbrella.core.Util.mapValues; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; @@ -27,10 +28,11 @@ public class TimeModule extends BaseHandler implements TimeService { private final TimeDb timeDb; - public TimeModule(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public TimeModule( Configuration config) throws UmbrellaException { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE)); timeDb = new SqliteDb(connect(dbFile)); + ModuleRegistry.add(this); } diff --git a/translations/src/main/java/de/srsoftware/umbrella/translations/Translations.java b/translations/src/main/java/de/srsoftware/umbrella/translations/Translations.java index 0f2ab66..a874f56 100644 --- a/translations/src/main/java/de/srsoftware/umbrella/translations/Translations.java +++ b/translations/src/main/java/de/srsoftware/umbrella/translations/Translations.java @@ -21,8 +21,8 @@ public class Translations extends PathHandler implements Translator { private HashMap translations = new HashMap<>(); - public Translations(ModuleRegistry registry) { - registry.add(this); + public Translations() { + ModuleRegistry.add(this); } @Override diff --git a/user/src/main/java/de/srsoftware/umbrella/user/Constants.java b/user/src/main/java/de/srsoftware/umbrella/user/Constants.java index 3988cb2..47ec123 100644 --- a/user/src/main/java/de/srsoftware/umbrella/user/Constants.java +++ b/user/src/main/java/de/srsoftware/umbrella/user/Constants.java @@ -35,8 +35,8 @@ public class Constants { public static final String SCOPE = "scope"; public static final String SERVICE_ID = "service_id"; - public static final String TABLE_LOGIN_SERVICES = "user_login_services"; - public static final String TABLE_SERVICE_IDS_USERS = "user_service_ids_users"; + public static final String TABLE_LOGIN_SERVICES = "login_services"; + public static final String TABLE_SERVICE_IDS_USERS = "service_ids_users"; public static final String TABLE_TOKENS = "tokens"; public static final String TABLE_TOKEN_USES = "token_uses"; public static final String TABLE_USERS = "users"; diff --git a/user/src/main/java/de/srsoftware/umbrella/user/UserModule.java b/user/src/main/java/de/srsoftware/umbrella/user/UserModule.java index 19a54ec..ec2bf47 100644 --- a/user/src/main/java/de/srsoftware/umbrella/user/UserModule.java +++ b/user/src/main/java/de/srsoftware/umbrella/user/UserModule.java @@ -8,6 +8,7 @@ import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.Constants.*; import static de.srsoftware.umbrella.core.Constants.CODE; import static de.srsoftware.umbrella.core.Constants.TOKEN; +import static de.srsoftware.umbrella.core.ModuleRegistry.postBox; import static de.srsoftware.umbrella.core.Paths.*; import static de.srsoftware.umbrella.core.ResponseCode.*; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR; @@ -80,12 +81,13 @@ public class UserModule extends BaseHandler implements UserService { } } - public UserModule(ModuleRegistry registry, Configuration config) throws UmbrellaException { - super(registry); + public UserModule(Configuration config) throws UmbrellaException { + super(); var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingConfigException(CONFIG_DATABASE)); // may be splitted in separate db files later logins = new SqliteDB(connect(dbFile)); users = new SqliteDB(connect(dbFile)); + ModuleRegistry.add(this); } private boolean deleteOIDC(HttpExchange ex, UmbrellaUser user, Path path) throws IOException { diff --git a/web/src/main/java/de/srsoftware/umbrella/web/WebHandler.java b/web/src/main/java/de/srsoftware/umbrella/web/WebHandler.java index d42f13d..4695c38 100644 --- a/web/src/main/java/de/srsoftware/umbrella/web/WebHandler.java +++ b/web/src/main/java/de/srsoftware/umbrella/web/WebHandler.java @@ -9,13 +9,14 @@ import com.sun.net.httpserver.HttpExchange; import de.srsoftware.tools.Path; import de.srsoftware.umbrella.core.BaseHandler; import de.srsoftware.umbrella.core.ModuleRegistry; + import java.io.ByteArrayOutputStream; import java.io.IOException; public class WebHandler extends BaseHandler { - public WebHandler(ModuleRegistry registry){ - super(registry); + public WebHandler(){ + super(); } @Override