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/25 09:11:10 UTC
[causeway] 02/02: CAUSEWAY-2485: polishes for @DomainObject#entityChangePublishing
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 66d1d98c49880b852fea95d8b65cee9ed110be27
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Thu May 25 10:10:22 2023 +0100
CAUSEWAY-2485: polishes for @DomainObject#entityChangePublishing
---
.../dom/_infra/values/ValueHolderRepository.java | 4 ++
.../_changes/ExposeCapturedChanges_clear.java | 4 +-
.../ExposeCapturedChanges_recentChanges.java | 4 +-
...ut.xml => DomainObjectEditingEntity.layout.xml} | 0
.../DomainObjectEditingPage-description.adoc | 38 +++++++++++++----
.../DomainObjectEditingEntityImpl-description.adoc | 3 +-
.../editing/jdo/DomainObjectEditingEntityImpl.java | 10 ++---
.../editing/jpa/DomainObjectEditingEntityImpl.java | 10 ++---
...inObjectEntityChangePublishingEntity.layout.xml | 5 +--
...jectEntityChangePublishingPage-description.adoc | 48 ++++++++++++++++++----
...mainObjectEntityChangePublishingPage.layout.xml | 3 ++
...ainObjectEntityChangePublishingPage_modify.java | 2 +
12 files changed, 96 insertions(+), 35 deletions(-)
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/_infra/values/ValueHolderRepository.java b/examples/demo/domain/src/main/java/demoapp/dom/_infra/values/ValueHolderRepository.java
index 22f8a1df90..f2ad829ba3 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/_infra/values/ValueHolderRepository.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/_infra/values/ValueHolderRepository.java
@@ -64,6 +64,10 @@ public abstract class ValueHolderRepository<T, E extends ValueHolder<T>> {
List<E> all = all();
return all.isEmpty() ? Collections.emptyList() : Collections.singletonList(all.get(0));
}
+ public List<E> lastAsList() {
+ List<E> all = all();
+ return all.isEmpty() ? Collections.emptyList() : Collections.singletonList(all.get(all.size()-1));
+ }
public void remove(final Object entity) {
repositoryService.removeAndFlush(entity);
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_clear.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_clear.java
index 65a062be23..e76f1d2a54 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_clear.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_clear.java
@@ -42,10 +42,10 @@ public class ExposeCapturedChanges_clear {
//tag::class[]
public DomainObjectEntityChangePublishingPage act() {
- entityChangesSubscriberToCaptureChangesInMemory.clear();
+ subscriber.clear();
return domainObjectAuditingVm;
}
- @Inject EntityChangesSubscriberToCaptureChangesInMemory entityChangesSubscriberToCaptureChangesInMemory;;
+ @Inject EntityChangesSubscriberToCaptureChangesInMemory subscriber;;
}
//end::class[]
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_recentChanges.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_recentChanges.java
index 4d5d627462..43118b29ef 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_recentChanges.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/_changes/ExposeCapturedChanges_recentChanges.java
@@ -43,13 +43,13 @@ public class ExposeCapturedChanges_recentChanges {
//tag::class[]
public List<ChangesVm> coll() {
val list = new LinkedList<ChangesVm>();
- entityChangesSubscriberToCaptureChangesInMemory
+ subscriber
.streamChangedEntities()
.map(ChangesVm::new)
.forEach(list::push); // reverse order
return list;
}
- @Inject EntityChangesSubscriberToCaptureChangesInMemory entityChangesSubscriberToCaptureChangesInMemory;
+ @Inject EntityChangesSubscriberToCaptureChangesInMemory subscriber;
}
//end::class[]
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditing.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingEntity.layout.xml
similarity index 100%
rename from examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditing.layout.xml
rename to examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/DomainObjectEditingEntity.layout.xml
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 78db02ad1f..ed7a1de9d5 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
@@ -15,19 +15,11 @@ causeway:
----
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.
-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.
-There are therefore three levels at which property editing can be defined:
+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.
- @Property > @DomainObject > global configuration property
-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.
-
-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.
-This 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].
== How this demo works
@@ -37,3 +29,31 @@ The "initialCharacter" property cannot be edited either, because it is a derived
Navigate through to the entity in order to edit its properties, and to see the corresponding source code.
+In terms of code:
+
+* the entity is defined thus:
++
+[source,java]
+----
+include::jpa/DomainObjectEditingEntityImpl.java[tags=class]
+----
+<.> indicates that the properties of this type may be edited, overriding the global default set by configuration property.
+<.> editable property because of the `@DomainObject#editing` annotation
+<.> this property cannot, after all, be edited, with `@Property#editing` overriding `@DomainObject#editing`.
+See section below for further discussion.
+<.> also a non-editable property, but this time because it is a derived property.
+
+
+
+== 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].
+
+There are therefore three levels at which property editing can be defined:
+
+ @Property > @DomainObject > global configuration property
+
+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/editing/jdo/DomainObjectEditingEntityImpl-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl-description.adoc
index 8d3c5449a1..ab23346cfd 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl-description.adoc
@@ -1,6 +1,7 @@
: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 [...]
-In this demo app, property editing has been disabled by default, but has been explicitly enabled for this class:
+In this demo app, property editing has been disabled by default.
+This entity class re-enables editing using `@DomainObject#editing`, and then selectively _disables_ it again for one of the properties using `@Property#editing`.
[source,java,indent=0]
.DomainObjectEditingJpa.java
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl.java
index 650150344a..ea4ac80580 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jdo/DomainObjectEditingEntityImpl.java
@@ -48,7 +48,7 @@ import demoapp.dom.domain.objects.DomainObject.editing.DomainObjectEditingEntity
// ...
@DomainObject(
nature = Nature.ENTITY,
- editing = Editing.ENABLED // <.>
+ editing = Editing.ENABLED // <.>
)
public class DomainObjectEditingEntityImpl
extends DomainObjectEditingEntity {
@@ -62,16 +62,16 @@ public class DomainObjectEditingEntityImpl
//tag::class[]
@Getter @Setter
- private String name; // <.>
+ private String name; // <.>
@Property(
- editing = Editing.DISABLED, // <.>
- editingDisabledReason = "This property may not be edited"
+ editing = Editing.DISABLED, // <.>
+ editingDisabledReason = "This property may not be edited"
)
@Getter @Setter
private String originalName;
- public Character getInitialCharacter() { // <.>
+ public Character getInitialCharacter() { // <.>
return getName().charAt(0);
}
//end::class[]
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jpa/DomainObjectEditingEntityImpl.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jpa/DomainObjectEditingEntityImpl.java
index bf0dccc1f1..8483aeb858 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jpa/DomainObjectEditingEntityImpl.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/editing/jpa/DomainObjectEditingEntityImpl.java
@@ -52,7 +52,7 @@ import demoapp.dom.domain.objects.DomainObject.editing.DomainObjectEditingEntity
// ...
@DomainObject(
nature = Nature.ENTITY,
- editing = Editing.ENABLED // <.>
+ editing = Editing.ENABLED // <.>
)
public class DomainObjectEditingEntityImpl
extends DomainObjectEditingEntity {
@@ -70,16 +70,16 @@ public class DomainObjectEditingEntityImpl
//tag::class[]
@Getter @Setter
- private String name; // <.>
+ private String name; // <.>
@Property(
- editing = Editing.DISABLED, // <.>
- editingDisabledReason = "This property may not be edited"
+ editing = Editing.DISABLED, // <.>
+ editingDisabledReason = "This property may not be edited"
)
@Getter @Setter
private String originalName;
- public Character getInitialCharacter() { // <.>
+ public Character getInitialCharacter() { // <.>
return getName().charAt(0);
}
//end::class[]
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingEntity.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingEntity.layout.xml
index ab9154b267..f5f586c95e 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingEntity.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingEntity.layout.xml
@@ -31,9 +31,8 @@
<bs3:row>
<bs3:col span="12">
<cpt:fieldSet name="General" id="general" >
- <cpt:property id="name"/>
- <cpt:property id="originalName"/>
- <cpt:property id="initialCharacter"/>
+ <cpt:property id="property"/>
+ <cpt:property id="propertyUpdatedByAction"/>
</cpt:fieldSet>
</bs3:col>
</bs3:row>
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 9947937205..52d064b9ae 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
@@ -21,21 +21,53 @@ causeway:
entity-change-publishing: 'none' # 'none' | 'all'
----
-This demo app has entity change publishing disabled by default.
-
-Entity change publishing can also be 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 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.
== How this demo works
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.)
-Using this view model, you can use the actions to create new instances of the entity, update them or to delete them.
+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.
-Meanwhile, at the bottom of this page 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.
-NOTE: there will always be some listed from the fixture scripts run when the application first bootstraps.)
+In terms of code:
+
+* the entity class re-enables change publishing using `DomainObject#entityChangePublishing`:
++
+[source,java]
+----
+include::jpa/DomainObjectEntityChangePublishingEntityImpl.java[tags=class]
+----
+
+* the modify action:
++
+[source,java,indent=0]
+----
+include::DomainObjectEntityChangePublishingPage_modify.java[tags=act]
+----
+
+* the subscriber:
++
+[source,java,indent=0]
+.EntityChangesSubscriberToCaptureChangesInMemory.java
+----
+include::../../../_changes/EntityChangesSubscriberToCaptureChangesInMemory.java[tags=class]
+----
+<.> 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).
+A mixin then contributes the "recentChanges" collection:
++
+[source,java,indent=0]
+.ExposeCapturedChanges_recentChanges.java
+----
+include::../../../_changes/ExposeCapturedChanges_recentChanges.java[tags=class]
+----
-Navigate into each of the domain entities to see the code examples.
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage.layout.xml
index 854c4942a3..fc01691735 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage.layout.xml
@@ -30,6 +30,9 @@
<cpt:collection id="objects">
<cpt:action id="modify"/>
</cpt:collection>
+ <cpt:collection id="recentChanges">
+ <cpt:action id="clear"/>
+ </cpt:collection>
</bs3:col>
<bs3:col span="6">
<cpt:fieldSet name="Description" id="description" >
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage_modify.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage_modify.java
index 18160b1fba..84b495cf8b 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage_modify.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/entityChangePublishing/DomainObjectEntityChangePublishingPage_modify.java
@@ -41,6 +41,7 @@ public class DomainObjectEntityChangePublishingPage_modify {
private final DomainObjectEntityChangePublishingPage page;
+//tag::act[]
@MemberSupport public DomainObjectEntityChangePublishingPage act(
final Integer howManyToCreate,
final List<? extends DomainObjectEntityChangePublishingEntity> toUpdate,
@@ -53,6 +54,7 @@ public class DomainObjectEntityChangePublishingPage_modify {
toDelete.forEach(x -> repositoryService.remove(x));
return page;
}
+//end::act[]
@MemberSupport public Integer default0Act() {
return 1;
}