preparing message system:
copied model from previous java implementation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user