preparing message system:

copied model from previous java implementation
This commit is contained in:
2025-07-04 14:21:14 +02:00
parent 3c898f36de
commit c934e19837
14 changed files with 538 additions and 6 deletions

View File

@@ -2,9 +2,12 @@
package de.srsoftware.umbrella.user.model;
import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.LANGUAGE;
import static java.text.MessageFormat.format;
import java.util.Objects;
import org.json.JSONObject;
public class User {
@@ -37,4 +40,20 @@ public class User {
public String toString() {
return format("{1}({0})", nullable(name()).orElse(email()),getClass().getSimpleName());
}
public static User of(JSONObject json){
if (json.has(USER)) json = json.getJSONObject(USER);
var name = json.has(NAME) ? json.getString(NAME) : null;
var email = json.has(EMAIL) ? json.getString(EMAIL) : null;
if (json.has(ID) && json.has(THEME)) {
return new UmbrellaUser(
json.getLong(ID),
name,
email,
json.getString(THEME),
json.has(LANGUAGE) ? json.getString(LANGUAGE) : null
);
}
return new User(name,email);
}
}