Skip to content

Commit

Permalink
FINERACT-2081: introduce builder pattern to Note entity instantiation.
Browse files Browse the repository at this point in the history
- Removed all redundant static instantiation methods and constructors from `Note.java`.
- Used Builder pattern to make it easy to instantiate the Note object.
- Changed all instantiation places to use the new implementation.
  • Loading branch information
Zeyad2003 committed Oct 1, 2024
1 parent 2d0c8db commit 6960c09
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Getter;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;

@Getter
public enum NoteType {

CLIENT(100, "noteType.client", "clients", "Client note"), //
Expand Down Expand Up @@ -51,22 +53,6 @@ public enum NoteType {
this.description = description;
}

public Integer getValue() {
return this.value;
}

public String getCode() {
return this.code;
}

public String getApiUrl() {
return this.apiUrl;
}

public String getDescription() {
return description;
}

public static NoteType fromInt(int i) {
return BY_ID.get(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException;
import org.apache.fineract.portfolio.note.domain.Note;
import org.apache.fineract.portfolio.note.domain.NoteRepository;
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
import org.apache.fineract.portfolio.paymenttype.domain.PaymentType;
import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepository;
Expand Down Expand Up @@ -465,7 +466,16 @@ public InteropTransferResponseData commitTransfer(@NotNull JsonCommand command)

String note = request.getNote();
if (!StringUtils.isBlank(note)) {
noteRepository.save(Note.savingsTransactionNote(savingsAccount, transaction, note));

Note noteEntity = Note.builder() //
.savingsAccount(savingsAccount) //
.client(savingsAccount.getClient()) //
.savingsTransaction(transaction) //
.noteTypeId(NoteType.SAVINGS_TRANSACTION.getValue()) //
.note(note) //
.build();

noteRepository.save(noteEntity);
}

return InteropTransferResponseData.build(command.commandId(), request.getTransactionCode(), InteropActionState.ACCEPTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.apache.fineract.portfolio.loanaccount.service.ReplayedTransactionBusinessEventService;
import org.apache.fineract.portfolio.note.domain.Note;
import org.apache.fineract.portfolio.note.domain.NoteRepository;
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
import org.apache.fineract.portfolio.repaymentwithpostdatedchecks.data.PostDatedChecksStatus;
import org.apache.fineract.portfolio.repaymentwithpostdatedchecks.domain.PostDatedChecks;
Expand Down Expand Up @@ -226,7 +227,15 @@ public LoanTransaction makeRepayment(final LoanTransactionType repaymentTransact
loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanTransactionNote(loan, newRepaymentTransaction, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.loanTransaction(newRepaymentTransaction) //
.noteTypeId(NoteType.LOAN_TRANSACTION.getValue()) //
.note(noteText) //
.build();

this.noteRepository.save(note);
}

Expand Down Expand Up @@ -413,7 +422,15 @@ public LoanTransaction makeChargePayment(final Loan loan, final Long chargeId, f
saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanTransactionNote(loan, newPaymentTransaction, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.loanTransaction(newPaymentTransaction) //
.noteTypeId(NoteType.LOAN_TRANSACTION.getValue()) //
.note(noteText) //
.build();

this.noteRepository.save(note);
}

Expand Down Expand Up @@ -500,7 +517,15 @@ public LoanTransaction makeRefund(final Long accountId, final CommandProcessingR
this.loanRepositoryWrapper.saveAndFlush(loan);

if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanTransactionNote(loan, newRefundTransaction, noteText);
final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.loanTransaction(newRefundTransaction) //
.noteTypeId(NoteType.LOAN_TRANSACTION.getValue()) //
.note(noteText) //
.build();

// NoteFactory.createLoanTransactionNote(loan, newRefundTransaction, noteText);
this.noteRepository.save(note);
}

Expand Down Expand Up @@ -549,7 +574,15 @@ public LoanTransaction makeDisburseTransaction(final Long loanId, final LocalDat
saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanTransactionNote(loan, disbursementTransaction, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.loanTransaction(disbursementTransaction) //
.noteTypeId(NoteType.LOAN_TRANSACTION.getValue()) //
.note(noteText) //
.build();

this.noteRepository.save(note);
}

Expand Down Expand Up @@ -638,7 +671,15 @@ public LoanTransaction creditBalanceRefund(final Loan loan, final LocalDate tran
newCreditBalanceRefundTransaction = this.loanTransactionRepository.saveAndFlush(newCreditBalanceRefundTransaction);

if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanTransactionNote(loan, newCreditBalanceRefundTransaction, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.loanTransaction(newCreditBalanceRefundTransaction) //
.noteTypeId(NoteType.LOAN_TRANSACTION.getValue()) //
.note(noteText) //
.build();

this.noteRepository.save(note);
}

Expand Down Expand Up @@ -682,7 +723,15 @@ public LoanTransaction makeRefundForActiveLoan(Long accountId, CommandProcessing
this.loanTransactionRepository.saveAndFlush(newRefundTransaction);

if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanTransactionNote(loan, newRefundTransaction, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.loanTransaction(newRefundTransaction) //
.noteTypeId(NoteType.LOAN_TRANSACTION.getValue()) //
.note(noteText) //
.build();

this.noteRepository.save(note);
}

Expand Down Expand Up @@ -772,7 +821,14 @@ public LoanTransaction foreCloseLoan(Loan loan, final LocalDate foreClosureDate,

if (StringUtils.isNotBlank(noteText)) {
changes.put("note", noteText);
final Note note = Note.loanNote(loan, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.noteTypeId(NoteType.LOAN.getValue()) //
.note(noteText) //
.build();

this.noteRepository.save(note);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.apache.fineract.portfolio.loanproduct.domain.RecalculationFrequencyType;
import org.apache.fineract.portfolio.note.domain.Note;
import org.apache.fineract.portfolio.note.domain.NoteRepository;
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.savings.data.GroupSavingsIndividualMonitoringAccountData;
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
Expand Down Expand Up @@ -841,7 +842,14 @@ private void createCalendar(JsonCommand command, Loan loan) {

private Optional<Note> createNote(String submittedOnNote, Loan newLoanApplication) {
if (StringUtils.isNotBlank(submittedOnNote)) {
final Note note = Note.loanNote(newLoanApplication, submittedOnNote);

final Note note = Note.builder() //
.loan(newLoanApplication) //
.client(newLoanApplication.client()) //
.noteTypeId(NoteType.LOAN.getValue()) //
.note(submittedOnNote) //
.build();

this.noteRepository.save(note);
return Optional.of(note);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
import org.apache.fineract.portfolio.loanproduct.exception.LinkedAccountRequiredException;
import org.apache.fineract.portfolio.note.domain.Note;
import org.apache.fineract.portfolio.note.domain.NoteRepository;
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
Expand Down Expand Up @@ -736,7 +737,14 @@ public CommandProcessingResult adjustmentForLoanCharge(Long loanId, Long loanCha

final String noteText = command.stringValueOfParameterNamed("note");
if (StringUtils.isNotBlank(noteText)) {
final Note note = Note.loanNote(loan, noteText);

final Note note = Note.builder() //
.loan(loan) //
.client(loan.client()) //
.noteTypeId(NoteType.LOAN.getValue()) //
.note(noteText) //
.build();

changes.put("note", noteText);
this.noteRepository.save(note);
}
Expand Down
Loading

0 comments on commit 6960c09

Please sign in to comment.