Skip to content

[NAE-2448] Migration for NAE v7 phase 2#451

Merged
machacjozef merged 6 commits into
release/7.0.0-rev10from
NAE-2448
Jun 16, 2026
Merged

[NAE-2448] Migration for NAE v7 phase 2#451
machacjozef merged 6 commits into
release/7.0.0-rev10from
NAE-2448

Conversation

@renczesstefan

@renczesstefan renczesstefan commented Jun 9, 2026

Copy link
Copy Markdown
Member

Description

Implements NAE-2448

Dependencies

No new dependencies were introduced.

Third party dependencies

No new dependencies were introduced.

Blocking Pull requests

Depends on #448

How Has Been This Tested?

This was tested manually and with unit tests.

Test Configuration

Name Tested on
OS macOS Tahoe 26.3
Runtime Java 21
Dependency Manager Maven 3.9.9n
Framework version Spring Boot 3.4.4
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @machacjozef
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved migration error handling so failures are captured and reported reliably without suppressing the originating exception.
    • Updated migration helper wiring so a default migration helper bean is provided only when one isn’t already defined, improving consistency in dependency injection.

Introduce `MigrationBeansConfiguration` and remove `@Component` annotation from `MigrationHelper`
@renczesstefan renczesstefan self-assigned this Jun 9, 2026
@renczesstefan renczesstefan added the new feature A change that introduces new functionality label Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@renczesstefan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 47 minutes and 22 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 70815ab5-dbf5-4c0b-9e04-6d5b4c47e63e

📥 Commits

Reviewing files that changed from the base of the PR and between 2013963 and e96643e.

📒 Files selected for processing (1)
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy

Walkthrough

MigrationHelper loses its @Component annotation; a new MigrationBeansConfiguration class registers it as a Spring bean guarded by @ConditionalOnMissingBean. Additionally, collectErrors(Closure) is corrected to return popErrors() after the try/finally block instead of inside finally, allowing exceptions from migrationCode to propagate.

Changes

MigrationHelper Bean Registration and collectErrors Fix

Layer / File(s) Summary
Remove @Component and add ConditionalOnMissingBean factory
application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy, application-engine/src/main/java/com/netgrif/application/engine/configuration/MigrationBeansConfiguration.java
@Component and its import are removed from MigrationHelper; expanded class-level Javadoc is added. A new MigrationBeansConfiguration class registers MigrationHelper via @Bean and @ConditionalOnMissingBean, allowing downstream projects to override the bean.
Fix collectErrors exception propagation
application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy
collectErrors(Closure) now returns popErrors() after the try/finally block instead of inside finally. Exceptions thrown by migrationCode.call() propagate to callers; caught Exception instances are logged with MigrationError metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • netgrif/application-engine#448: Directly introduces MigrationHelper and its collectErrors error-caching logic that this PR modifies—removing @Component and fixing the finally-return exception suppression behavior.

Suggested labels

breaking change

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title references ticket NAE-2448 and mentions 'Migration for NAE v7 phase 2', which aligns with the commit message and objectives but is vague about the specific implementation details. The changes involve refactoring MigrationHelper error handling and adding a new Spring configuration class, but the title does not clearly convey the primary technical change—it reads more as a ticket reference than a descriptive summary of what was implemented. Consider a more descriptive title such as 'Refactor MigrationHelper error handling and add MigrationBeansConfiguration' to better communicate the technical changes to reviewers scanning commit history.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added the Large label Jun 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/AbstractMigrationHelper.groovy`:
- Around line 193-195: Fix the malformed Javadoc on AbstractMigrationHelper by
removing the leading space and splitting the merged lines into a properly
formatted Javadoc description: start with /** on its own line, then each
sentence on its own line prefixed with " *", describing that the method iterates
documents, applies updates, executes bulk operations, supports pagination via
page size, allows custom bulk processing and optional sleep between pages;
ensure the closing " */" is on its own line and attach this comment to the
corresponding method in AbstractMigrationHelper.

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy`:
- Around line 340-361: Update the Javadoc to reference the correct parameter
name (toRemove) and guard the unsafe cast in removeChoices(Case useCase,
Map<String, List<String>> toRemove): before casting dataField.value to Set,
verify its type (e.g., instanceof Collection or Set) and only call removeAll on
it when safe; if the field holds a single String (enum) handle that case by
comparing/removing the value accordingly, and ensure you only call removeAll on
dataField.choices when dataField.choices != null as already done.
- Around line 368-381: The method changeFileFieldToFileList is casting
existingValue to FileFieldValue unsafely; update it to check the runtime type of
existingValue before adding to FileListFieldValue.namesPaths (e.g., use
instanceof or an explicit type check on existingValue) and only add when it's a
FileFieldValue, otherwise skip and optionally log a warning on dataField or
useCase to aid debugging; adjust handling in the block referencing
existingValue, FileFieldValue, FileListFieldValue, dataField and namesPaths so
no ClassCastException can occur during migration.
- Around line 443-455: The removeCase method validates MongoDB deletion but
doesn't handle failures from elasticCaseService.remove(useCase.getStringId());
wrap that call in a try-catch inside removeCase, catch Exception (or a more
specific exception if appropriate), log the error and call
handleMigrationError(errorPolicy, "removeCase", type, useCase.stringId, <error
message>) so Elasticsearch removal failures are reported using the same error
policy; ensure successful trace logging remains after the try block and return
or continue consistent with existing error handling.

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/PetriNetMigrationHelper.groovy`:
- Around line 5-15: PetriNetMigrationHelper.groovy references the unqualified
symbol VersionType (e.g. VersionType.MAJOR) but lacks its import; add the
missing import statement for
com.netgrif.application.engine.objects.petrinet.domain.VersionType to the top
import block so the Groovy compiler can resolve VersionType when used in
PetriNetMigrationHelper (search for the VersionType.MAJOR usage to verify).

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy`:
- Around line 235-242: The addRoleToExistingTasks method currently calls
updateTasks without forwarding the caller's error policy, causing it to always
use defaultErrorPolicy; change the call in addRoleToExistingTasks to accept and
pass an explicit ErrorPolicy argument (propagate the active policy from
MigrationHelper.withErrorPolicy) so updateTasks receives the caller's policy
instead of falling back to defaultErrorPolicy(); update the updateTasks
invocation signature usage in addRoleToExistingTasks to include the policy
parameter (and ensure MigrationHelper.withErrorPolicy callers pass their policy
through) while keeping the existing role/permissions closure unchanged.

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy`:
- Around line 600-606: collectErrors currently returns from the finally block
which swallows exceptions from migrationCode.call(); change the method to avoid
returning inside finally: call clearErrors(), declare a List<MigrationError>
variable (e.g. errors), invoke migrationCode.call() inside try, in finally
assign errors = popErrors(), and after the try/finally return errors so any
exception thrown by migrationCode.call() will propagate while still ensuring
popErrors() runs (refer to collectErrors, migrationCode.call, clearErrors,
popErrors).

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/model/MigrationError.groovy`:
- Around line 132-134: The getter getEntityType() currently declares return type
String but the field entityType is Class<?>; update the method signature to
"Class<?> getEntityType()" and return the entityType field unchanged so the
types match, i.e., change the return type to Class<?> in the getEntityType()
method (or if string semantics were intended, alternatively convert the field to
String and adjust any constructor/assignments to store a String instead).

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/model/MigrationErrorPolicy.groovy`:
- Around line 100-108: The factory method throwAfterLimit currently rejects
maxErrors <= 0 which contradicts setMaxErrors, the
MigrationProperties.ErrorPolicy javadoc and
AbstractMigrationHelper.finishMigrationErrorPolicy; update throwAfterLimit to
accept maxErrors == 0 (i.e., only reject negative values) so THROW_AFTER_LIMIT
with maxErrors == 0 is allowed and handled consistently, ensuring behavior
aligns with MigrationErrorHandlingMode.THROW_AFTER_LIMIT and the logic in
AbstractMigrationHelper.finishMigrationErrorPolicy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: aad25209-009a-4016-9393-71fbf79e87bb

📥 Commits

Reviewing files that changed from the base of the PR and between 39e1172 and 3b9c60e.

📒 Files selected for processing (17)
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/AbstractMigrationHelper.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/PetriNetMigrationHelper.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/model/MigrationError.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/model/MigrationErrorHandlingMode.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/model/MigrationErrorPolicy.groovy
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/throwable/MigrationErrorException.groovy
  • application-engine/src/main/java/com/netgrif/application/engine/configuration/MigrationBeansConfiguration.java
  • application-engine/src/main/java/com/netgrif/application/engine/configuration/properties/MigrationProperties.java
  • application-engine/src/main/java/com/netgrif/application/engine/utils/MongodbUtils.java
  • application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticSearchTest.groovy
  • application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticTaskTest.groovy
  • application-engine/src/test/groovy/com/netgrif/application/engine/migration/MigrationTest.groovy
  • application-engine/src/test/resources/petriNets/migration_test_v1.xml
  • application-engine/src/test/resources/petriNets/migration_test_v2.xml
💤 Files with no reviewable changes (2)
  • application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticTaskTest.groovy
  • application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticSearchTest.groovy

Retoocs
Retoocs previously approved these changes Jun 15, 2026
@dpulls

dpulls Bot commented Jun 16, 2026

Copy link
Copy Markdown

🎉 All dependencies have been resolved !

@renczesstefan renczesstefan dismissed Retoocs’s stale review June 16, 2026 10:49

The merge-base changed after approval.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 16, 2026
@renczesstefan renczesstefan requested a review from Retoocs June 16, 2026 10:53
@coderabbitai coderabbitai Bot added improvement A change that improves on an existing feature Extra Small labels Jun 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy (1)

600-606: ⚠️ Potential issue | 🔴 Critical

Pop the error cache inside finally, not after it.

If migrationCode.call() throws, execution never reaches line 606, so errors collected before the failure remain cached in the sub-helpers (caseMigrationHelper, taskMigrationHelper, petriNetMigrationHelper) and can pollute later getErrors() / hasErrors() reads. Store the popped errors in finally to ensure cleanup always occurs; the exception still propagates after the finally block executes.

Proposed fix
 List<MigrationError> collectErrors(Closure migrationCode) {
     clearErrors()
+    List<MigrationError> errors = []
     try {
         migrationCode.call()
     } finally {
+        errors = popErrors()
     }
-    return popErrors()
+    return errors
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy`
around lines 600 - 606, The `collectErrors` method currently calls `popErrors()`
after the finally block, which means if `migrationCode.call()` throws an
exception, the error cache is never cleared and errors remain in the sub-helpers
(caseMigrationHelper, taskMigrationHelper, petriNetMigrationHelper), polluting
subsequent calls. Move the error cache cleanup into the finally block by storing
the result of `popErrors()` inside the finally block and then returning it after
the finally block completes. This ensures the error cache is always cleared
regardless of whether an exception is thrown, while still allowing any exception
to propagate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy`:
- Around line 600-606: The `collectErrors` method currently calls `popErrors()`
after the finally block, which means if `migrationCode.call()` throws an
exception, the error cache is never cleared and errors remain in the sub-helpers
(caseMigrationHelper, taskMigrationHelper, petriNetMigrationHelper), polluting
subsequent calls. Move the error cache cleanup into the finally block by storing
the result of `popErrors()` inside the finally block and then returning it after
the finally block completes. This ensures the error cache is always cleared
regardless of whether an exception is thrown, while still allowing any exception
to propagate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e74a5d6f-e0fe-4fcb-a1e1-5e146a5c2bbe

📥 Commits

Reviewing files that changed from the base of the PR and between 3b9c60e and 83c1fa2.

📒 Files selected for processing (1)
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy

machacjozef
machacjozef previously approved these changes Jun 16, 2026
…ng exceptions, logging them, and including in the result
@coderabbitai coderabbitai Bot added the breaking change Fix or feature that would cause existing functionality doesn't work as expected label Jun 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy`:
- Around line 596-600: The Javadoc tags in the method comment are malformed—they
use backticks within braces (e.g., {`@code`, {`@link`) which won't render
correctly in generated documentation. Replace these with proper Javadoc syntax
using `@code`{...} and `@link`{...} respectively. Additionally, the documentation
claims "this method never throws" which is inaccurate since only Exception is
caught, not JVM Errors or failures in finally block cleanup. Update this
statement to accurately reflect that only Exception instances are caught and
included in the returned error list, while other exceptions and errors may still
propagate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5fec5c80-4c82-40f2-b1d3-556bb8270013

📥 Commits

Reviewing files that changed from the base of the PR and between 83c1fa2 and 2013963.

📒 Files selected for processing (1)
  • application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy

machacjozef
machacjozef previously approved these changes Jun 16, 2026
Retoocs
Retoocs previously approved these changes Jun 16, 2026
…on exception handling and parameter annotations
@machacjozef machacjozef merged commit 35299b7 into release/7.0.0-rev10 Jun 16, 2026
6 of 7 checks passed
@machacjozef machacjozef deleted the NAE-2448 branch June 16, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Fix or feature that would cause existing functionality doesn't work as expected Extra Small improvement A change that improves on an existing feature Large new feature A change that introduces new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants