Skip to content

Commit

Permalink
FINERACT-1971: Minor bug-fixes and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-jankovics authored and adamsaghy committed Sep 28, 2023
1 parent 3f088e9 commit f7f41d3
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ private static void init() {
commandStrategies.put(
CommandContext.resource("v1\\/loans\\/" + NUMBER_REGEX + "\\/transactions\\/" + NUMBER_REGEX + OPTIONAL_COMMAND_PARAM_REGEX)
.method(POST).build(),
"adjustTransactionCommandStrategy");
"adjustLoanTransactionCommandStrategy");
commandStrategies.put(
CommandContext.resource("v1\\/loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/transactions\\/external-id\\/"
+ UUID_PARAM_REGEX + OPTIONAL_COMMAND_PARAM_REGEX).method(POST).build(),
"adjustTransactionByExternalIdCommandStrategy");
"adjustLoanTransactionByExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("v1\\/clients\\/" + NUMBER_REGEX + "\\?command=activate").method(POST).build(),
"activateClientCommandStrategy");
commandStrategies.put(CommandContext.resource("v1\\/loans\\/" + NUMBER_REGEX + "\\?command=approve").method(POST).build(),
Expand All @@ -196,9 +196,11 @@ private static void init() {
"approveLoanRescheduleCommandStrategy");
commandStrategies.put(
CommandContext.resource("v1\\/loans\\/" + NUMBER_REGEX + "\\/transactions\\/" + NUMBER_REGEX).method(GET).build(),
"getTransactionByIdCommandStrategy");
commandStrategies.put(CommandContext.resource("v1\\/loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/transactions\\/external-id\\/"
+ UUID_PARAM_REGEX + OPTIONAL_QUERY_PARAM_REGEX).method(GET).build(), "getTransactionByExternalIdCommandStrategy");
"getLoanTransactionByIdCommandStrategy");
commandStrategies.put(
CommandContext.resource("v1\\/loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/transactions\\/external-id\\/"
+ UUID_PARAM_REGEX + OPTIONAL_QUERY_PARAM_REGEX).method(GET).build(),
"getLoanTransactionByExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("v1\\/datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/" + NUMBER_REGEX)
.method(POST).build(), "createDatatableEntryCommandStrategy");
commandStrategies.put(CommandContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.fineract.batch.command.internal;

import static org.apache.http.HttpStatus.SC_NOT_IMPLEMENTED;

import jakarta.ws.rs.core.UriInfo;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
Expand All @@ -35,15 +37,8 @@ public class UnknownCommandStrategy implements CommandStrategy {

@Override
public BatchResponse execute(BatchRequest batchRequest, @SuppressWarnings("unused") UriInfo uriInfo) {

final BatchResponse batchResponse = new BatchResponse();

batchResponse.setRequestId(batchRequest.getRequestId());
batchResponse.setStatusCode(501);
batchResponse.setBody("Resource with method " + batchRequest.getMethod() + " and relativeUrl " + batchRequest.getRelativeUrl()
+ " doesn't exist");

return batchResponse;
return new BatchResponse().setRequestId(batchRequest.getRequestId()).setStatusCode(SC_NOT_IMPLEMENTED)
.setBody("Resource with method " + batchRequest.getMethod() + " and relativeUrl " + batchRequest.getRelativeUrl()
+ " doesn't exist");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public CommandProcessingResultBuilder withCreditReport(final Map<String, Object>
}

public CommandProcessingResultBuilder setRollbackTransaction(final boolean rollbackTransaction) {
this.rollbackTransaction = this.rollbackTransaction || rollbackTransaction;
this.rollbackTransaction |= rollbackTransaction;
return this;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import jakarta.persistence.Table;
import java.time.LocalDate;
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.staff.domain.Staff;

@Entity
Expand Down Expand Up @@ -72,16 +73,16 @@ public void updateEndDate(final LocalDate endDate) {
this.endDate = endDate;
}

public boolean matchesStartDateOf(final LocalDate matchingDate) {
return getStartDate().isEqual(matchingDate);
}

public LocalDate getStartDate() {
return this.startDate;
}

public boolean hasStartDateBefore(final LocalDate matchingDate) {
return matchingDate.isBefore(getStartDate());
public boolean matchesStartDateOf(final LocalDate matchingDate) {
return DateUtils.isEqual(matchingDate, getStartDate());
}

public boolean isBeforeStartDate(final LocalDate matchingDate) {
return DateUtils.isBefore(matchingDate, getStartDate());
}

public boolean isCurrentRecord() {
Expand All @@ -95,7 +96,7 @@ public boolean isCurrentRecord() {
* @return
*/
public boolean isEndDateAfter(final LocalDate compareDate) {
return this.endDate.isAfter(compareDate);
return DateUtils.isAfter(this.endDate, compareDate);
}

public LocalDate getEndDate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.Set;
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.organisation.monetary.domain.Money;
import org.apache.fineract.portfolio.repaymentwithpostdatedchecks.domain.PostDatedChecks;
Expand Down Expand Up @@ -625,7 +626,7 @@ public Money writeOffOutstandingPenaltyCharges(final LocalDate transactionDate,
}

public boolean isOverdueOn(final LocalDate date) {
return getDueDate().isBefore(date);
return DateUtils.isAfter(date, getDueDate());
}

public void updateChargePortion(final Money feeChargesDue, final Money feeChargesWaived, final Money feeChargesWrittenOff,
Expand Down Expand Up @@ -665,11 +666,11 @@ private Money asMoney(final BigDecimal decimal, final MonetaryCurrency currency)
}

private boolean isInAdvance(final LocalDate transactionDate) {
return transactionDate.isBefore(getDueDate());
return DateUtils.isBefore(transactionDate, getDueDate());
}

private boolean isLatePayment(final LocalDate transactionDate) {
return transactionDate.isAfter(getDueDate());
return DateUtils.isAfter(transactionDate, getDueDate());
}

private void checkIfRepaymentPeriodObligationsAreMet(final LocalDate transactionDate, final MonetaryCurrency currency) {
Expand Down Expand Up @@ -928,6 +929,11 @@ public boolean isFirstPeriod() {
return (this.installmentNumber == 1);
}

public boolean isInPeriod(LocalDate date) {
return (isFirstPeriod() ? !DateUtils.isBefore(date, getFromDate()) : DateUtils.isAfter(date, getFromDate()))
&& !DateUtils.isAfter(date, getDueDate());
}

public Set<LoanTransactionToRepaymentScheduleMapping> getLoanTransactionToRepaymentScheduleMappings() {
return this.loanTransactionToRepaymentScheduleMappings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
@Component
@RequiredArgsConstructor
public class AdjustTransactionByExternalIdCommandStrategy implements CommandStrategy {
public class AdjustLoanTransactionByExternalIdCommandStrategy implements CommandStrategy {

/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
@Component
@RequiredArgsConstructor
public class AdjustTransactionCommandStrategy implements CommandStrategy {
public class AdjustLoanTransactionCommandStrategy implements CommandStrategy {

/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
@Component
@RequiredArgsConstructor
public class GetTransactionByExternalIdCommandStrategy implements CommandStrategy {
public class GetLoanTransactionByExternalIdCommandStrategy implements CommandStrategy {

/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
@Component
@RequiredArgsConstructor
public class GetTransactionByIdCommandStrategy implements CommandStrategy {
public class GetLoanTransactionByIdCommandStrategy implements CommandStrategy {

/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.savings.DepositAccountOnClosureType;
import org.apache.fineract.portfolio.savings.SavingsPeriodFrequencyType;
import org.apache.fineract.portfolio.savings.service.SavingsEnumerations;
Expand Down Expand Up @@ -315,11 +316,7 @@ public boolean isTransferInterestToLinkedAccount() {
}

public boolean isAfterExpectedFirstDepositDate(final LocalDate compareDate) {
boolean isAfterExpectedFirstDepositDate = false;
if (this.expectedFirstDepositOnDate != null) {
isAfterExpectedFirstDepositDate = compareDate.isAfter(getExpectedFirstDepositOnDate());
}
return isAfterExpectedFirstDepositDate;
return this.expectedFirstDepositOnDate != null && DateUtils.isAfter(compareDate, getExpectedFirstDepositOnDate());
}

public Integer getOnAccountClosureType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
@Transactional
@Override
public CommandProcessingResult activateFDAccount(final Long savingsId, final JsonCommand command) {

final AppUser user = this.context.authenticatedUser();

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
Expand Down Expand Up @@ -621,7 +620,6 @@ public CommandProcessingResult adjustFDTransaction(final Long savingsId, @Suppre

@Override
public CommandProcessingResult adjustRDTransaction(final Long savingsId, final Long transactionId, final JsonCommand command) {

AppUser user = getAppUserIfPresent();

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
Expand Down Expand Up @@ -894,7 +892,6 @@ public CommandProcessingResult prematureCloseRDAccount(final Long savingsId, fin
@Override
public SavingsAccountTransaction initiateSavingsTransfer(final Long accountId, final LocalDate transferDate,
final DepositAccountType depositAccountType) {

AppUser user = getAppUserIfPresent();
final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
.isSavingsInterestPostingAtCurrentPeriodEnd();
Expand Down Expand Up @@ -927,7 +924,6 @@ public SavingsAccountTransaction initiateSavingsTransfer(final Long accountId, f
@Override
public SavingsAccountTransaction withdrawSavingsTransfer(final Long accountId, final LocalDate transferDate,
final DepositAccountType depositAccountType) {

AppUser user = getAppUserIfPresent();

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
Expand Down Expand Up @@ -969,7 +965,6 @@ public void rejectSavingsTransfer(final Long accountId, final DepositAccountType
@Override
public SavingsAccountTransaction acceptSavingsTransfer(final Long accountId, final LocalDate transferDate,
final Office acceptedInOffice, final Staff fieldOfficer, final DepositAccountType depositAccountType) {

AppUser user = getAppUserIfPresent();

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
Expand Down Expand Up @@ -1125,7 +1120,6 @@ public CommandProcessingResult updateSavingsAccountCharge(final JsonCommand comm
@Override
public CommandProcessingResult waiveCharge(final Long savingsAccountId, final Long savingsAccountChargeId,
@SuppressWarnings("unused") final DepositAccountType depositAccountType) {

AppUser user = getAppUserIfPresent();

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
Expand Down Expand Up @@ -1261,7 +1255,6 @@ public void applyChargeDue(final Long savingsAccountChargeId, final Long account
.findOneWithNotFoundDetection(savingsAccountChargeId, accountId);

final DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd MM yyyy");

while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate())) {
payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt);
}
Expand All @@ -1270,7 +1263,6 @@ public void applyChargeDue(final Long savingsAccountChargeId, final Long account
@Transactional
private void payCharge(final SavingsAccountCharge savingsAccountCharge, final LocalDate transactionDate, final BigDecimal amountPaid,
final DateTimeFormatter formatter) {

AppUser user = getAppUserIfPresent();

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
Expand Down Expand Up @@ -1314,7 +1306,6 @@ private void payCharge(final SavingsAccountCharge savingsAccountCharge, final Lo
@Transactional
@Override
public void updateMaturityDetails(Long depositAccountId, DepositAccountType depositAccountType) {

final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
.isSavingsInterestPostingAtCurrentPeriodEnd();
final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.apache.fineract.batch.command.internal.ActivateClientCommandStrategy;
import org.apache.fineract.batch.command.internal.AdjustChargeByChargeExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.AdjustChargeCommandStrategy;
import org.apache.fineract.batch.command.internal.AdjustTransactionByExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.AdjustTransactionCommandStrategy;
import org.apache.fineract.batch.command.internal.AdjustLoanTransactionByExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.AdjustLoanTransactionCommandStrategy;
import org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy;
import org.apache.fineract.batch.command.internal.ApplySavingsCommandStrategy;
import org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy;
Expand All @@ -50,8 +50,8 @@
import org.apache.fineract.batch.command.internal.GetDatatableEntryByQueryCommandStrategy;
import org.apache.fineract.batch.command.internal.GetLoanByExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.GetLoanByIdCommandStrategy;
import org.apache.fineract.batch.command.internal.GetTransactionByExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.GetTransactionByIdCommandStrategy;
import org.apache.fineract.batch.command.internal.GetLoanTransactionByExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.GetLoanTransactionByIdCommandStrategy;
import org.apache.fineract.batch.command.internal.LoanStateTransistionsByExternalIdCommandStrategy;
import org.apache.fineract.batch.command.internal.ModifyLoanApplicationCommandStrategy;
import org.apache.fineract.batch.command.internal.UnknownCommandStrategy;
Expand Down Expand Up @@ -140,18 +140,18 @@ private static Stream<Arguments> provideCommandStrategies() {
mock(CreateTransactionLoanCommandStrategy.class)),
Arguments.of("loans/123/transactions?command=chargeRefund", HttpMethod.POST, "createTransactionLoanCommandStrategy",
mock(CreateTransactionLoanCommandStrategy.class)),
Arguments.of("loans/123/transactions/123", HttpMethod.POST, "adjustTransactionCommandStrategy",
mock(AdjustTransactionCommandStrategy.class)),
Arguments.of("loans/123/transactions/123?command=chargeback", HttpMethod.POST, "adjustTransactionCommandStrategy",
mock(AdjustTransactionCommandStrategy.class)),
Arguments.of("loans/123/transactions/123", HttpMethod.POST, "adjustLoanTransactionCommandStrategy",
mock(AdjustLoanTransactionCommandStrategy.class)),
Arguments.of("loans/123/transactions/123?command=chargeback", HttpMethod.POST, "adjustLoanTransactionCommandStrategy",
mock(AdjustLoanTransactionCommandStrategy.class)),
Arguments.of(
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions/external-id/7dfad438-2319-48ce-8520-10a62801e9ab",
HttpMethod.POST, "adjustTransactionByExternalIdCommandStrategy",
mock(AdjustTransactionByExternalIdCommandStrategy.class)),
HttpMethod.POST, "adjustLoanTransactionByExternalIdCommandStrategy",
mock(AdjustLoanTransactionByExternalIdCommandStrategy.class)),
Arguments.of(
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions/external-id/7dfad438-2319-48ce-8520-10a62801e9ab?command=chargeback",
HttpMethod.POST, "adjustTransactionByExternalIdCommandStrategy",
mock(AdjustTransactionByExternalIdCommandStrategy.class)),
HttpMethod.POST, "adjustLoanTransactionByExternalIdCommandStrategy",
mock(AdjustLoanTransactionByExternalIdCommandStrategy.class)),
Arguments.of("clients/456?command=activate", HttpMethod.POST, "activateClientCommandStrategy",
mock(ActivateClientCommandStrategy.class)),
Arguments.of("loans/123?command=approve", HttpMethod.POST, "approveLoanCommandStrategy",
Expand All @@ -166,11 +166,12 @@ private static Stream<Arguments> provideCommandStrategies() {
mock(CreateLoanRescheduleRequestCommandStrategy.class)),
Arguments.of("rescheduleloans/123?command=approve", HttpMethod.POST, "approveLoanRescheduleCommandStrategy",
mock(ApproveLoanRescheduleCommandStrategy.class)),
Arguments.of("loans/123/transactions/123", HttpMethod.GET, "getTransactionByIdCommandStrategy",
mock(GetTransactionByIdCommandStrategy.class)),
Arguments.of("loans/123/transactions/123", HttpMethod.GET, "getLoanTransactionByIdCommandStrategy",
mock(GetLoanTransactionByIdCommandStrategy.class)),
Arguments.of(
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions/external-id/7dfad438-2319-48ce-8520-10a62801e9ab?fields=id",
HttpMethod.GET, "getTransactionByExternalIdCommandStrategy", mock(GetTransactionByExternalIdCommandStrategy.class)),
HttpMethod.GET, "getLoanTransactionByExternalIdCommandStrategy",
mock(GetLoanTransactionByExternalIdCommandStrategy.class)),
Arguments.of("datatables/test_dt_table/123", HttpMethod.GET, "getDatatableEntryByAppTableIdCommandStrategy",
mock(GetDatatableEntryByAppTableIdCommandStrategy.class)),
Arguments.of("datatables/test_dt_table/123?genericResultSet=true", HttpMethod.GET,
Expand Down
Loading

0 comments on commit f7f41d3

Please sign in to comment.