Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-2081: introduce builder pattern to Note entity instantiation. #4071

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 @@ 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();

this.noteRepository.save(note);
}

Expand Down Expand Up @@ -549,7 +573,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 +670,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 +722,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 +820,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
Loading