-
Notifications
You must be signed in to change notification settings - Fork 6
[NAE-2186] PetriNet objects gRPC serialization #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Refactored removeRoleOfDeletedPetriNet methods to simplify parameters and ensure usage of the default realm.
WalkthroughReplaced the two-parameter removeRoleOfDeletedPetriNet(PetriNet, Collection) API with two overloads: removeRoleOfDeletedPetriNet(PetriNet) and removeRoleOfDeletedPetriNet(Set). PetriNetService now calls the single-argument overload. UserServiceImpl now removes roles scoped to the default realm and pages users by role IDs. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Admin
participant PNService as PetriNetService
participant UserSvc as UserServiceImpl
participant UserRepo as UserRepository
Admin->>PNService: deletePetriNet(petriNetId)
PNService->>UserSvc: removeRoleOfDeletedPetriNet(petriNet)
rect rgb(245,250,255)
note right of UserSvc: operate on default realm only
UserSvc->>UserSvc: extract Set<ProcessRole> from PetriNet
loop per page (do-while)
UserSvc->>UserRepo: searchUsersByRoleIds(roleIds, realm=default, page)
UserRepo-->>UserSvc: Page<User>
alt users in page
UserSvc->>UserSvc: removeRoles(user, roleIds)
end
UserSvc->>UserSvc: pageable.next()
end
end
PNService-->>Admin: continue deletion flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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.
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)
nae-user-common/src/main/java/com/netgrif/application/engine/auth/service/UserService.java (1)
351-364: Fix Javadoc: method no longer operates on “specified realms”Docs still mention “specified realms” despite default-realm behavior and missing realm parameter. Update to avoid misleading API consumers.
- /** - * Removes roles associated with a deleted Petri net from users in specified realms. - * - * @param process the deleted Petri net - */ + /** + * Removes roles associated with the deleted Petri net from all users in the default realm. + * + * @param process the deleted Petri net + */ void removeRoleOfDeletedPetriNet(PetriNet process); - /** - * Removes roles associated with a deleted Petri net from users in specified realms. - * - * @param petriNetRoles roles of deleted Petri net - */ + /** + * Removes roles associated with the deleted Petri net from all users in the default realm. + * Prefer this overload in distributed/GRPC setups to minimize payload. + * + * @param petriNetRoles roles of the deleted Petri net + */ void removeRoleOfDeletedPetriNet(Set<ProcessRole> petriNetRoles);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
application-engine/src/main/java/com/netgrif/application/engine/petrinet/service/PetriNetService.java(1 hunks)nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java(2 hunks)nae-user-common/src/main/java/com/netgrif/application/engine/auth/service/UserService.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (2)
nae-user-common/src/main/java/com/netgrif/application/engine/auth/service/UserService.java (1)
19-19: LGTM: import for Set addedNeeded for the new overload.
nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java (1)
215-221: Null guard on realmIds is a safe improvementAvoids NPE when the caller passes null.
...on-engine/src/main/java/com/netgrif/application/engine/petrinet/service/PetriNetService.java
Show resolved
Hide resolved
nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java
Show resolved
Hide resolved
nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
- Extracted and reused role removal logic to simplify code structure. - Optimized user search and role removal process with improved iteration handling.
# Conflicts: # application-engine/src/main/java/com/netgrif/application/engine/petrinet/service/PetriNetService.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
application-engine/src/main/java/com/netgrif/application/engine/petrinet/service/PetriNetService.java (1)
541-541: Prefer roles-only overload to cut gRPC payload (NAE-2186).Pass only the roles to avoid serializing the whole PetriNet over gRPC.
- userService.removeRoleOfDeletedPetriNet(petriNet); + userService.removeRoleOfDeletedPetriNet(new HashSet<>(petriNet.getRoles().values()));nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java (1)
530-539: Paging bug: advancing pages while mutating results can skip users; loop page 0 until empty.After removals, later matches shift into page 0. Re-query page 0 until no users remain. Also short-circuit on null/empty roles.
@Override public void removeRoleOfDeletedPetriNet(Set<ProcessRole> petriNetRoles) { - String defaultRealmCollection = collectionNameProvider.getDefaultRealmCollection(); - Pageable pageable = PageRequest.of(0, paginationProperties.getBackendPageSize()); - Collection<ProcessResourceId> roleIds = petriNetRoles.stream().map(ProcessRole::get_id).collect(Collectors.toSet()); - Page<AbstractUser> users; - do { - users = searchUsersByRoleIds(roleIds, defaultRealmCollection, pageable); - users.getContent().forEach(u -> removeRoles(u, petriNetRoles)); - pageable = pageable.next(); - } while (users.hasNext()); + if (petriNetRoles == null || petriNetRoles.isEmpty()) { + return; + } + String collectionName = collectionNameProvider.getDefaultRealmCollection(); + Pageable page0 = PageRequest.of(0, paginationProperties.getBackendPageSize()); + Collection<ProcessResourceId> roleIds = + petriNetRoles.stream().map(ProcessRole::get_id).collect(Collectors.toSet()); + while (true) { + Page<AbstractUser> users = searchUsersByRoleIds(roleIds, collectionName, page0); + if (users.isEmpty()) { + break; + } + users.getContent().forEach(u -> removeRoles(u, petriNetRoles)); + } }Optional: implement a single repository-level updateMany with $pull for roleIds to avoid paging and per-user saves.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
application-engine/src/main/java/com/netgrif/application/engine/petrinet/service/PetriNetService.java(1 hunks)nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java(1 hunks)nae-user-common/src/main/java/com/netgrif/application/engine/auth/service/UserService.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Test
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
🔇 Additional comments (2)
nae-user-common/src/main/java/com/netgrif/application/engine/auth/service/UserService.java (1)
19-19: LGTM: Set import added for new API.nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/UserServiceImpl.java (1)
525-527: Delegation to Set-based overload is correct.
Description
Implements [NAE-2186]
Dependencies
None
Third party dependencies
None
Blocking Pull requests
None
How Has Been This Tested?
This was tested via Docker in cluster version
Test Configuration
Checklist:
Summary by CodeRabbit
Refactor
Bug Fixes