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 2024/05/26 08:20:58 UTC

(causeway-app-petclinic) branch v2 updated (5211a61 -> 53f78a3)

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a change to branch v2
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git


 discard 5211a61  Terminal Updates PetOwners#create to use new value type
 discard 9e793b8  Terminal Updates PetOwner#emailAddress to use new value type
 discard b8e413f  adds EmailAddressValueSemantics
 discard 009abed  Adds EmailAddress value type
     new 60a4892  Adds EmailAddress value type
     new 057cf83  adds EmailAddressValueSemantics
     new 711e057  updates PetOwner#emailAddress to use new value type
     new 53f78a3  updates PetOwners#create to use new value type

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5211a61)
            \
             N -- N -- N   refs/heads/v2 (53f78a3)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../modules/petowner/dom/petowner/PetOwner.java    |  4 +--
 .../modules/petowner/value/EmailAddress.java       | 40 ++++++++++++++++------
 .../petowner/value/EmailAddressValueSemantics.java | 20 ++++-------
 3 files changed, 38 insertions(+), 26 deletions(-)


(causeway-app-petclinic) 03/04: updates PetOwner#emailAddress to use new value type

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git

commit 711e0571752986f2f251197f8570ce092922a250
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sun May 26 09:18:26 2024 +0100

    updates PetOwner#emailAddress to use new value type
    
    
    Changes optionality of EmailAddress
---
 .../java/domainapp/modules/petowner/dom/petowner/PetOwner.java    | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
index 4cbe325..60fa583 100644
--- a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
@@ -65,6 +65,8 @@ import domainapp.modules.petowner.types.Notes;
 
 import domainapp.modules.petowner.types.PhoneNumber;
 
+import domainapp.modules.petowner.value.EmailAddress;
+
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
@@ -147,11 +149,11 @@ public class PetOwner implements Comparable<PetOwner>, CalendarEventable {
     @PropertyLayout(fieldSetId = "contact", sequence = "1.1")
     private String telephoneNumber;
 
-    @Column(length = 40, nullable = true, name = "emailAddress")
+    @javax.persistence.Embedded
     @Getter @Setter
-    @Property(editing = Editing.ENABLED)
+    @Property(editing = Editing.ENABLED, optionality = Optionality.OPTIONAL)
     @PropertyLayout(fieldSetId = "contact", sequence = "1.2")
-    private String emailAddress;
+    private EmailAddress emailAddress;
 
     @Notes
     @Column(length = Notes.MAX_LEN, nullable = true)


(causeway-app-petclinic) 04/04: updates PetOwners#create to use new value type

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git

commit 53f78a3a50eb1dbf2e3fcceaebe25d2fdf0209cb
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 16:18:54 2024 +0100

    updates PetOwners#create to use new value type
---
 .../java/domainapp/modules/petowner/dom/petowner/PetOwners.java     | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwners.java b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwners.java
index 77eef38..e8e242b 100644
--- a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwners.java
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwners.java
@@ -26,6 +26,8 @@ import org.apache.causeway.persistence.jpa.applib.services.JpaSupportService;
 
 import domainapp.modules.petowner.types.PhoneNumber;
 
+import domainapp.modules.petowner.value.EmailAddress;
+
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 
@@ -53,8 +55,8 @@ public class PetOwners {
             final String knownAs,
             @PhoneNumber
             final String telephoneNumber,
-            @Parameter(maxLength = 40, optionality = Optionality.OPTIONAL)
-            final String emailAddress) {
+            @Parameter(optionality = Optionality.OPTIONAL)
+            final EmailAddress emailAddress) {
         final var petOwner = PetOwner.withName(name);
         petOwner.setKnownAs(knownAs);
         petOwner.setTelephoneNumber(telephoneNumber);


(causeway-app-petclinic) 02/04: adds EmailAddressValueSemantics

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git

commit 057cf83ef6e5030b448113bf5e28fd24450025bf
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sun May 26 09:17:10 2024 +0100

    adds EmailAddressValueSemantics
    
    Adds EmaulAddressValueSemantics
    
    ... which tells Causeway how to interact with properties of type EmailAddress
---
 .../petowner/value/EmailAddressValueSemantics.java | 103 +++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddressValueSemantics.java b/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddressValueSemantics.java
new file mode 100644
index 0000000..0cd3139
--- /dev/null
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddressValueSemantics.java
@@ -0,0 +1,103 @@
+package domainapp.modules.petowner.value;
+
+import domainapp.modules.petowner.PetOwnerModule;
+
+import lombok.NonNull;
+
+import javax.inject.Named;
+
+import org.apache.causeway.applib.services.bookmark.IdStringifier;
+import org.apache.causeway.applib.value.semantics.DefaultsProvider;
+import org.apache.causeway.applib.value.semantics.Parser;
+import org.apache.causeway.applib.value.semantics.Renderer;
+import org.apache.causeway.applib.value.semantics.ValueDecomposition;
+import org.apache.causeway.applib.value.semantics.ValueSemanticsAbstract;
+import org.apache.causeway.commons.internal.base._Strings;
+
+import org.apache.causeway.schema.common.v2.ValueType;
+import org.apache.causeway.schema.common.v2.ValueWithTypeDto;
+
+import org.springframework.stereotype.Component;
+
+@Named(PetOwnerModule.NAMESPACE + ".EmailAddressValueSemantics")
+@Component
+public class EmailAddressValueSemantics
+        extends ValueSemanticsAbstract<EmailAddress> {
+
+    @Override
+    public Class<EmailAddress> getCorrespondingClass() {
+        return EmailAddress.class;
+    }
+
+    @Override
+    public ValueType getSchemaValueType() {
+        return ValueType.STRING;
+    }
+
+    @Override
+    public ValueDecomposition decompose(final EmailAddress value) {
+        return decomposeAsNullable(value, EmailAddress::getValue, ()->null);
+    }
+
+    @Override
+    public EmailAddress compose(final ValueDecomposition decomposition) {
+        return composeFromNullable(
+                decomposition, ValueWithTypeDto::getString, EmailAddress::of, ()->null);
+    }
+
+    @Override
+    public DefaultsProvider<EmailAddress> getDefaultsProvider() {
+        return () -> null;
+    }
+
+    @Override
+    public Renderer<EmailAddress> getRenderer() {
+        return (context, emailAddress) ->  emailAddress == null ? null : emailAddress.getValue();
+    }
+
+    @Override
+    public Parser<EmailAddress> getParser() {
+        return new Parser<>() {
+
+            @Override
+            public String parseableTextRepresentation(Context context, EmailAddress emailAddress) {
+                return renderTitle(emailAddress, EmailAddress::getValue);
+            }
+
+            @Override
+            public EmailAddress parseTextRepresentation(Context context, String text) {
+                return EmailAddress.of(text);
+            }
+
+            @Override
+            public int typicalLength() {
+                return EmailAddress.TYPICAL_LEN;
+            }
+
+            @Override
+            public int maxLength() {
+                return EmailAddress.MAX_LEN;
+            }
+        };
+    }
+
+    @Override
+    public IdStringifier<EmailAddress> getIdStringifier() {
+        return new IdStringifier.EntityAgnostic<>() {
+            @Override
+            public Class<EmailAddress> getCorrespondingClass() {
+                return EmailAddressValueSemantics.this.getCorrespondingClass();
+            }
+
+            @Override
+            public String enstring(@NonNull EmailAddress value) {
+                return _Strings.base64UrlEncode(value.getValue());
+            }
+
+            @Override
+            public EmailAddress destring(@NonNull String stringified) {
+                return EmailAddress.of(_Strings.base64UrlDecode(stringified));
+            }
+        };
+    }
+}


(causeway-app-petclinic) 01/04: Adds EmailAddress value type

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git

commit 60a489273e440b6dcb135c91bce2f49deb5ab106
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