19 changed files with 145 additions and 109 deletions
@ -1,5 +1,7 @@ |
|||||||
/* © SRSoftware 2025 */ |
/* © SRSoftware 2025 */ |
||||||
package de.srsoftware.umbrella.message.model; |
package de.srsoftware.umbrella.core.api; |
||||||
|
|
||||||
|
import de.srsoftware.umbrella.core.model.Envelope; |
||||||
|
|
||||||
public interface PostBox { |
public interface PostBox { |
||||||
public void send(Envelope envelope); |
public void send(Envelope envelope); |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
/* © SRSoftware 2025 */ |
||||||
|
package de.srsoftware.umbrella.core.model; |
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.Constants.*; |
||||||
|
import static de.srsoftware.umbrella.core.Constants.EMAIL; |
||||||
|
import static de.srsoftware.umbrella.core.Constants.LANGUAGE; |
||||||
|
import static de.srsoftware.umbrella.core.Constants.NAME; |
||||||
|
import static de.srsoftware.umbrella.core.Constants.THEME; |
||||||
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
||||||
|
|
||||||
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
||||||
|
import org.json.JSONObject; |
||||||
|
|
||||||
|
public class User { |
||||||
|
private String lang, name; |
||||||
|
private EmailAddress email; |
||||||
|
|
||||||
|
public User(String name, EmailAddress email, String languageCode){ |
||||||
|
lang = languageCode; |
||||||
|
this.name = name; |
||||||
|
this.email = email; |
||||||
|
} |
||||||
|
|
||||||
|
public EmailAddress email(){ |
||||||
|
return email; |
||||||
|
} |
||||||
|
|
||||||
|
public String language(){ |
||||||
|
return lang; |
||||||
|
} |
||||||
|
|
||||||
|
public String name(){ |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public static User of(JSONObject json) throws UmbrellaException { |
||||||
|
if (json.has(USER)) json = json.getJSONObject(USER); |
||||||
|
|
||||||
|
if (!(json.has(NAME) && json.get(NAME) instanceof String name)) throw missingFieldException(NAME); |
||||||
|
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL); |
||||||
|
if (!(json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String lang)) throw missingFieldException(LANGUAGE); |
||||||
|
|
||||||
|
var addr = new EmailAddress(email); |
||||||
|
if (json.has(ID) && json.get(ID) instanceof Number id) { |
||||||
|
var theme = json.has(THEME) ? json.getString(THEME) : null; |
||||||
|
return new UmbrellaUser(id.longValue(), name, addr, theme, lang); |
||||||
|
} |
||||||
|
return new User(name,addr,lang); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue