major refactoring: working towards more interface-implementation splitting
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
description = "Umbrella : Backend"
|
||||
@@ -22,6 +21,7 @@ dependencies{
|
||||
implementation("de.srsoftware:configuration.api:1.0.2")
|
||||
implementation("de.srsoftware:configuration.json:1.0.3")
|
||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||
implementation("de.srsoftware:tools.slf4j2syslog:1.0.1") // this provides a slf4j implementation that forwards to System.Logger
|
||||
implementation("de.srsoftware:tools.util:2.0.3")
|
||||
implementation("org.json:json:20240303")
|
||||
}
|
||||
|
||||
@@ -4,22 +4,17 @@ package de.srsoftware.umbrella.backend;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.mapLogLevel;
|
||||
import static java.lang.System.Logger.Level.INFO;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import de.srsoftware.configuration.JsonConfig;
|
||||
import de.srsoftware.tools.ColorLogger;
|
||||
import de.srsoftware.umbrella.core.ConnectionProvider;
|
||||
import de.srsoftware.umbrella.core.UmbrellaException;
|
||||
import de.srsoftware.umbrella.documents.DocumentApi;
|
||||
import de.srsoftware.umbrella.documents.SqliteDb;
|
||||
import de.srsoftware.umbrella.legacy.LegacyApi;
|
||||
import de.srsoftware.umbrella.message.MessageApi;
|
||||
import de.srsoftware.umbrella.message.MessageSystem;
|
||||
import de.srsoftware.umbrella.message.SqliteMessageDb;
|
||||
import de.srsoftware.umbrella.translations.Translations;
|
||||
import de.srsoftware.umbrella.user.UserModule;
|
||||
import de.srsoftware.umbrella.user.sqlite.SqliteDB;
|
||||
import de.srsoftware.umbrella.web.WebHandler;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -29,7 +24,7 @@ import org.json.JSONObject;
|
||||
public class Application {
|
||||
private static final System.Logger LOG = System.getLogger("Umbrella");
|
||||
|
||||
private static void configureLogging(JsonConfig jsonConfig) {
|
||||
private static JsonConfig configureLogging(JsonConfig jsonConfig) {
|
||||
var rootLevel = jsonConfig.get("umbrella.logging.rootLevel", "INFO");
|
||||
ColorLogger.setRootLogLevel(mapLogLevel(rootLevel));
|
||||
|
||||
@@ -40,36 +35,33 @@ public class Application {
|
||||
ColorLogger.setLogLevel(key,lvl);
|
||||
});
|
||||
}
|
||||
return jsonConfig;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, UmbrellaException {
|
||||
LOG.log(INFO, "Starting Umbrella:");
|
||||
var config = new JsonConfig(UMBRELLA);
|
||||
configureLogging(config);
|
||||
var port = config.get("umbrella.http.port", 8080);
|
||||
var threads = config.get("umbrella.threads", 16);
|
||||
var docDbFile = config.get("umbrella.database.documents",config.file().getParent()+"/documents.db");
|
||||
var userDbFile = config.get("umbrella.database.user", config.file().getParent()+"/umbrella.db");
|
||||
var loginDbFile = config.get("umbrella.database.login_services",config.file().getParent()+"/umbrella.db");
|
||||
var messageDbFile = config.get("umbrella.database.messages", config.file().getParent()+"/umbrella.db");
|
||||
var connectionProvider = new ConnectionProvider();
|
||||
var documentDb = new SqliteDb(connectionProvider.get(docDbFile));
|
||||
var messageDb = new SqliteMessageDb(connectionProvider.get(messageDbFile));
|
||||
var userDb = new SqliteDB(connectionProvider.get(userDbFile));
|
||||
var loginServiceDb = new SqliteDB(connectionProvider.get(loginDbFile));
|
||||
var moduleConfig = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException(format(ERROR_MISSING_CONFIG,"umbrella.modules")));
|
||||
var translationModule = new Translations();
|
||||
var config = configureLogging(new JsonConfig(UMBRELLA));
|
||||
var port = config.get("umbrella.http.port", 8080);
|
||||
var threads = config.get("umbrella.threads", 16);
|
||||
|
||||
var translationModule = new Translations();
|
||||
var messageSystem = new MessageSystem(translationModule,config);
|
||||
var server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
|
||||
var userModule = new UserModule(config,messageSystem);
|
||||
var documentApi = new DocumentApi(userModule, config);
|
||||
var legacyApi = new LegacyApi(userModule.userDb(),config);
|
||||
var messageApi = new MessageApi(messageSystem);
|
||||
var webHandler = new WebHandler();
|
||||
|
||||
documentApi .bindPath("/api/document") .on(server);
|
||||
legacyApi .bindPath("/legacy") .on(server);
|
||||
messageApi .bindPath("/api/messages") .on(server);
|
||||
translationModule.bindPath("/api/translations").on(server);
|
||||
userModule .bindPath("/api/user") .on(server);
|
||||
webHandler .bindPath("/") .on(server);
|
||||
|
||||
var messageSystem = new MessageSystem(messageDb,translationModule,moduleConfig.subset("message").orElseThrow(() -> new RuntimeException(format(ERROR_MISSING_CONFIG,"umbrella.modules.message"))));
|
||||
var server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
server.setExecutor(Executors.newFixedThreadPool(threads));
|
||||
var userModule = new UserModule(userDb,loginServiceDb,messageSystem);
|
||||
new LegacyApi(userDb,config) .bindPath("/legacy") .on(server);
|
||||
new DocumentApi(documentDb, userModule, moduleConfig) .bindPath("/api/document") .on(server);
|
||||
new MessageApi(messageSystem).bindPath("/api/messages") .on(server);
|
||||
translationModule .bindPath("/api/translations").on(server);
|
||||
userModule .bindPath("/api/user") .on(server);
|
||||
new WebHandler() .bindPath("/") .on(server);
|
||||
server.start();
|
||||
LOG.log(INFO,"Started web server at {0}",port);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user