FINERACT-2021: migrate fund resource to MVC
Description
Initial PR on FINERACT-2021 Migrated Fund resource.
Type-safe
- Each endpoint in Fund receives and returns a specific class instead of json.
- To keep the type-safe request until it reaches the target service, I added classes that mirror JsonCommand/Wrapper functionality but instead of json and JsonElement have the type-safe request.
- For this reason, I had to duplicate some services so that they could use these new classes.
- However, some of the classes that I duplicated, such as SynchronousCommandProcessingService have a lot of code that relies on JsonCommand/Wrapper. I didn't want to completely rewrite it and create even more duplicate classes just for the sake of it. That's why the new classes that mirror JsonCommand/Wrapper temporarily have JsonCommand/Wrapper inside. I can rewrite all the other classes completely in future PRs. However, the end classes like FundWritePlatformService only use my new class.
Errors
- All MVC errors are managed by SpringErrorHandler. To map to the correct response, it uses the existing jakarta ExceptionMapper and findMostSpecificExceptionHandler method. It also handles UnsupportedParameter errors that are thrown by Jackson failOnUnknownProperties(true).
- I migrated from manual validation to Spring's. To make the validation error response exactly as it was, I created ValidationErrorConverter to correctly map the message and the messageCode.
Features
- I migrated the partial parameter response (JacksonPartialResponseFilter).
- I didn't implement the prettyPrint flag. Currently the response is always pretty printed.
- The partial resource update looks a bit strange as it uses Optional, but I haven't found another way to implement it.
MVC
- To run the server in MVC mode, you need to add the "mvc" profile.
- Any bean classes I added or duplicated will only be initialized if the application has the "mvc" profile.
- To route requests to MVC, I created MvcRoutingFilter. If Spring can handle the request, it routes it to the Spring dispatcher.
Tests
- The integration tests will work in MVC if you run the cargo with the "mvc" profile.
Note
To work as the original classes, all duplicate classes must be up to date with the original. Classes that I had to duplicate completely or to some extent in order to be able to use a type-safe API:
ApiRequestParameterHelper
CommandHandlerProvider
CommandProcessingService
SynchronousCommandProcessingService
CommandWrapper (CommandTypeWrapper)
CommandWrapperBuilder (CommandTypeWrapperBuilder)
JsonCommand (TypeCommand)
JacksonConverterConfig
PlatformSecurityContext
SpringSecurityPlatformSecurityContext
NewCommandSourceHandler (NewCommandSourceHandlerType)
FundsApiResource
FundsApiResourceSwagger
CreateFundCommandHandler
UpdateFundCommandHandler
FundWritePlatformService
FundWritePlatformServiceJpaRepositoryImpl
FundConfiguration
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
-
[x] Write the commit message as per https://github.com/apache/fineract/#pull-requests
-
[x] 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.
-
[x] Create/update unit or integration tests for verifying the changes made.
-
[x] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
-
[x] 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
-
[x] Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)
FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
Let's talk first...
This is part of a GSoC project and needs some more discussions (and documentation) before any solution will be accepted. Closing for now.