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 2023/05/30 06:24:27 UTC

[causeway] 01/03: CAUSEWAY-2485: polishes demo app

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

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

commit 31cb24edad58ff593582e18e2e3abad5223fa9f3
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue May 30 06:48:31 2023 +0100

    CAUSEWAY-2485: polishes demo app
---
 .../DomainObjectEditingPage-description.adoc       | 43 ++++++-------
 ...jectEntityChangePublishingPage-description.adoc | 41 ++++++------
 .../DomainObjectIntrospectionPage-description.adoc | 75 ++++++++++++++++------
 ...omainObjectIntrospectionAnnotOptEntityImpl.java |  6 +-
 ...nObjectIntrospectionEncapsulatedEntityImpl.java | 12 ++--
 5 files changed, 109 insertions(+), 68 deletions(-)

diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc
index ed7a1de9d5..19ee8ddb17 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingPage-description.adoc
@@ -1,24 +1,20 @@
 :Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or ag [...]
 
 The state of the application can be changed either by invoking actions on domain objects, or by directly editing their properties.
-
-If the application has complicated business logic, then it's usually preferable to make all changes using actions, with editing globally disabled using a configuration property:
-
-[source,yaml]
-.application.yml
-----
-causeway:
-  applib:
-    annotation:
-      domain-object:
-        editing: false    # false | true
-----
-
+If the application has complicated business logic, then it's usually preferable to make all changes using actions, with editing globally disabled using a configuration property (see section below for details).
 This demo application is configured in this recommended way, with property editing disabled by default.
-The link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#editing[@DomainObject#editing] annotation can be used to override the default for a specific object, so that all of its properties can be edited.
 
+The link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#editing[@DomainObject#editing] annotation can be used to override the default for a specific object, so that all of its properties can be edited.
 In addition, the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#editingDisabledReason[@DomainObject#editingDisabledReason] can be used to specify the reason why a property cannot be edited.
 
+It's also possible to override the class-level default on a per-property basis, using the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editing[@Property#editing] attribute.
+A reason can also be specified at the property level using link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editingDisabledReason[@Property#editingDisabledReason].
+There are therefore three levels at which property editing can be defined:
+
+    global configuration < @DomainObject < @Property
+
+This works in the opposite direction also: if the global config property is to _allow_ properties to be edited, then the `@DomainObject#editing` (or `@Property#editing`) could be used to disable editing.
+Such a setup is likely to be much less common, though.
 
 
 == How this demo works
@@ -45,15 +41,18 @@ See section below for further discussion.
 
 
 
-== See also
-
-It's also possible to override the class-level default on a per-property basis, using the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editing[@Property#editing] attribute.
-A reason can also be specified at the property level using link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html#editingDisabledReason[@Property#editingDisabledReason].
+== Configuration property
 
-There are therefore three levels at which property editing can be defined:
+To disable/enable editing globally, use:
 
-    @Property > @DomainObject > global configuration property
+[source,yaml]
+.application.yml
+----
+causeway:
+  applib:
+    annotation:
+      domain-object:
+        editing: false    # false | true
+----
 
-Alternatively, this works in the opposite direction also: if the global config property is to _allow_ properties to be edited, then the `@DomainObject#editing` (or `@Property#editing`) could be used to disable editing.
-This would be much less common, though.
 
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage-description.adoc
index 52d064b9ae..71e1e43735 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage-description.adoc
@@ -7,23 +7,12 @@ This callback is done only at the end of the interaction.
 Common use cases are to replicate data to another system, or for gathering metrics ("which objects change the most?").
 A typical SPI implementation could publish the event over the network, or perhaps store in a database.
 
-NOTE: Publishing of domain objects is only supported for domain entities, not view models.
-
-Entity change publishing can be enabled or disabled globally using a configuration property:
-
-[source,yaml]
-.application.yml
-----
-causeway:
-  applib:
-    annotation:
-      domain-object:
-        entity-change-publishing: 'none'    # 'none' | 'all'
-----
-
-This demo app has entity change publishing disabled by default, but can be re-enabled on a case by case basis using the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#entitychangepublishing[@DomainObject#entitychangepublishing] attribute.
+Entity change publishing can be enabled or disabled globally using a configuration property (see section below).
+This demo app has entity change publishing disabled by default, but can be re-enabled on a case by case basis using the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#entitychangepublishing[@DomainObject#entityChangePublishing] attribute.
 This page references a domain object that uses this attribute.
 
+NOTE: Publishing of domain objects is only supported for domain entities, not view models.
+
 
 
 == How this demo works
@@ -31,7 +20,7 @@ This page references a domain object that uses this attribute.
 The collection on the left shows a set of entity instances, which have `@DomainObject#entityChangePublishing` to enable the publishing of any changes to their state.
 Below it is a collection that simply lists all of the changes that have been received.
 This uses an implementation of `EntityChangesSubscriber` that captures changes and simply holds them in-memory.
-(There will always be some listed from the fixture scripts run when the application first bootstraps.)
+(There will always be some listed from the fixture scripts that are run when the application bootstraps.)
 
 Using the "modify" action, you can (in one go) create new instances of the entity class, update existing instances, or delete instances.
 This will cause new events to be logged.
@@ -46,14 +35,14 @@ In terms of code:
 include::jpa/DomainObjectEntityChangePublishingEntityImpl.java[tags=class]
 ----
 
-* the modify action:
+* the modify action can be used to create new instances, update existing instances and/or delete existing instances:
 +
 [source,java,indent=0]
 ----
 include::DomainObjectEntityChangePublishingPage_modify.java[tags=act]
 ----
 
-* the subscriber:
+* the subscriber listens to the events and simply adds them to the list:
 +
 [source,java,indent=0]
 .EntityChangesSubscriberToCaptureChangesInMemory.java
@@ -62,7 +51,7 @@ include::../../../_changes/EntityChangesSubscriberToCaptureChangesInMemory.java[
 ----
 <.> describes the set of changes
 
-* NB: this page shows the list of recent changes by virtue of also implementing a `ExposeCapturedChanges` marker interface (part of the demo app, not the framework).
+* the list of recent changes is shown because this page implementing an `ExposeCapturedChanges` marker interface (part of the demo app, not the framework).
 A mixin then contributes the "recentChanges" collection:
 +
 [source,java,indent=0]
@@ -71,3 +60,17 @@ A mixin then contributes the "recentChanges" collection:
 include::../../../_changes/ExposeCapturedChanges_recentChanges.java[tags=class]
 ----
 
+== Configuration property
+
+To enable/disable entity change publishing, use this configuration property:
+
+[source,yaml]
+.application.yml
+----
+causeway:
+  applib:
+    annotation:
+      domain-object:
+        entity-change-publishing: 'none'    # 'none' | 'all'
+----
+
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/DomainObjectIntrospectionPage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/DomainObjectIntrospectionPage-description.adoc
index 770f77e066..cb47948edc 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/DomainObjectIntrospectionPage-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/DomainObjectIntrospectionPage-description.adoc
@@ -5,26 +5,73 @@ Introspection is the process by which the framework builds up its internal metam
 The framework supports three different introspection policies, depending on your taste of whether the metamodel should be explicitly called out (but that means more 'boilerplate'), or should be inferred so far as possible.
 These introspection policies are:
 
-* "annotation optional"
-+
-Introspect public methods only, recognising getters as either properties or collections, and other public methods as actions.
+* *annotation optional* - introspect public methods only, recognising getters as either properties or collections, and other public methods as actions.
 +
 Supporting methods for either domain members (`hide`, `disable`, `validate`, `choices`, `autoComplete`) or for the object (`title`, `iconName`, `layout`, `cssClass`) do not need to be annotated either.
 
-* "annotation required"
-+
-Requires that getter methods representing properties or collections, and public methods representing actions are all explicitly annotated (with link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html[@Property], link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Collection.html[@Collection] and link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Action.html[@Action])
+* *annotation required* - requires that getter methods representing properties or collections, and public methods representing actions are all explicitly annotated (with link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Property.html[@Property], link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Collection.html[@Collection] and link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/Action.html[@Action])
 +
 However supporting methods for domain members (`hide`, `disable`, `validate`, `choices`, `autoComplete`) and for the object (`title`, `iconName`, `layout`, `cssClass`) do not need to be annotated.
 
-* "encapsulation enabled"
-+
-Requires that both the methods representing properties, collections an actions are annotated (with `@Property,` `@Collection` and `@Action`), and _also_ that the supporting methods are annotated (with link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/MemberSupport.html[@MemberSupport] for methods relating to domain members, and link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/ObjectSupport.html[@ObjectSupport] for the object-level supp [...]
+* *encapsulation enabled* - requires that both the methods representing properties, collections an actions are annotated (with `@Property,` `@Collection` and `@Action`), and _also_ that the supporting methods are annotated (with link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/MemberSupport.html[@MemberSupport] for methods relating to domain members, and link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/ObjectSupport.html[@ObjectSuppor [...]
 +
 However, the methods can have _any_ visibility, including `private` visibility.
 This reduces the programmatic API of the domain object can so can help eliminate bugs.
++
+[NOTE]
+====
+entities using this type do not render correctly in collections - properties are not shown as columns.
+Tracking with https://issues.apache.org/jira/browse/CAUSEWAY-3471[CAUSEWAY-3471]
+====
+
+The default policy is set using a configuration property (see section below).
+Normally there would be little reason to override this - just adopt the convention that best fits your style, and leave it at that.
+However, it the need arises then it can be overridden on a class by class basis using the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#introspection[@DomainObject#introspection] attribute.
+
+== How this demo works
+
+The collections on the left show three variants of the same entity, each with a property and an action, but each configured to use a different introspection policy.
+
+Navigate through to the entity to inspect the differences in their source code.
+
+In terms of code:
+
+* annotation optional:
++
+[source,java]
+----
+include::annotOpt/jpa/DomainObjectIntrospectionAnnotOptEntityImpl.java[tags=class]
+----
+<.> no need to annotate with `@Property`.
+It would also be ok to remove the methods but then annotate the field with `@lombok.Getter` and `@lombok.Setter`
+<.> no need to annotate with `@Action`
+<.> no need to annotate with `@MemberSupport`
 
-The default policy is set using a configuration property:
+* annotation required:
++
+[source,java]
+----
+include::annotReqd/jpa/DomainObjectIntrospectionAnnotReqdEntityImpl.java[tags=class]
+----
+<.> must annotate as `@Property`.
+It would also be ok to remove the methods but then annotate the field with `@Property` and also with `@lombok.Getter` and `@lombok.Setter`
+<.> must annotate as `@Action`
+<.> no need to annotate with `@MemberSupport`
+
+* encapsulated:
++
+[source,java]
+----
+include::encapsulated/jpa/DomainObjectIntrospectionEncapsulatedEntityImpl.java[tags=class]
+----
+<.> must annotate as `@Property`, but can have any visibility
+<.> must annotate as `@Action`, but can have any visibility
+<.> must annotate as @`MemberSupport` or `@Domain.Include`, but can have any visibility
+
+
+== Configuration property
+
+The default introspection policy is set using a configuration property:
 
 [source,yaml]
 .application.yaml
@@ -37,11 +84,3 @@ causeway:
 ----
 <.> `annotation_optional` | `annotation_required` | `encapsulation_enabled`
 
-Normally there would be little reason to override this - just adopt the convention that best fits your style, and leave it at that.
-However, it the need arises then it can be overridden on a class by class basis using the link:https://causeway.apache.org/refguide/2.0.0-RC1/applib/index/annotation/DomainObject.html#introspection[@DomainObject#introspection] attribute.
-
-== How this demo works
-
-The collections on the left show three variants of the same entity, each with a property and an action, but each configured to use a different introspection policy.
-
-Navigate through to the entity to inspect the differences in their source code.
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/annotOpt/jpa/DomainObjectIntrospectionAnnotOptEntityImpl.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/annotOpt/jpa/DomainObjectIntrospectionAnnotOptEntityImpl.java
index 1893ecdb56..fa71c43a11 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/annotOpt/jpa/DomainObjectIntrospectionAnnotOptEntityImpl.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/annotOpt/jpa/DomainObjectIntrospectionAnnotOptEntityImpl.java
@@ -63,7 +63,7 @@ public class DomainObjectIntrospectionAnnotOptEntityImpl
     private Long id;
 //tag::class[]
 
-    private String name;                                                        // <.>
+    private String name;                                                                // <.>
     public String getName() {
         return name;
     }
@@ -71,11 +71,11 @@ public class DomainObjectIntrospectionAnnotOptEntityImpl
         this.name = name;
     }
 
-    public DomainObjectIntrospectionAnnotOptEntityImpl updateName(final String name) { // <.>
+    public DomainObjectIntrospectionAnnotOptEntityImpl updateName(final String name) {  // <.>
         setName(name);
         return this;
     }
-    public String default0UpdateName() {                                        // <.>
+    public String default0UpdateName() {                                                // <.>
         return getName();
     }
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/encapsulated/jpa/DomainObjectIntrospectionEncapsulatedEntityImpl.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/encapsulated/jpa/DomainObjectIntrospectionEncapsulatedEntityImpl.java
index 7ea5c9ac6c..20a261c4b0 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/encapsulated/jpa/DomainObjectIntrospectionEncapsulatedEntityImpl.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/introspection/encapsulated/jpa/DomainObjectIntrospectionEncapsulatedEntityImpl.java
@@ -73,21 +73,21 @@ public class DomainObjectIntrospectionEncapsulatedEntityImpl
 //tag::class[]
 
     private String name;
-    @Property                                                                       // <.>
-    private String getName() {                                                      // <1>
+    @Property                                                                           // <.>
+    private String getName() {                                                          // <1>
         return name;
     }
     private void setName(String name) {
         this.name = name;
     }
 
-    @Action(semantics = SemanticsOf.IDEMPOTENT)                                     // <.>
-    private DomainObjectIntrospectionEncapsulatedEntity updateName(final String name) {   // <2>
+    @Action(semantics = SemanticsOf.IDEMPOTENT)                                         // <.>
+    private DomainObjectIntrospectionEncapsulatedEntity updateName(final String name) { // <2>
         setName(name);
         return this;
     }
-    @MemberSupport                                                                  // <.>
-    private String default0UpdateName() {                                           // <3>
+    @MemberSupport                                                                      // <.>
+    private String default0UpdateName() {                                               // <3>
         return getName();
     }
 }