Skip to content

[Customer Entity] Add POST /security-report-analyses/search endpoint - #906

Merged
Rashmika998 merged 9 commits into
wso2-open-operations:v2from
cloby99:task/entity-service
Jun 22, 2026
Merged

[Customer Entity] Add POST /security-report-analyses/search endpoint#906
Rashmika998 merged 9 commits into
wso2-open-operations:v2from
cloby99:task/entity-service

Conversation

@cloby99

@cloby99 cloby99 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds POST /security-report-analyses/search endpoint backed exclusively by the ServiceNow data source (returns 503 for Postgres)
  • Calls the existing SN POST /cases/search API with caseTypes: ["security_report_analysis"]
  • Supports filters: projectIds, searchQuery, stateKeys, date ranges (closedStart/EndDate, startCreatedDate/endCreatedDate, startUpdatedDate/endUpdatedDate), deploymentId, deploymentIds, createdBy, createdByMe
  • Response includes securityReportAnalyses[] with id, internalId, number, createdOn, createdBy, title, description, state, workState (nullable string label), product, project, deployment, deployedProduct, assignedEngineer, parentCase, relatedCase

Summary by CodeRabbit

  • New Features
    • Added search functionality for security report analyses with filtering by project, deployment, date ranges, and creator
    • Results support custom sorting and pagination
    • Currently available for ServiceNow data source

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@cloby99, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 4 minutes and 40 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: afd60b13-5550-4ea6-a6d0-469afc4a5bbd

📥 Commits

Reviewing files that changed from the base of the PR and between 8f12a7d and 0e0abd0.

📒 Files selected for processing (3)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/service/sn_case_service.go
  • entity-service/openapi.yaml
📝 Walkthrough

Walkthrough

Adds a new POST /security-report-analyses/search endpoint end-to-end. New OpenAPI schemas and Go domain DTOs define request filters, a paginated response, and a result view. The CaseService interface gains the method; the default service returns ServiceUnavailableError; the ServiceNow service implements full validation, SN payload mapping, and response conversion. The HTTP handler and router are wired up accordingly.

Changes

Security Report Analysis Search Endpoint

Layer / File(s) Summary
OpenAPI contract and domain DTOs
entity-service/openapi.yaml, entity-service/internal/domain/entity.go
Defines the POST /security-report-analyses/search operation with 200/400/503/500 responses, and adds SearchSecurityReportAnalysisRequest, SecurityReportAnalysisView, and SearchSecurityReportAnalysisResponse schemas in OpenAPI and as Go structs in the domain package.
CaseService interface, stub, and SN implementation
entity-service/internal/service/interfaces.go, entity-service/internal/service/case_service.go, entity-service/internal/service/sn_case_service.go
Adds SearchSecurityReportAnalysis to the CaseService interface; the default caseService returns ServiceUnavailableError; snCaseService performs pagination/query/date validation, builds the SN payload with caseTypes=security_report_analysis, calls /cases/search, and maps results to SecurityReportAnalysisView using new snCaseStateLabel/snCaseLabelPtr helpers.
HTTP handler and route registration
entity-service/internal/handler/case_handler.go, entity-service/internal/server/routes.go
Adds the SearchSecurityReportAnalysis handler (decodes body, calls service, writes JSON) and registers POST /security-report-analyses/search in NewRouter.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CaseHandler
    participant snCaseService
    participant ChoreoAPI as Choreo /cases/search

    Client->>CaseHandler: POST /security-report-analyses/search (JSON body)
    CaseHandler->>CaseHandler: decode SearchSecurityReportAnalysisRequest
    CaseHandler->>snCaseService: SearchSecurityReportAnalysis(ctx, req)
    snCaseService->>snCaseService: validate pagination, query, date ranges
    snCaseService->>snCaseService: extract x-user-id-token from context
    snCaseService->>snCaseService: map sortBy → SN field, merge deploymentId into deploymentIds
    snCaseService->>ChoreoAPI: POST /cases/search (snCaseSearchPayload, caseTypes=security_report_analysis)
    ChoreoAPI-->>snCaseService: snSecurityReportAnalysisResponse
    snCaseService->>snCaseService: convert cases → []SecurityReportAnalysisView
    snCaseService-->>CaseHandler: SearchSecurityReportAnalysisResponse
    CaseHandler-->>Client: 200 JSON (SearchSecurityReportAnalysisResponse)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wso2-open-operations/cs-tools#902: Extends SearchCases with the same date-range, createdBy/createdByMe filter semantics and auth validation pattern used in the new SearchSecurityReportAnalysis implementation.
  • wso2-open-operations/cs-tools#903: Adds a parallel search endpoint through the same CaseService interface + CaseHandler + snCaseService stack with caseTypes filtering, structurally identical to this PR.
  • wso2-open-operations/cs-tools#905: Modifies AssignedEngineerRef and SN assigned-engineer mapping in the same files touched by the new security-report-analysis view conversion.

Suggested labels

Type/Improvement, Area/Backend

Suggested reviewers

  • dilshanfardil
  • Rashmika998

🐇 A new path has bloomed in the route garden,
POST /security-report-analyses/search — pardon!
The SN service maps fields with care,
Filters and pages float through the air,
A stub says "ServiceNow only, beware!" 🌸

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing most required template sections (Purpose, Goals, Approach, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, Learning). Provide a complete PR description following the repository template, including sections for Purpose, Goals, Approach, and at minimum explanations for Documentation, Certification, and other applicable sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a new POST endpoint for searching security report analyses.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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 left a comment

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.

🧹 Nitpick comments (2)
entity-service/openapi.yaml (2)

1996-2003: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Clarify the dual deploymentId/deploymentIds design or add deduplication.

The schema allows both deploymentId (singular) and deploymentIds (array). If a client provides the same deployment ID in both fields, the ServiceNow implementation (lines 1339-1343 of sn_case_service.go) will include it twice in the request payload. Whether this is problematic depends on ServiceNow's handling of duplicate filter values.

Consider either:

  1. Documenting that deploymentId is a convenience alias and duplicates are acceptable, or
  2. Adding deduplication logic in the ServiceNow implementation to prevent duplicate IDs.
🤖 Prompt for 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.

In `@entity-service/openapi.yaml` around lines 1996 - 2003, The OpenAPI schema
allows both deploymentId (singular) and deploymentIds (array) fields, which can
result in duplicate deployment IDs being sent to ServiceNow when a client
provides the same ID in both fields. In the ServiceNow implementation in
sn_case_service.go around lines 1339-1343 where the request payload is
constructed, add deduplication logic to combine deploymentId and deploymentIds
into a single deduplicated set before passing to ServiceNow, ensuring each
unique deployment ID appears only once in the final request regardless of how
the client provided the input.

2047-2049: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Consider consistent workState representation across case-type search endpoints.

workState is represented differently across similar endpoints:

  • SecurityReportAnalysisView (here): plain string
  • ServiceRequestView (lines 1928-1930): structured ServiceRequestWorkStateRef with id and label
  • CaseSearchView (lines 1625-1629): enum string

If these differences reflect the underlying ServiceNow data models, document the rationale in comments. Otherwise, consider aligning the representation for consistency.

🤖 Prompt for 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.

In `@entity-service/openapi.yaml` around lines 2047 - 2049, The workState property
has inconsistent representations across similar endpoints:
SecurityReportAnalysisView defines it as a plain nullable string,
ServiceRequestView uses a structured ServiceRequestWorkStateRef object with id
and label fields, and CaseSearchView defines it as an enum string. Either align
all three endpoints to use the same workState representation (choose one
consistent approach across SecurityReportAnalysisView, ServiceRequestView, and
CaseSearchView), or if the differences intentionally reflect underlying
ServiceNow data model variations, add explanatory comments above each workState
definition documenting why they differ.
🤖 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.

Nitpick comments:
In `@entity-service/openapi.yaml`:
- Around line 1996-2003: The OpenAPI schema allows both deploymentId (singular)
and deploymentIds (array) fields, which can result in duplicate deployment IDs
being sent to ServiceNow when a client provides the same ID in both fields. In
the ServiceNow implementation in sn_case_service.go around lines 1339-1343 where
the request payload is constructed, add deduplication logic to combine
deploymentId and deploymentIds into a single deduplicated set before passing to
ServiceNow, ensuring each unique deployment ID appears only once in the final
request regardless of how the client provided the input.
- Around line 2047-2049: The workState property has inconsistent representations
across similar endpoints: SecurityReportAnalysisView defines it as a plain
nullable string, ServiceRequestView uses a structured ServiceRequestWorkStateRef
object with id and label fields, and CaseSearchView defines it as an enum
string. Either align all three endpoints to use the same workState
representation (choose one consistent approach across
SecurityReportAnalysisView, ServiceRequestView, and CaseSearchView), or if the
differences intentionally reflect underlying ServiceNow data model variations,
add explanatory comments above each workState definition documenting why they
differ.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 96326378-98d6-41ba-9132-cabc68e0bc3d

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec9936 and 8f12a7d.

📒 Files selected for processing (7)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/handler/case_handler.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/case_service.go
  • entity-service/internal/service/interfaces.go
  • entity-service/internal/service/sn_case_service.go
  • entity-service/openapi.yaml

@cloby99

cloby99 commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Rashmika998
Rashmika998 merged commit 6b63cfe into wso2-open-operations:v2 Jun 22, 2026
1 check passed
cloby99 pushed a commit that referenced this pull request Jun 22, 2026
…engagements/search endpoints

Mirrors entity service PRs #906 and #908: adds BFF handler, entity client methods, routes, and OpenAPI spec for both new case-type search endpoints.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants