|
|
|
@ -1,16 +1,25 @@ |
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
package de.srsoftware.umbrella.legacy; |
|
|
|
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 com.sun.net.httpserver.HttpExchange; |
|
|
|
import de.srsoftware.configuration.Configuration; |
|
|
|
import de.srsoftware.configuration.Configuration; |
|
|
|
import de.srsoftware.tools.Path; |
|
|
|
import de.srsoftware.tools.Path; |
|
|
|
|
|
|
|
import de.srsoftware.tools.Tag; |
|
|
|
import de.srsoftware.umbrella.core.BaseHandler; |
|
|
|
import de.srsoftware.umbrella.core.BaseHandler; |
|
|
|
import de.srsoftware.umbrella.core.ModuleRegistry; |
|
|
|
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.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 { |
|
|
|
public class NotesLegacy extends BaseHandler { |
|
|
|
private final ModuleRegistry registry; |
|
|
|
private final ModuleRegistry registry; |
|
|
|
@ -43,15 +52,29 @@ public class NotesLegacy extends BaseHandler { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean doPost(Path path, HttpExchange ex) throws IOException { |
|
|
|
public boolean doPost(Path path, HttpExchange ex) throws IOException { |
|
|
|
addCors(ex); |
|
|
|
var params = formData(ex); |
|
|
|
var data = formData(ex); |
|
|
|
if (!(params.get(URI) instanceof String uri)) throw invalidFieldException(URI,"URI of the form \"module:entry-id\""); |
|
|
|
var noteService = registry.noteService(); |
|
|
|
var parts = uri.split(":"); |
|
|
|
if (!(data.get(URI) instanceof String uri)) throw missingFieldException(URI); |
|
|
|
if (parts.length<2) throw invalidFieldException(URI,"URI of the form \"module:entry-id\""); |
|
|
|
var parts = uri.split(":",2); |
|
|
|
var module = parts[0]; |
|
|
|
if (parts.length<2) throw unprocessable("Expected URI to contain colon (:)!"); |
|
|
|
var entryId = parts[1]; |
|
|
|
String module = parts[0]; |
|
|
|
var notes = registry.noteService().getNotes(module,entryId); |
|
|
|
String entityId = parts[1]; |
|
|
|
var authors = new HashMap<Long, UmbrellaUser> (); |
|
|
|
var notes = noteService.getNotes(module,entityId); |
|
|
|
var users = registry.userService(); |
|
|
|
return super.doPost(path, ex); |
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|