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/25 15:12:43 UTC
(causeway-app-petclinic) branch v2 updated (8e6d1b6 -> 2d43a07)
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
from 8e6d1b6 Updates PhoneNumber meta-annotation, adds regex validation
new b398464 Adds a mustSatisfy Specification to Name meta-annotation
new 9d9fbee Removes validation for PetOwner#updateName
new aedd258 Updates ActionLayout#describedAs text, as constant has moved to Name meta-annotation
new 95d38a7 Adds EmailAddress value type
new c9cefd8 Adds EmailAddressValueSemantics
new f6fc7b0 Updates PetOwner#emailAddress to use new value type
new 2d43a07 Updates PetOwners#create to use new value type
The 7 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 | 17 +---
.../modules/petowner/dom/petowner/PetOwners.java | 6 +-
.../domainapp/modules/petowner/types/Name.java | 17 +++-
.../modules/petowner/value/EmailAddress.java | 18 ++++
.../petowner/value/EmailAddressValueSemantics.java | 109 +++++++++++++++++++++
5 files changed, 151 insertions(+), 16 deletions(-)
create mode 100644 module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddress.java
create mode 100644 module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddressValueSemantics.java
(causeway-app-petclinic) 04/07: 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 95d38a718efe2a812ae2beecc00065c4c1166143
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 16:11:07 2024 +0100
Adds EmailAddress value type
---
.../domainapp/modules/petowner/value/EmailAddress.java | 18 ++++++++++++++++++
1 file changed, 18 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..7d613af
--- /dev/null
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddress.java
@@ -0,0 +1,18 @@
+package domainapp.modules.petowner.value;
+
+import lombok.AccessLevel;
+
+import javax.persistence.Column;
+
+@javax.persistence.Embeddable
+@org.apache.causeway.applib.annotation.Value
+@lombok.Getter
+@lombok.Setter(AccessLevel.PRIVATE)
+@lombok.AllArgsConstructor(staticName = "of")
+@lombok.NoArgsConstructor
+public class EmailAddress {
+ public static final int MAX_LEN = 40;
+
+ @Column(length = EmailAddress.MAX_LEN, nullable = true, name = "emailAddress")
+ String emailAddress;
+}
\ No newline at end of file
(causeway-app-petclinic) 06/07: 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 f6fc7b0873eebd50cc1693c52885cabe22c3c3f9
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 16:12:21 2024 +0100
Updates PetOwner#emailAddress to use new value type
... adds necessary JPA annotation
---
.../main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java | 6 ++++--
1 file changed, 4 insertions(+), 2 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..be038c6 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)
@PropertyLayout(fieldSetId = "contact", sequence = "1.2")
- private String emailAddress;
+ private EmailAddress emailAddress;
@Notes
@Column(length = Notes.MAX_LEN, nullable = true)
(causeway-app-petclinic) 02/07: Removes validation for PetOwner#updateName
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 9d9fbee3e8850cfcae3683ebaeebac4fd87cc9e9
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 15:33:28 2024 +0100
Removes validation for PetOwner#updateName
no longer needed, handled by the @Name meta-annotation
---
.../java/domainapp/modules/petowner/dom/petowner/PetOwner.java | 9 ---------
1 file changed, 9 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 da3fa68..982e660 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
@@ -227,15 +227,6 @@ public class PetOwner implements Comparable<PetOwner>, CalendarEventable {
@MemberSupport public String default0UpdateName() {
return getName();
}
- @MemberSupport public String validate0UpdateName(final String newName) {
- for (char prohibitedCharacter : PROHIBITED_CHARACTERS.toCharArray()) {
- if( newName.contains(""+prohibitedCharacter)) {
- return "Character '" + prohibitedCharacter + "' is not allowed.";
- }
- }
- return null;
- }
- static final String PROHIBITED_CHARACTERS = "&%$!";
(causeway-app-petclinic) 01/07: Adds a mustSatisfy Specification to Name meta-annotation
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 b398464983c4728958c6bf40f537791e38144e1e
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 15:30:54 2024 +0100
Adds a mustSatisfy Specification to Name meta-annotation
---
.../java/domainapp/modules/petowner/types/Name.java | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java b/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java
index 0e36990..8110a5b 100644
--- a/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java
@@ -8,13 +8,26 @@ import java.lang.annotation.Target;
import org.apache.causeway.applib.annotation.Parameter;
import org.apache.causeway.applib.annotation.ParameterLayout;
import org.apache.causeway.applib.annotation.Property;
+import org.apache.causeway.applib.spec.AbstractSpecification;
-@Property(maxLength = Name.MAX_LEN)
-@Parameter(maxLength = Name.MAX_LEN)
+@Property(maxLength = Name.MAX_LEN, mustSatisfy = Name.Spec.class)
+@Parameter(maxLength = Name.MAX_LEN, mustSatisfy = Name.Spec.class)
@ParameterLayout(named = "Name")
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Name {
int MAX_LEN = 40;
+ String PROHIBITED_CHARACTERS = "&%$!";
+
+ class Spec extends AbstractSpecification<String> {
+ @Override public String satisfiesSafely(String candidate) {
+ for (char prohibitedCharacter : PROHIBITED_CHARACTERS.toCharArray()) {
+ if( candidate.contains(""+prohibitedCharacter)) {
+ return "Character '" + prohibitedCharacter + "' is not allowed.";
+ }
+ }
+ return null;
+ }
+ }
}
(causeway-app-petclinic) 03/07: Updates ActionLayout#describedAs text, as constant has moved to Name meta-annotation
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 aedd258f0a9b9b952b96fb51fff8ae7df74330c1
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 15:35:39 2024 +0100
Updates ActionLayout#describedAs text, as constant has moved to Name meta-annotation
---
.../src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 982e660..4cbe325 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
@@ -218,7 +218,7 @@ public class PetOwner implements Comparable<PetOwner>, CalendarEventable {
@ActionLayout(
associateWith = "name",
// promptStyle = PromptStyle.INLINE,
- describedAs = "Updates the name of this object, certain characters (" + PROHIBITED_CHARACTERS + ") are not allowed.")
+ describedAs = "Updates the name of this object, certain characters (" + Name.PROHIBITED_CHARACTERS + ") are not allowed.")
public PetOwner updateName(
@Name final String name) {
setName(name);
(causeway-app-petclinic) 05/07: 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 c9cefd81d3f08385c9c7783d13ae05c85a614ae0
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 16:11:33 2024 +0100
Adds EmailAddressValueSemantics
... that defines how to interact with the EmailAddress
---
.../petowner/value/EmailAddressValueSemantics.java | 109 +++++++++++++++++++++
1 file changed, 109 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..516d72e
--- /dev/null
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/value/EmailAddressValueSemantics.java
@@ -0,0 +1,109 @@
+package domainapp.modules.petowner.value;
+
+import lombok.NonNull;
+
+import java.util.regex.Pattern;
+
+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("demo.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::getEmailAddress, ()->null);
+ }
+
+ @Override
+ public EmailAddress compose(final ValueDecomposition decomposition) {
+ return composeFromNullable(
+ decomposition, ValueWithTypeDto::getString, EmailAddress::of, ()->null);
+ }
+
+ @Override
+ public DefaultsProvider<EmailAddress> getDefaultsProvider() {
+ return () -> EmailAddress.of("");
+ }
+
+ @Override
+ public Renderer<EmailAddress> getRenderer() {
+ return (context, emailAddress) -> emailAddress == null ? null : emailAddress.getEmailAddress();
+ }
+
+ @Override
+ public Parser<EmailAddress> getParser() {
+ return new Parser<>() {
+ // https://stackoverflow.com/a/47181151
+ final Pattern REGEX = Pattern.compile("^[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-zA-Z]{2,})$");
+
+ @Override
+ public String parseableTextRepresentation(Context context, EmailAddress value) {
+ return renderTitle(value, EmailAddress::getEmailAddress);
+ }
+
+ @Override
+ public EmailAddress parseTextRepresentation(Context context, String text) {
+ if(!REGEX.matcher(text).matches()) {
+ throw new RuntimeException("Invalid email format");
+ }
+ if (_Strings.isEmpty(text)) return null;
+ return EmailAddress.of(text);
+ }
+
+ @Override
+ public int typicalLength() {
+ return 30;
+ }
+
+ @Override
+ public int maxLength() {
+ return 100;
+ }
+ };
+ }
+
+ @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.getEmailAddress());
+ }
+
+ @Override
+ public EmailAddress destring(@NonNull String stringified) {
+ return EmailAddress.of(_Strings.base64UrlDecode(stringified));
+ }
+ };
+ }
+}
(causeway-app-petclinic) 07/07: 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 2d43a07b59b8d5c4ba356470f2221b0f1990b1f0
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat May 25 16:12:41 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);