Skip to content

SDKS-5168 Add MetadataCollector and associated UI components - #226

Merged
spetrov merged 5 commits into
developfrom
SDKS-5168
Jul 23, 2026
Merged

SDKS-5168 Add MetadataCollector and associated UI components#226
spetrov merged 5 commits into
developfrom
SDKS-5168

Conversation

@vibhorgoswami

@vibhorgoswami vibhorgoswami commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

JIRA Ticket

SDKS-5168

Description

Add Metadata collector to support DaVinci callbacks.
Success

{
  "id": "4r92vx2x9u",
  "eventName": "continue",
  "parameters": {
    "eventType": "action",
    "data": {
      "actionKey": "sdkMetadata",
      "formData": {
        "sdkMetadata": {
          "status": "success"
        }
      }
    }
  }
}

Error

{
  "id": "4r92vx2x9u",
  "eventName": "continue",
  "parameters": {
    "eventType": "action",
    "data": {
      "actionKey": "sdkMetadata",
      "formData": {
        "sdkMetadata": {
          "error": {
            "code": "100",
            "message": "An error occurred"
          }
        }
      }
    }
  }
}

Summary by CodeRabbit

  • New Features
    • Added an “SDK Metadata” collector to capture server-provided metadata and enable success/error resume payloads.
    • Updated the continue-node flow to render the metadata step and proceed immediately after success/error selection.
    • Updated JSON generation for metadata submissions to include both the metadata identifier and its value in formData.
  • Tests
    • Added unit tests covering initialization, result/error payload lifecycle, validation behavior, and JSON/event type integration.

@vibhorgoswami vibhorgoswami self-assigned this Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 MetadataCollector for DaVinci METADATA fields, registers it with the collector factory, serializes its results, validates its JSON state and payload handling, and adds sample-app UI actions for success or error metadata.

Changes

Metadata collector

Layer / File(s) Summary
Collector contract and payload handling
davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt
Stores server metadata, creates success or error payloads, validates result state, exposes the action event type, and clears results on close.
Registration, serialization, and validation
davinci/src/main/kotlin/com/pingidentity/davinci/CollectorRegistry.kt, davinci/src/main/kotlin/com/pingidentity/davinci/collector/Collectors.kt, davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt
Registers METADATA, includes metadata results in formData with actionKey, and tests initialization, defaults, payload lifecycle, errors, validation, and integration behavior.
Sample app metadata interaction
samples/pingsampleapp/.../DaVinciContinueNode.kt, samples/pingsampleapp/.../Metadata.kt
Dispatches MetadataCollector to a Compose screen that displays metadata and submits success or error results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: spetrov, witrisna, vahancouver

Sequence Diagram(s)

sequenceDiagram
  participant DaVinci
  participant CollectorRegistry
  participant MetadataCollector
  participant Metadata
  participant Collectors
  DaVinci->>CollectorRegistry: Register METADATA collector
  DaVinci->>MetadataCollector: Initialize payload and metadata
  MetadataCollector->>Metadata: Render metadata and actions
  Metadata->>MetadataCollector: Set success or error result
  Metadata->>Collectors: Continue with onNext
  Collectors-->>DaVinci: Serialize actionKey and formData
Loading

Poem

A bunny hops through metadata bright,
Displays the payload in cards of light.
“Success!” it says, or “Error, alas!”
Then sends the result through the form-data grass.
The collector resets, ready to play—
And resumes the flow along its way.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly names the new MetadataCollector and UI components, matching the main change.
Description check ✅ Passed The description matches the required template with JIRA Ticket and Description sections and includes useful callback examples.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SDKS-5168

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.

@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 (1)
davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt (1)

48-81: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Declare public explicitly on the documented API surface.

As per coding guidelines, "Prefer internal for module-private APIs, and declare public explicitly on the documented API surface." Since MetadataCollector and its properties are intended to be accessed by SDK integrators to retrieve metadata and set output or error, they should explicitly use the public modifier.

♻️ Proposed refactor
-class MetadataCollector : Collector<Nothing>, ContinueNodeAware, RequestInterceptor {
+public class MetadataCollector : Collector<Nothing>, ContinueNodeAware, RequestInterceptor {
 
     override lateinit var continueNode: ContinueNode
 
     /**
      * The key of this field (typically "sdkMetadata").
      */
-    var key = ""
+    public var key: String = ""
         private set
 
     /**
      * The raw type string (always "METADATA").
      */
-    var type = ""
+    public var type: String = ""
         private set
 
     /**
      * The metadata payload sent by the server — arbitrary JSON the SDK must process.
      */
-    var metadata: JsonObject = JsonObject(emptyMap())
+    public var metadata: JsonObject = JsonObject(emptyMap())
         private set
 
     /**
      * The SDK result to send back on resume (success path).
      * Set this before calling [ContinueNode.next].
      */
-    var output: JsonObject? = null
+    public var output: JsonObject? = null
 
     /**
      * The SDK error to send back on resume (failure path).
      * When set, [output] is ignored and the flow takes the error branch.
      * Set this before calling [ContinueNode.next].
      */
-    var error: JsonObject? = null
+    public var error: JsonObject? = null
🤖 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
`@davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt`
around lines 48 - 81, Explicitly declare public visibility on MetadataCollector
and its documented API properties: continueNode, key, type, metadata, output,
and error. Preserve the existing private setters and nullable types while making
the integrator-facing surface unambiguous.

Source: Coding guidelines

🤖 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
`@davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt`:
- Around line 48-81: Explicitly declare public visibility on MetadataCollector
and its documented API properties: continueNode, key, type, metadata, output,
and error. Preserve the existing private setters and nullable types while making
the integrator-facing surface unambiguous.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 604e6cf3-3844-485a-bc9b-1fcdb85d1a56

📥 Commits

Reviewing files that changed from the base of the PR and between 5f1e47f and 1cd4b80.

📒 Files selected for processing (5)
  • davinci/src/main/kotlin/com/pingidentity/davinci/CollectorRegistry.kt
  • davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt
  • davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt
  • samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/davinci/collector/DaVinciContinueNode.kt
  • samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/davinci/collector/Metadata.kt

@vibhorgoswami
vibhorgoswami marked this pull request as ready for review July 14, 2026 23:10
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (5f1e47f) to head (e9131e0).

Additional details and impacted files
@@      Coverage Diff       @@
##   develop   #226   +/-   ##
==============================
==============================

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt Outdated
Comment thread davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt Outdated

@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)
davinci/src/main/kotlin/com/pingidentity/davinci/collector/Collectors.kt (1)

62-79: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reduce code duplication by lifting it.payload()?.let outside the when block.

The it.payload()?.let { ... } check is duplicated across all branches of the when statement. You can improve readability and maintainability by extracting the null-check and restructuring the when block.

♻️ Proposed refactor
-            when {
-                it is MetadataCollector -> {
-                    it.payload()?.let { payload ->
-                        put("actionKey", it.id())
-                        map[it.id()] = payload
-                    }
-                }
-                it is SubmitCollector || it is FlowCollector -> {
-                    it.payload()?.let { _ ->
-                        put("actionKey", it.id())
-                    }
-                }
-                else -> {
-                    it.payload()?.let { payload ->
-                        map[it.id()] = payload
-                    }
-                }
-            }
+            it.payload()?.let { payload ->
+                when (it) {
+                    is MetadataCollector -> {
+                        put("actionKey", it.id())
+                        map[it.id()] = payload
+                    }
+                    is SubmitCollector, is FlowCollector -> {
+                        put("actionKey", it.id())
+                    }
+                    else -> {
+                        map[it.id()] = payload
+                    }
+                }
+            }
🤖 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 `@davinci/src/main/kotlin/com/pingidentity/davinci/collector/Collectors.kt`
around lines 62 - 79, Refactor the collector handling around the when expression
so the shared it.payload()?.let null-check is performed once outside the
branch-specific logic. Inside that block, keep MetadataCollector adding
actionKey and storing the payload, SubmitCollector/FlowCollector adding only
actionKey, and other collectors storing the payload in map.
davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt (1)

112-123: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use consistent and idiomatic JSON boolean assertions.

The test assertions for isClientError use different access patterns (content?.toBoolean() vs boolean ?: true). For consistency and better readability, prefer using boolean and assertEquals, which matches the assertion style used on line 176.

♻️ Proposed refactor
-        val error = collector.payload()!!["error"]?.jsonObject
-        assertEquals(true, error?.get("isClientError")?.jsonPrimitive?.content?.toBoolean())
-    }
-
-    `@Test`
-    fun setErrorWithIsClientErrorFalseIncludesFlag() {
-        val collector = MetadataCollector().apply { init(buildFullMetadataJson()) }
-        collector.setError(errorCode = "E1", message = "m", isClientError = false)
-
-        val error = collector.payload()!!["error"]?.jsonObject
-        assertFalse(error?.get("isClientError")?.jsonPrimitive?.boolean ?: true)
+        val error = collector.payload()!!["error"]?.jsonObject
+        assertEquals(true, error?.get("isClientError")?.jsonPrimitive?.boolean)
+    }
+
+    `@Test`
+    fun setErrorWithIsClientErrorFalseIncludesFlag() {
+        val collector = MetadataCollector().apply { init(buildFullMetadataJson()) }
+        collector.setError(errorCode = "E1", message = "m", isClientError = false)
+
+        val error = collector.payload()!!["error"]?.jsonObject
+        assertEquals(false, error?.get("isClientError")?.jsonPrimitive?.boolean)
🤖 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 `@davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt`
around lines 112 - 123, Update the `setErrorWithIsClientErrorFalseIncludesFlag`
test assertion to use the JSON primitive’s `boolean` property with
`assertEquals`, matching the existing `isClientError` assertion style and the
pattern used elsewhere in `MetadataCollectorTest`; remove the fallback-based
`assertFalse` form.
🤖 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 `@davinci/src/main/kotlin/com/pingidentity/davinci/collector/Collectors.kt`:
- Around line 62-79: Refactor the collector handling around the when expression
so the shared it.payload()?.let null-check is performed once outside the
branch-specific logic. Inside that block, keep MetadataCollector adding
actionKey and storing the payload, SubmitCollector/FlowCollector adding only
actionKey, and other collectors storing the payload in map.

In `@davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt`:
- Around line 112-123: Update the `setErrorWithIsClientErrorFalseIncludesFlag`
test assertion to use the JSON primitive’s `boolean` property with
`assertEquals`, matching the existing `isClientError` assertion style and the
pattern used elsewhere in `MetadataCollectorTest`; remove the fallback-based
`assertFalse` form.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ebd23aae-9129-48a3-9d08-cde7f0cd6cb8

📥 Commits

Reviewing files that changed from the base of the PR and between da2742e and eddfdf5.

📒 Files selected for processing (4)
  • davinci/src/main/kotlin/com/pingidentity/davinci/collector/Collectors.kt
  • davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt
  • davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt
  • samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/davinci/collector/Metadata.kt

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt (1)

61-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare the public API visibility explicitly.

Use public fun setError(...) rather than relying on Kotlin’s default visibility for this documented SDK API.

🤖 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
`@davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt`
at line 61, Update the MetadataCollector.setError method declaration to
explicitly use public visibility, preserving its existing parameters and
behavior.

Source: Coding guidelines

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

Inline comments:
In
`@davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt`:
- Around line 61-68: Update the KDoc and any published contract examples for
MetadataCollector.setError to remove the optional isClientError field and
document that the error payload contains only code and message. Keep the
implementation unchanged.

---

Nitpick comments:
In
`@davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt`:
- Line 61: Update the MetadataCollector.setError method declaration to
explicitly use public visibility, preserving its existing parameters and
behavior.
🪄 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: 2496c6b0-acfe-4715-9bf8-e85e13dea865

📥 Commits

Reviewing files that changed from the base of the PR and between eddfdf5 and 42a6cdc.

📒 Files selected for processing (3)
  • davinci/src/main/kotlin/com/pingidentity/davinci/collector/MetadataCollector.kt
  • davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt
  • samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/davinci/collector/Metadata.kt
💤 Files with no reviewable changes (2)
  • samples/pingsampleapp/src/main/java/com/pingidentity/samples/pingsampleapp/davinci/collector/Metadata.kt
  • davinci/src/test/kotlin/com/pingidentity/davinci/MetadataCollectorTest.kt

@vahancouver vahancouver left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

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

Can you add an end to end test under DaVinciTest to make sure the actionKey and eventType are changed for MetadataCallback

@vibhorgoswami

Copy link
Copy Markdown
Contributor Author

I think we should also add the E2E test in the FormFieldsTest similar to how we have other collectors. I think we can add that later

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

LGTM!

@spetrov
spetrov merged commit 04c8a6b into develop Jul 23, 2026
34 of 38 checks passed
@spetrov
spetrov deleted the SDKS-5168 branch July 23, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants