[NAE-2442] Fix dataset update from database and action handling#444
[NAE-2442] Fix dataset update from database and action handling#444renczesstefan wants to merge 2 commits into
Conversation
Introduced `updateCaseFromDb` in `IWorkflowService` and its implementation in `WorkflowService` to synchronize case data with the database. Updated `EventService` to invoke this method during action execution.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughAdds updateCaseFromDb to refresh an in-memory Case from the persisted Case and integrates that refresh into EventService run paths; also widens ActionApi.setData and ActionApiImpl.setData parameter types to accept non-string values (Map<String, Object>). ChangesCase state refresh before action execution
Action API setData type widening
Sequence DiagramsequenceDiagram
participant EventService
participant WorkflowService
participant Repository
EventService->>WorkflowService: updateCaseFromDb(useCase)
WorkflowService->>Repository: find case by ID
Repository-->>WorkflowService: persisted case
WorkflowService->>WorkflowService: merge newer dataset fields
WorkflowService-->>EventService: refresh complete
EventService->>EventService: execute actions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/java/com/netgrif/application/engine/workflow/service/EventService.java`:
- Around line 54-56: The refresh (updateCaseFromDb) is being called after
actionsRunner.run(...), causing actions to run against stale state; move the
call to workflowService.updateCaseFromDb(useCase) to immediately before each
actionsRunner.run(...) invocation within EventService so the case is reloaded
from the DB prior to executing actions (apply the same change at the other
occurrence referenced around the second actionsRunner.run(...) block as well).
In
`@application-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowService.java`:
- Around line 255-263: updateCaseFromDb currently assigns persisted DataField
objects from findOneNoNet directly into the runtime Case, which can mix
encrypted persisted fields into in-memory state; instead, when a persisted
DataField (from actual.getDataSet()) is newer than the corresponding runtime
field, copy only the safe primitive/value and metadata into the existing runtime
DataField (do not replace the object reference). In practice: in
updateCaseFromDb, for each id where
dataField.isNewerThen(useCase.getDataField(id)), obtain the target DataField =
useCase.getDataField(id) (or create a new non-persisted instance) and call its
setters to copy value, plainValue/decodedValue, timestamp, and other
non-persistence-specific metadata from dataField, rather than doing
useCase.getDataSet().put(id, dataField); this preserves in-memory
decryption/representation and avoids injecting persisted/encrypted objects
returned by findOneNoNet.
🪄 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: 72387161-fb2d-4021-8388-5c4ed913dee0
📒 Files selected for processing (3)
application-engine/src/main/java/com/netgrif/application/engine/workflow/service/EventService.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowService.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/service/interfaces/IWorkflowService.java
Refactored `setData` method in `ActionApi` to use `Map<String, Map<String, Object>>` for flexible data handling. Adjusted `WorkflowService` to use the `findOne` method for better database case update synchronization.
|
@coderabbitai pls review once more and approve if it is OK |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Get the PR diff
gh pr diff 444 --repo netgrif/application-engineLength of output: 5982 🏁 Script executed: #!/bin/bash
# Look at the changed files
fd -e java -t f | xargs grep -l "updateCaseFromDb\|setData" 2>/dev/null | head -20Length of output: 2289 🏁 Script executed: #!/bin/bash
# Check isNewerThen method on DataField
rg -n "isNewerThen" --type java -C 5
# Check findOne implementation
rg -n "findOne" application-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowService.java -A 5
# Check getDataField for null safety
rg -n "getDataField" --type java -C 3 | head -60
# Check callers of setData with old/new signature
rg -n "setData" --type java -C 2 | grep -v "\.class\|//\|\.xml" | head -60Length of output: 24185
Review Summary1.
2.
3.
The changes correctly fix the data-loss issue caused by stale in-memory state during multi-action execution. No blocking issues found. [approve] |
Description
Fixes NAE-2442
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
Checklist:
Summary by CodeRabbit
Bug Fixes
New Features