Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor command class hierarchy to better support engine independent commands #6443

Open
steve-kasica opened this issue Mar 13, 2024 · 1 comment · May be fixed by #6452
Open

Refactor command class hierarchy to better support engine independent commands #6443

steve-kasica opened this issue Mar 13, 2024 · 1 comment · May be fixed by #6452
Labels
refactoring Status: Pending Review Indicates that the issue or pull request is awaiting review by project maintainers or collaborators Type: Feature Request Identifies requests for new features or enhancements. These involve proposing new improvements.

Comments

@steve-kasica
Copy link

steve-kasica commented Mar 13, 2024

When implementing an engine independent command (one that performs an abstract operation on all rows), you have to copy code that's already in EngineDependentCommand::doPost. Validating the CSRF token, getting the project, creating a process, and handling the response are necessary when writing a command that performs abstract operations on all rows, too.

It also seems counter intuitive to implement engine independent commands by extending Command directly because Command has two methods for working with engine configuration:,getEngineConfig() and getEngine().

Proposed solution

From discussion in #1855 and at the suggestion of @tfmorris, I'm wondering what folks think of refactoring the Command class hierarchy to facilitate the development of new commands and refactor existing engine independent commands for maintainability.

In my mind, I think it'd be nice to have three abstract classes:

  • Command
    • EngineDependentCommand
    • EngineIndependentCommand

Alternatives considered

  • Continue extending Command: It's not hugely annoying to extend Command and override doPost when writing an engine independent command because those useful methods are hoisted in the super class. But it still feels redundant.

  • Extend EngineDependentOperation and ignore engineConfig when overriding EngineDependentCommand::createOperation: This is actually what ReorderColumnsCommand does.

Additional context

As a newbie to OpenRefine's codebase, my initial instinct was just to extend the EngineDependentCommand when tinkering around with a command for adding rows to a project.

Among the core commands, these engine independent commands (in particular) basically copy EngineDependentCommand::doPost or extend EngineDependentCommand and ignore engine configuration:

@steve-kasica steve-kasica added Status: Pending Review Indicates that the issue or pull request is awaiting review by project maintainers or collaborators Type: Feature Request Identifies requests for new features or enhancements. These involve proposing new improvements. labels Mar 13, 2024
tfmorris added a commit to tfmorris/OpenRefine that referenced this issue Mar 14, 2024
tfmorris added a commit to tfmorris/OpenRefine that referenced this issue Mar 14, 2024
@tfmorris
Copy link
Member

There are a number of engine independent commands which aren't project related or which don't create Operations, which is really the main benefit to using EngineDependentCommand, so I've put up a draft PR which restructures the hierarchy to move most EngineDependentCommand functionality into a new OperationCommand.

@steve-kasica Please have a look and see if something along those lines would be helpful for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Status: Pending Review Indicates that the issue or pull request is awaiting review by project maintainers or collaborators Type: Feature Request Identifies requests for new features or enhancements. These involve proposing new improvements.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants