[MAGNOLIA-6100] Make AbstractNodeBuilderTask more flexible Created: 27/Feb/15  Updated: 19/May/22  Resolved: 19/May/22

Status: Closed
Project: Magnolia
Component/s: updatemechanism
Affects Version/s: 5.3.7
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Stefan Baur Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: quickwin
Remaining Estimate: 5m
Time Spent: Not Specified
Original Estimate: 5m

Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Visible to:
Michael Rauch

 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



 Comments   
Comment by Stefan Baur [ 27/Feb/15 ]

HINT: This functionality could also go in a base class that has no constructor with operations but an abstract protected method. The current AbstractNodeBuilderTask could then implement that base class using the ctor arguments value.

Comment by Roman Kovařík [ 19/May/22 ]

Hello,

This ticket is now marked as closed due to one of the following reasons:

  • A long period of inactivity
  • Uses an old or Beta version of an application, module, or framework that we no longer support
  • The issue is no longer reproducible or has been fixed in later versions

If you are still facing a problem or consider this issue still relevant, please feel free to re-open the ticket and we will reach out to you.

Thank you,
The Magnolia Team

Generated at Mon Feb 12 04:11:18 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.