You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/04/09 10:56:57 UTC
(causeway-app-petclinic) 01/06: Adds EmailAddress value type
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to tag tags/3.6.0/03-13-scalar-custom-value-type-for-email-address
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git
commit bbb785abbf1562c5d4f8384e9eb9d7f01396b807
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sun May 26 09:16:43 2024 +0100
Adds EmailAddress value type
Adds EmailAddress value type
---
.../modules/petowner/value/EmailAddress.java | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddress.java b/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddress.java
new file mode 100644
index 0000000..652962b
--- /dev/null
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddress.java
@@ -0,0 +1,39 @@
+package domainapp.modules.petowner.value;
+
+import javax.persistence.Column;
+
+import lombok.Getter;
+
+import java.io.Serializable;
+import java.util.regex.Pattern;
+
+import org.apache.causeway.commons.internal.base._Strings;
+
+@javax.persistence.Embeddable
+@org.apache.causeway.applib.annotation.Value
+@lombok.EqualsAndHashCode
+public class EmailAddress implements Serializable {
+
+ static final int MAX_LEN = 100;
+ static final int TYPICAL_LEN = 30;
+ static final Pattern REGEX = Pattern.compile("^[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-zA-Z]{2,})$");
+
+ public static EmailAddress of(String value) {
+ if (_Strings.isNullOrEmpty(value)) {
+ return null;
+ }
+ if(!REGEX.matcher(value).matches()) {
+ throw new RuntimeException("Invalid email format");
+ }
+
+ final var ea = new EmailAddress();
+ ea.value = value;
+ return ea;
+ }
+
+ protected EmailAddress() {} // required by JPA
+
+ @Getter
+ @Column(length = MAX_LEN, nullable = true, name = "emailAddress")
+ String value;
+}
\ No newline at end of file