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/24 06:22:53 UTC
(causeway) branch CAUSEWAY-2873 updated (bebe78fc00 -> 4182e4ccfa)
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a change to branch CAUSEWAY-2873
in repository https://gitbox.apache.org/repos/asf/causeway.git
discard bebe78fc00 CAUSEWAY-2873: updates petclinic tutorial up to 2.5 incl.
add 0c13b4c7b5 adds PageRenderSubscriber into refguide docs.
add c8f20f2a32 ESTUP2-668 enable bulk mode for property change audit trails
add 35e3015471 ESTUP2-668 enabled bulk processing for repository service
add 13fb837c06 ESTUP2-668 enabled bulk processing for repository service for a given class
add 8978aab9be ESTUP2-668 this should make bulk processing thread safe
add 7b0b703619 ESTUP2-668 a little cleanup
add e7d8d98107 ESTUP2-668 review changes
add e0a8593e18 ESTUP2-668 review changes PtII
add 1c2c80a2e8 ESTUP2-668 regression test finetuning
add c0bd9a91b0 Merge branch 'ESTUP2-668' into CAUSEWAY-3745
add f3905f657e CAUSEWAY-3745: updates javadoc is all.
add d389e3c482 CAUSEWAY-3745: updates javadoc is all.
add 46655c69cd CAUSEWAY-3745: renames AuditEntryRepository#createForBulk ...
add 2d39c84661 CAUSEWAY-3745: renames EntityPropertychangeSubscriber#onBulkChanging ...
add 7817369ba0 CAUSEWAY-3745: renames EntityPropertychangeSubscriber#onBulkChanging ...
add ccfb0c6e62 CAUSEWAY-3745: renames RepositoryServiceDefault's 'bulkMode' thread local...
add 6eb1c52458 CAUSEWAY-3745: factors out 'suppressFlushing' and 'resumeFlushing' methods
add ead2170ca7 CAUSEWAY-3745: inlines setSuppressFlushing wherever called, and simplify
add 416930a375 CAUSEWAY-3745: fixes the config property in the regression test
add 69b7f3d4fa Merge pull request #2424 from apache/CAUSEWAY-3745
new f98a9eb83f CAUSEWAY-2873: updates petclinic tutorial up to 2.5 incl.
new deceb525a0 CAUSEWAY-2873: exercises 3-1, 3-2, 3-3
new 4182e4ccfa CAUSEWAY-2873: 02-05, 03-04
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 (bebe78fc00)
\
N -- N -- N refs/heads/CAUSEWAY-2873 (4182e4ccfa)
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 3 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:
.gitignore | 3 +
.../partials/_presentation-layer-spi.adoc | 7 +
.../petclinic/pages/020-the-petclinic-domain.adoc | 52 +++-
.../petclinic/pages/030-petowner-entity.adoc | 300 ++++++++++++++-------
.../modules/petclinic/pages/100-todo.adoc | 4 +
.../modules/petclinic/partials/domain.adoc | 8 +-
.../publishing/log/EntityPropertyChangeLogger.java | 8 +-
.../spi/EntityPropertyChangeSubscriber.java | 14 +
.../services/repository/RepositoryService.java | 10 +
.../core/config/CausewayConfiguration.java | 22 ++
.../EntityPropertyChangePublisherDefault.java | 14 +-
.../applib/dom/AuditTrailEntryRepository.java | 5 +
.../dom/AuditTrailEntryRepositoryAbstract.java | 7 +
...ntityPropertyChangeSubscriberForAuditTrail.java | 10 +
.../repository/RepositoryServiceDefault.java | 33 ++-
.../testdomain/fixtures/EntityTestFixtures.java | 24 +-
.../causeway/testdomain/jdo/JdoTestFixtures.java | 12 +
.../causeway/testdomain/jpa/JpaTestFixtures.java | 11 +
.../persistence/jpa/JpaBootstrappingTest.java | 2 +-
...est.java => JpaPropertyBulkPublishingTest.java} | 2 +-
...t.java => JpaPropertySinglePublishingTest.java} | 3 +-
21 files changed, 433 insertions(+), 118 deletions(-)
create mode 100644 antora/components/tutorials/modules/petclinic/pages/100-todo.adoc
copy regressiontests/publishing-jpa/src/test/java/org/apache/causeway/testdomain/publishing/jpa/{JpaPropertyPublishingTest.java => JpaPropertyBulkPublishingTest.java} (98%)
rename regressiontests/publishing-jpa/src/test/java/org/apache/causeway/testdomain/publishing/jpa/{JpaPropertyPublishingTest.java => JpaPropertySinglePublishingTest.java} (94%)
(causeway) 01/03: CAUSEWAY-2873: updates petclinic tutorial up to 2.5 incl.
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-2873
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit f98a9eb83f20a18a319b5f850320946360838dbf
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed May 22 23:21:27 2024 +0100
CAUSEWAY-2873: updates petclinic tutorial up to 2.5 incl.
---
.../petclinic/pages/010-getting-started.adoc | 40 ++-
.../petclinic/pages/020-the-petclinic-domain.adoc | 317 ++++++++++++++++++++-
.../partials/fixture-scripts/api-and-usage.adoc | 1 +
3 files changed, 330 insertions(+), 28 deletions(-)
diff --git a/antora/components/tutorials/modules/petclinic/pages/010-getting-started.adoc b/antora/components/tutorials/modules/petclinic/pages/010-getting-started.adoc
index ec13043e16..a4a1e6e8a8 100644
--- a/antora/components/tutorials/modules/petclinic/pages/010-getting-started.adoc
+++ b/antora/components/tutorials/modules/petclinic/pages/010-getting-started.adoc
@@ -10,11 +10,11 @@ You'll need:
* Java 11
+
-Apache Causeway should work up to at least Java 15, but stick with Java 11 for now.
+Apache Causeway works up to at least Java 21, but stick with Java 11 for now.
-* Maven 3.6.x
+* Maven 3.9.x
+
-Maven 3.6.x or later is recommended.
+Maven 3.9.x or later is recommended.
* git
+
@@ -25,14 +25,14 @@ This has multiple tags for the various checkpoints so you can pick up the tutori
+
The Apache Causeway website has detailed documentation for setting up to use xref:setupguide:intellij:about.adoc[IntelliJ] or xref:setupguide:eclipse:about.adoc[Eclipse].
+
-For this tutorial, make sure that your IDE is configured to support Lombok.
+For this tutorial, also make sure that your IDE is configured to support Lombok.
[#exercise-1-1-starter-apps-clone-the-repo]
== Ex 1.1: Starter apps / clone the repo
-Apache Causeway provides a two starter apps, xref:docs:starters:helloworld.adoc[HelloWorld] and xref:docs:starters:simpleapp.adoc[SimpleApp].
+Apache Causeway provides two starter apps, xref:docs:starters:helloworld.adoc[HelloWorld] and xref:docs:starters:simpleapp.adoc[SimpleApp].
These are identical in terms of functionality, but the simpleapp provides more structure and includes example tests.
NOTE: there are JPA and JDO variants of the starter apps.
@@ -40,7 +40,6 @@ This tutorial uses JPA as it is the more commonly used persistence mechanism.
We start the tutorial simply with a copy of xref:docs:starters:simpleapp.adoc[SimpleApp]; in subsequent exercises we'll refactor and build upon it to morph it into the petclinic domain.
-
* Clone the repo:
+
[source,bash]
@@ -59,6 +58,16 @@ This will make it easier to inspect differences between different tags.
git checkout tags/01-01-starter-app
mvn clean install
----
++
+[NOTE]
+====
+The code at this tag was created by copying the `v2-jpa` tag of xref:docs:starters:simpleapp.adoc[SimpleApp]:
+
+[source,bash]
+----
+curl https://codeload.github.com/apache/causeway-app-simpleapp/zip/v2-jpa | jar xv
+----
+====
* run the app:
+
@@ -93,13 +102,11 @@ Running from the command line isn't ideal, so
* load the project into your IDE as a Maven project, build and run.
-* The app is a Spring boot application, so locate the class with a main, and run.
+* The app is a Spring boot application, so locate the class with a `main()` method, and run.
* alternatively, your IDE might also have specialised support for Spring Boot apps, so run the app that way if you wish.
-* with the IDE load
-
-If you want to go deeper, open up the xref:docs:starters:simpleapp.adoc[page describing the SimpleApp] and start to explore the xref:docs:starters:simpleapp.adoc#structure-of-the-app[structure of the app] files.
+If you want to go deeper, use the xref:docs:starters:simpleapp.adoc[Simple App docs] to xref:docs:starters:simpleapp.adoc#structure-of-the-app[explore the structure] of the application.
@@ -111,10 +118,9 @@ Apache Causeway is an implementation of the _naked objects pattern_, which means
[TIP]
====
An ORM such as JPA (EclipseLink or Hibernate) maps domain objects into an RDBMS or other datastore.
-You can think of Apache Causeway (and naked objects) similarly, but it's an OIM - an object _interface_ mapper.
-It maps to the UI layer rather than the persistence layer.
+Apache Causeway does a similar trick, but in the opposite direction: it maps the domain objects to the UI layer.
-Common to both ORMs and OIMs is an internal metamodel; this is where much of the power comes from.
+Common to both is an internal metamodel, which is where much of the power comes from.
====
We can explore this by looking at the classes provided by the starter app:
@@ -167,7 +173,7 @@ Typically this is static and in the same package as the class; see `SimpleObject
*Mini-Exercise*:
-(No solution is provided for this exercise).
+(no solution is provided for this exercise).
* replace the `@Title` annotation with a `title()` method:
+
@@ -190,7 +196,7 @@ In many cases the details of that representation can be inferred directly from t
For example the label of a field for an object's property (eg `SimpleObject#name`) can be derived directly from the name of the object property itself (`getName()`).
In the absence of other metadata, Apache Causeway will render a domain object with its properties to the left-hand side and its collections (if any) to the right.
-The order of these properties and collections can be specified using the `@PropertyLayout` annotation and the `@CollectionLayout` annotation.
+The order of these properties and collections can be specified using the xref:refguide:applib:index/annotation/PropertyLayout.adoc[@PropertyLayout] annotation and the xref:refguide:applib:index/annotation/CollectionLayout.adoc[@CollectionLayout] annotation.
There are other annotations to group properties together and to associate action buttons with either properties or collections.
The downside of using annotations is that changing the layout requires that the application be restarted, and certain more complex UIs, such as multi-columns or tab groups are difficult or impossible to express.
@@ -200,6 +206,8 @@ This is modelled upon bootstrap and so supports arbitrary rows and columns as we
*Mini-Exercise*:
+(no solution is provided for this exercise).
+
* locate the `SimpleObject.layout.xml` file
* compare the structure of the layout file to that of the rendered object
* change the file, eg the relative widths of the columns
@@ -220,6 +228,8 @@ In a similar fashion, the actions of the various domain services are grouped int
*Mini-Exercise*:
+(no solution is provided for this exercise).
+
* locate the `menubars.layout.xml` file
* compare the structure of the layout file to that of the rendered menu bar
* change the file, eg reorder menu items or create new menus
diff --git a/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc b/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc
index bd3033c4a4..72d06a82ee 100644
--- a/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc
+++ b/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc
@@ -29,36 +29,327 @@ Some of the use cases we might want to support include:
This tutorial has worked solutions for all of these.
[#exercise-2-1-refactor-simpleobject-to-petowner]
-== Ex 2.1: Refactor `SimpleObject` to `PetOwner`
+== Ex 2.1: Create a new `pets` module with `PetOwner`
+
+Using the `simple` module as a guide, we'll create a new `petowners` module and create a `PetOwner` and `PetOwners` domain service as reference.
+(We leave the `simple` module untouched, to use as a reference).
-To start with, let's rename the `SimpleObject` entity to `PetOwner`
=== Solution
[source,bash]
----
-git checkout tags/02-01-renames-SimpleObject-to-PetOwner
+git checkout tags/02-01-copies-SimpleObject-to-PetOwner
mvn clean install
mvn -pl spring-boot:run
----
=== Tasks
-Just checkout the solution above and review the git history to see the changes that have already been made.
-These include:
-
-* Domain classes renamed (along with corresponding tests)
+To save time, just checkout the solution tag above and review the git history to see the classes that were copied and renamed:
-** `SimpleObject` entity -> `PetOwner`
-** `SimpleObjects` domain service -> `PetOwners`
+* `dom.petowner` package:
+** `SimpleObject` -> `PetOwner` (entity)
++
+plus related `.layout.xml`, `.png` and `.columnOrder.txt` files
+** `SimpleObjects` -> `PetOwners` (domain service)
** `SimpleObjectRepository` repository service -> `PetOwnerRepository`
+** `SimpleModule` -> `PetOwnerModule` (module)
+* `fixture` package:
+** `PetOwner_persona` (fixture script)
+* `types` package
+** `Name` (meta annotation)
+** `Notes` (meta annotation)
+* root package of module
+** `PetOwnerModule` (Spring `@Configuration`, aka module class)
+
+* In the `PetOwnerModule`, the namespace and schema constants were changed:
++
+[source, java]
+.PetOwnerModule.java
+----
+// ...
+public class PetOwnerModule implements ModuleWithFixtures {
+
+ public static final String NAMESPACE = "petowner";
+ public static final String SCHEMA = "petowner";
+
+ // ...
+}
+----
+
+* in `application.properties`, the "petowner" schema was also added to the xref:refguide:config:sections/causeway.persistence.schema.adoc#causeway.persistence.schema.auto-create-schemas[causeway.persistence.schema.auto-create-schemas] config property:
++
+[source,properties]
+.application.properties
+----
+causeway.persistence.schema.auto-create-schemas=petowner,simple,...
+----
+
+Resource classes were also copied.
+
+In addition, the new Maven module was defined in the top-level `pom.xml`, and included in `<modules>`.
+
+Confirm that the code still builds:
+
+[source,bash]
+----
+mvn install
+----
+
+However, if you run the app confirm that it is still showing just the original `simpleapp` module:
+
+[source,bash]
+----
+mvn -pl webapp spring-boot:run
+----
+
+We'll fix this in the next exercise.
+
+
+[#exercise-2-2-configure-the-app-to-include-the-petowner-module]
+== Ex 2.2: Configure the app to include the `petowner` module
+
+We have our new `petowner` module, but we're not actually using it; if we run the application we still see the original `simpleapp` module.
+
+[source,bash]
+----
+mvn -pl webapp spring-boot:run
+----
-** Infrastructure classes renamed
+In this exercise we'll update the app to include `petowners` as well.
-** `SimpleModule` -> `PetsModule`
-** `SimpleApp` -> `PetClinicApp`
+=== Solution
+
+[source,bash]
+----
+git checkout tags/02-02-configure-the-app-to-include-petowner
+mvn clean install
+mvn -pl spring-boot:run
+----
+
+=== Tasks
+
+Rename the main class that acts as the entry point for the app (annotated with `@@SpringBootApplication`):
+
+* locate the `SimpleApp` class and rename to `PetClinicApp`
+
+* Also update classes that reference this type (in particular, in `pom.xml`).
++
+Your IDE can probably do this for you automatically.
+
+The `PetClinicApp` main class references the `AppManifest`, a top-level Spring `@Configuration` which imports all the other classes.
+
+* Inspect the `AppManifest` class: most will be ``CausewayXxxModule``s
+* note that it also imports the `ApplicationModule`, which defines your own modules which make up the application
+
+We want to update `ApplicationModule` to reference `PetOwnerModule`.
+We need to change both Maven and then Spring:
-Build and run the application (note that the main class has changed) to make sure it still runs fine.
+* in the `pom.xml` (of the `webapp` module), add in a dependency to the `petowner` module:
++
+[source,xml]
+.webapp/pom.xml
+----
+<dependencies>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>simpleapp-jpa-module-petowner</artifactId>
+ </dependency>
+ ...
+<dependencies>
+----
++
+You might need to reimport or refresh so that your IDE rebuilds its classpath.
+
+* in the `ApplicationModule`, update the `@Import` to reference the `PetOwnerModule`:
++
+[source,java]
+.Application.java
+----
+@Configuration
+@Import({
+ PetOwnerModule.class, //<.>
+ SimpleModule.class,
+})
+@ComponentScan
+public class ApplicationModule {
+
+}
+----
+<.> add this import
+
+Run up the application using the IDE or from maven command line.
+Although everything looks good, in fact you won't see any change.
+That's because the simpleapp starter app includes the xref:security:secman:about.adoc[SecMan] security module, for users, roles and permissions.
+We'll fix this in the next exercise.
+
+
+[#exercise-2-3-add-security-role-for-petowner-module]
+== Ex 2.3: Add security role for the `petowner` module
+
+In this exercise we'll add a security role to grant access to our new `petowner` module, and we'll make sure that our "sven" demo user is a member of this role.
+
+=== Solution
+
+[source,bash]
+----
+git checkout tags/02-03-add-security-role-for-petowner
+mvn clean install
+mvn -pl spring-boot:run
+----
+
+=== Tasks
+
+The starter app is configured to use an in-memory database.
+The xref:security:secman:about.adoc[SecMan] roles and permissions are therefore set up each time the applicatoin is bootstrapped, using a fixture scripts.
+We'll learn more about fixture scripts and their role in testing in a later exercise.
+For now, all that's necessary to know is that we can use them to set up the roles.
+
+* Locate the `CustomRolesAndUsers` fixture script class
+
+* within it, copy the existing `SimpleModuleSuperuserRole` to create a similar `PetOwnerModuleSuperuserRole`:
++
+[source,java]
+.CustomRolesAndUsers.java
+----
+private static class PetOwnerModuleSuperuserRole
+ extends AbstractRoleAndPermissionsFixtureScript {
+
+ public static final String ROLE_NAME = "petowner-superuser";
+
+ public PetOwnerModuleSuperuserRole() {
+ super(ROLE_NAME, "Permission to use everything in the 'petowner' module");
+ }
+
+ @Override
+ protected void execute(ExecutionContext executionContext) {
+ newPermissions(
+ ApplicationPermissionRule.ALLOW,
+ ApplicationPermissionMode.CHANGING,
+ Can.of(ApplicationFeatureId.newNamespace("petowner"))
+ );
+ }
+}
+----
+
+* further down in the same class, update the fixture script for the "sven" end-user, and add them into our new role:
++
+[source,java]
+.CustomRolesAndUsers.java
+----
+private static class SvenUser extends AbstractUserAndRolesFixtureScript {
+ ...
+
+ private static class RoleSupplier implements Supplier<Can<String>> {
+ @Override
+ public Can<String> get() {
+ return Can.of(
+ causewayConfiguration.getExtensions().getSecman().getSeed().getRegularUser().getRoleName(), // built-in stuff
+ PetOwnerModuleSuperuserRole.ROLE_NAME, // <.>
+ SimpleModuleSuperuserRole.ROLE_NAME
+ );
+ }
+ @Inject CausewayConfiguration causewayConfiguration;
+ }
+}
+----
+<.> reference new role.
+
+* and in the `execute()` method at top of the class, remember to include the call to the new fixture script:
++
+[source,java]
+.CustomRolesAndUsers.java
+----
+@Override
+protected void execute(ExecutionContext executionContext) {
+ executionContext.executeChildren(this,
+ new SimpleModuleSuperuserRole(),
+ new PetOwnerModuleSuperuserRole(), // <.>
+ new SvenUser());
+}
+----
+<.> Remember to call the new module
+
+
+Now run the application from the IDE or Maven:
+
+* The menubar should now show a new "Other" menu - these are the now-visible actions arising from the `PetOwners` domain service.
+
+* Create a new `PetOwner` using "Other > Create".
++
+The resultant object will look identical in structure to a `SimpleObject`, but you can confirm that it is indeed an instance of a `PetOwner` by hovering over the title or icon and checking the tooltip.
+
+The fact that the `PetOwners` domain service's actions are displayed automatically is an important principle of the _naked objects pattern_ as implemented by Apache Causeway.
+
+[#exercise-2-4-update-menubar-for-PetOwners]
+== Ex 2.4: Update menubar for PetOwners
+
+Let's now update the menu bar so that the actions to create ``PetOwner``s live under an appropriately named menu, "Pet Owners".
+
+=== Solution
+
+[source,bash]
+----
+git checkout tags/02-04-update-menubar-for-petowners
+mvn clean install
+mvn -pl spring-boot:run
+----
+
+=== Tasks
+
+* Locate the `menubars.layout.xml` file.
++
+You should find it in `src/main/resources` (in the `webapp` module).
+
+* Add in the following XML, under the `<mb3:primary>` tag:
++
+[source,xml]
+.menubars.layout.xml
+----
+<mb3:primary>
+ <mb3:menu>
+ <mb3:named>Pet Owners</mb3:named>
+ <mb3:section>
+ <mb3:serviceAction objectType="petowner.PetOwners" id="create"/>
+ <mb3:serviceAction objectType="petowner.PetOwners" id="findByName"/>
+ <mb3:serviceAction objectType="petowner.PetOwners" id="findByNameLike"/>
+ <mb3:serviceAction objectType="petowner.PetOwners" id="listAll"/>
+ </mb3:section>
+ </mb3:menu>
+...
+</mb3:primary>
+----
++
+The `objectType` attribute corresponds to the `@Named` value of the `PetOwners` domain service (its "logical type name"), while the `id` attribute matches the method name of each action.
+
+Run the application; the menubar should be updated correctly.
+
+
+[#exercise-2-5-setup-demo-PetOwners]
+== Ex 2.5: Set up demo PetOwners
+
+xref:testing:fixtures:about.adoc#fixture-scripts[Fixture scripts] are used for both prototyping and for integration testing, allowing us to quickly create demo data in the H2 in-memory database.
+
+The xref:testing:fixtures:about.adoc#personas-and-builders[persona] pattern lets us define example data in an enum (the "what"), while a companion builder uses that data to set up the corresponding domain entities (the "how").
+
+In this exercise we'll modify the `PetOwners_persona` (copied from `SimpleObjects_persona` earlier) to create more realistic data.
+
+
+=== Solution
+
+[source,bash]
+----
+git checkout tags/02-05-setup-demo-petowners
+mvn clean install
+mvn -pl spring-boot:run
+----
+
+=== Tasks
+* locate the `PetOwners_persona` class
+* refactor the enum constants and values to create 10 realistic pet owner names
+* (optional) we'll use the associated `.pdf` to store a "veterinary clinic service agreement" for each pet owner.
diff --git a/testing/fixtures/adoc/modules/fixtures/partials/fixture-scripts/api-and-usage.adoc b/testing/fixtures/adoc/modules/fixtures/partials/fixture-scripts/api-and-usage.adoc
index 43b1160552..86b26e697f 100644
--- a/testing/fixtures/adoc/modules/fixtures/partials/fixture-scripts/api-and-usage.adoc
+++ b/testing/fixtures/adoc/modules/fixtures/partials/fixture-scripts/api-and-usage.adoc
@@ -192,6 +192,7 @@ This was demonstrated in the <<fixturescript, previous section>>
The latter use case is much less frequently used, but can be helpful for example in demos, where the number of objects can be specified in the `parameters` parameter of the xref:refguide:testing:index/fixtures/applib/fixturescripts/FixtureScripts.adoc#runFixtureScript_String_String[run fixture script] action.
+[#personas-and-builders]
== Personas and Builders
Good integration tests are probably the best way to understand the behaviour of the domain model: better, even, than reading the code itself.
(causeway) 02/03: CAUSEWAY-2873: exercises 3-1, 3-2, 3-3
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-2873
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit deceb525a0735c1afad7c4bcf015537cf125e8a7
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu May 23 17:39:12 2024 +0100
CAUSEWAY-2873: exercises 3-1, 3-2, 3-3
---
.../petclinic/pages/030-petowner-entity.adoc | 236 +++++++++++----------
.../modules/petclinic/partials/domain.adoc | 8 +-
2 files changed, 125 insertions(+), 119 deletions(-)
diff --git a/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc b/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc
index 6b6e6b9bac..a7b0d399fb 100644
--- a/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc
+++ b/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc
@@ -5,12 +5,11 @@
In this set of exercises we'll just focus on the `PetOwner` entity.
-[#exercise-3-1-rename-petowners-name-property]
-== Ex 3.1: Rename PetOwner's name property
+[#exercise-3-1-rename-petowners-knownAs-property]
+== Ex 3.1: Add PetOwner's knownAs property
-In the domain we are working on, `PetOwner` has a `firstName` and a `lastName` property, not a single `name` property.
-
-In this exercise, we'll rename ``PetOwner``'s `name` property to be `lastName`, and change the fixture script that sets up data to something more realistic.
+In this exercise, we'll add a new property, `knownAs`, to capture the ``PetOwner``'s preferred name.
+We'll also update the fixture script that sets up data to something more realistic.
@@ -18,181 +17,184 @@ In this exercise, we'll rename ``PetOwner``'s `name` property to be `lastName`,
[source,bash]
----
-git checkout tags/03-01-renames-PetOwner-name-property
+git checkout tags/03-01-adds-PetOwner-knownAs-property
mvn clean install
mvn -pl spring-boot:run
----
-Remember you can use the menu:Prototyping[Fixture Scripts] menu to setup some example data.
+Use the menu:Prototyping[Fixture Scripts] menu to setup some example data.
=== Tasks
-Checkout the solution above and review the git history to see the changes that have already been made.
-These include:
-
-* property `PetOwner#name` -> `PetOwner#lastName` renamed
-* JPA mappings updated:
-** the corresponding JPQL named queries
-** the method names of `PetOwnerRepository`
+* add a `knownAs` property:
+
-This is a Spring Data repository, which uses a link:https://www.baeldung.com/spring-data-derived-queries[naming convention] to infer the queries
-
-** uniqueness constraint for `PetOwner`
-
-* the action method names of `PetOwners` domain service renamed
+[source,java]
+.PetOwner.java
+----
+@Column(length = 40, nullable = true, name = "knownAs") // <.>
+@Getter @Setter
+@Property(editing = Editing.ENABLED) // <.>
+@PropertyLayout(
+ fieldSetId = LayoutConstants.FieldSetId.IDENTITY, // <.>
+ sequence = "1.1" // <.>
+)
+private String knownAs;
+----
+<.> JPA annotation, declared to be `nullable` because we don't necessarily have a value
+<.> The xref:refguide:applib:index/annotation/Property.adoc[@Property] annotation provides domain semantics.
+(In comparison, the xref:refguide:applib:index/annotation/PropertyLayout.adoc[@PropertyLayout] annotation defines UI hints/semantics.
+Directly editable (similar to the "notes" property)
+<.> Renders this new property in the same field set as `name` ...
+<.> ... and after the `name`, not before it
+
-This also requires updating the `menubars.layout.xml`, which references these action names.
+It's also possible to define UI semantics through the associated `.layout.xml` file; we'll look at that alternative in a later exercise.
-* updating the xref:refguide:applib:index/annotation/ActionLayout.adoc#associateWith[@ActionLayout] of the `updateName` and `delete` action methods in `PetOwner`
+* update `PetOwner_persona` to specify an `knownAs` for some of the owners:
+
-In the UI, the buttons for these actions are located close to the renamed "lastName" property
+[source,java]
+.PetOwner_persona.java
+----
+public enum PetOwner_persona
+implements Persona<PetOwner, PetOwner_persona.Builder> {
+
+ JAMAL("Jamal Washington", "jamal.pdf", "J"),
+ CAMILA("Camila González", "camila.pdf", null),
+ ARJUN("Arjun Patel", "arjun.pdf", null),
+ NIA("Nia Robinson", "nia.pdf", null),
+ OLIVIA("Olivia Hartman", "olivia.pdf", null),
+ LEILA("Leila Hassan", "leila.pdf", null),
+ MATT("Matthew Miller", "matt.pdf", "Matt"),
+ BENJAMIN("Benjamin Thatcher", "benjamin.pdf", "Ben"),
+ JESSICA("Jessica Raynor", "jessica.pdf", "Jess"),
+ DANIEL("Daniel Keating", "daniel.pdf", "Dan");
+
+ private final String name;
+ private final String contentFileName;
+ private final String knownAs;
+
+ ...
+}
+----
-* renames `@Name` meta-annotation to `@LastName`.
+* for the builder, use the `knownAs` value of the entity once created:
+
-Meta-annotations are a useful way of eliminating duplication where the same value type appears in multiple locations, for example as both an entity property and in action parameters.
+[source,java]
+.PetOwner_persona.java
+----
+@Override
+protected PetOwner buildResult(final ExecutionContext ec) {
-Build and run the application to make sure it still runs fine.
+ val petOwner = wrap(PetOwners).create(persona.name);
+ // ...
+ if (persona.knownAs != null) {
+ petOwner.setKnownAs(persona.knownAs);
+ }
+
+ // ...
+}
+----
-[#exercise-3-2-add-petowners-firstname-property]
-== Ex 3.2: Add PetOwner's firstName property
-Now that `PetOwner` has a `lastName` property, let's also add a `firstName` property.
-We'll also update our fixture script (which sets up ``PetOwner``s) so that it is more descriptive.
+
+[#exercise-3-2-define-PetOwners-title-imperatively]
+== Ex 3.2: Define PetOwner's title imperatively
+
+Every domain object has a title, allowing end-users to distinguish one object instance from another.
+There's no requirement for this title to be unique, but it does need to be unique "enough".
+
+Our app currently declares the title of `PetOwner` declaratively using the xref:refguide:applib:index/annotation/Title.adoc[@Title] annotation on the `name` property.
+In this exercise, let's change that to also include the `knownAs` property as defined.
+Our rule will be:
+
+* if there is a `knownAs`, then the title should be "<name> (<knownAs>)"
+* but if `knownAs` is empty, then the title should be simply the `name`, as it is now.
+
+To do that, we need to define the title imperatively, using the xref:refguide:applib-methods:ui-hints.adoc#title[title()] method.
=== Solution
[source,bash]
----
-git checkout tags/03-02-adds-PetOwner-firstName-property
+git checkout tags/03-02-define-PetOwner-title-imperatively
mvn clean install
mvn -pl spring-boot:run
----
=== Tasks
-* copy `@LastName` meta-annotation to create `@FirstName`:
-+
-[source,java]
-.FirstName.java
-----
-@Property(maxLength = FirstName.MAX_LEN, optionality = Optionality.OPTIONAL)
-@Parameter(maxLength = FirstName.MAX_LEN, optionality = Optionality.OPTIONAL)
-@ParameterLayout(named = "First Name")
-@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
-@Retention(RetentionPolicy.RUNTIME)
-public @interface FirstName {
-
- int MAX_LEN = 40;
-}
-----
-+
-Note that this property/parameter is optional.
-Its parameter name has also been updated.
-
+* locate the `name` property of `PetOwner`, and remove the `@Title` annotation
-* add a new (JPA nullable) property `firstName` to `PetOwner`:
-+
-[source,java]
-----
-@FirstName
-@Column(length = FirstName.MAX_LEN, nullable = true)
-@Getter @Setter @ToString.Include
-@PropertyLayout(fieldSetId = "name", sequence = "2")
-private String firstName;
-----
-
-* add a new factory method to accept a `firstName`, and refactor the existing one:
+* add a new `title()` method:
+
[source,java]
.PetOwner.java
----
-public static PetOwner withName(String name) {
- return withName(name, null);
-}
-
-public static PetOwner withName(String lastName, String firstName) {
- val simpleObject = new PetOwner();
- simpleObject.setLastName(lastName);
- simpleObject.setFirstName(firstName);
- return simpleObject;
+@ObjectSupport // <.>
+public String title() {
+ return getName() + (getKnownAs() != null ? " (" + getKnownAs() + ")" : "");
}
----
+<.> The xref:refguide:applib:index/annotation/ObjectSupport.adoc[@ObjectSupport] annotation tells the framework to include this method in the metamodel.
-* remove `@Title` annotation from `lastName` property, and add a `title()` method to derive from both properties:
-+
-[source,java]
-.PetOwner.java
-----
-public String title() {
- return getLastName() + (getFirstName() != null ? ", " + getFirstName() : "");
-}
-----
+[#exercise-3-3-remaining-PetOwner-properties]
+== Ex 3.3: Remaining `PetOwner` properties
-* Update the `PetOwner_persona` enum with more realistically last names (family names).
-+
-Learn more about fixture scripts xref:testing:fixtures:about.adoc[here].
+Comparing `PetOwner` as it is currently defined with our domain model, there are a couple of changes still to make:
+* we need to rename `lastCheckedIn` property to `lastVisit` property
+* we still need to add in a `telephoneNumber` property, and an `emailAddress` property
-[#exercise-3-3-modify-petowners-updatename-action]
-== Ex 3.3: Modify PetOwner's updateName action
-Although we've added a `firstName` property, currently it can't be edited.
-In this exercise we'll modify the `updateName` action to also allow the `firstName` to be changed.
+We'll make these changes in this exercise.
=== Solution
[source,bash]
----
-git checkout tags/03-03-modifies-PetOwner-updateName-action
+git checkout tags/03-03-remaining-PetOwner-properties
mvn clean install
mvn -pl spring-boot:run
----
=== Tasks
-* update `PetOwner#updateName` to also accept a new `firstName` parameter:
-+
-image::03-03/refactor-updateName.png[width=800px]
-+
-[source,java]
-.PetOwner.java
-----
-@Action(semantics = IDEMPOTENT, commandPublishing = Publishing.ENABLED, executionPublishing = Publishing.ENABLED)
-@ActionLayout(associateWith = "lastName", promptStyle = PromptStyle.INLINE)
-public PetOwner updateName(
- @LastName final String lastName,
- @FirstName String firstName) {
- setLastName(lastName);
- setFirstName(firstName);
- return this;
-}
-public String default0UpdateName() {
- return getLastName();
-}
-public String default1UpdateName() {
- return getFirstName();
-}
-----
+Rename the `lastCheckedIn` property to `lastVisit`:
-* add in a "default" supporting method for the new parameter.
+* rename the field in `PetOwner`
+* update `PetOwner_persona` also (but your IDE probably refactored this already).
+* to make it more realistic, let's change the fixture script so that the value of `lastVisit` is some number of days in the past:
+
[source,java]
-.PetOwner.java
+.PetOwner_persona.java
----
-public String default1UpdateName() {
- return getFirstName();
-}
+final var numDaysAgo = fakeDataService.ints().between(100, 2); // <.>
+final var lastVisit = clockService.getClock().nowAsLocalDate().minusDays(numDaysAgo); // <.>
+petOwner.setLastVisit(lastVisit);
----
-+
-The "default" supporting methods are called when the action prompt is rendered, providing the default for the "Nth" parameter of the corresponding action.
+<.> The xref:refguide:testing:index/fakedata/applib/services/FakeDataService.adoc[FakeDataService] provides an easy way to create fake data for testing and prototyping
+<.> It's good practice to use xref:refguide:applib:index/services/clock/ClockService.adoc[ClockService], so it can be easily mocked in tests
+
+Add the `telephoneNumber` property:
+
+* ...
+* ...
+
+Add the `emailAddress` property:
+
+* ...
+* ...
+
+TODO: ideas for future steps:
+- introduce a meta-annotation
+- introduce a custom type for these
diff --git a/antora/components/tutorials/modules/petclinic/partials/domain.adoc b/antora/components/tutorials/modules/petclinic/partials/domain.adoc
index 87641da592..e699f8cd23 100644
--- a/antora/components/tutorials/modules/petclinic/partials/domain.adoc
+++ b/antora/components/tutorials/modules/petclinic/partials/domain.adoc
@@ -28,11 +28,15 @@ package pets {
class PetOwner <<role>> {
+id
..
- #lastName
- #firstName
+ #name
+ #knownAs
..
-phoneNumber
-emailAddress
+ ..
+ -lastVisit
+ ..
+ -notes
}
}
(causeway) 03/03: CAUSEWAY-2873: 02-05, 03-04
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-2873
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 4182e4ccfa2596f8874a90b1ae67561e8de88241
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Fri May 24 07:11:05 2024 +0100
CAUSEWAY-2873: 02-05, 03-04
---
.gitignore | 3 +
.../petclinic/pages/020-the-petclinic-domain.adoc | 52 ++++++++-
.../petclinic/pages/030-petowner-entity.adoc | 116 +++++++++++++++++++--
.../modules/petclinic/pages/100-todo.adoc | 4 +
4 files changed, 162 insertions(+), 13 deletions(-)
diff --git a/.gitignore b/.gitignore
index 69fc1a2cdd..5a54c9a8f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+# Linux
+nohup.out
+
# IDEA
.idea
*.iml
diff --git a/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc b/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc
index 72d06a82ee..f7b58db22f 100644
--- a/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc
+++ b/antora/components/tutorials/modules/petclinic/pages/020-the-petclinic-domain.adoc
@@ -337,6 +337,9 @@ The xref:testing:fixtures:about.adoc#personas-and-builders[persona] pattern lets
In this exercise we'll modify the `PetOwners_persona` (copied from `SimpleObjects_persona` earlier) to create more realistic data.
+We'll also update the existing top-level `DomainAppDemo` fixture script, so that it will recreate our new ``PetOwner``s.
+This will allow us to quickly create a whole set of `PetOwner` objects from the "Prototyping" menu.
+
=== Solution
@@ -349,7 +352,50 @@ mvn -pl spring-boot:run
=== Tasks
-* locate the `PetOwners_persona` class
-* refactor the enum constants and values to create 10 realistic pet owner names
-* (optional) we'll use the associated `.pdf` to store a "veterinary clinic service agreement" for each pet owner.
+* locate the `PetOwners_persona` class, and refactor the enum constants and values to create 10 realistic pet owner names
++
+[source,java]
+.PetOwners_persona.java
+----
+@RequiredArgsConstructor
+public enum PetOwner_persona
+implements Persona<PetOwner, PetOwner_persona.Builder> {
+
+ JAMAL("Jamal Washington", "jamal.pdf", "J"),
+ CAMILA("Camila González", "camila.pdf", null),
+ ARJUN("Arjun Patel", "arjun.pdf", null),
+ NIA("Nia Robinson", "nia.pdf", null),
+ OLIVIA("Olivia Hartman", "olivia.pdf", null),
+ LEILA("Leila Hassan", "leila.pdf", null),
+ MATT("Matthew Miller", "matt.pdf", "Matt"),
+ BENJAMIN("Benjamin Thatcher", "benjamin.pdf", "Ben"),
+ JESSICA("Jessica Raynor", "jessica.pdf", "Jess"),
+ DANIEL("Daniel Keating", "daniel.pdf", "Dan");
+
+ ...
+}
+----
+
+* create new `.pdf` files each pet owner, to store a "veterinary clinic service agreement" for each.
++
+The solution already provides these `.pdf` files, so you might want to borrow them.
+
+* locate the `DomainAppDemo` class and update:
++
+[source,java]
+.DomainAppDemo.java
+----
+@Override
+protected void execute(final ExecutionContext ec) {
+ ec.executeChildren(this, moduleWithFixturesService.getTeardownFixture());
+ ec.executeChild(this, new PetOwner_persona.PersistAll()); // <.>
+}
+----
+<.> change to set up ``PetOwner``s (rather than ``SimpleObject``s, as before)
+
+
+Test that you can quickly create a whole set of `PetOwner` objects
+from the "Prototyping" menu:
+* "Prototyping > Run Fixture Script" and select "Domain App Demo", or
+* "Prototyping > Recreate Objects and Return First".
diff --git a/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc b/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc
index a7b0d399fb..d51996df78 100644
--- a/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc
+++ b/antora/components/tutorials/modules/petclinic/pages/030-petowner-entity.adoc
@@ -151,7 +151,6 @@ Comparing `PetOwner` as it is currently defined with our domain model, there are
* we still need to add in a `telephoneNumber` property, and an `emailAddress` property
-
We'll make these changes in this exercise.
=== Solution
@@ -181,22 +180,119 @@ petOwner.setLastVisit(lastVisit);
<.> The xref:refguide:testing:index/fakedata/applib/services/FakeDataService.adoc[FakeDataService] provides an easy way to create fake data for testing and prototyping
<.> It's good practice to use xref:refguide:applib:index/services/clock/ClockService.adoc[ClockService], so it can be easily mocked in tests
-Add the `telephoneNumber` property:
+Now add the two new properties:
-* ...
-* ...
+* Add the `telephoneNumber` property:
++
+[source,java]
+.PetOwner.java
+----
+@Column(length = 40, nullable = true, name = "telephoneNumber")
+@Getter @Setter
+@Property(editing = Editing.ENABLED)
+@PropertyLayout(fieldSetId = "contact", sequence = "1.1") // <.>
+private String telephoneNumber;
+----
+<.> This places the property in a new "contact" fieldset group; we'll define that below
-Add the `emailAddress` property:
+* and add the `emailAddress` property:
++
+[source,java]
+.PetOwner.java
+----
+@Column(length = 40, nullable = true, name = "emailAddress")
+@Getter @Setter
+@Property(editing = Editing.ENABLED)
+@PropertyLayout(fieldSetId = "contact", sequence = "1.2")
+private String emailAddress;
+----
-* ...
-* ...
+And now let's define the referenced "contact" fieldset.
+* Locate the associated `.layout.xml` file for `PetOwner`.
+Before the "Details" fieldset, add:
++
+[source,xml]
+.PetOwner.layout.xml
+----
+<bs3:col span="12">
+ <cpt:fieldSet name="Contact" id="contact"/>
+</bs3:col>
+----
+
+TIP: if you make changes to this file then your IDE may be able detect the changes automatically.
+For example, with IntelliJ you can use "Reload Changed Classes" menu item.
+
+You can learn more about layout files xref:userguide::ui-layout-and-hints.adoc[here].
+
+[#exercise-3-4-list-new-properties-of-PetOwner]
+== Ex 3.4: List-new-properties-of-PetOwner
+
+Several of the actions in the "Pet Owners" menu return lists of ``PetOwner``s; the "list" action returns all of them.
+
+When we do this we see only the `name` property of the `PetOwner`.
+Let's update the app to see some other properties we added in the previous exercise.
+
+=== Solution
-TODO: ideas for future steps:
-- introduce a meta-annotation
-- introduce a custom type for these
+[source,bash]
+----
+git checkout tags/03-04-list-new-properties-of-PetOwner
+mvn clean install
+mvn -pl spring-boot:run
+----
+=== Tasks
+* Locate the `PetOwner.columnOrder.txt` and make these changes:
++
+[source,text]
+.PetOwner.columnOrder.txt
+----
+name
+telephoneNumber
+emailAddress
+lastVisit
+----
+
+Confirm that "Pet Owners > List" now shows the additional properties as columns.
+
+TIP: if you make changes to this file then your IDE may be able detect the changes automatically.
+For example, with IntelliJ you can use "Reload Changed Classes" menu item.
+
+You can learn more about layout files xref:userguide::ui-layout-and-hints.adoc[here].
+
+
+
+[#exercise-3-5-run-default-fixture-at-startup]
+== Ex 3.5: Run default fixture at startup
+
+Prototyping involves a lot of iteration, meaning make a change, re-run the app, in the app re-create some example objects, inspect the result.
+
+One way to create objects is from the Prototyping menu; you might already have been doing this.
+
+xxx
+
+=== Solution
+
+[source,bash]
+----
+git checkout tags/03-04-list-new-properties-of-PetOwner
+mvn clean install
+mvn -pl spring-boot:run
+----
+
+=== Tasks
+
+----
+----
+
+----
+----
+
+----
+----
+*UP TO HERE*
[#exercise-3-4-modify-the-menu-action-to-create-petowners]
== Ex 3.4: Modify the menu action to create PetOwners
diff --git a/antora/components/tutorials/modules/petclinic/pages/100-todo.adoc b/antora/components/tutorials/modules/petclinic/pages/100-todo.adoc
new file mode 100644
index 0000000000..a669ffc86b
--- /dev/null
+++ b/antora/components/tutorials/modules/petclinic/pages/100-todo.adoc
@@ -0,0 +1,4 @@
+
+TODO: ideas for future steps:
+- introduce a meta-annotation
+- introduce a custom type for these