Skip to content

[NAE-2409] Implement Plugin save/get file over gRPC for worker#433

Merged
machacjozef merged 4 commits intorelease/7.0.0-rev10from
NAE-2409
Apr 21, 2026
Merged

[NAE-2409] Implement Plugin save/get file over gRPC for worker#433
machacjozef merged 4 commits intorelease/7.0.0-rev10from
NAE-2409

Conversation

@renczesstefan
Copy link
Copy Markdown
Member

@renczesstefan renczesstefan commented Apr 17, 2026

Description

Implements NAE-2409

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.

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

  • New Features

    • File management APIs now available: save single or batch files, delete files, retrieve files by case and field references
    • Direct file access through case-and-field identification for improved accessibility
    • Multiple file operation methods supporting both single and batch processing scenarios
  • Improvements

    • File retrieval mechanism simplified with reduced parameter requirements
    • Enhanced operational flexibility across file management operations

- Removed redundant task parameter from various file retrieval methods in `IDataService` and its implementations.
- Updated `ActionDelegate` to match refactored method signatures in `IDataService`.
- Added new file handling methods in `ActionApi` and their implementations in `ActionApiImpl`:
  - `saveFile`
  - `saveFiles`
  - `deleteFile`
  - `deleteFileByName`
  - `getFile`
  - `getFileByCaseAndName`
- Introduced `ActionFileHolder` class for better encapsulation of file metadata and content.
- Modified method signatures in `WorkflowController` to align with the updated service logic.

These changes improve consistency, adhere to clean code principles, and extend file management capabilities.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Warning

Rate limit exceeded

@renczesstefan has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 58 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 39 minutes and 58 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 067fea22-71e5-4343-a171-d3345f112cfd

📥 Commits

Reviewing files that changed from the base of the PR and between 374f8b9 and 8544ed9.

📒 Files selected for processing (8)
  • application-engine/src/main/groovy/com/netgrif/application/engine/petrinet/domain/dataset/logic/action/ActionDelegate.groovy
  • application-engine/src/main/java/com/netgrif/application/engine/actions/ActionApiImpl.java
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/service/DataService.java
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/service/interfaces/IDataService.java
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/web/WorkflowController.java
  • nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApi.java
  • nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApiMethods.java
  • nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionFileHolder.java

Walkthrough

The PR removes the Task parameter from file retrieval APIs across DataService and related call sites, simplifies method signatures by introducing case/field-keyed variants, and adds six new file management methods to the Action API (saveFile, saveFiles, deleteFile, deleteFileByName, getFile, getFileByCaseAndName), along with a supporting ActionFileHolder data transfer class.

Changes

Cohort / File(s) Summary
File Retrieval API Refactoring
application-engine/.../workflow/service/interfaces/IDataService.java, application-engine/.../workflow/service/DataService.java
Removed Task parameter from getFile(...) and getFileByCase(...) method signatures; added new string-identifier variant getFile(String caseId, String fieldId, boolean forPreview, Map params); updated delegation chains to use FileField directly instead of Task.
Call Site Updates
application-engine/.../petrinet/domain/dataset/logic/action/ActionDelegate.groovy, application-engine/.../workflow/web/WorkflowController.java
Updated method calls to use new DataService signatures without Task parameter; ActionDelegate and WorkflowController now pass only caseId, fieldId, and forPreview to file retrieval methods.
Action API Interface Extension
nae-spring-core-adapter/.../ActionApi.java
Added six new interface methods for file management: saveFile, saveFiles, deleteFile, deleteFileByName, getFile (with forPreview flag), and getFileByCaseAndName; two retrieval methods declare throws IOException.
Action API Implementation
application-engine/.../ActionApiImpl.java
Implemented six new file management methods; save methods convert ActionFileHolder to Spring MultipartFile via MockMultipartFile; delete methods delegate to DataService; retrieval methods delegate to DataService and reconstruct ActionFileHolder from returned stream using IOUtils.toByteArray.
Action API Method Registry
nae-spring-core-adapter/.../ActionApiMethods.java
Extended enum with six new constants: SAVE_FILE, SAVE_FILES, DELETE_FILE, DELETE_FILE_BY_NAME, GET_FILE, GET_FILE_BY_CASE_NAME for method name resolution.
Data Transfer Object
nae-spring-core-adapter/.../ActionFileHolder.java
New serializable class with fileName (String) and fileContent (byte[]) fields; uses Lombok @Data and @Builder for standard accessors and builder pattern.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

improvement, breaking change, Large

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main objective: implementing file save/get functionality over gRPC for worker plugins, which aligns with the substantial API additions and service refactoring throughout the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 improvement A change that improves on an existing feature breaking change Fix or feature that would cause existing functionality doesn't work as expected Large labels Apr 17, 2026
Integrated new debug and trace logging to monitor core API methods such as data retrieval, task and case management, and file operations. This enhances traceability and simplifies troubleshooting by capturing detailed runtime information for key API calls.
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: 3

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/java/com/netgrif/application/engine/workflow/service/DataService.java (1)

599-616: ⚠️ Potential issue | 🟠 Major

Propagate file-read failures instead of returning null.

WorkflowController#getFile(...) and ActionApiImpl#getFile(...) both dereference this result immediately. Returning null here turns storage/preview failures into NPEs or opaque transport errors instead of surfacing the real cause.

🛠️ Proposed fix
         try {
             if (forPreview) {
                 return getFilePreview(field, useCase);
             } else {
                 return new FileFieldInputStream(field, storageResolverService.resolve(field.getStorageType()).get(field, field.getValue().getPath()));
             }
         } catch (IOException | StorageException e) {
-            log.error("Getting file failed: ", e);
-            return null;
+            String message = "Getting file from field %s in case %s failed"
+                    .formatted(field.getStringId(), useCase.getStringId());
+            log.error(message, e);
+            throw new EventNotExecutableException(message, e);
         }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@application-engine/src/main/java/com/netgrif/application/engine/workflow/service/DataService.java`
around lines 599 - 616, The getFile method in DataService currently catches
IOException and StorageException and returns null which causes callers to NPE;
change getFile(Case,useCase,FileField,boolean,Map) to propagate these failures
instead of returning null by updating its throws clause to include IOException
and StorageException (in addition to FileNotFoundException) and remove the
try/catch or rethrow the caught exceptions (e.g. throw e) so that failures from
getFilePreview(...) and storageResolverService.resolve(...).get(...) bubble up
as their original exceptions; ensure callers (WorkflowController#getFile and
ActionApiImpl#getFile) continue to handle or declare these exceptions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@application-engine/src/main/java/com/netgrif/application/engine/actions/ActionApiImpl.java`:
- Around line 217-229: The MockMultipartFile is being constructed without
preserving the original filename so multipartFile.getOriginalFilename() returns
empty; update both saveFile (in ActionApiImpl.saveFile) and saveFiles
(ActionApiImpl.saveFiles) to construct MockMultipartFile with the
originalFilename parameter (e.g., use the MockMultipartFile constructor that
accepts name, originalFilename, contentType, content) and pass
file.getFileName() as originalFilename (and a sensible contentType or null),
ensuring each element in multipartFiles preserves its original filename before
calling dataService.saveFile(s).
- Around line 243-257: Both getFile(...) and getFileByCaseAndName(...) read an
InputStream from FileFieldInputStream via IOUtils.toByteArray(...) but never
close the stream; wrap the stream in a try-with-resources to ensure it is closed
after reading. In each method (getFile and getFileByCaseAndName) obtain the
FileFieldInputStream, then use try (InputStream in =
fileFieldInputStream.getInputStream()) { byte[] bytes = IOUtils.toByteArray(in);
return
ActionFileHolder.builder().fileName(fileFieldInputStream.getFileName()).fileContent(bytes).build();
} so the InputStream (or the FileFieldInputStream if it implements Closeable) is
always closed even on exceptions.

In
`@nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApiMethods.java`:
- Around line 27-28: The enum value GET_FILE_BY_CASE_NAME in ActionApiMethods is
registered with the wrong string ("getFileByCaseName"); update its registered
name to "getFileByCaseAndName" so lookups like
ActionApiMethods.fromMethodName("getFileByCaseAndName") will match the actual
method exposed by ActionApi/ActionApiImpl (getFileByCaseAndName(...)). Locate
the GET_FILE_BY_CASE_NAME enum constant and change its associated string to
"getFileByCaseAndName".

---

Outside diff comments:
In
`@application-engine/src/main/java/com/netgrif/application/engine/workflow/service/DataService.java`:
- Around line 599-616: The getFile method in DataService currently catches
IOException and StorageException and returns null which causes callers to NPE;
change getFile(Case,useCase,FileField,boolean,Map) to propagate these failures
instead of returning null by updating its throws clause to include IOException
and StorageException (in addition to FileNotFoundException) and remove the
try/catch or rethrow the caught exceptions (e.g. throw e) so that failures from
getFilePreview(...) and storageResolverService.resolve(...).get(...) bubble up
as their original exceptions; ensure callers (WorkflowController#getFile and
ActionApiImpl#getFile) continue to handle or declare these exceptions.
🪄 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: 16b05a35-cdc7-45d2-a412-d9c66664009c

📥 Commits

Reviewing files that changed from the base of the PR and between 374f8b9 and 49a7189.

📒 Files selected for processing (8)
  • application-engine/src/main/groovy/com/netgrif/application/engine/petrinet/domain/dataset/logic/action/ActionDelegate.groovy
  • application-engine/src/main/java/com/netgrif/application/engine/actions/ActionApiImpl.java
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/service/DataService.java
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/service/interfaces/IDataService.java
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/web/WorkflowController.java
  • nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApi.java
  • nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApiMethods.java
  • nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionFileHolder.java

Integrated new debug and trace logging to monitor core API methods such as data retrieval, task and case management, and file operations. This enhances traceability and simplifies troubleshooting by capturing detailed runtime information for key API calls.
Replaced direct InputStream usage with try-with-resources to ensure proper resource management and avoid potential memory leaks. Updated method signature and implementation to reflect accurate naming for file retrieval by case and name.
@renczesstefan
Copy link
Copy Markdown
Member Author

@coderabbitai pls review the PR once more.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

@renczesstefan Sure! I'll kick off a fresh review of the PR right away.

✅ Actions performed

Full review triggered.

@machacjozef machacjozef merged commit 5f885b8 into release/7.0.0-rev10 Apr 21, 2026
6 of 7 checks passed
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 improvement A change that improves on an existing feature Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants