[NAE-2409] Implement Plugin save/get file over gRPC for worker#433
[NAE-2409] Implement Plugin save/get file over gRPC for worker#433machacjozef merged 4 commits intorelease/7.0.0-rev10from
Conversation
- 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.
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (8)
WalkthroughThe PR removes the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
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.
There was a problem hiding this comment.
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 | 🟠 MajorPropagate file-read failures instead of returning
null.
WorkflowController#getFile(...)andActionApiImpl#getFile(...)both dereference this result immediately. Returningnullhere 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
📒 Files selected for processing (8)
application-engine/src/main/groovy/com/netgrif/application/engine/petrinet/domain/dataset/logic/action/ActionDelegate.groovyapplication-engine/src/main/java/com/netgrif/application/engine/actions/ActionApiImpl.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/service/DataService.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/service/interfaces/IDataService.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/web/WorkflowController.javanae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApi.javanae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/actions/ActionApiMethods.javanae-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.
|
@coderabbitai pls review the PR once more. |
|
✅ Actions performedFull review triggered. |
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
Checklist:
Summary by CodeRabbit
Release Notes
New Features
Improvements