[MGNLUI-3431] Replace usages of cloner in favor of less fragile solution Created: 18/May/15  Updated: 10/Aug/21  Resolved: 27/Jun/16

Status: Closed
Project: Magnolia UI
Component/s: configuration, content app
Affects Version/s: None
Fix Version/s: 5.4.8, 5.5

Type: Task Priority: Neutral
Reporter: Magnolia International Assignee: Federico Grilli
Resolution: Fixed Votes: 0
Labels: koiinos
Remaining Estimate: 0d
Time Spent: 2d
Original Estimate: Not Specified

Attachments: PNG File p13n.png    
Issue Links:
dependency
depends upon MAGNOLIA-6693 Introduce proxy-based mutable wrapper... Closed
is depended upon by MAGNOLIA-6654 Decorating the definition of an app w... Closed
is depended upon by MGNLPN-291 Preview app: get rid of Cloner and Co... Closed
supersession
supersedes MGNLUI-3755 Possible StackOverflow when Definitio... Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Date of First Response:
Sprint: Basel 50, Basel 50
Story Points: 5

 Description   

For MGNLUI-3428, we introduced info.magnolia.ui.contentapp.DefinitionCloner to workaround problems we found when cloning definitions.

Really though, those definitions should never have been cloned in the first place. The use-case is to slightly "customize" a given configured definition and reuse it in a slightly different context (e.g reuse a workbench config in a choose dialog)

Not only does this cause unnecessary complexity (e.g doesn't play well with proxies), it's also just really unnecessary and unportable. Many usages explicitly cast to the Configured* implementation of their definition, to be able to call setter methods. This will thus obviously never work with any other implementation of the interfaces.

Instead, we should introduce simple decorators for our definition interfaces. Let them delegate all getters to a delegatee. And in place of cloning, we could do something along these lines:

diff --git a/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java b/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java
index f24d597..0ec973c 100644
--- a/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java
+++ b/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java
@@ -222,13 +223,12 @@ public class MoveDialogPresenterImpl extends BaseDialogPresenter implements Move
     }
 
     private ContentPresenterDefinition prepareTreePresenter(ContentPresenterDefinition treePresenter) {
-        ContentPresenterDefinition def = cloner.deepClone(treePresenter);
-        if (!def.getColumns().isEmpty()) {
-            ColumnDefinition column = def.getColumns().get(0);
-            def.getColumns().clear();
-            def.getColumns().add(column);
-        }
-        return def;
+        return new ContentPresenterDefinitionDecorator(treePresenter) {
+            @Override
+            public List<ColumnDefinition> getColumns() {
+                return Collections.singletonList(delegate().getColums().get(0));
+            }
+        };
     }

(and of course using a non-anonymous class to do this would provide greater debuggability)

This goes hand-in-hand with tasks related to "use interfaces everywhere" and "builders for definitions".



 Comments   
Comment by Maxime Michel [ 21/Oct/16 ]

Added 5.4.10 fixVersion after Roman suggested it when I showed him the following missing keys I encountered. (seen in Personas, Traits, Cookie)

p13n.png

Comment by Roman Kovařík [ 21/Oct/16 ]

I changed that to 5.4.8 (which is the correct version according to the PR).

Generated at Mon Feb 12 09:06:32 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.