implemented legacy interface for Notes and Project
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -16,6 +16,7 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.documents.DocumentApi;
|
||||
import de.srsoftware.umbrella.items.ItemApi;
|
||||
import de.srsoftware.umbrella.legacy.NotesLegacy;
|
||||
import de.srsoftware.umbrella.legacy.ProjectLegacy;
|
||||
import de.srsoftware.umbrella.legacy.UserLegacy;
|
||||
import de.srsoftware.umbrella.markdown.MarkdownApi;
|
||||
import de.srsoftware.umbrella.message.MessageSystem;
|
||||
@@ -75,6 +76,7 @@ public class Application {
|
||||
var markdownApi = new MarkdownApi(registry);
|
||||
var notesModule = new NoteModule(registry,config);
|
||||
var projectModule = new ProjectModule(registry, config);
|
||||
var projectLegacy = new ProjectLegacy(registry,config);
|
||||
var taskModule = new TaskModule(registry, config);
|
||||
var timeModule = new TimeModule(registry, config);
|
||||
var webHandler = new WebHandler();
|
||||
@@ -92,6 +94,7 @@ public class Application {
|
||||
translationModule.bindPath("/api/translations").on(server);
|
||||
userModule .bindPath("/api/user") .on(server);
|
||||
notesLegacy .bindPath("/legacy/notes") .on(server);
|
||||
projectLegacy .bindPath("/legacy/project") .on(server);
|
||||
userLegacy .bindPath("/legacy/user") .on(server);
|
||||
webHandler .bindPath("/") .on(server);
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ public class Constants {
|
||||
public static final String URI = "uri";
|
||||
public static final String URL = "url";
|
||||
public static final String USER = "user";
|
||||
public static final String USERS = "users";
|
||||
public static final String USER_ID = "user_id";
|
||||
public static final String USER_LIST = "user_list";
|
||||
public static final String USES = "uses";
|
||||
|
||||
@@ -2,24 +2,26 @@
|
||||
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.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.URI;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class NotesLegacy extends BaseHandler {
|
||||
private final ModuleRegistry registry;
|
||||
@@ -53,8 +55,21 @@ public class NotesLegacy extends BaseHandler {
|
||||
@Override
|
||||
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||
var params = formData(ex);
|
||||
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
if (token.isEmpty()) token = nullable(params.get(TOKEN)).map(Object::toString).map(Token::of);
|
||||
var user = registry.userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
|
||||
return switch (path.pop()){
|
||||
case "html" -> postNotesHtml(ex,params);
|
||||
default -> super.doPost(path,ex);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean postNotesHtml(HttpExchange ex, Map<String, Object> params) throws IOException {
|
||||
if (!(params.get(URI) instanceof String uri)) throw invalidFieldException(URI,"URI of the form \"module:entry-id\"");
|
||||
var parts = uri.split(":");
|
||||
var parts = uri.split(":",2);
|
||||
if (parts.length<2) throw invalidFieldException(URI,"URI of the form \"module:entry-id\"");
|
||||
var module = parts[0];
|
||||
var entryId = parts[1];
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* © SRSoftware 2025 */
|
||||
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.Paths.JSON;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
|
||||
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.model.Token;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class ProjectLegacy extends BaseHandler {
|
||||
private final ModuleRegistry registry;
|
||||
private final Configuration config;
|
||||
|
||||
public ProjectLegacy(ModuleRegistry registry, Configuration config) {
|
||||
this.registry = registry;
|
||||
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
||||
return super.doDelete(path, ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/.*",""));
|
||||
return super.doGet(path, ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
||||
return super.doOptions(path, ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
|
||||
return super.doPatch(path, ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPost(Path path, HttpExchange ex) throws IOException{
|
||||
var params = formData(ex);
|
||||
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
if (token.isEmpty()) token = nullable(params.get(TOKEN)).map(Object::toString).map(Token::of);
|
||||
var user = registry.userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
|
||||
return switch (path.pop()){
|
||||
case JSON -> postProjectJson(ex,params,user.get());
|
||||
default -> super.doPost(path, ex);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean postProjectJson(HttpExchange ex, Map<String, Object> params, UmbrellaUser user) throws IOException {
|
||||
var includeUsers = "1".equals(params.get(USERS));
|
||||
var projects = registry.projectService().listUserProjects(user.id(), false);
|
||||
return sendContent(ex, mapValues(projects));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user