Skip to content

Conversation

@adamsaghy
Copy link
Contributor

@adamsaghy adamsaghy commented May 29, 2024

Added further refactor that shared by @kjozsa! Thank you for it! ;)

The submit / modify loan application feature implementation contains various validations and conditions to decide on what logic to be executed based on the provided configuration.

The validations and conditions got mixed a little bit and now it is hard to understand what is happening and why.

The job here was to refactor a little bit an d group the validations and logics to be executed together and extract the business logic into methods to separate them a little bit.

The rule of thumb was

  • Validations
    - Data validations
    - Domain rule validations (sometimes it is only after entity was assembled)
  • Assembling (from the json command → entity / data objects)
    - Assemble the entity
    - Some actions on the entity to be extracted into utility classes or service classes
    - Move some of the logic from service into here if make sense
    - Update product related details
    - New assemblers
    - collateral
    - charges
    - etc
  • Actions on the loans
    - Generate schedule
    - Notes
    - GLIM
    - Calendar

Description

Describe the changes made and why they were made.

Ignore if these details are present on the associated Apache Fineract JIRA ticket.

Checklist

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

  • Write the commit message as per https://github.com/apache/fineract/#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 for verifying the changes made.

  • Follow coding conventions at 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

  • 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.

@adamsaghy adamsaghy force-pushed the FINERACT-2090/restructure_loan_submit_modify branch 6 times, most recently from 3fca516 to 3dd9e81 Compare May 31, 2024 10:57
@adamsaghy adamsaghy requested review from taskain7 and vidakovic May 31, 2024 11:13
if (command.has(LoanApiConstants.disbursementDataParameterName)) {
final JsonArray disbursementDataArray = command.getAsJsonArray(LoanApiConstants.disbursementDataParameterName);
if (disbursementDataArray != null && !disbursementDataArray.isEmpty()) {
int i = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

@adamsaghy I made an attempt to improve this code slightly further.

Please check my commit at d544a35 and tell me if you wish to have a PR of this version.

Copy link
Contributor Author

@adamsaghy adamsaghy Jun 6, 2024

Choose a reason for hiding this comment

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

Yes, LGTM. I am happy to add your changes as part of this PR.

@adamsaghy adamsaghy force-pushed the FINERACT-2090/restructure_loan_submit_modify branch from 3dd9e81 to 5fc956e Compare June 6, 2024 15:10
@adamsaghy adamsaghy requested a review from kjozsa June 6, 2024 15:22
@adamsaghy
Copy link
Contributor Author

@taskain7 @vidakovic @kjozsa @ruchiD @alberto-art3ch Please as your time lets you give me a review. I know this is a monster PR, but it was unfortunately required to have a clearer restructure...

Copy link
Contributor

Choose a reason for hiding this comment

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

... minor: technically needs this

@Serial
private static final long serialVersionUID = 1L;

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! Mapstruct... I think you could get away without a default function implementation and just provide:

Set<LoanChargeCommand> map(Set<LoanCharge> loanCharge, MonetaryCurrency currency);

I think Mapstruct is smart enough to create automatically a for loop and use the single value implementation on each element; with just the parameter "loanCharge" I'd be 100% sure, with the additional currency parameter I'd say 90%.

Minor issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting the following exception:

error: The return type Set<LoanChargeCommand> is an abstract class or interface. Provide a non abstract / non interface result type or a factory method.
     Set<LoanChargeCommand> map(Set<LoanCharge> loanCharge, MonetaryCurrency currency);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If i changed to return HashSet, it generated a dummy method:

    @Override
    public HashSet<LoanChargeCommand> map(Set<LoanCharge> loanCharge, MonetaryCurrency currency) {
        if ( loanCharge == null && currency == null ) {
            return null;
        }

        HashSet<LoanChargeCommand> hashSet = new HashSet<LoanChargeCommand>();

        return hashSet;
    }

Copy link
Contributor

@vidakovic vidakovic left a comment

Choose a reason for hiding this comment

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

LGTM

@adamsaghy adamsaghy force-pushed the FINERACT-2090/restructure_loan_submit_modify branch from 5fc956e to d1f0cd1 Compare June 6, 2024 17:07
@adamsaghy adamsaghy merged commit 92e291a into apache:develop Jun 6, 2024
Copy link
Contributor

@alberto-art3ch alberto-art3ch left a comment

Choose a reason for hiding this comment

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

In genral LGTM, Thanks!

@adamsaghy adamsaghy deleted the FINERACT-2090/restructure_loan_submit_modify branch June 8, 2024 06:40
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.

4 participants