Skip to content

Allowing configurable value override when equal and DataReplacementStrategy.IF_NOT_ALREADY_PRESENT#14127

Merged
obinna-h-n merged 1 commit into
developmentfrom
feat/14123-allowed-equal-value-override
Jul 2, 2026
Merged

Allowing configurable value override when equal and DataReplacementStrategy.IF_NOT_ALREADY_PRESENT#14127
obinna-h-n merged 1 commit into
developmentfrom
feat/14123-allowed-equal-value-override

Conversation

@Pa-Touche

@Pa-Touche Pa-Touche commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #14123

Summary by CodeRabbit

  • New Features

    • Added support for selectively allowing certain value overrides during patching.
    • Introduced configuration-based matching for exact or type-prefixed values.
  • Bug Fixes

    • Patch updates now preserve existing values unless an override is explicitly allowed.
    • Improved error reporting when a value override is rejected, including both current and incoming values.
  • Tests

    • Added coverage for override configuration scenarios and successful patch application when overrides are permitted.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new EqualValueOverrideHelper service that checks a configured allowlist to permit value overrides during patching. DataPatcherImpl now consults this helper in the IF_NOT_ALREADY_PRESENT replacement strategy before rejecting mismatched value overrides. Corresponding unit and integration tests are added.

Changes

Equal Value Override Feature

Layer / File(s) Summary
EqualValueOverrideHelper implementation
sormas-backend/.../patch/EqualValueOverrideHelper.java
New bean with allowedOverride(Object value) that normalizes a value and checks it (plain or type-prefixed) against an allowlist parsed from a system configuration key.
DataPatcherImpl integration with override helper
sormas-backend/.../patch/DataPatcherImpl.java
Adds explicit imports, injects EqualValueOverrideHelper, and updates IF_NOT_ALREADY_PRESENT handling to consult allowedOverride(currentValue) before returning FORBIDDEN_VALUE_OVERRIDE; renames a local variable to newTypedValue.
EqualValueOverrideHelper unit tests
sormas-backend/src/test/.../patch/EqualValueOverrideHelperTest.java
New test class covering plain/type-prefixed matches, null configuration, whitespace trimming, and case/accent/whitespace-insensitive matching (including a parameterized CSV test).
DataPatcherImplTest integration test
sormas-backend/src/test/.../patch/DataPatcherImplTest.java
Adds explicit imports and a new test that configures the override allowlist and verifies a patch to EpiData.exposureDetailsKnown applies and stores YesNoUnknown.YES.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant DataPatcherImpl
  participant EqualValueOverrideHelper
  participant SystemConfigurationValueFacade

  Client->>DataPatcherImpl: patch(field, newValue)
  DataPatcherImpl->>DataPatcherImpl: compare currentValue vs newTypedValue
  alt values differ
    DataPatcherImpl->>EqualValueOverrideHelper: allowedOverride(currentValue)
    EqualValueOverrideHelper->>SystemConfigurationValueFacade: getValue(ALLOWED_EQUALITY_VALUE_OVERRIDE_KEY)
    SystemConfigurationValueFacade-->>EqualValueOverrideHelper: configured allowlist
    EqualValueOverrideHelper-->>DataPatcherImpl: allowed / not allowed
    alt allowed
      DataPatcherImpl->>DataPatcherImpl: apply newTypedValue
    else not allowed
      DataPatcherImpl-->>Client: DataPatchFailure(FORBIDDEN_VALUE_OVERRIDE)
    end
  else values equal
    DataPatcherImpl->>DataPatcherImpl: skip override
  end
Loading

Related issues: #14123 (External survey tool: Behavioural Rules Override Unk Value)

Suggested labels: backend, enhancement, patch

Suggested reviewers: backend maintainers familiar with DataPatcherImpl and system configuration

A rabbit hopped through fields of config keys, Found "Unknown" locked behind old override decrees, Now a helper whispers, "let it through, it's fine," And YesNoUnknown values fall neatly into line. Hoppy tests confirm it, case by case, with glee. 🐇
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The implementation allows configurable overrides, but it checks the existing value rather than the incoming Unknown value requested in #14123. Change the override rule to permit overwriting when the incoming YesNoUnknown value is Unknown, and add a test for that path.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description satisfies the template by including the required Fixes #14123 reference.
Out of Scope Changes check ✅ Passed The changes stay within the patching logic and related tests, with no unrelated scope introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly reflects the core change: configurable equal-value overrides for IF_NOT_ALREADY_PRESENT patching.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/14123-allowed-equal-value-override

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

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sormas-backend/src/main/java/de/symeda/sormas/backend/patch/DataPatcherImpl.java (1)

88-110: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Initialize the new helper in the explicit constructor.

Instances created through the public constructor leave equalValueOverrideHelper null, then line 311 can throw when IF_NOT_ALREADY_PRESENT sees a differing value.

Proposed fix
 	public DataPatcherImpl(
 		PatchFieldHelper patchFieldHelper,
 		ValueMapperRegistry valueMapperRegistry,
 		FieldCustomMapperRegistry fieldCustomMapperRegistry,
 		PatchEqualityCheckersRegistry patchEqualityCheckersRegistry,
 		BusinessDtoFacade businessDtoFacade,
 		FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal featureConfigurationFacade,
-		ConfigFacadeEjb.ConfigFacadeEjbLocal configFacade) {
+		ConfigFacadeEjb.ConfigFacadeEjbLocal configFacade,
+		EqualValueOverrideHelper equalValueOverrideHelper) {
 
 		this.patchFieldHelper = patchFieldHelper;
 		this.valueMapperRegistry = valueMapperRegistry;
 		this.fieldCustomMapperRegistry = fieldCustomMapperRegistry;
 		this.patchEqualityCheckersRegistry = patchEqualityCheckersRegistry;
 		this.businessDtoFacade = businessDtoFacade;
 		this.featureConfigurationFacade = featureConfigurationFacade;
 		this.configFacade = configFacade;
+		this.equalValueOverrideHelper = equalValueOverrideHelper;
 	}
🤖 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
`@sormas-backend/src/main/java/de/symeda/sormas/backend/patch/DataPatcherImpl.java`
around lines 88 - 110, The public DataPatcherImpl constructor is missing
initialization for equalValueOverrideHelper, so instances created there can hit
a null reference when IF_NOT_ALREADY_PRESENT is processed. Update the explicit
constructor to accept and assign EqualValueOverrideHelper alongside the other
dependencies, and make sure the field is consistently set for both construction
paths in DataPatcherImpl.
🧹 Nitpick comments (1)
sormas-backend/src/test/java/de/symeda/sormas/patch/DataPatcherImplTest.java (1)

773-793: 📐 Maintainability & Code Quality | 🔵 Trivial

Minor: exception-driven control flow to check for an existing default category.

Catching IllegalStateException to detect "category doesn't exist yet" works but is a smell if SystemConfigurationCategoryService exposes (or could expose) a non-throwing lookup (e.g., Optional-returning finder). Not blocking since this is test-only setup code.

🤖 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 `@sormas-backend/src/test/java/de/symeda/sormas/patch/DataPatcherImplTest.java`
around lines 773 - 793, The helper setAllowedEqualityValueOverride currently
uses exception-driven control flow to detect whether the default
SystemConfigurationCategory exists. Update the setup to use a non-throwing
lookup from SystemConfigurationCategoryService if available, or add one, and
only create/persist a new category when the lookup returns empty instead of
catching IllegalStateException. Keep the rest of the test setup unchanged,
including the SystemConfigurationValueDto creation and save path.
🤖 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
`@sormas-backend/src/main/java/de/symeda/sormas/backend/patch/DataPatcherImpl.java`:
- Around line 310-320: The override check in DataPatcherImpl currently validates
currentValue, but it should validate the incoming configured exception value
instead so allowlisted inputs like YesNoUnknown.UNKNOWN/NA/Unk can pass through
IF_NOT_ALREADY_PRESENT. Update the condition around
patchEqualityCheckersRegistry.areEqual and
equalValueOverrideHelper.allowedOverride to compare against the incoming
untypedTargetValue/newTypedValue as appropriate, and keep the
FORBIDDEN_VALUE_OVERRIDE failure path for non-allowlisted inputs.

---

Outside diff comments:
In
`@sormas-backend/src/main/java/de/symeda/sormas/backend/patch/DataPatcherImpl.java`:
- Around line 88-110: The public DataPatcherImpl constructor is missing
initialization for equalValueOverrideHelper, so instances created there can hit
a null reference when IF_NOT_ALREADY_PRESENT is processed. Update the explicit
constructor to accept and assign EqualValueOverrideHelper alongside the other
dependencies, and make sure the field is consistently set for both construction
paths in DataPatcherImpl.

---

Nitpick comments:
In
`@sormas-backend/src/test/java/de/symeda/sormas/patch/DataPatcherImplTest.java`:
- Around line 773-793: The helper setAllowedEqualityValueOverride currently uses
exception-driven control flow to detect whether the default
SystemConfigurationCategory exists. Update the setup to use a non-throwing
lookup from SystemConfigurationCategoryService if available, or add one, and
only create/persist a new category when the lookup returns empty instead of
catching IllegalStateException. Keep the rest of the test setup unchanged,
including the SystemConfigurationValueDto creation and save path.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a99b6bc-4022-4dcd-b063-8d7c92d65fb9

📥 Commits

Reviewing files that changed from the base of the PR and between ffa7ff7 and 6f85fec.

📒 Files selected for processing (4)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/patch/DataPatcherImpl.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/patch/EqualValueOverrideHelper.java
  • sormas-backend/src/test/java/de/symeda/sormas/backend/patch/EqualValueOverrideHelperTest.java
  • sormas-backend/src/test/java/de/symeda/sormas/patch/DataPatcherImplTest.java

@Pa-Touche Pa-Touche changed the title ✨: Allowing configurable value override when equal and DataReplacementStrategy.IF_NOT_ALREADY_PRESENT Allowing configurable value override when equal and DataReplacementStrategy.IF_NOT_ALREADY_PRESENT Jul 2, 2026
@Pa-Touche Pa-Touche requested a review from obinna-h-n July 2, 2026 08:09
@obinna-h-n obinna-h-n merged commit 69d2532 into development Jul 2, 2026
7 checks passed
@obinna-h-n obinna-h-n deleted the feat/14123-allowed-equal-value-override branch July 2, 2026 08:12
@Pa-Touche Pa-Touche self-assigned this Jul 6, 2026
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.

External survey tool: Behavioural Rules Override Unk Value

2 participants