working on legacy note rendering
This commit is contained in:
@@ -4,6 +4,7 @@ dependencies{
|
||||
implementation(project(":core"))
|
||||
implementation(project(":user"))
|
||||
implementation("de.srsoftware:tools.mime:1.1.2")
|
||||
implementation("de.srsoftware:tools.web:1.3.16")
|
||||
implementation("org.bitbucket.b_c:jose4j:0.9.6")
|
||||
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
|
||||
}
|
||||
@@ -1,16 +1,25 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.legacy;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.URI;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
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.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.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;
|
||||
|
||||
public class NotesLegacy extends BaseHandler {
|
||||
private final ModuleRegistry registry;
|
||||
@@ -43,15 +52,29 @@ public class NotesLegacy extends BaseHandler {
|
||||
|
||||
@Override
|
||||
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
var data = formData(ex);
|
||||
var noteService = registry.noteService();
|
||||
if (!(data.get(URI) instanceof String uri)) throw missingFieldException(URI);
|
||||
var parts = uri.split(":",2);
|
||||
if (parts.length<2) throw unprocessable("Expected URI to contain colon (:)!");
|
||||
String module = parts[0];
|
||||
String entityId = parts[1];
|
||||
var notes = noteService.getNotes(module,entityId);
|
||||
return super.doPost(path, ex);
|
||||
var params = formData(ex);
|
||||
if (!(params.get(URI) instanceof String uri)) throw invalidFieldException(URI,"URI of the form \"module:entry-id\"");
|
||||
var parts = uri.split(":");
|
||||
if (parts.length<2) throw invalidFieldException(URI,"URI of the form \"module:entry-id\"");
|
||||
var module = parts[0];
|
||||
var entryId = parts[1];
|
||||
var notes = registry.noteService().getNotes(module,entryId);
|
||||
var authors = new HashMap<Long, UmbrellaUser> ();
|
||||
var users = registry.userService();
|
||||
for (var note : notes.values()) {
|
||||
var userId = note.authorId();
|
||||
authors.computeIfAbsent(userId,k -> users.loadUser(userId));
|
||||
}
|
||||
var html = new Tag("div");
|
||||
for (var note : notes.values()){
|
||||
var author = authors.get(note.authorId());
|
||||
var authorName = author != null ? author.name() : "";
|
||||
new Tag("fieldset")
|
||||
.add(new Tag("legend").content(authorName))
|
||||
.add(new Tag("legend").content(note.timestamp().format(DateTimeFormatter.ISO_DATE_TIME)))
|
||||
.add(new Tag("div").content(markdown(note.text())))
|
||||
.addTo(html);
|
||||
}
|
||||
return sendContent(ex,html.toString(2));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user