Skip to content

Conversation

@Monica-CodingWorld
Copy link
Contributor

@Monica-CodingWorld Monica-CodingWorld commented Jan 21, 2026

Description

Modified StandingInstructionDataValidator.java to make amount, interval, recurrence frequency, and on month day fields optional when standing instruction type is "DUES". These fields are automatically picked from the loan repayment schedule for DUES type instructions, so they should not be required during validation.

Changes:

  • CREATE validation: Made amount field .notNull() only for FIXED type; recurrence fields optional for DUES type
  • UPDATE validation: Applied same conditional logic for partial updates; fixed variable scope for standingInstructionType
  • Periodic validation: Moved recurrenceInterval.integerGreaterThanZero() inside if (isPeriodic) block where it belongs

JIRA ticket : https://issues.apache.org/jira/browse/FINERACT-2048

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our coding conventions.
  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Your assigned reviewer(s) will follow our guidelines for code reviews.

.notNull();
baseDataValidator.reset().parameter(StandingInstructionApiConstants.recurrenceFrequencyParamName).value(recurrenceFrequency)
.notNull();
if (standingInstructionType == null || !StandingInstructionType.fromInt(standingInstructionType).isDuesAmoutTransfer()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

standingInstructionType == null || !StandingInstructionType.fromInt(standingInstructionType).isDuesAmoutTransfer()

You are using this logic in repeatedly throughout the code change i think you can extract this into a helper function

baseDataValidator.reset().parameter(StandingInstructionApiConstants.recurrenceFrequencyParamName).value(recurrenceFrequency)
.notNull();
if (standingInstructionType == null || !StandingInstructionType.fromInt(standingInstructionType).isDuesAmoutTransfer()) {
baseDataValidator.reset().parameter(StandingInstructionApiConstants.recurrenceIntervalParamName).value(recurrenceInterval)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a little bit complicated. and if conditions can be merged, also of there is any business rule that is implemented make sure to document that helper function

Business rules should be explicit and self-documenting

while the Github Action is not run here is a pro tip you can run the check on your forked repo and add testcase for more coverage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Aman-Mittal Thank you so much for your guidance and suggestions. I will improve the PR and update shortly.

@Monica-CodingWorld
Copy link
Contributor Author

Hi @Aman-Mittal,
I've addressed all your feedback:

  • Extracted helper methods - isAmountRequired() and isRecurrenceRequired() to eliminate code duplication
  • Added JavaDoc - Explaining business rules clearly
  • Added unit tests - 8 tests covering all scenarios (amount/recurrence requirements for both DUES and FIXED_AMOUNT_TRANSFER types)
    All tests pass locally. Please review the changes. Once you approve, I'll squash the commits into a single clean commit before merging.
    Thank you!

…ng instruction type

- Add isAmountRequired() and isRecurrenceRequired() helper methods
- Replace repetitive conditional patterns
- Add comprehensive JavaDoc
- Add unit tests for validation logic
- Apply Spotless code formatting
Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

StandingInstructionDataValidatorTest is not testing the validator at all.

I looks like auto generated by AI... poorly.. :(

@Aman-Mittal
Copy link
Contributor

@Monica-CodingWorld - Take a look at the ticket and understand usecase first

When standing instruction type selected is "dues", the following fields should be optional since they will be picked from the loan repayment schedule:

amount,
interval,
recurrence frequency,
on month day

Before the requirement im assuming that e2e tests have covered the if all fields have the value (this may be the use case where we are trying to update the loan repayment schedule itself // need to check the code)

Now you can add cases for following scenarios
eg. lets assume user does not pass any of the values then what should happen?
Ans. missing value should be fetched from the loan repayment schedule

Open end questions and things need to be checked (what is the existing implementation can you make sense to a non tech person)

test case 1 -> amount, (inputted)
interval,(blank from user)
recurrence frequency, (blank from user)
on month day , blank from user

test case 2 -> amount, (inputted)
interval,(inputted)
recurrence frequency, (blank from user)
on month day , blank from user

and so on

@adamsaghy Please correct me if i missed something, im just assuming things as example based on what ticket is saying

@Monica-CodingWorld
Copy link
Contributor Author

StandingInstructionDataValidatorTest is not testing the validator at all.

I looks like auto generated by AI... poorly.. :(

Acknowledged - these tests aren't actually exercising validation logic. I'm rewriting them to test constraint violations properly (null checks, boundary values, error messages) rather than just method calls. Will push the updated version shortly.

@Monica-CodingWorld
Copy link
Contributor Author

Monica-CodingWorld commented Jan 27, 2026

@Monica-CodingWorld - Take a look at the ticket and understand usecase first

When standing instruction type selected is "dues", the following fields should be optional since they will be picked from the loan repayment schedule:

amount, interval, recurrence frequency, on month day

Before the requirement im assuming that e2e tests have covered the if all fields have the value (this may be the use case where we are trying to update the loan repayment schedule itself // need to check the code)

Now you can add cases for following scenarios eg. lets assume user does not pass any of the values then what should happen? Ans. missing value should be fetched from the loan repayment schedule

Open end questions and things need to be checked (what is the existing implementation can you make sense to a non tech person)

test case 1 -> amount, (inputted) interval,(blank from user) recurrence frequency, (blank from user) on month day , blank from user

test case 2 -> amount, (inputted) interval,(inputted) recurrence frequency, (blank from user) on month day , blank from user

and so on

@adamsaghy Please correct me if i missed something, im just assuming things as example based on what ticket is saying

Thanks @Aman-Mittal for the detailed scenarios. This is my first unit test, so I want to make sure I understand the requirement correctly before rewriting.
Confirming the logic: When type="dues", if the user provides some of the four fields (amount, interval, recurrence frequency, onMonthDay) but leaves others blank, the system should:

  • Use the user-provided values as-is, and
  • Fetch only the missing values from the loan repayment schedule?
    Or should it be strictly all-or-nothing (either user provides all four, or system fetches all four from schedule)?

Error handling: If the loan repayment schedule doesn't have these values available, should the validator:

  • Fail fast with a validation error here, or
  • Pass through and let downstream service handle the missing data exception?
    I'll check the existing implementation to see if this fallback logic is already in place or needs to be built. Let me know if there's existing test coverage I should reference for the "fetch from schedule" behavior.

@Aman-Mittal
Copy link
Contributor

Aman-Mittal commented Jan 27, 2026 via email

@Monica-CodingWorld
Copy link
Contributor Author

Yes I think it should be like this. Well these things should be updated and clarified in the ticket itself. In case of usecase there can be partial input also. I think based on requirement if user didn't pass these values then fetched from loan repayment schedule. If there is no such field available then we may force user to input. You should also clarify this on ticket too. The orignal reporter and someone who is knowledgeable in functional side can answer you more clearly.

On Tue, 27 Jan, 2026, 7:30 pm Monica, @.> wrote: Monica-CodingWorld left a comment (apache/fineract#5362) <#5362 (comment)> @Monica-CodingWorld https://github.com/Monica-CodingWorld - Take a look at the ticket and understand usecase first When standing instruction type selected is "dues", the following fields should be optional since they will be picked from the loan repayment schedule: amount, interval, recurrence frequency, on month day Before the requirement im assuming that e2e tests have covered the if all fields have the value (this may be the use case where we are trying to update the loan repayment schedule itself // need to check the code) Now you can add cases for following scenarios eg. lets assume user does not pass any of the values then what should happen? Ans. missing value should be fetched from the loan repayment schedule Open end questions and things need to be checked (what is the existing implementation can you make sense to a non tech person) test case 1 -> amount, (inputted) interval,(blank from user) recurrence frequency, (blank from user) on month day , blank from user test case 2 -> amount, (inputted) interval,(inputted) recurrence frequency, (blank from user) on month day , blank from user and so on @adamsaghy https://github.com/adamsaghy Please correct me if i missed something, im just assuming things as example based on what ticket is saying Thanks @Aman-Mittal https://github.com/Aman-Mittal for the detailed scenarios. This is my first unit test, so I want to make sure I understand the requirement correctly before rewriting. Confirming the logic: When type="dues", if the user provides some of the four fields (amount, interval, recurrence frequency, onMonthDay) but leaves others blank, the system should: Use the user-provided values as-is, and Fetch only the missing values from the loan repayment schedule? Or should it be strictly all-or-nothing (either user provides all four, or system fetches all four from schedule)? Error handling: If the loan repayment schedule doesn't have these values available, should the validator: Fail fast with a validation error here, or Pass through and let downstream service handle the missing data exception? I'll check the existing implementation to see if this fallback logic is already in place or needs to be built. Let me know if there's existing test coverage I should reference for the "fetch from schedule" behavior. — Reply to this email directly, view it on GitHub <#5362 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHV6TA67T256D32AMHMMI7L4I5VORAVCNFSM6AAAAACSN7B7YOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQMBVGM3TANRQHA . You are receiving this because you were mentioned.Message ID: @.>

@Aman-Mittal Got it, thanks for the clarification. i'll clarify on ticket as well.

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