Skip to content

[NAE-2446] Migration for NAE v7 phase 1#448

Open
renczesstefan wants to merge 6 commits into
release/7.0.0-rev10from
NAE-2446
Open

[NAE-2446] Migration for NAE v7 phase 1#448
renczesstefan wants to merge 6 commits into
release/7.0.0-rev10from
NAE-2446

Conversation

@renczesstefan
Copy link
Copy Markdown
Member

@renczesstefan renczesstefan commented Jun 3, 2026

Description

Implements NAE-2446

Dependencies

No new dependencies were introduced

Third party dependencies

  • No new dependencies were introduced

Blocking Pull requests

There are no dependencies on other PR

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

New Features

  • Added a comprehensive migration system enabling bulk updates to cases, tasks, and workflow models with support for pagination and cursor-based operations.
  • Introduced configurable data field transformations (e.g., field type conversions, choice additions/removals, file field migrations).
  • Added role management and permission synchronization capabilities for workflow models and existing tasks.
  • Implemented flexible error handling policies (continue on error, throw immediately, throw after limit, or throw after completion) with error collection and reporting.
  • Added Elasticsearch indexing integration for migrated cases and tasks.

Added comprehensive test cases for the `nae_2432` process migration. Introduced `MigrationHelper` to facilitate data field addition, transition updates, and error handling during migrations. Created `MigrationError` to encapsulate migration failure states with detailed metadata. Updated PetriNet versions from v1.0 to v2.0 and verified seamless case migration, role updates, and task modifications.
Update migration tests: rename PetriNet files and identifiers from `nae_2432` to `migration_test`
Remove unused `webEnvironment` property from Elastic test annotations
- Add support for case removal synchronized between MongoDB and Elasticsearch in `MigrationHelper` and `CaseMigrationHelper`.
- Introduce `updateCasesCursor` for ObjectId-based case updates.
- Refactor and streamline `migratePetriNet` logic to update case IDs.
- Implement MongoDB bulk operations with upsert using `FindAndReplaceOptions`.
- Update migration tests with constants, improved assertions, and enhanced logic.
@renczesstefan renczesstefan self-assigned this Jun 3, 2026
@renczesstefan renczesstefan added the improvement A change that improves on an existing feature label Jun 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Walkthrough

This PR introduces a comprehensive MongoDB migration framework for bulk document operations on Cases, Tasks, and Petri Nets. It includes configurable error handling policies, QueryDSL predicate support, pagination with cursor streaming, and Elasticsearch integration for case/task indexing. The framework provides a public facade (MigrationHelper) that orchestrates specialized helpers while managing thread-local error policies and centralizing error caching across subsystems.

Changes

Migration System Implementation

Layer / File(s) Summary
Error handling model and configuration
application-engine/src/main/groovy/com/netgrif/application/engine/migration/model/MigrationError*.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/properties/MigrationProperties.java
MigrationError model captures error details with timestamp and cause; MigrationErrorHandlingMode enum defines four strategies (THROW_IMMEDIATELY, CONTINUE, THROW_AFTER_LIMIT, THROW_AFTER_PROCESSING); MigrationErrorPolicy encapsulates configuration with factory methods; MigrationErrorException wraps immutable error lists; MigrationProperties binds configuration for cases/tasks/petri nets with nested page size and error policy settings.
MongoDB QueryDSL integration
application-engine/src/main/java/com/netgrif/application/engine/utils/MongodbUtils.java
Utility converts QueryDSL Predicate instances to Spring MongoDB Query objects via SpringDataMongodbQuery.
Abstract bulk migration infrastructure
application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/AbstractMigrationHelper.groovy
Generic AbstractMigrationHelper<T> handles pagination, document streaming from MongoDB cursor, bulk operation batching, error caching, and policy-driven exception routing; subclasses implement page size, operation preparation, and entity ID resolution.
Case migration with Elasticsearch indexing
application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy
CaseMigrationHelper extends abstract base for Case documents with filtering/iteration/cursor-based updates, Elasticsearch indexing with retry logic when lastModified is missing, and static utilities for dataset transformations (field deletion, value conversion, choice updates, file-field conversion), permission synchronization from Petri nets, case removal, and net migration.
Petri Net migration with role remapping
application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/PetriNetMigrationHelper.groovy
PetriNetMigrationHelper extends abstract base for PetriNet documents with model re-import from resources, role/permission remapping using importId while preserving existing role references, dataset sorting, transition role permission updates, role creation (per-net and global), role event synchronization, and utilities for extracting dataset component maps.
Task migration with permission updates
application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy
TaskMigrationHelper extends abstract base for Task documents with predicate-based and process-specific cursor queries (optionally filtered by transition IDs), task reloading, Elasticsearch indexing with error handling, bulk role additions, and permission updates synchronized from Petri net transitions.
Public migration facade with thread-local policy management
application-engine/src/main/groovy/com/netgrif/application/engine/migration/MigrationHelper.groovy
MigrationHelper Spring component orchestrates all three specialized helpers via delegation, manages active error policy per thread via currentErrorPolicy ThreadLocal with withErrorPolicy(...), and provides centralized error access (getErrors, popErrors, clearErrors, hasErrors, collectErrors). Delegates case/task/net migrations while passing active policy; includes static/instance wrappers for dataset transforms and component operations.
Integration tests and Petri net fixtures
application-engine/src/test/groovy/com/netgrif/application/engine/migration/MigrationTest.groovy, application-engine/src/test/resources/petriNets/migration_test_v*.xml
MigrationTest validates end-to-end migrations of cases from v1 to v2, net updates with role remapping, task role additions, and error policies (throwImmediately, throwAfterLimit, throwAfterProcessing, continueOnError); XML fixtures define two Petri net versions with transitions, places, data fields, and roles for migration scenarios.
Test configuration cleanup
application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticSearchTest.groovy, application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticTaskTest.groovy
Removed redundant webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT annotation parameters.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

Large

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 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.
Title check ✅ Passed The title clearly and specifically identifies the main change: implementing migration support for NAE v7 phase 1, referenced by ticket NAE-2446.

✏️ 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 3, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🤖 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 53-58: Update the field Javadoc for migrationErrors in
AbstractMigrationHelper to reflect that it is a List<MigrationError> (not a
map): describe that migrationErrors is a collection holding MigrationError
entries encountered during migration, each representing an individual migration
failure; remove references to keys, string identifiers, and lists-per-key, and
adjust any thread-safety wording to match the actual implementation (e.g., note
whether the list is synchronized or not) so the comment accurately matches the
migrationErrors field.
- Around line 192-194: The Javadoc block in AbstractMigrationHelper is malformed
because the first line of the comment lacks the leading "*" and runs into the
next line; update the Javadoc for the method (the comment starting at the block
above the iterator/bulk-operation method in class AbstractMigrationHelper) by
adding the missing "*" at the start of the first line so each line begins with
"*" and the comment renders correctly as a standard Javadoc block.
- Around line 226-266: The outer catch in the iterate loop is re-invoking
handleMigrationError for exceptions that have already been routed (and possibly
re-thrown) by prepareOperations or effectiveProcessOperations, which causes
double-handling and masks original errors; modify the catch block around the
cursor iteration so it checks for MigrationErrorException (or a marker that
handleMigrationError already threw) and rethrows it immediately without calling
handleMigrationError again, and only call handleMigrationError for other
unexpected exceptions (so keep references to prepareOperations,
effectiveProcessOperations, handleMigrationError, MigrationErrorException and
finishMigrationErrorPolicy to locate the logic).
- Around line 317-321: The THROW_AFTER_LIMIT branch incorrectly throws
immediately when policy.maxErrors == 0 and bypasses throwOriginal; change the
logic in the MigrationErrorHandlingMode.THROW_AFTER_LIMIT case to first treat
maxErrors==0 as "no limit" (i.e. only apply the limit when policy.maxErrors > 0)
and when the limit is reached call the central throwError(...) path instead of
directly throwing new MigrationErrorException so throwOriginal and cacheErrors
behavior are honored; specifically update the condition around
getErrors().size() and policy.maxErrors to require policy.maxErrors > 0 and
route handling through throwError(...) (respecting cacheErrors and existing
error caching) rather than constructing/throwing MigrationErrorException inline.

In
`@application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy`:
- Around line 448-450: The error logging and error handler call in removeCase
are mislabelled: update the message string and the handleMigrationError
operation parameter to reference "removeCase" (or "removeCase: delete case"
phrasing) instead of "migratePetriNet"; specifically modify the local variable
message and the handleMigrationError(errorPolicy, "migratePetriNet", type,
useCase.stringId, message) invocation in the removeCase method so both
accurately reflect removeCase while keeping errorPolicy, type and
useCase.stringId unchanged.

In
`@application-engine/src/main/java/com/netgrif/application/engine/configuration/properties/MigrationProperties.java`:
- Around line 143-147: The docs say maxErrors == 0 means "no limit" but the
handler throws immediately because it checks getErrors().size() >=
policy.maxErrors; update AbstractMigrationHelper.handleMigrationError to treat 0
as unlimited by changing the throw condition to only apply when policy.maxErrors
> 0 (e.g., require policy.maxErrors > 0 && getErrors().size() >=
policy.maxErrors), keeping existing behavior for positive limits and preserving
references to getErrors(), policy.maxErrors, and the THROW_AFTER_LIMIT policy.

In
`@application-engine/src/main/java/com/netgrif/application/engine/utils/MongodbUtils.java`:
- Around line 9-15: MongodbUtils currently exposes only the static method
toQuery but is instantiable; make the intent explicit by adding a private
constructor to MongodbUtils (e.g., private MongodbUtils() { throw new
AssertionError("No instances."); } or simply private MongodbUtils() {} ) so
callers cannot instantiate the class; update class MongodbUtils to include this
private constructor while leaving the static toQuery(MongoTemplate, Class<T>,
Predicate...) unchanged.

In
`@application-engine/src/test/groovy/com/netgrif/application/engine/migration/MigrationTest.groovy`:
- Around line 69-104: The beforeEach setup resets the DBs but not the
centralized migration error cache, causing flaky tests; add a call to clear the
error cache (e.g., migrationHelper.clearErrors() or the appropriate
clearErrors() method on the migration helper) immediately after
testHelper.truncateDbs() inside the beforeEach method so the shared error state
is reset before importing nets and creating cases, ensuring
migrationHelper.hasErrors() checks in other tests are not impacted by prior
runs.
🪄 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: 4ceca0d7-f7c3-4af9-9ed4-eec4c19742fd

📥 Commits

Reviewing files that changed from the base of the PR and between 837a70b and 4bca04f.

📒 Files selected for processing (16)
  • 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/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/ElasticSearchTest.groovy
  • application-engine/src/test/groovy/com/netgrif/application/engine/elastic/ElasticTaskTest.groovy

- Update error handling logic in `CaseMigrationHelper` and `AbstractMigrationHelper`, including better handling of migration limits and error policies.
- Replace error map with a thread-safe `CopyOnWriteArrayList` in migration processes.
- Add safeguards for `MigrationErrorException` handling.
- Make `MongodbUtils` a utility class with a private constructor to prevent instantiation.
- Enhance migration tests with error clearing before execution.
@renczesstefan renczesstefan changed the title [NAE-2446] Migration for NAE v7 [NAE-2446] Migration for NAE v7 phase 1 Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement A change that improves on an existing feature Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant