Uploaded image for project: 'Magnolia UI'
  1. Magnolia UI
  2. MGNLUI-3431

Replace usages of cloner in favor of less fragile solution

    XMLWordPrintable

Details

    • Basel 50, Basel 50
    • 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".

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                fgrilli Federico Grilli
                gjoseph Magnolia International
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Task DoR

                    Time Tracking

                      Estimated:
                      Original Estimate - Not Specified
                      Not Specified
                      Remaining:
                      Remaining Estimate - 0d
                      0d
                      Logged:
                      Time Spent - 2d
                      2d