Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-6100

Make AbstractNodeBuilderTask more flexible

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Won't Do
    • Neutral
    • None
    • 5.3.7
    • updatemechanism
    • Yes

    Description

      Hi. Whenever I use this great class, I miss a feature that could easily be added with no harm.

      --> Make it possible to override the NodeOperations by a subclass.

      Just add a (protected?) getter for the operations field and use it in the doExecute method. Like this:

          @Override
          protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException {
              final Node root = getRootNode(ctx);
              final ErrorHandler errorHandler = newErrorHandler(ctx);
              final NodeBuilder nodeBuilder = new NodeBuilder(errorHandler, root, getOperations());
              try {
                  nodeBuilder.exec();
              } catch (NodeOperationException e) {
                  throw new TaskExecutionException(e.getMessage(), e);
              }
          }
      
          protected NodeOperation[] getOperations() {
              return operations;
          }
      

      This little change enables users to override the getter an build node operations with more complex logic if needed. The problem actually is, that in constructors you cannot use instance methods yet. So if you want to generate part of your NodeOperations in a nicely separated method, you have to make that method static and break the possibility to override it again.

      Example: https://git.magnolia-cms.com/gitweb/?p=forge/namics-mgnl-thymeleaf.git;a=blob;f=src/main/java/com/namics/mgnl/thymeleaf/setup/InstallThymeleafTemplateEngineConfigurationTask.java;h=edceef15d4a53a77dba947afec70ea4ce35d731f;hb=HEAD

      Cheers,
      Stefan

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              Unassigned Unassigned
              sbaur Stefan Baur
              Michael Rauch
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Task DoD

                  Time Tracking

                    Estimated:
                    Original Estimate - 5m
                    5m
                    Remaining:
                    Remaining Estimate - 5m
                    5m
                    Logged:
                    Time Spent - Not Specified
                    Not Specified