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/03/27 08:34:01 UTC

[causeway] 02/02: CAUSEWAY-2485: polishes DomainObject#aliased, DomainObject#autoComplete...

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 39bdbce2504b713a7f5515811ea10e5f256e38e6
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Mar 27 09:32:16 2023 +0100

    CAUSEWAY-2485: polishes DomainObject#aliased, DomainObject#autoComplete...
---
 ...ities.java => DomainObjectAliasedRepository.java} | 20 ++++++--------------
 .../aliased/DomainObjectAliasedVm-description.adoc   |  5 +++--
 .../aliased/DomainObjectAliasedVm_lookup.java        | 15 +++++++++++++++
 .../aliased/jpa/DomainObjectAliasedJpaEntities.java  | 10 +++++++++-
 .../DomainObjectAutoCompleteVm-description.adoc      |  8 +++++---
 .../demoapp/dom/homepage/DemoHomePage-welcome.adoc   |  4 ++--
 6 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedRepository.java
similarity index 69%
copy from examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java
copy to examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedRepository.java
index be6c05735b..5f02c80287 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedRepository.java
@@ -16,25 +16,17 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package demoapp.dom.domain.objects.DomainObject.aliased.jpa;
+package demoapp.dom.domain.objects.DomainObject.aliased;
 
 import demoapp.dom._infra.values.ValueHolderRepository;
+import demoapp.dom.domain.objects.DomainObject.aliased.jpa.DomainObjectAliasedJpa;
+
+import java.util.List;
 
 import org.springframework.context.annotation.Profile;
 import org.springframework.stereotype.Service;
 
-@Profile("demo-jpa")
-@Service
-public class DomainObjectAliasedJpaEntities
-extends ValueHolderRepository<String, DomainObjectAliasedJpa> {
-
-    protected DomainObjectAliasedJpaEntities() {
-        super(DomainObjectAliasedJpa.class);
-    }
-
-    @Override
-    protected DomainObjectAliasedJpa newDetachedEntity(String value) {
-        return new DomainObjectAliasedJpa(value);
-    }
+public interface DomainObjectAliasedRepository {
 
+    List<? extends DomainObjectAliased> allInstances();
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm-description.adoc
index 68b16e09ea..003a3ad349 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm-description.adoc
@@ -16,9 +16,10 @@ However, any bookmarks in the old format of "customer.Customer:1234" should stil
 
 === How this demo works
 
-The collection on the left shows a set of `Customer` entity instances, each indicating their current bookmark and a previous bookmark that corresponds to the value of their link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/DomainObject.html#aliased[@DomainObject#alias].
+The collection on the left shows a set of entity instances, each indicating their current bookmark and a previous bookmark that corresponds to the value of their link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/DomainObject.html#aliased[@DomainObject#alias].
 
-The "lookup" (mixin) action allows any of these objects to be shown using either bookmark:
+The "lookup" (mixin) action uses the https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/services/bookmark/BookmarkService.html[BookmarkService] to lookup any object using either their current bookmark (defined by `@Named`) or their previous bookmark (defined by `@DomainObject#alias`).
+For convenience, the action provides a choices method for all possible values.
 
 [source,java,indent=0]
 ----
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm_lookup.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm_lookup.java
index 2c65abc4af..46b865d35c 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm_lookup.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/DomainObjectAliasedVm_lookup.java
@@ -1,12 +1,17 @@
 package demoapp.dom.domain.objects.DomainObject.aliased;
 
 import lombok.RequiredArgsConstructor;
+import lombok.val;
+
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.inject.Inject;
 
 import org.apache.causeway.applib.annotation.*;
 import org.apache.causeway.applib.services.bookmark.Bookmark;
 import org.apache.causeway.applib.services.bookmark.BookmarkService;
+import org.apache.causeway.applib.services.repository.RepositoryService;
 
 //tag::class[]
 @Action(semantics = SemanticsOf.SAFE)
@@ -20,7 +25,17 @@ public class DomainObjectAliasedVm_lookup {
     public DomainObjectAliased act(final String bookmark) {
         return bookmarkService.lookup(Bookmark.parseElseFail(bookmark), DomainObjectAliased.class).orElseThrow(() -> new org.apache.causeway.applib.exceptions.RecoverableException("No customer exists for that bookmark"));
     }
+    public List<String> choices0Act() {
+        val bookmarks = new ArrayList<String>();
+        val aliases = repository.allInstances();
+        aliases.stream().forEach(obj -> {
+            bookmarks.add(obj.getBookmark());
+            bookmarks.add(obj.getPreviousBookmark());
+        });
+        return bookmarks;
+    }
 
+    @Inject DomainObjectAliasedRepository repository;
     @Inject BookmarkService bookmarkService;
 }
 //end::class[]
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java
index be6c05735b..cd3f92d90e 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/aliased/jpa/DomainObjectAliasedJpaEntities.java
@@ -19,6 +19,10 @@
 package demoapp.dom.domain.objects.DomainObject.aliased.jpa;
 
 import demoapp.dom._infra.values.ValueHolderRepository;
+import demoapp.dom.domain.objects.DomainObject.aliased.DomainObjectAliased;
+import demoapp.dom.domain.objects.DomainObject.aliased.DomainObjectAliasedRepository;
+
+import java.util.List;
 
 import org.springframework.context.annotation.Profile;
 import org.springframework.stereotype.Service;
@@ -26,7 +30,7 @@ import org.springframework.stereotype.Service;
 @Profile("demo-jpa")
 @Service
 public class DomainObjectAliasedJpaEntities
-extends ValueHolderRepository<String, DomainObjectAliasedJpa> {
+extends ValueHolderRepository<String, DomainObjectAliasedJpa> implements DomainObjectAliasedRepository {
 
     protected DomainObjectAliasedJpaEntities() {
         super(DomainObjectAliasedJpa.class);
@@ -37,4 +41,8 @@ extends ValueHolderRepository<String, DomainObjectAliasedJpa> {
         return new DomainObjectAliasedJpa(value);
     }
 
+    @Override
+    public List<? extends DomainObjectAliased> allInstances() {
+        return all();
+    }
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/autoComplete/DomainObjectAutoCompleteVm-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/autoComplete/DomainObjectAutoCompleteVm-description.adoc
index 214487e598..b44e2a81d1 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/autoComplete/DomainObjectAutoCompleteVm-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/DomainObject/autoComplete/DomainObjectAutoCompleteVm-description.adoc
@@ -11,15 +11,17 @@ TIP: In fact, the return type of the `autoComplete` method does not need to exac
 
 === How this demo works
 
-The collection on the left shows a set of `Customer` entity instances.
+The collection on the left shows a set of entity instances, of type `DomainObjectAutoComplete`.
 
-The "find" (mixin) action defines a `Customer` as its parameter type, and simply returns it.
+The "find" (mixin) action defines the entity class as its parameter type, and simply returns it.
 
 [source,java,indent=0]
 ----
 include::DomainObjectAutoCompleteVm_find.java[tags=class]
 ----
 
-The autoComplete search is specified in the `Customer` type itself, using the link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/DomainObject.html#autoCompleteRepository[autoCompleteRepository] and link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/DomainObject.html#autoCompleteMethod[autoCompleteMethod] attributes.
+<.> xxx
+
+The autoComplete search to perform is specified using the link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/DomainObject.html#autoCompleteRepository[autoCompleteRepository] and link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/DomainObject.html#autoCompleteMethod[autoCompleteMethod] attributes.
 
 Navigate through to the entity to see the corresponding source code.
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc
index 04c9d0562b..372e776627 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc
@@ -4,7 +4,7 @@ This is an link:https://causeway.apache.org[Apache Causeway] application to demo
 
 On the left hand side of each web page you'll find the feature, and on the right hand side you'll find an explanation of the feature with code examples.
 
-== Page Layout
+=== Page Layout
 
 This is as good place as any to explain the page layout of an Apache Causeway webapp:
 
@@ -31,7 +31,7 @@ Click into the application and try things out.
 The demo app uses an in-memory database, so any changes made will be lost when the app is stopped.
 ====
 
-== Getting Help and Assistance
+=== Getting Help and Assistance
 
 There is plenty of documentation on our link:https://causeway.apache.org/docs/${CAUSEWAY_VERSION}/about.html[website].
 Also subscribe to our link:https://causeway.apache.org/docs/${CAUSEWAY_VERSION}/support/mailing-list.html[mailing list] or join our link:https://causeway.apache.org/docs/${CAUSEWAY_VERSION}/support/slack-channel.html[Slack channel].