Specify query parameters for LoansApi retrieveLoan
This commit is contained in:
committed by
Arnold Gálovics
parent
ba1fddbc51
commit
fb0556c20e
+1
-1
@@ -82,7 +82,7 @@ public class AdHocScheduledJobRunnerServiceImpl implements AdHocScheduledJobRunn
|
|||||||
run = Math.toIntExact(ChronoUnit.YEARS.between(start, end)) >= 1;
|
run = Math.toIntExact(ChronoUnit.YEARS.between(start, end)) >= 1;
|
||||||
break;
|
break;
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
next = start.plusDays((int) (long) adhoc.getReportRunEvery());
|
next = start.plusDays((long) adhoc.getReportRunEvery());
|
||||||
run = Math.toIntExact(ChronoUnit.DAYS.between(start, end)) >= adhoc.getReportRunEvery();
|
run = Math.toIntExact(ChronoUnit.DAYS.between(start, end)) >= adhoc.getReportRunEvery();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
+20
-2
@@ -72,9 +72,10 @@ public class GetLoanByIdCommandStrategy implements CommandStrategy {
|
|||||||
// - Add them to the UriInfo query parameters list
|
// - Add them to the UriInfo query parameters list
|
||||||
// - Call loansApiResource.retrieveLoan(loanId, false, uriInfo)
|
// - Call loansApiResource.retrieveLoan(loanId, false, uriInfo)
|
||||||
// - Remove the relative url query parameters from UriInfo in the finally (after loan details are retrieved)
|
// - Remove the relative url query parameters from UriInfo in the finally (after loan details are retrieved)
|
||||||
|
Map<String, String> queryParameters = null;
|
||||||
if (relativeUrl.indexOf('?') > 0) {
|
if (relativeUrl.indexOf('?') > 0) {
|
||||||
loanId = Long.parseLong(StringUtils.substringBetween(relativeUrl, "/", "?"));
|
loanId = Long.parseLong(StringUtils.substringBetween(relativeUrl, "/", "?"));
|
||||||
Map<String, String> queryParameters = getQueryParameters(relativeUrl);
|
queryParameters = getQueryParameters(relativeUrl);
|
||||||
|
|
||||||
// Add the query parameters sent in the relative URL to UriInfo
|
// Add the query parameters sent in the relative URL to UriInfo
|
||||||
addQueryParametersToUriInfo(parameterizedUriInfo, queryParameters);
|
addQueryParametersToUriInfo(parameterizedUriInfo, queryParameters);
|
||||||
@@ -84,7 +85,24 @@ public class GetLoanByIdCommandStrategy implements CommandStrategy {
|
|||||||
|
|
||||||
// Calls 'retrieveLoan' function from 'LoansApiResource' to
|
// Calls 'retrieveLoan' function from 'LoansApiResource' to
|
||||||
// get the loan details based on the loan id
|
// get the loan details based on the loan id
|
||||||
responseBody = loansApiResource.retrieveLoan(loanId, false, parameterizedUriInfo);
|
final boolean staffInSelectedOfficeOnly = false;
|
||||||
|
String associations = null;
|
||||||
|
String exclude = null;
|
||||||
|
String fields = null;
|
||||||
|
if (queryParameters != null && queryParameters.size() > 0) {
|
||||||
|
if (queryParameters.containsKey("associations")) {
|
||||||
|
associations = queryParameters.get("associations");
|
||||||
|
}
|
||||||
|
if (queryParameters.containsKey("exclude")) {
|
||||||
|
exclude = queryParameters.get("exclude");
|
||||||
|
}
|
||||||
|
if (queryParameters.containsKey("fields")) {
|
||||||
|
fields = queryParameters.get("fields");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody = loansApiResource.retrieveLoan(loanId, staffInSelectedOfficeOnly, associations, exclude, fields,
|
||||||
|
parameterizedUriInfo);
|
||||||
|
|
||||||
response.setStatusCode(HttpStatus.SC_OK);
|
response.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
|
||||||
|
|||||||
+15
-13
@@ -48,11 +48,11 @@ public final class ApiParameterHelper {
|
|||||||
|
|
||||||
public static Set<String> extractFieldsForResponseIfProvided(final MultivaluedMap<String, String> queryParams) {
|
public static Set<String> extractFieldsForResponseIfProvided(final MultivaluedMap<String, String> queryParams) {
|
||||||
Set<String> fields = new HashSet<>();
|
Set<String> fields = new HashSet<>();
|
||||||
String commaSerperatedParameters = "";
|
String commaSeparatedParameters = "";
|
||||||
if (queryParams.getFirst("fields") != null) {
|
if (queryParams.getFirst("fields") != null) {
|
||||||
commaSerperatedParameters = queryParams.getFirst("fields");
|
commaSeparatedParameters = queryParams.getFirst("fields");
|
||||||
if (StringUtils.isNotBlank(commaSerperatedParameters)) {
|
if (StringUtils.isNotBlank(commaSeparatedParameters)) {
|
||||||
fields = new HashSet<>(Arrays.asList(commaSerperatedParameters.split("\\s*,\\s*"))); // NOSONAR
|
fields = new HashSet<>(Arrays.asList(commaSeparatedParameters.split("\\s*,\\s*"))); // NOSONAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fields;
|
return fields;
|
||||||
@@ -60,23 +60,25 @@ public final class ApiParameterHelper {
|
|||||||
|
|
||||||
public static Set<String> extractAssociationsForResponseIfProvided(final MultivaluedMap<String, String> queryParams) {
|
public static Set<String> extractAssociationsForResponseIfProvided(final MultivaluedMap<String, String> queryParams) {
|
||||||
Set<String> fields = new HashSet<>();
|
Set<String> fields = new HashSet<>();
|
||||||
String commaSerperatedParameters = "";
|
String commaSeparatedParameters = "";
|
||||||
if (queryParams.getFirst("associations") != null) {
|
if (queryParams.getFirst("associations") != null) {
|
||||||
commaSerperatedParameters = queryParams.getFirst("associations");
|
commaSeparatedParameters = queryParams.getFirst("associations");
|
||||||
if (StringUtils.isNotBlank(commaSerperatedParameters)) {
|
if (StringUtils.isNotBlank(commaSeparatedParameters)) {
|
||||||
fields = new HashSet<>(Arrays.asList(commaSerperatedParameters.split("\\s*,\\s*"))); // NOSONAR
|
fields = new HashSet<>(Arrays.asList(commaSeparatedParameters.split("\\s*,\\s*"))); // NOSONAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void excludeAssociationsForResponseIfProvided(final String commaSeparatedParameters, Set<String> fields) {
|
||||||
|
if (StringUtils.isNotBlank(commaSeparatedParameters)) {
|
||||||
|
fields.removeAll(new HashSet<>(Arrays.asList(commaSeparatedParameters.split("\\s*,\\s*")))); // NOSONAR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void excludeAssociationsForResponseIfProvided(final MultivaluedMap<String, String> queryParams, Set<String> fields) {
|
public static void excludeAssociationsForResponseIfProvided(final MultivaluedMap<String, String> queryParams, Set<String> fields) {
|
||||||
String commaSerperatedParameters = "";
|
|
||||||
if (queryParams.getFirst("exclude") != null) {
|
if (queryParams.getFirst("exclude") != null) {
|
||||||
commaSerperatedParameters = queryParams.getFirst("exclude");
|
excludeAssociationsForResponseIfProvided(queryParams.getFirst("exclude"), fields);
|
||||||
if (StringUtils.isNotBlank(commaSerperatedParameters)) {
|
|
||||||
fields.removeAll(new HashSet<>(Arrays.asList(commaSerperatedParameters.split("\\s*,\\s*")))); // NOSONAR
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
@@ -80,6 +80,10 @@ public interface LoanApiConstants {
|
|||||||
String daysInYearTypeParameterName = "daysInYearType";
|
String daysInYearTypeParameterName = "daysInYearType";
|
||||||
String daysInMonthTypeParameterName = "daysInMonthType";
|
String daysInMonthTypeParameterName = "daysInMonthType";
|
||||||
|
|
||||||
|
String MULTIDISBURSE_DETAILS_PARAMNAME = "multiDisburseDetails";
|
||||||
|
String EMI_AMOUNT_VARIATIONS_PARAMNAME = "emiAmountVariations";
|
||||||
|
String COLLECTION_PARAMNAME = "collection";
|
||||||
|
|
||||||
// Interest recalculation related
|
// Interest recalculation related
|
||||||
String isInterestRecalculationEnabledParameterName = "isInterestRecalculationEnabled";
|
String isInterestRecalculationEnabledParameterName = "isInterestRecalculationEnabled";
|
||||||
String interestRecalculationCompoundingMethodParameterName = "interestRecalculationCompoundingMethod";
|
String interestRecalculationCompoundingMethodParameterName = "interestRecalculationCompoundingMethod";
|
||||||
@@ -137,4 +141,5 @@ public interface LoanApiConstants {
|
|||||||
|
|
||||||
String fixedPrincipalPercentagePerInstallmentParamName = "fixedPrincipalPercentagePerInstallment";
|
String fixedPrincipalPercentagePerInstallmentParamName = "fixedPrincipalPercentagePerInstallment";
|
||||||
|
|
||||||
|
String LOAN_ASSOCIATIONS_ALL = "all";
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -23,7 +23,9 @@ import static org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
@@ -96,8 +98,6 @@ import org.apache.fineract.portfolio.charge.data.ChargeData;
|
|||||||
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
|
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
|
||||||
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
|
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
|
||||||
import org.apache.fineract.portfolio.client.data.ClientData;
|
import org.apache.fineract.portfolio.client.data.ClientData;
|
||||||
import org.apache.fineract.portfolio.collateral.data.CollateralData;
|
|
||||||
import org.apache.fineract.portfolio.collateral.service.CollateralReadPlatformService;
|
|
||||||
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralResponseData;
|
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralResponseData;
|
||||||
import org.apache.fineract.portfolio.collateralmanagement.service.LoanCollateralManagementReadPlatformService;
|
import org.apache.fineract.portfolio.collateralmanagement.service.LoanCollateralManagementReadPlatformService;
|
||||||
import org.apache.fineract.portfolio.floatingrates.data.InterestRatePeriodData;
|
import org.apache.fineract.portfolio.floatingrates.data.InterestRatePeriodData;
|
||||||
@@ -220,7 +220,8 @@ public class LoansApiResource {
|
|||||||
"loanCounter", "loanProductCounter", "notes", "accountLinkingOptions", "linkedAccount", "interestRateDifferential",
|
"loanCounter", "loanProductCounter", "notes", "accountLinkingOptions", "linkedAccount", "interestRateDifferential",
|
||||||
"isFloatingInterestRate", "interestRatesPeriods", LoanApiConstants.canUseForTopup, LoanApiConstants.isTopup,
|
"isFloatingInterestRate", "interestRatesPeriods", LoanApiConstants.canUseForTopup, LoanApiConstants.isTopup,
|
||||||
LoanApiConstants.loanIdToClose, LoanApiConstants.topupAmount, LoanApiConstants.clientActiveLoanOptions,
|
LoanApiConstants.loanIdToClose, LoanApiConstants.topupAmount, LoanApiConstants.clientActiveLoanOptions,
|
||||||
LoanApiConstants.datatables, LoanProductConstants.RATES_PARAM_NAME));
|
LoanApiConstants.datatables, LoanProductConstants.RATES_PARAM_NAME, LoanApiConstants.MULTIDISBURSE_DETAILS_PARAMNAME,
|
||||||
|
LoanApiConstants.EMI_AMOUNT_VARIATIONS_PARAMNAME, LoanApiConstants.COLLECTION_PARAMNAME));
|
||||||
|
|
||||||
private final Set<String> loanApprovalDataParameters = new HashSet<>(Arrays.asList("approvalDate", "approvalAmount"));
|
private final Set<String> loanApprovalDataParameters = new HashSet<>(Arrays.asList("approvalDate", "approvalAmount"));
|
||||||
final Set<String> glimAccountsDataParameters = new HashSet<>(Arrays.asList("glimId", "groupId", "clientId", "parentLoanAccountNo",
|
final Set<String> glimAccountsDataParameters = new HashSet<>(Arrays.asList("glimId", "groupId", "clientId", "parentLoanAccountNo",
|
||||||
@@ -234,7 +235,6 @@ public class LoansApiResource {
|
|||||||
private final FundReadPlatformService fundReadPlatformService;
|
private final FundReadPlatformService fundReadPlatformService;
|
||||||
private final ChargeReadPlatformService chargeReadPlatformService;
|
private final ChargeReadPlatformService chargeReadPlatformService;
|
||||||
private final LoanChargeReadPlatformService loanChargeReadPlatformService;
|
private final LoanChargeReadPlatformService loanChargeReadPlatformService;
|
||||||
private final CollateralReadPlatformService loanCollateralReadPlatformService;
|
|
||||||
private final LoanScheduleCalculationPlatformService calculationPlatformService;
|
private final LoanScheduleCalculationPlatformService calculationPlatformService;
|
||||||
private final GuarantorReadPlatformService guarantorReadPlatformService;
|
private final GuarantorReadPlatformService guarantorReadPlatformService;
|
||||||
private final CodeValueReadPlatformService codeValueReadPlatformService;
|
private final CodeValueReadPlatformService codeValueReadPlatformService;
|
||||||
@@ -264,7 +264,6 @@ public class LoansApiResource {
|
|||||||
final LoanProductReadPlatformService loanProductReadPlatformService,
|
final LoanProductReadPlatformService loanProductReadPlatformService,
|
||||||
final LoanDropdownReadPlatformService dropdownReadPlatformService, final FundReadPlatformService fundReadPlatformService,
|
final LoanDropdownReadPlatformService dropdownReadPlatformService, final FundReadPlatformService fundReadPlatformService,
|
||||||
final ChargeReadPlatformService chargeReadPlatformService, final LoanChargeReadPlatformService loanChargeReadPlatformService,
|
final ChargeReadPlatformService chargeReadPlatformService, final LoanChargeReadPlatformService loanChargeReadPlatformService,
|
||||||
final CollateralReadPlatformService loanCollateralReadPlatformService,
|
|
||||||
final LoanScheduleCalculationPlatformService calculationPlatformService,
|
final LoanScheduleCalculationPlatformService calculationPlatformService,
|
||||||
final GuarantorReadPlatformService guarantorReadPlatformService,
|
final GuarantorReadPlatformService guarantorReadPlatformService,
|
||||||
final CodeValueReadPlatformService codeValueReadPlatformService, final GroupReadPlatformService groupReadPlatformService,
|
final CodeValueReadPlatformService codeValueReadPlatformService, final GroupReadPlatformService groupReadPlatformService,
|
||||||
@@ -292,7 +291,6 @@ public class LoansApiResource {
|
|||||||
this.fundReadPlatformService = fundReadPlatformService;
|
this.fundReadPlatformService = fundReadPlatformService;
|
||||||
this.chargeReadPlatformService = chargeReadPlatformService;
|
this.chargeReadPlatformService = chargeReadPlatformService;
|
||||||
this.loanChargeReadPlatformService = loanChargeReadPlatformService;
|
this.loanChargeReadPlatformService = loanChargeReadPlatformService;
|
||||||
this.loanCollateralReadPlatformService = loanCollateralReadPlatformService;
|
|
||||||
this.calculationPlatformService = calculationPlatformService;
|
this.calculationPlatformService = calculationPlatformService;
|
||||||
this.guarantorReadPlatformService = guarantorReadPlatformService;
|
this.guarantorReadPlatformService = guarantorReadPlatformService;
|
||||||
this.codeValueReadPlatformService = codeValueReadPlatformService;
|
this.codeValueReadPlatformService = codeValueReadPlatformService;
|
||||||
@@ -495,6 +493,10 @@ public class LoansApiResource {
|
|||||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoansApiResourceSwagger.GetLoansLoanIdResponse.class))) })
|
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoansApiResourceSwagger.GetLoansLoanIdResponse.class))) })
|
||||||
public String retrieveLoan(@PathParam("loanId") @Parameter(description = "loanId") final Long loanId,
|
public String retrieveLoan(@PathParam("loanId") @Parameter(description = "loanId") final Long loanId,
|
||||||
@DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") @Parameter(description = "staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly,
|
@DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") @Parameter(description = "staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly,
|
||||||
|
@DefaultValue("all") @QueryParam("associations") @Parameter(in = ParameterIn.QUERY, name = "associations", description = "Loan object relations to be included in the response", required = false, examples = {
|
||||||
|
@ExampleObject(value = "all"), @ExampleObject(value = "repaymentSchedule,transactions") }) final String associations,
|
||||||
|
@QueryParam("exclude") @Parameter(in = ParameterIn.QUERY, name = "exclude", description = "Optional Loan object relation list to be filtered in the response", required = false, example = "guarantors,futureSchedule") final String exclude,
|
||||||
|
@QueryParam("fields") @Parameter(in = ParameterIn.QUERY, name = "fields", description = "Optional Loan attribute list to be in the response", required = false, example = "id,principal,annualInterestRate") final String fields,
|
||||||
@Context final UriInfo uriInfo) {
|
@Context final UriInfo uriInfo) {
|
||||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
||||||
|
|
||||||
@@ -535,7 +537,6 @@ public class LoansApiResource {
|
|||||||
LoanScheduleData repaymentSchedule = null;
|
LoanScheduleData repaymentSchedule = null;
|
||||||
Collection<LoanChargeData> charges = null;
|
Collection<LoanChargeData> charges = null;
|
||||||
Collection<GuarantorData> guarantors = null;
|
Collection<GuarantorData> guarantors = null;
|
||||||
Collection<CollateralData> collateral = null;
|
|
||||||
CalendarData meeting = null;
|
CalendarData meeting = null;
|
||||||
Collection<NoteData> notes = null;
|
Collection<NoteData> notes = null;
|
||||||
PortfolioAccountData linkedAccount = null;
|
PortfolioAccountData linkedAccount = null;
|
||||||
@@ -548,7 +549,6 @@ public class LoansApiResource {
|
|||||||
final Set<String> mandatoryResponseParameters = new HashSet<>();
|
final Set<String> mandatoryResponseParameters = new HashSet<>();
|
||||||
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
|
|
||||||
if (associationParameters.contains(DataTableApiConstant.allAssociateParamName)) {
|
if (associationParameters.contains(DataTableApiConstant.allAssociateParamName)) {
|
||||||
associationParameters.addAll(Arrays.asList(DataTableApiConstant.repaymentScheduleAssociateParamName,
|
associationParameters.addAll(Arrays.asList(DataTableApiConstant.repaymentScheduleAssociateParamName,
|
||||||
DataTableApiConstant.futureScheduleAssociateParamName, DataTableApiConstant.originalScheduleAssociateParamName,
|
DataTableApiConstant.futureScheduleAssociateParamName, DataTableApiConstant.originalScheduleAssociateParamName,
|
||||||
@@ -558,7 +558,7 @@ public class LoansApiResource {
|
|||||||
DataTableApiConstant.multiDisburseDetailsAssociateParamName, DataTableApiConstant.collectionAssociateParamName));
|
DataTableApiConstant.multiDisburseDetailsAssociateParamName, DataTableApiConstant.collectionAssociateParamName));
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiParameterHelper.excludeAssociationsForResponseIfProvided(uriInfo.getQueryParameters(), associationParameters);
|
ApiParameterHelper.excludeAssociationsForResponseIfProvided(exclude, associationParameters);
|
||||||
|
|
||||||
if (associationParameters.contains(DataTableApiConstant.guarantorsAssociateParamName)) {
|
if (associationParameters.contains(DataTableApiConstant.guarantorsAssociateParamName)) {
|
||||||
mandatoryResponseParameters.add(DataTableApiConstant.guarantorsAssociateParamName);
|
mandatoryResponseParameters.add(DataTableApiConstant.guarantorsAssociateParamName);
|
||||||
|
|||||||
+3
-11
@@ -142,7 +142,6 @@ import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
|||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanAccountDomainService;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanAccountDomainService;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanCharge;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanCharge;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargePaidBy;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargePaidBy;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargePaidByRepository;
|
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargeRepository;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargeRepository;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanCollateralManagement;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanCollateralManagement;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanDisbursementDetails;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanDisbursementDetails;
|
||||||
@@ -152,7 +151,6 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanInterestRecalcualtio
|
|||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanLifecycleStateMachine;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanLifecycleStateMachine;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanOverdueInstallmentCharge;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanOverdueInstallmentCharge;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallmentRepository;
|
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleTransactionProcessorFactory;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleTransactionProcessorFactory;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
|
||||||
@@ -238,7 +236,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
private final FromJsonHelper fromApiJsonHelper;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
private final AccountTransferRepository accountTransferRepository;
|
private final AccountTransferRepository accountTransferRepository;
|
||||||
private final CalendarRepository calendarRepository;
|
private final CalendarRepository calendarRepository;
|
||||||
private final LoanRepaymentScheduleInstallmentRepository repaymentScheduleInstallmentRepository;
|
|
||||||
private final LoanScheduleHistoryWritePlatformService loanScheduleHistoryWritePlatformService;
|
private final LoanScheduleHistoryWritePlatformService loanScheduleHistoryWritePlatformService;
|
||||||
private final LoanApplicationCommandFromApiJsonHelper loanApplicationCommandFromApiJsonHelper;
|
private final LoanApplicationCommandFromApiJsonHelper loanApplicationCommandFromApiJsonHelper;
|
||||||
private final AccountAssociationsRepository accountAssociationRepository;
|
private final AccountAssociationsRepository accountAssociationRepository;
|
||||||
@@ -255,7 +252,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
private final LoanRepository loanRepository;
|
private final LoanRepository loanRepository;
|
||||||
private final RepaymentWithPostDatedChecksAssembler repaymentWithPostDatedChecksAssembler;
|
private final RepaymentWithPostDatedChecksAssembler repaymentWithPostDatedChecksAssembler;
|
||||||
private final PostDatedChecksRepository postDatedChecksRepository;
|
private final PostDatedChecksRepository postDatedChecksRepository;
|
||||||
private final LoanChargePaidByRepository loanChargePaidByRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public LoanWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
public LoanWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||||
@@ -274,7 +270,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
final LoanChargeReadPlatformService loanChargeReadPlatformService, final LoanReadPlatformService loanReadPlatformService,
|
final LoanChargeReadPlatformService loanChargeReadPlatformService, final LoanReadPlatformService loanReadPlatformService,
|
||||||
final FromJsonHelper fromApiJsonHelper, final AccountTransferRepository accountTransferRepository,
|
final FromJsonHelper fromApiJsonHelper, final AccountTransferRepository accountTransferRepository,
|
||||||
final CalendarRepository calendarRepository,
|
final CalendarRepository calendarRepository,
|
||||||
final LoanRepaymentScheduleInstallmentRepository repaymentScheduleInstallmentRepository,
|
|
||||||
final LoanScheduleHistoryWritePlatformService loanScheduleHistoryWritePlatformService,
|
final LoanScheduleHistoryWritePlatformService loanScheduleHistoryWritePlatformService,
|
||||||
final LoanApplicationCommandFromApiJsonHelper loanApplicationCommandFromApiJsonHelper,
|
final LoanApplicationCommandFromApiJsonHelper loanApplicationCommandFromApiJsonHelper,
|
||||||
final AccountAssociationsRepository accountAssociationRepository,
|
final AccountAssociationsRepository accountAssociationRepository,
|
||||||
@@ -286,7 +281,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
final CodeValueRepositoryWrapper codeValueRepository, final LoanRepositoryWrapper loanRepositoryWrapper,
|
final CodeValueRepositoryWrapper codeValueRepository, final LoanRepositoryWrapper loanRepositoryWrapper,
|
||||||
final CashierTransactionDataValidator cashierTransactionDataValidator, final GLIMAccountInfoRepository glimRepository,
|
final CashierTransactionDataValidator cashierTransactionDataValidator, final GLIMAccountInfoRepository glimRepository,
|
||||||
final LoanRepository loanRepository, final RepaymentWithPostDatedChecksAssembler repaymentWithPostDatedChecksAssembler,
|
final LoanRepository loanRepository, final RepaymentWithPostDatedChecksAssembler repaymentWithPostDatedChecksAssembler,
|
||||||
final PostDatedChecksRepository postDatedChecksRepository, final LoanChargePaidByRepository loanChargePaidByRepository) {
|
final PostDatedChecksRepository postDatedChecksRepository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.loanEventApiJsonValidator = loanEventApiJsonValidator;
|
this.loanEventApiJsonValidator = loanEventApiJsonValidator;
|
||||||
this.loanAssembler = loanAssembler;
|
this.loanAssembler = loanAssembler;
|
||||||
@@ -312,7 +307,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||||
this.accountTransferRepository = accountTransferRepository;
|
this.accountTransferRepository = accountTransferRepository;
|
||||||
this.calendarRepository = calendarRepository;
|
this.calendarRepository = calendarRepository;
|
||||||
this.repaymentScheduleInstallmentRepository = repaymentScheduleInstallmentRepository;
|
|
||||||
this.loanScheduleHistoryWritePlatformService = loanScheduleHistoryWritePlatformService;
|
this.loanScheduleHistoryWritePlatformService = loanScheduleHistoryWritePlatformService;
|
||||||
this.loanApplicationCommandFromApiJsonHelper = loanApplicationCommandFromApiJsonHelper;
|
this.loanApplicationCommandFromApiJsonHelper = loanApplicationCommandFromApiJsonHelper;
|
||||||
this.accountAssociationRepository = accountAssociationRepository;
|
this.accountAssociationRepository = accountAssociationRepository;
|
||||||
@@ -329,7 +323,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
this.glimRepository = glimRepository;
|
this.glimRepository = glimRepository;
|
||||||
this.repaymentWithPostDatedChecksAssembler = repaymentWithPostDatedChecksAssembler;
|
this.repaymentWithPostDatedChecksAssembler = repaymentWithPostDatedChecksAssembler;
|
||||||
this.postDatedChecksRepository = postDatedChecksRepository;
|
this.postDatedChecksRepository = postDatedChecksRepository;
|
||||||
this.loanChargePaidByRepository = loanChargePaidByRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() {
|
private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() {
|
||||||
@@ -1760,7 +1753,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppUser currentUser = getAppUserIfPresent();
|
|
||||||
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
||||||
checkClientOrGroupActive(loan);
|
checkClientOrGroupActive(loan);
|
||||||
final LoanCharge loanCharge = retrieveLoanChargeBy(loanId, loanChargeId);
|
final LoanCharge loanCharge = retrieveLoanChargeBy(loanId, loanChargeId);
|
||||||
@@ -2813,10 +2805,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
LocalDate startDate = dueDate.plusDays(penaltyWaitPeriodValue.intValue() + 1);
|
LocalDate startDate = dueDate.plusDays(penaltyWaitPeriodValue.intValue() + 1);
|
||||||
Integer frequencyNunber = 1;
|
Integer frequencyNunber = 1;
|
||||||
if (feeFrequency == null) {
|
if (feeFrequency == null) {
|
||||||
scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue()));
|
scheduleDates.put(frequencyNunber++, startDate.minusDays(diff));
|
||||||
} else {
|
} else {
|
||||||
while (!startDate.isAfter(DateUtils.getLocalDateOfTenant())) {
|
while (!startDate.isAfter(DateUtils.getLocalDateOfTenant())) {
|
||||||
scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue()));
|
scheduleDates.put(frequencyNunber++, startDate.minusDays(diff));
|
||||||
LocalDate scheduleDate = scheduledDateGenerator.getRepaymentPeriodDate(PeriodFrequencyType.fromInt(feeFrequency),
|
LocalDate scheduleDate = scheduledDateGenerator.getRepaymentPeriodDate(PeriodFrequencyType.fromInt(feeFrequency),
|
||||||
chargeDefinition.feeInterval(), startDate);
|
chargeDefinition.feeInterval(), startDate);
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -43,6 +43,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException;
|
import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.apache.fineract.portfolio.client.exception.ClientNotFoundException;
|
import org.apache.fineract.portfolio.client.exception.ClientNotFoundException;
|
||||||
|
import org.apache.fineract.portfolio.loanaccount.api.LoanApiConstants;
|
||||||
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
||||||
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
||||||
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
|
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
|
||||||
@@ -106,7 +107,10 @@ public class SelfLoansApiResource {
|
|||||||
validateAppuserLoanMapping(loanId);
|
validateAppuserLoanMapping(loanId);
|
||||||
|
|
||||||
final boolean staffInSelectedOfficeOnly = false;
|
final boolean staffInSelectedOfficeOnly = false;
|
||||||
return this.loansApiResource.retrieveLoan(loanId, staffInSelectedOfficeOnly, uriInfo);
|
final String associations = LoanApiConstants.LOAN_ASSOCIATIONS_ALL;
|
||||||
|
final String exclude = null;
|
||||||
|
final String fields = null;
|
||||||
|
return this.loansApiResource.retrieveLoan(loanId, staffInSelectedOfficeOnly, associations, exclude, fields, uriInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
|||||||
+31
-13
@@ -24,6 +24,8 @@ import static org.mockito.ArgumentMatchers.eq;
|
|||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
@@ -46,8 +48,10 @@ import org.mockito.MockitoAnnotations;
|
|||||||
public class GetLoanByIdCommandStrategyTest {
|
public class GetLoanByIdCommandStrategyTest {
|
||||||
|
|
||||||
private static Stream<Arguments> provideQueryParameters() {
|
private static Stream<Arguments> provideQueryParameters() {
|
||||||
return Stream.of(Arguments.of(null, 0), Arguments.of("associations=all", 1),
|
return Stream.of(Arguments.of(null, null, null, 0), Arguments.of("all", null, null, 1),
|
||||||
Arguments.of("fields=id,principal,annualInterestRate&associations=repaymentSchedule,transactions", 2));
|
Arguments.of("repaymentSchedule,transactions", null, "guarantors,futureSchedule", 2),
|
||||||
|
Arguments.of("repaymentSchedule,transactions", "id,principal,annualInterestRate", null, 2),
|
||||||
|
Arguments.of("repaymentSchedule,transactions", "id,principal,annualInterestRate", "guarantors,futureSchedule", 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,15 +60,17 @@ public class GetLoanByIdCommandStrategyTest {
|
|||||||
*/
|
*/
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideQueryParameters")
|
@MethodSource("provideQueryParameters")
|
||||||
public void testExecuteSuccessScenario(final String queryParameter, final int noOfQueryParams) {
|
public void testExecuteSuccessScenario(final String associations, final String fields, final String exclude,
|
||||||
|
final int noOfQueryParams) {
|
||||||
// given
|
// given
|
||||||
final TestContext testContext = new TestContext();
|
final TestContext testContext = new TestContext();
|
||||||
|
|
||||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||||
final BatchRequest request = getBatchRequest(loanId, queryParameter);
|
final BatchRequest request = getBatchRequest(loanId, associations, exclude, fields);
|
||||||
final String responseBody = "{\\\"id\\\":2,\\\"accountNo\\\":\\\"000000002\\\"}";
|
final String responseBody = "{\\\"id\\\":2,\\\"accountNo\\\":\\\"000000002\\\"}";
|
||||||
|
|
||||||
given(testContext.loansApiResource.retrieveLoan(eq(loanId), eq(false), any(UriInfo.class))).willReturn(responseBody);
|
given(testContext.loansApiResource.retrieveLoan(eq(loanId), eq(false), eq(associations), eq(exclude), eq(fields),
|
||||||
|
any(UriInfo.class))).willReturn(responseBody);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final BatchResponse response = testContext.underTest.execute(request, testContext.uriInfo);
|
final BatchResponse response = testContext.underTest.execute(request, testContext.uriInfo);
|
||||||
@@ -75,7 +81,8 @@ public class GetLoanByIdCommandStrategyTest {
|
|||||||
assertThat(response.getHeaders()).isEqualTo(request.getHeaders());
|
assertThat(response.getHeaders()).isEqualTo(request.getHeaders());
|
||||||
assertThat(response.getBody()).isEqualTo(responseBody);
|
assertThat(response.getBody()).isEqualTo(responseBody);
|
||||||
|
|
||||||
verify(testContext.loansApiResource).retrieveLoan(eq(loanId), eq(false), testContext.uriInfoCaptor.capture());
|
verify(testContext.loansApiResource).retrieveLoan(eq(loanId), eq(false), eq(associations), eq(exclude), eq(fields),
|
||||||
|
testContext.uriInfoCaptor.capture());
|
||||||
MutableUriInfo mutableUriInfo = testContext.uriInfoCaptor.getValue();
|
MutableUriInfo mutableUriInfo = testContext.uriInfoCaptor.getValue();
|
||||||
assertThat(mutableUriInfo.getAdditionalQueryParameters()).hasSize(noOfQueryParams);
|
assertThat(mutableUriInfo.getAdditionalQueryParameters()).hasSize(noOfQueryParams);
|
||||||
}
|
}
|
||||||
@@ -88,9 +95,9 @@ public class GetLoanByIdCommandStrategyTest {
|
|||||||
// given
|
// given
|
||||||
final TestContext testContext = new TestContext();
|
final TestContext testContext = new TestContext();
|
||||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||||
final BatchRequest request = getBatchRequest(loanId, null);
|
final BatchRequest request = getBatchRequest(loanId, null, null, null);
|
||||||
|
|
||||||
given(testContext.loansApiResource.retrieveLoan(eq(loanId), eq(false), any(UriInfo.class)))
|
given(testContext.loansApiResource.retrieveLoan(eq(loanId), eq(false), eq(null), eq(null), eq(null), any(UriInfo.class)))
|
||||||
.willThrow(new RuntimeException("Some error"));
|
.willThrow(new RuntimeException("Some error"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -111,9 +118,9 @@ public class GetLoanByIdCommandStrategyTest {
|
|||||||
// given
|
// given
|
||||||
final TestContext testContext = new TestContext();
|
final TestContext testContext = new TestContext();
|
||||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||||
final BatchRequest request = getBatchRequest(loanId, null);
|
final BatchRequest request = getBatchRequest(loanId, null, null, null);
|
||||||
|
|
||||||
given(testContext.loansApiResource.retrieveLoan(eq(loanId), eq(false), any(UriInfo.class)))
|
given(testContext.loansApiResource.retrieveLoan(eq(loanId), eq(false), eq(null), eq(null), eq(null), any(UriInfo.class)))
|
||||||
.willThrow(new LoanNotFoundException(loanId));
|
.willThrow(new LoanNotFoundException(loanId));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -145,12 +152,23 @@ public class GetLoanByIdCommandStrategyTest {
|
|||||||
* the loan id
|
* the loan id
|
||||||
* @return BatchRequest
|
* @return BatchRequest
|
||||||
*/
|
*/
|
||||||
private BatchRequest getBatchRequest(final Long loanId, final String queryParamStr) {
|
private BatchRequest getBatchRequest(final Long loanId, final String associations, final String exclude, final String fields) {
|
||||||
|
|
||||||
final BatchRequest br = new BatchRequest();
|
final BatchRequest br = new BatchRequest();
|
||||||
String relativeUrl = "loans/" + loanId;
|
String relativeUrl = "loans/" + loanId;
|
||||||
if (queryParamStr != null) {
|
|
||||||
relativeUrl = relativeUrl + "?" + queryParamStr;
|
Set<String> queryParams = new HashSet<>();
|
||||||
|
if (associations != null) {
|
||||||
|
queryParams.add("associations=" + associations);
|
||||||
|
}
|
||||||
|
if (exclude != null) {
|
||||||
|
queryParams.add("exclude=" + exclude);
|
||||||
|
}
|
||||||
|
if (fields != null) {
|
||||||
|
queryParams.add("fields=" + fields);
|
||||||
|
}
|
||||||
|
if (!queryParams.isEmpty()) {
|
||||||
|
relativeUrl = relativeUrl + "?" + String.join("&", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||||
|
|||||||
Reference in New Issue
Block a user