Cocoa-Puffs opened a new pull request, #6691:
URL: https://github.com/apache/fineract/pull/6691
## Description
Global configurations whose `stringValue` takes one of a fixed set of values
are now validated against that set on update. The allowed values are defined by
enums and exposed in the API.
### Restricted configurations
| Configuration | Allowed values | Multiple |
|---|---|---|
| `charge-accrual-date` | `due-date`, `submitted-date` | no |
| `next-payment-due-date` | `earliest-unpaid-date`, `next-unpaid-due-date` |
no |
| `wcl-charge-accrual-time` | `eod`, `real-time` | no |
| `outstanding-interest-calculation-strategy-for-external-asset-transfer` |
`TOTAL_OUTSTANDING_INTEREST`, `PAYABLE_OUTSTANDING_INTEREST` | no |
| `account-mapping-for-payment-type` | `Asset`, `Liability`, `Expense` | yes
|
| `account-mapping-for-charge` | `Income`, `Liability`, `Expense` | yes |
| `allowed-loan-statuses-for-external-asset-transfer`,
`allowed-loan-statuses-of-delayed-settlement-for-external-asset-transfer` | any
`LoanStatus` except `INVALID` | yes |
### Changes
- **Registry**: `GlobalConfigurationAllowedValues` (fineract-core) holds one
typed `AllowedValues<E>` entry per restricted configuration: the enum
constants, their canonical spelling, whether a comma-separated list is allowed,
and the default (the value the configuration's changelog inserted). All value
matching happens in this one place.
- **Update validation**: `PUT /configurations/{id}` and
`/configurations/name/{name}` reject a `stringValue` that is not allowed with
`400
validation.msg.globalConfiguration.stringValue.is.not.one.of.expected.enumerations`,
which lists the allowed values. Each bad entry in a list is reported
separately. Generic request validation still runs before the configuration is
looked up, so a malformed request returns 400 before 404.
- **Canonical storage**: matching ignores case and surrounding whitespace,
and duplicate list entries are dropped. The update API stores values in their
canonical spelling (`EOD` → `eod`), so a difference in case alone is not
reported as a change.
- **API**: configuration responses gain `allowedValues` and
`multipleValuesAllowed`. Both are omitted for unrestricted configurations.
- **Typed getters**: `ConfigurationDomainService` returns enums
(`ChargeAccrualDateConfig`, `NextPaymentDueDateConfig`,
`WclChargeAccrualTimeConfig`, `OutstandingInterestStrategyConfig`,
`List<LoanStatus>`). They replace the ad-hoc string comparisons in loan
accruals, delinquency, working-capital charge accruals and external asset
transfer. The account-mapping getters still return the canonical
comma-separated `String`, because it is passed through unchanged to the savings
product and charge template responses.
- **Existing values are not rewritten**:
- A stored value that is blank or not allowed is left in the database and
read as the configuration's default.
- `GlobalConfigurationAllowedValuesStartupCheck` logs a WARN for each such
value, per tenant, after the tenant databases are upgraded. It only reads and
logs, so it never fails startup.
- Values that are allowed but differ in case (e.g. the `EOD` seeded for
`wcl-charge-accrual-time`) are read correctly, and get their canonical spelling
the next time they are updated through the API.
- **Liquibase**: `0261_update_charge_accrual_date_description.xml` corrects
the `charge-accrual-date` description, which still asked for comma-separated
values.
### ⚠️ Behaviour changes for reviewers
Invalid values that are already stored are now **read as the default instead
of failing**, and the only signal is a WARN at startup. Please check the
startup log after upgrading, particularly for the transfer configurations:
| Configuration | Before (invalid stored value) | Now |
|---|---|---|
| `allowed-loan-statuses-*` | a typo (e.g. `ACTIVE,ACTIV`) failed asset
transfers with `IllegalArgumentException` | the whole list is read as the
default: `ACTIVE,TRANSFER_IN_PROGRESS,TRANSFER_ON_HOLD` (plus
`OVERPAID,CLOSED_OBLIGATIONS_MET` for delayed settlement). **This can change
which loans are allowed to transfer.** |
| outstanding-interest strategy | asset transfer failed with a 500 |
`TOTAL_OUTSTANDING_INTEREST` |
| `charge-accrual-date` (working-capital loans) | no charge accruals were
created | accrues on `due-date` |
| `next-payment-due-date` | delinquency returned a `null` next payment date
| `earliest-unpaid-date` |
| account mapping | the raw value was passed through to the template
response | `Asset` / `Income` |
### Adding a restricted configuration
1. Add an `AllowedValues` constant to `GlobalConfigurationAllowedValues` and
list it in `ALL`.
2. Read the value through `resolve` / `resolveAll` instead of parsing the
raw string.
3. Make sure its changelog inserts an allowed value.
`GlobalConfigurationTest.testRestrictedConfigurationsHoldAllowedValues` fails
otherwise.
## Checklist
Please make sure these boxes are checked before submitting your pull request
- thanks!
- [ ] Write the commit message as per [our
guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
- [ ] 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](https://fineract.apache.org/docs/current/#_testing) for verifying the
changes made.
- [ ] Follow our [coding
conventions](https://cwiki.apache.org/confluence/display/FINERACT/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"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit).
Large changes can be made in a branch, with assistance. Ask for help on the
[developer mailing list](https://fineract.apache.org/#contribute).
- [ ] If merging this PR resolves a JIRA issue, I will mark that issue as
resolved and set "Fix Version/s" appropriately.
- [ ] I followed the [AI
Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy).
Your assigned reviewer(s) will follow our [guidelines for code
reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]