Skip to content

[RHCLOUD-46428] Filter drawer entries from event log and behavior group apis#4280

Open
g-duval wants to merge 6 commits intoRedHatInsights:masterfrom
g-duval:RHCLOUD-46428_hideDrawerFromBackend
Open

[RHCLOUD-46428] Filter drawer entries from event log and behavior group apis#4280
g-duval wants to merge 6 commits intoRedHatInsights:masterfrom
g-duval:RHCLOUD-46428_hideDrawerFromBackend

Conversation

@g-duval
Copy link
Copy Markdown
Contributor

@g-duval g-duval commented Mar 31, 2026

We want to controle Drawer endpoint visibility from backend event if some integrations/System behavior groups/ notifications history exists.

Summary by CodeRabbit

  • New Features

    • Added an org-level option to exclude a specific endpoint type from behavior groups and from event action history; changes affect which actions are shown in group listings and event details.
  • Tests

    • Expanded tests to cover action-filtering behavior across different configuration states and query modes.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

SC Environment Impact Assessment

Overall Impact: 🟢 LOW

View full report

Summary

  • Total Issues: 1
  • 🟢 Low: 1

Detailed Findings

🟢 LOW Impact

Feature flag change detected

  • File: backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java
  • Category: feature_flags
  • Details:
    • Found unleash in backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java at line 327
    • Found unleash in backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java at line 328
    • Found Unleash in backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java at line 328
  • Recommendation: Verify feature flags are properly configured for SC Environment. Test bypass options for services not available in SC Environment.

Required Actions

  • Review all findings above
  • Verify SC Environment compatibility for all detected changes
  • Update deployment documentation if needed
  • Coordinate with ROSA Core team or deployment timeline

This assessment was automatically generated. Please review carefully and consult with the ROSA Core team for critical/high impact changes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a feature-flagged branch to behavior-group queries and conditional filtering of drawer-type endpoints: repository queries may fetch endpoints and prune DRAWER actions based on a new Unleash toggle; event mapping also omits DRAWER history entries unless drawer is enabled. Tests and BackendConfig were updated.

Changes

Cohort / File(s) Summary
Repository Logic
backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
Query now branches on backendConfig.isUseDrawerFilteredQuery(orgId) (drawer-filtered branch uses LEFT JOIN FETCH a.endpoint e). When isDrawerEnabled(orgId) is false the returned BehaviorGroup.actions list is pruned to remove entries with EndpointType.DRAWER. behaviorGroup.filterOutBundle() still applied.
Resource Logic
backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java
When includeActions is true, history entries with EndpointType.DRAWER are excluded unless backendConfig.isDrawerEnabled(orgId) returns true; mapping to EventLogEntryAction otherwise unchanged.
Repository Tests
backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java
Added updateAndFetchBehaviorGroupActions(...), refactored helpers to return fetched actions, made findBehaviorGroupActions(...) return empty list when no group, and extended testAddMultipleDrawerSubscriptionBehaviorGroupActions to assert behavior with isUseDrawerFilteredQuery and isDrawerEnabled toggles.
Resource Tests
backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java
Split testAllQueryParams into drawer-disabled and drawer-enabled scenarios and adjusted assertions (ordering, payload nulls, pagination links, action sets); stubbed backendConfig.isDrawerEnabled(DEFAULT_ORG_ID) in testEventsWithKesselCriterion.
Configuration
backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java
Registered new Unleash toggle remove-drawer-endpoint-from-behavior-group, added useDrawerFilteredQuery field and public accessor isUseDrawerFilteredQuery(String orgId) which evaluates the toggle using an orgId Unleash context when Unleash is enabled.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant EventResource
participant BackendConfig
participant BehaviorGroupRepo
participant Database

Client->>EventResource: GET events (includeActions=true)
EventResource->>BackendConfig: isDrawerEnabled(orgId)?
BackendConfig-->>EventResource: true/false
EventResource->>BehaviorGroupRepo: findByBundleId(bundleId, orgId)
BehaviorGroupRepo->>BackendConfig: isUseDrawerFilteredQuery(orgId)?
BackendConfig-->>BehaviorGroupRepo: true/false
alt use drawer-filtered query
    BehaviorGroupRepo->>Database: JPQL with LEFT JOIN FETCH a.endpoint
    Database-->>BehaviorGroupRepo: BehaviorGroups w/ endpoints
    BehaviorGroupRepo->>BackendConfig: isDrawerEnabled(orgId)?
    BackendConfig-->>BehaviorGroupRepo: true/false
    alt drawer disabled
        BehaviorGroupRepo->>BehaviorGroupRepo: prune actions with EndpointType.DRAWER
    end
else non-filtered query
    BehaviorGroupRepo->>Database: previous JPQL (no endpoint fetch)
    Database-->>BehaviorGroupRepo: BehaviorGroups
end
BehaviorGroupRepo-->>EventResource: BehaviorGroups (filtered as needed)
EventResource-->>Client: Events with actions (drawer entries excluded if disabled)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

"I hopped through toggles, nibbling bits of code,
pruned drawer hops from lists where they strode.
A twitch, a hop, tests check both tracks,
toggle on or off — I tidy up the stacks. 🐇"

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: filtering drawer entries from event log and behavior group APIs, which aligns with the core modifications across BehaviorGroupRepository, EventResource, and their tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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: 1

🧹 Nitpick comments (1)
backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java (1)

255-270: Note: Mock state persists for remaining tests in the method.

The when(backendConfig.isDrawerEnabled()).thenReturn(true) at line 255 persists for all subsequent tests (#2 through #36) within testAllQueryParams. This appears intentional since later tests (e.g., Test #4, #5, etc.) assert on drawer actions like history6 and history7.

However, consider adding a comment clarifying this is intentional behavior, or reset the mock at the end for clarity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java`
around lines 255 - 270, The mock setting
when(backendConfig.isDrawerEnabled()).thenReturn(true) in testAllQueryParams
currently persists for subsequent tests; either add a clear inline comment next
to that line stating the persistence is intentional for tests `#2`–#36, or
explicitly reset/restore the mock after the block (e.g.,
Mockito.reset(backendConfig) or
when(backendConfig.isDrawerEnabled()).thenReturn(false)) so later assertions
remain unambiguous; reference the test method testAllQueryParams and the
backendConfig.isDrawerEnabled() mock when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java`:
- Around line 815-824: The helper updateAndFetchBehaviorGroupActions currently
performs the update again, causing duplicate calls; change it to only fetch
actions (remove the call to behaviorGroupRepository.updateBehaviorGroupActions
from updateAndFetchBehaviorGroupActions) so updateAndCheckBehaviorGroupActions
remains the single place that calls
behaviorGroupRepository.updateBehaviorGroupActions, and ensure the helper only
queries and returns the List<BehaviorGroupAction> (keeping entityManager.clear()
before the fetch if needed); update any references or rename the helper to
reflect it is a fetch-only method.

---

Nitpick comments:
In
`@backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java`:
- Around line 255-270: The mock setting
when(backendConfig.isDrawerEnabled()).thenReturn(true) in testAllQueryParams
currently persists for subsequent tests; either add a clear inline comment next
to that line stating the persistence is intentional for tests `#2`–#36, or
explicitly reset/restore the mock after the block (e.g.,
Mockito.reset(backendConfig) or
when(backendConfig.isDrawerEnabled()).thenReturn(false)) so later assertions
remain unambiguous; reference the test method testAllQueryParams and the
backendConfig.isDrawerEnabled() mock when making the change.
🪄 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: CHILL

Plan: Pro

Run ID: 01a4759f-54c9-4c48-8b24-c207f28a2264

📥 Commits

Reviewing files that changed from the base of the PR and between 9e78043 and b779c3a.

📒 Files selected for processing (4)
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
  • backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java
  • backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java
  • backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java

@g-duval g-duval force-pushed the RHCLOUD-46428_hideDrawerFromBackend branch from b779c3a to d7165e5 Compare March 31, 2026 12:55
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java (1)

160-175: Filter logic is correct; consider hoisting config check outside the stream.

The filter condition correctly excludes DRAWER entries when the feature is disabled. However, backendConfig.isDrawerEnabled() is evaluated on every history entry despite being invariant within the request. For readability and minor efficiency, consider evaluating it once before the stream.

♻️ Suggested refactor
             } else {
+                boolean drawerEnabled = backendConfig.isDrawerEnabled();
                 actions = event.getHistoryEntries().stream()
-                    .filter(notificationHistory -> EndpointType.DRAWER != notificationHistory.getEndpointType() || backendConfig.isDrawerEnabled())
+                    .filter(notificationHistory -> EndpointType.DRAWER != notificationHistory.getEndpointType() || drawerEnabled)
                     .map(historyEntry -> {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java`
around lines 160 - 175, The stream filter is calling
backendConfig.isDrawerEnabled() for every history entry; hoist that invariant
out of the stream by evaluating boolean drawerEnabled =
backendConfig.isDrawerEnabled() before mapping event.getHistoryEntries() and
then use EndpointType.DRAWER != notificationHistory.getEndpointType() ||
drawerEnabled in the filter so the logic (in EventResource, actions
construction) remains the same but avoids repeated calls for each historyEntry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java`:
- Around line 160-175: The stream filter is calling
backendConfig.isDrawerEnabled() for every history entry; hoist that invariant
out of the stream by evaluating boolean drawerEnabled =
backendConfig.isDrawerEnabled() before mapping event.getHistoryEntries() and
then use EndpointType.DRAWER != notificationHistory.getEndpointType() ||
drawerEnabled in the filter so the logic (in EventResource, actions
construction) remains the same but avoids repeated calls for each historyEntry.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a1b27b0d-16b4-4bb0-9915-6bf12351f635

📥 Commits

Reviewing files that changed from the base of the PR and between b779c3a and d7165e5.

📒 Files selected for processing (4)
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
  • backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java
  • backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java
  • backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java
✅ Files skipped from review due to trivial changes (1)
  • backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
  • backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java

@gwenneg gwenneg self-assigned this Apr 2, 2026
Comment on lines +184 to +189
behaviorGroup.setActions(
behaviorGroup.getActions().stream()
.filter(action -> action.getEndpoint() == null
|| EndpointType.DRAWER != action.getEndpoint().getType())
.collect(Collectors.toList())
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
behaviorGroup.setActions(
behaviorGroup.getActions().stream()
.filter(action -> action.getEndpoint() == null
|| EndpointType.DRAWER != action.getEndpoint().getType())
.collect(Collectors.toList())
);
behaviorGroup.getActions().removeIf(action ->
action.getEndpoint() != null && EndpointType.DRAWER == action.getEndpoint().getType());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tested, but actually we can't, because if we alter the collection, Hibernate will consider it as "dirty" state and needs to persit it.
Creating a new collection does not trigger this Hibernate behavior.

* When PostgreSQL sorts a BOOLEAN column in DESC order, true comes first. That's not true for all DBMS.
*/
String query = "SELECT DISTINCT b FROM BehaviorGroup b LEFT JOIN FETCH b.actions a " +
"LEFT JOIN FETCH a.endpoint e " +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From a DB perf perspective, it would be a bit better to have 2 distinct SQL queries (old one unchanged, new one that filters out drawer endpoint) and switch between them based on the feature toggle. This would remove the need for fetching endpoints data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java (1)

389-392: Make the drawer-disabled assumption explicit in this test.

Line 391 currently relies on Mockito’s default false for backendConfig.isDrawerEnabled(). Stubbing it explicitly makes intent and test stability clearer.

Proposed test tweak
         when(backendConfig.isUseDrawerfilteredQuery(eq(DEFAULT_ORG_ID))).thenReturn(true);
+        when(backendConfig.isDrawerEnabled()).thenReturn(false);
         bgActions = updateAndFetchBehaviorGroupActions(DEFAULT_ORG_ID, bundle.getId(), behaviorGroup.getId(), endpoint1.getId(), endpoint2.getId());
         assertTrue(bgActions.isEmpty());
         when(backendConfig.isDrawerEnabled()).thenReturn(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java`
around lines 389 - 392, The test currently relies on Mockito’s default false for
backendConfig.isDrawerEnabled(); make this explicit by stubbing
backendConfig.isDrawerEnabled() to return false before calling
updateAndFetchBehaviorGroupActions(DEFAULT_ORG_ID, bundle.getId(),
behaviorGroup.getId(), endpoint1.getId(), endpoint2.getId()) so that the
behavior of isUseDrawerfilteredQuery(DEFAULT_ORG_ID) and the resulting bgActions
assertion are deterministic and self-documenting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java`:
- Around line 389-392: The test currently relies on Mockito’s default false for
backendConfig.isDrawerEnabled(); make this explicit by stubbing
backendConfig.isDrawerEnabled() to return false before calling
updateAndFetchBehaviorGroupActions(DEFAULT_ORG_ID, bundle.getId(),
behaviorGroup.getId(), endpoint1.getId(), endpoint2.getId()) so that the
behavior of isUseDrawerfilteredQuery(DEFAULT_ORG_ID) and the resulting bgActions
assertion are deterministic and self-documenting.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92125ac9-4053-466f-ae63-5cabc17b219f

📥 Commits

Reviewing files that changed from the base of the PR and between d7165e5 and 0138aed.

📒 Files selected for processing (3)
  • backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
  • backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java

@g-duval g-duval force-pushed the RHCLOUD-46428_hideDrawerFromBackend branch from 0138aed to fedb03d Compare April 10, 2026 14:19
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java (1)

54-54: Naming inconsistency: useDrawerfilteredQuery should use proper camelCase.

The field name has inconsistent casing - filtered should be Filtered to follow camelCase convention. This also affects the method name at line 326.

✏️ Suggested fix
-    private String useDrawerfilteredQuery;
+    private String useDrawerFilteredQuery;

And update the corresponding method name:

-    public boolean isUseDrawerfilteredQuery(String orgId) {
+    public boolean isUseDrawerFilteredQuery(String orgId) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java`
at line 54, The field name useDrawerfilteredQuery violates camelCase; rename the
field to useDrawerFilteredQuery and update all usages and accessors accordingly
(e.g., rename any getter/setter methods such as
getUseDrawerfilteredQuery/setUseDrawerfilteredQuery to
getUseDrawerFilteredQuery/setUseDrawerFilteredQuery and adjust references in
BackendConfig and consumers); ensure serialization/deserialization annotations
(if any) and tests are updated to the new name so behavior remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java`:
- Line 54: The field name useDrawerfilteredQuery violates camelCase; rename the
field to useDrawerFilteredQuery and update all usages and accessors accordingly
(e.g., rename any getter/setter methods such as
getUseDrawerfilteredQuery/setUseDrawerfilteredQuery to
getUseDrawerFilteredQuery/setUseDrawerFilteredQuery and adjust references in
BackendConfig and consumers); ensure serialization/deserialization annotations
(if any) and tests are updated to the new name so behavior remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07424a37-cf1f-47f9-8a5f-d04445a7beb0

📥 Commits

Reviewing files that changed from the base of the PR and between 0138aed and fedb03d.

📒 Files selected for processing (5)
  • backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
  • backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java
  • backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java
  • backend/src/test/java/com/redhat/cloud/notifications/routers/handlers/event/EventResourceTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java

Copy link
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java`:
- Around line 831-837: The test currently hides a missing BehaviorGroup by
returning an empty list; change the behavior to fail fast: after calling
behaviorGroupRepository.findByBundleId(orgId, bundleId) and filtering for
behaviorGroupId, if the resulting list is empty, throw an assertion or explicit
exception (e.g., Assertions.fail or NoSuchElementException) instead of returning
new ArrayList<>() so that missing groups cause the test to fail; then return
behaviorGroups.get(0).getActions() as before.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db5888c1-01d1-4387-a3bc-9c709d9da63f

📥 Commits

Reviewing files that changed from the base of the PR and between fedb03d and 55f0c77.

📒 Files selected for processing (4)
  • backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java
  • backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java
  • backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java
✅ Files skipped from review due to trivial changes (1)
  • backend/src/main/java/com/redhat/cloud/notifications/routers/handlers/event/EventResource.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/src/main/java/com/redhat/cloud/notifications/config/BackendConfig.java
  • backend/src/main/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepository.java

Comment on lines +831 to +837
final List<BehaviorGroup> behaviorGroups = behaviorGroupRepository.findByBundleId(orgId, bundleId)
.stream().filter(behaviorGroup -> behaviorGroup.getId().equals(behaviorGroupId)).toList();
if (behaviorGroups.isEmpty()) {
return new ArrayList<>();
} else {
return behaviorGroups.get(0).getActions();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Avoid silently returning empty when the behavior group is missing.

Returning new ArrayList<>() here can hide real regressions (missing behavior group) as a “valid empty actions” case. Fail fast when the group isn’t found.

Suggested change
 private List<BehaviorGroupAction> findBehaviorGroupActions(String orgId, UUID bundleId, UUID behaviorGroupId) {
-    final List<BehaviorGroup> behaviorGroups = behaviorGroupRepository.findByBundleId(orgId, bundleId)
-        .stream().filter(behaviorGroup -> behaviorGroup.getId().equals(behaviorGroupId)).toList();
-    if (behaviorGroups.isEmpty()) {
-        return new ArrayList<>();
-    } else {
-        return behaviorGroups.get(0).getActions();
-    }
+    return behaviorGroupRepository.findByBundleId(orgId, bundleId).stream()
+        .filter(behaviorGroup -> behaviorGroup.getId().equals(behaviorGroupId))
+        .findFirst()
+        .map(BehaviorGroup::getActions)
+        .orElseThrow(() -> new AssertionError(
+            "Expected behavior group " + behaviorGroupId + " in bundle " + bundleId + " for org " + orgId
+        ));
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
final List<BehaviorGroup> behaviorGroups = behaviorGroupRepository.findByBundleId(orgId, bundleId)
.stream().filter(behaviorGroup -> behaviorGroup.getId().equals(behaviorGroupId)).toList();
if (behaviorGroups.isEmpty()) {
return new ArrayList<>();
} else {
return behaviorGroups.get(0).getActions();
}
private List<BehaviorGroupAction> findBehaviorGroupActions(String orgId, UUID bundleId, UUID behaviorGroupId) {
return behaviorGroupRepository.findByBundleId(orgId, bundleId).stream()
.filter(behaviorGroup -> behaviorGroup.getId().equals(behaviorGroupId))
.findFirst()
.map(BehaviorGroup::getActions)
.orElseThrow(() -> new AssertionError(
"Expected behavior group " + behaviorGroupId + " in bundle " + bundleId + " for org " + orgId
));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/src/test/java/com/redhat/cloud/notifications/db/repositories/BehaviorGroupRepositoryTest.java`
around lines 831 - 837, The test currently hides a missing BehaviorGroup by
returning an empty list; change the behavior to fail fast: after calling
behaviorGroupRepository.findByBundleId(orgId, bundleId) and filtering for
behaviorGroupId, if the resulting list is empty, throw an assertion or explicit
exception (e.g., Assertions.fail or NoSuchElementException) instead of returning
new ArrayList<>() so that missing groups cause the test to fail; then return
behaviorGroups.get(0).getActions() as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants