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/09/22 10:44:35 UTC
[causeway] branch CAUSEWAY-3599 created (now 4743d46aa9)
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a change to branch CAUSEWAY-3599
in repository https://gitbox.apache.org/repos/asf/causeway.git
at 4743d46aa9 CAUSEWAY-3599: implements new logic
This branch includes the following new commits:
new 4743d46aa9 CAUSEWAY-3599: implements new logic
The 1 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.
[causeway] 01/01: CAUSEWAY-3599: implements new logic
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-3599
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 4743d46aa9895dc14ebb2fb42add1337ddd16ca1
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Sep 22 11:44:27 2023 +0100
CAUSEWAY-3599: implements new logic
and cleans up existing impl a little, updates out-of-date javadoc
---
.../TableColumnOrderForCollectionTypeAbstract.java | 16 ++++-----
.../services/tablecol/TableColumnOrderService.java | 40 +++++++++------------
.../tablecol/TableColumnOrderServiceDefault.java | 20 +++++------
.../TableColumnOrderServiceUsingTxtFile.java | 42 +++++++++++-----------
.../services/tablecol/Order.columnOrder.txt | 2 +-
.../TableColumnOrderServiceUsingTxtFile_Test.java | 21 +++++++++--
6 files changed, 74 insertions(+), 67 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderForCollectionTypeAbstract.java b/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderForCollectionTypeAbstract.java
index bbd4f47697..04ce8c945b 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderForCollectionTypeAbstract.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderForCollectionTypeAbstract.java
@@ -48,12 +48,12 @@ public abstract class TableColumnOrderForCollectionTypeAbstract<T>
public final List<String> orderParented(
final Object parent,
final String collectionId,
- final Class<?> collectionType,
- final List<String> propertyIds) {
- if (! this.collectionType.isAssignableFrom(collectionType)) {
+ final Class<?> elementType,
+ final List<String> associationIds) {
+ if (! this.collectionType.isAssignableFrom(elementType)) {
return null;
}
- return orderParented(parent, collectionId, propertyIds);
+ return orderParented(parent, collectionId, associationIds);
}
/**
@@ -79,12 +79,12 @@ public abstract class TableColumnOrderForCollectionTypeAbstract<T>
*/
@Override
public final List<String> orderStandalone(
- final Class<?> collectionType,
- final List<String> propertyIds) {
- if (! this.collectionType.isAssignableFrom(collectionType)) {
+ final Class<?> domainType,
+ final List<String> associationIds) {
+ if (! this.collectionType.isAssignableFrom(domainType)) {
return null;
}
- return orderStandalone(propertyIds);
+ return orderStandalone(associationIds);
}
/**
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderService.java b/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderService.java
index 104e032657..6b2e074db8 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderService.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/services/tablecol/TableColumnOrderService.java
@@ -62,41 +62,33 @@ import java.util.List;
public interface TableColumnOrderService {
/**
- * For the parent collection owned by the specified parent and collection
- * Id, return the set of property ids in the same or other order.
+ * For the parent collection owned by the specified parent and collection Id, return a list of association ids
+ * to be rendered as columns, in a particular order; those not included will be hidden.
*
- * <p>
- * Return <code>null</code> if has no opinion/provides no reordering
- * for this parent and collection.
- * </p>
+ * @param parent - the parent object (eg an <i>Order</i>).
+ * @param collectionId - the logical member name that identifies the collection within its domain object type (eg <i>items</i>).
+ * @param elementType - the class of the elements of the collection (eg <i>OrderItem</i>s in a collection of <i>Order#items</i>).
+ * @param associationIds - the associations (properties or collections) of the element type that should be rendered in the parent object's collection
*
- * @param parent
- * @param collectionId - the logical member name that identifies the collection
- * within its domain object type
- * @param collectionType
- * @param propertyIds
+ * @return <code>null</code> if has no opinion/provides no reordering for this parent and collection.
*/
List<String> orderParented(
final Object parent,
final String collectionId,
- final Class<?> collectionType,
- final List<String> propertyIds);
+ final Class<?> elementType,
+ final List<String> associationIds);
/**
- * For the standalone collection of the specified type, return the set of
- * property ids in the same or other order.
+ * For the standalone collection of the specified type, return a list of association ids to be rendered as columns,
+ * in a particular order; those not included will be hidden.
*
- * <p>
- * Return <code>null</code> if has no opinion/provides no reordering
- * for this type.
- * </p>
+ * @param domainType - the class of the domain object being rendered in the standalone collection
+ * @param associationIds - the associations (properties or collections) of the domain type that should be rendered in the parent object's collection
*
- * @param collectionType
- * @param propertyIds - the logical member names that identify the properties
- * within their domain object type
+ * @return <code>null</code> if has no opinion/provides no reordering for this type.
*/
List<String> orderStandalone(
- final Class<?> collectionType,
- final List<String> propertyIds);
+ final Class<?> domainType,
+ final List<String> associationIds);
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceDefault.java
index 18b7ffaee6..ec4be29c30 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceDefault.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceDefault.java
@@ -46,28 +46,28 @@ public class TableColumnOrderServiceDefault implements TableColumnOrderService {
*
* @param parent
* @param collectionId
- * @param collectionType
- * @param propertyIds
+ * @param elementType
+ * @param associationIds
*/
@Override
public List<String> orderParented(
final Object parent,
final String collectionId,
- final Class<?> collectionType,
- final List<String> propertyIds) {
- return propertyIds;
+ final Class<?> elementType,
+ final List<String> associationIds) {
+ return associationIds;
}
/**
* Just returns the <code>propertyIds</code> unchanged.
*
- * @param collectionType
- * @param propertyIds
+ * @param domainType
+ * @param associationIds
*/
@Override
public List<String> orderStandalone(
- final Class<?> collectionType,
- final List<String> propertyIds) {
- return propertyIds;
+ final Class<?> domainType,
+ final List<String> associationIds) {
+ return associationIds;
}
}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile.java
index 1dc3367a9c..eae6578243 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile.java
@@ -71,8 +71,8 @@ import lombok.extern.log4j.Log4j2;
public class TableColumnOrderServiceUsingTxtFile implements TableColumnOrderService {
/**
- * Reads propertyIds of the collection from a file named <i>ClassName#collectionId.columnOrder.txt</i>. relative
- * to the class itself.
+ * Reads association Ids of the collection from a file named <i>ClassName#collectionId.columnOrder.txt</i> relative
+ * to the class itself; if there is no such file then falls back to <i>CollectionType.columnOrder.txt</i>.
*
* <p>
* Additional files can be provided by overriding {@link #addResourceNames(Class, String, List)}.
@@ -82,19 +82,14 @@ public class TableColumnOrderServiceUsingTxtFile implements TableColumnOrderServ
public List<String> orderParented(
final Object domainObject,
final String collectionId,
- final Class<?> collectionType,
- final List<String> propertyIds) {
+ final Class<?> elementType,
+ final List<String> associationIds) {
val domainClass = domainObject.getClass();
val resourceNames = buildResourceNames(domainClass, collectionId);
+ addResourceNames(elementType, resourceNames); // fallback to reading the element type's own .txt file.
val contentsIfAny = tryLoad(domainClass, resourceNames);
- if(!contentsIfAny.isPresent()) {
- return null;
- }
- val s = contentsIfAny.get();
- return TextUtils.readLines(s)
- .filter(propertyIds::contains)
- .toList();
+ return contentsMatching(contentsIfAny, associationIds);
}
private List<String> buildResourceNames(final Class<?> domainClass, final String collectionId) {
@@ -149,17 +144,11 @@ public class TableColumnOrderServiceUsingTxtFile implements TableColumnOrderServ
*/
@Override
public List<String> orderStandalone(
- final Class<?> domainClass,
- final List<String> propertyIds) {
- val resourceNames = buildResourceNames(domainClass);
- val contentsIfAny = tryLoad(domainClass, resourceNames);
- if(!contentsIfAny.isPresent()) {
- return null;
- }
- val s = contentsIfAny.get();
- return TextUtils.readLines(s)
- .filter(propertyIds::contains)
- .toList();
+ final Class<?> domainType,
+ final List<String> associationIds) {
+ val resourceNames = buildResourceNames(domainType);
+ val contentsIfAny = tryLoad(domainType, resourceNames);
+ return contentsMatching(contentsIfAny, associationIds);
}
private List<String> buildResourceNames(final Class<?> domainClass) {
@@ -184,4 +173,13 @@ public class TableColumnOrderServiceUsingTxtFile implements TableColumnOrderServ
addTo.add(String.format("%s.columnOrder.txt", domainClass.getSimpleName()));
}
+ private static List<String> contentsMatching(
+ final Optional<String> contentsIfAny,
+ final List<String> associationIds) {
+ return contentsIfAny
+ .map(content -> TextUtils.readLines(content)
+ .filter(associationIds::contains)
+ .toList()).orElse(null);
+ }
+
}
diff --git a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/Order.columnOrder.txt b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/Order.columnOrder.txt
index 969d8614ba..da59a89b57 100644
--- a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/Order.columnOrder.txt
+++ b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/Order.columnOrder.txt
@@ -1,5 +1,5 @@
orderNum
#orderAmount
-orderDate
+#orderDate
orderStatus
nonsense
\ No newline at end of file
diff --git a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile_Test.java b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile_Test.java
index 6e833fdf4d..b28e1da8c0 100644
--- a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile_Test.java
+++ b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/services/tablecol/TableColumnOrderServiceUsingTxtFile_Test.java
@@ -40,6 +40,9 @@ class TableColumnOrderServiceUsingTxtFile_Test {
@Nested
class orderParented {
+ /**
+ * should read from Customer#orders.columnOrder.txt
+ */
@Test
void happy_case() {
// when
@@ -50,15 +53,29 @@ class TableColumnOrderServiceUsingTxtFile_Test {
assertThat(ordered).containsExactly("orderNum", "orderDate", "orderStatus");
}
+ /**
+ * should read from Order.columnOrder.txt
+ */
+ @Test
+ void fallback_file() {
+ // when
+ val ordered = service.orderParented(new Customer(), "previousOrders", Order.class,
+ Arrays.asList("orderNum", "orderStatus", "orderDate", "orderAmount")); // "orderDate" is not in the file being read
+
+ // then
+ assertThat(ordered).containsExactly("orderNum", "orderStatus");
+ }
+
@Test
void missing_file() {
// when
- val ordered = service.orderParented(new Customer(), "nonExistent", Order.class,
+ val ordered = service.orderParented(new Customer(), "nonExistent", Order2.class,
Arrays.asList("orderNum", "orderStatus", "orderDate", "orderAmount"));
// then
assertThat(ordered).isNull();
}
+
}
@Nested
@@ -71,7 +88,7 @@ class TableColumnOrderServiceUsingTxtFile_Test {
Arrays.asList("orderNum", "orderStatus", "orderDate", "orderAmount"));
// then
- assertThat(ordered).containsExactly("orderNum", "orderDate", "orderStatus");
+ assertThat(ordered).containsExactly("orderNum", "orderStatus");
}
@Test