Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

FINERACT-3171: Move client validation to ClientDataValidator - #7118

Merged
adamsaghy merged 3 commits into
apache:developfrom
Joab-SC:FINERACT-3171-client-group
Dec 6, 2026
Merged

adamsaghy merged 3 commits into
apache:developfrom
Joab-SC:FINERACT-3171-client-group

Conversation

@Joab-SC

@Joab-SC Joab-SC commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Move client name and date validation from the Client entity to ClientDataValidator. The create, update, and activation services now call the validator explicitly, keeping the request validation rules in one place while preserving the existing API errors.

Client.activate(...) retains the already-active guard so a second activation cannot overwrite the original activation date, activating user, or office joining date. The activation service checks the client's state first, validates the requested activation date, and then changes the entity. This preserves which error is returned if the client is already active and the requested date is also invalid.

Add validator tests for the specific errors returned and service tests that verify downstream work is skipped when validation fails. The entity test also verifies that a rejected second activation preserves the original fields and that the error uses the requested date format.

The existing mismatch between the reopen-date comparison and its error code and message is preserved for a separate follow-up. Non-person client validation is handled separately in #7064.

JIRA: FINERACT-3171

Verification

  • Before the review fixes, all 31 focused unit tests passed across the three test classes exercised at that stage.
  • After the review fixes, all 28 focused unit tests passed across ClientActivationTest, ClientDataValidatorTest, and ClientLifecycleWritePlatformServiceTest.
  • Fineract's Spotless Java formatter completed on the changed files with no Java changes to commit.
  • An earlier local provider Cucumber run stopped during Spring context setup.
  • GitHub CI passed on the revision reviewed by Imlaka. See the Checks tab for results on the latest revision.

Checklist

  • The signed commits follow the commit and PR title guidelines.
  • I understand that I’m responsible for getting the build green before review.
  • Added and updated unit tests to verify the changes.
  • Followed the project’s coding conventions and verified formatting with Spotless.
  • Swagger and legacy API documentation updates are not applicable because this refactor preserves the API contract.
  • The PR is scoped to client validation and its tests.
  • If this PR resolves the JIRA issue, I will mark it resolved and set the appropriate Fix Version/s.
  • I followed the AI Policy. The implementation and review-fix commits include Assisted-By: OpenAI-Codex-GPT-6.2-Sol.

Move the existing name, date, and activation checks out of the Client entity and call them from the write services. Cover validation errors and the side effects skipped on failure.

Assisted-By: OpenAI-Codex-GPT-6.2-Sol
@ImalkaPerera

Copy link
Copy Markdown
Contributor

Thanks @Joab-SC, looks good to me. I compared the moved checks with what was removed from Client and they're the same (codes, messages, order), and each of instance(), activate() and validateUpdate() has only one caller, which now calls the validator in the same spot. Nice that the service tests check nothing gets saved on failure.

A few small things, nothing blocking:

  • In validateClientActivationRejectsAlreadyActiveClient you only check the code. The formatter matters because the date goes into the error args, but with ISO_LOCAL_DATE it looks the same as the default. Maybe use dd/MM/yyyy and check for "09/01/2026"?
  • FINERACT-3171: Move ClientNonPerson creation validation #7064 adds tests at the same place in ClientDataValidatorTest, so one of the two will need a small rebase.
  • The ticket says to validate before the entity changes. Activation still validates after client.activate(...). Same result because of the rollback, so up to you.
  • The description still says CI is pending, it's green now. Might also be worth mentioning FINERACT-3171: Move ClientNonPerson creation validation #7064 / the Group follow-up. And since the reopen-date check compares against the activation date but its error code and message talk about submittedOnDate, maybe open a small JIRA ticket for that follow-up and link it, so it doesn't get lost.

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

Thanks @Joab-SC. The request checks keep their codes, messages, parameters and order, and they run at the same points as before, so the API behaviour is unchanged. One change goes beyond the ticket, though:

  • The "already active" guard should stay in Client.activate. FINERACT-3171 says to move request validation out but "keep invariant checks that protect the entity's own state in the entity". "Cannot activate an already active client" is exactly that kind of check. Without it, Client.activate silently re-activates an active client and overwrites activationDate, activatedBy and officeJoiningDate. FINERACT-3169 did the same split for SavingsAccount (requirePendingApproval stayed in the entity). Please keep that check in Client.activate (as before, or as a small requireNotActive(...) method on Client) and move only the name and date checks to ClientDataValidator.

Optional:

  • The ticket says to validate "before it changes the entity". For activation this is easy: the only checked value that activate changes is activationDate, which you already have. So validateClient(...) can run before client.activate(...) with activationDate passed in (inline). ImalkaPerera raised this too.
  • validateClientActivationRejectsAlreadyActiveClient: if the check stays in the validator, use a non-ISO pattern (e.g. dd/MM/yyyy) and assert the formatted value, so the test proves the formatter is used.
  • #7064 adds tests at the same place in ClientDataValidatorTest, so whichever PR lands second needs a small rebase.

@Joab-SC

Joab-SC commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Adam and Imlaka. I restored the already-active guard in Client.activate(...) and moved request validation ahead of the state change. The service still reports the already-active error first if both checks would fail. The entity test verifies that a second activation preserves the original fields and that the error carries the requested date formatted as 09/01/2026. All 28 focused tests passed across the three affected test classes, and Spotless passed.

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

Thanks @Joab-SC, all points from my earlier review are addressed. The already-active guard stays in the entity as requireNotActive, and request validation now runs before client.activate(...). The moved checks are identical to the removed entity code and run at the same points for create, update and activate, so error codes, messages, parameters, order and the already-active precedence are unchanged. CI is green; the one E2E failure was an unrelated random short-name collision in a working capital scenario and passed on re-run. Follow-ups worth a ticket: the reopen-date rule's code/message mismatch and the shape of the already-active error. Note that #7064 adds the same ClientCreateUpdateWritePlatformServiceTest file, so it will need a rebase after this lands.

@adamsaghy
adamsaghy merged commit f8cb9dd into apache:develop Dec 6, 2026
186 of 187 checks passed
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