Skip to content

UNOMI-920 Improve debugging with YAML-based toString() for core API types#754

Open
sergehuber wants to merge 6 commits into
masterfrom
UNOMI-920-yaml-tostring
Open

UNOMI-920 Improve debugging with YAML-based toString() for core API types#754
sergehuber wants to merge 6 commits into
masterfrom
UNOMI-920-yaml-tostring

Conversation

@sergehuber
Copy link
Copy Markdown
Contributor

JIRA: https://issues.apache.org/jira/browse/UNOMI-920

Why this change

Core Unomi API objects are deeply nested and interconnected—conditions recurse, rules bundle conditions and actions, metadata types carry parameters, and real graphs can contain cycles (for example when inspecting profile ↔ event ↔ session). In many places, toString() is missing, falls back to Object.toString(), or uses ad-hoc concatenation that is hard to read in logs and breakpoints. That slows down live debugging, operational triage, and support, because engineers cannot see structure and field names at a glance.

YAML-formatted output gives indentation, named fields, and readable nesting, which makes logged or inspected values far easier to scan than opaque object identities or flat string blobs. Together with explicit circular-reference markers, we get safe, repeatable dumps suitable for logs and copy/paste into issues or docs.

What changed

  • Introduce YamlUtils (SnakeYaml) with YamlConvertible, YamlMapBuilder, identity-based cycle detection, optional depth limits, and $ref: circular where the same instance reappears.
  • Implement toYaml / toString on key Item / MetadataItem types (including Condition, ConditionType, Action, ActionType, Rule, Segment, Goal, Scoring, ScoringElement, Parameter, Metadata, etc.).
  • Add YamlUtilsTest for the helper API and representative usage.

Supporting changes

  • unomi-api: SnakeYAML + test dependencies; mockito-core version managed in unomi-bom (mockito.version).
  • RESTParameter: defaultValue as Object to match Parameter#getDefaultValue().
  • RulesServiceImpl: avoid null defaultValue before splitting tracked-condition parameter strings.
  • unomi-itests: pin awaitility to 3.1.6 for Karaf/OSGi (Hamcrest 1.3 bundle), Karaf itests logback exclusions, Hamcrest bundle test scope (aligned with unomi-3-dev).

- Add YamlUtils (SnakeYaml) with YamlConvertible, YamlMapBuilder, circular
  reference detection (identity-based visited sets), and recursion depth limits.
- Implement YAML-backed toString()/toYaml() on core API types extending Item /
  MetadataItem (Condition, ConditionType, Action, ActionType, Rule, Segment,
  Goal, Scoring, ScoringElement, Parameter, Metadata, etc.).
- Add YamlUtilsTest coverage for builder, toYamlValue, and representative rules.

Build and integration alignment:
- unomi-api: snakeyaml + test dependencies; manage mockito-core version in BOM.
- RESTParameter: use Object for defaultValue to match Parameter#getDefaultValue().
- RulesServiceImpl: avoid NPE when tracked parameter defaultValue is null before split.
- itests: override awaitility to 3.1.6 for OSGi (Hamcrest 1.3 bundle); Karaf
  itests common logback exclusions; hamcrest bundle scope test.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a YAML-based debugging representation (toYaml() + YAML-formatted toString()) for core Unomi API model types to make deeply nested graphs (including cycles) easier to inspect in logs and debuggers. It also adjusts supporting dependency management and aligns defaultValue typing across API/REST.

Changes:

  • Add YamlUtils (+ tests) and implement YAML conversion / YAML toString() across multiple core API types with cycle detection and depth limiting.
  • Update Parameter / RESTParameter defaultValue to Object and harden rule tracked-parameter parsing against null default values.
  • Update BOM/root/itests poms for SnakeYAML and test-library version management/overrides (Mockito, Awaitility, JUnit Jupiter).

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java Avoid NPE when splitting tracked-condition parameter default values.
rest/src/main/java/org/apache/unomi/rest/models/RESTParameter.java Align REST model defaultValue type with API (Object).
pom.xml Add/adjust shared version properties for new test deps (plus SLF4J property).
itests/pom.xml Override Awaitility for OSGi/Hamcrest compatibility; adjust test dependency exclusions/scopes.
bom/pom.xml Manage Mockito/JUnit Jupiter/Awaitility versions in the BOM.
api/src/main/java/org/apache/unomi/api/utils/YamlUtils.java New YAML builder/formatting utilities and YAML conversion API.
api/src/test/java/org/apache/unomi/api/utils/YamlUtilsTest.java Unit tests for YAML utilities and circular reference behavior.
api/src/main/java/org/apache/unomi/api/Item.java Add YAML conversion + YAML toString() base implementation for Items.
api/src/main/java/org/apache/unomi/api/MetadataItem.java Add YAML conversion + YAML toString() including metadata.
api/src/main/java/org/apache/unomi/api/Metadata.java Add YAML conversion + YAML toString() for metadata.
api/src/main/java/org/apache/unomi/api/Parameter.java Change defaultValue to Object; add YAML conversion + YAML toString().
api/src/main/java/org/apache/unomi/api/conditions/Condition.java Add YAML conversion + YAML toString(); add deepCopy(); null-safety adjustments.
api/src/main/java/org/apache/unomi/api/conditions/ConditionType.java Add YAML conversion for condition type definitions.
api/src/main/java/org/apache/unomi/api/actions/Action.java Add YAML conversion + YAML toString() for actions.
api/src/main/java/org/apache/unomi/api/actions/ActionType.java Add YAML conversion for action type definitions.
api/src/main/java/org/apache/unomi/api/rules/Rule.java Add YAML conversion for rules with condition/actions/linkage.
api/src/main/java/org/apache/unomi/api/segments/Segment.java Add YAML conversion for segments.
api/src/main/java/org/apache/unomi/api/segments/Scoring.java Add YAML conversion for scoring definitions.
api/src/main/java/org/apache/unomi/api/segments/ScoringElement.java Add YAML conversion + YAML toString() for scoring elements.
api/src/main/java/org/apache/unomi/api/goals/Goal.java Add YAML conversion for goals.
api/pom.xml Add SnakeYAML dependency and test deps for new YAML utility tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/src/main/java/org/apache/unomi/api/utils/YamlUtils.java
Comment thread api/src/main/java/org/apache/unomi/api/conditions/Condition.java
Comment thread api/src/main/java/org/apache/unomi/api/conditions/Condition.java
Comment thread api/src/main/java/org/apache/unomi/api/Parameter.java Outdated
Comment thread api/src/main/java/org/apache/unomi/api/Parameter.java
Comment thread api/src/main/java/org/apache/unomi/api/Item.java
Comment thread pom.xml
Comment thread api/src/test/java/org/apache/unomi/api/utils/YamlUtilsTest.java Outdated
sergehuber and others added 5 commits May 15, 2026 08:10
Run mikepenz/action-junit-report after every integration matrix leg
(if: always), with update_check and per-matrix check_name, so a green
re-run replaces the stale red JUnit check. Use fail_on_failure=false and
require_tests=false; continue-on-error so missing XML cannot fail the job.
Use identity-based visited sets for circular-reference detection, harden
Condition deepCopy and parameter handling, fix Parameter max-depth YAML,
wire slf4j.version in unomi-api, and expand unit test coverage.
@sergehuber
Copy link
Copy Markdown
Contributor Author

Thanks for the review. The eight inline points are addressed in bcf5a68 (identity-based visited sets, Condition null/deepCopy hardening, Parameter max-depth YAML fix, slf4j.version wiring, test cleanup/expansion). Unit and integration tests are green on our side.

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