FINERACT-1724: Loan Charge API support for batch APIs and a couple of other batch API enhancements

This commit is contained in:
Arnold Galovics
2022-12-19 22:46:36 +01:00
committed by Arnold Gálovics
parent cb39a23467
commit 8ab206aa4a
56 changed files with 4220 additions and 150 deletions
@@ -18,6 +18,10 @@
*/
package org.apache.fineract.batch.command;
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.HttpMethod.PUT;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.fineract.batch.command.internal.UnknownCommandStrategy;
@@ -38,6 +42,41 @@ public class CommandStrategyProvider {
private final ApplicationContext applicationContext;
private static final Map<CommandContext, String> commandStrategies = new ConcurrentHashMap<>();
/**
* Regex pattern for specifying any number of query params or not specific any query param
*/
private static final String OPTIONAL_QUERY_PARAM_REGEX = "(\\?(\\w+(?:\\=[\\w,]+|&)+)+)?";
/**
* Regex pattern for specifying query params
*/
private static final String MANDATORY_QUERY_PARAM_REGEX = "(\\?(\\w+(?:\\=[\\w,]+|&)+)+)";
/**
* Regex pattern for specifying any query param that has key = 'command' or not specific anything.
*/
private static final String OPTIONAL_COMMAND_PARAM_REGEX = "(\\?command=[\\w]+)?";
/**
* Regex pattern for specifying a mandatory query param that has key = 'command'.
*/
private static final String MANDATORY_COMMAND_PARAM_REGEX = "\\?command=[\\w]+";
/**
* Regex pattern for specifying a UUID param.
*/
private static final String UUID_PARAM_REGEX = "[\\w\\d-]+";
/**
* Regex pattern for specifying a param that's should be a number.
*/
private static final String NUMBER_REGEX = "\\d+";
/**
* Regex pattern for specifying a param that contains case in-sensitive alphanumeric characters with underscores.
*/
private static final String ALPHANUMBERIC_WITH_UNDERSCORE_REGEX = "[a-zA-Z0-9_]*";
/**
* Constructs a CommandStrategyProvider with argument of ApplicationContext type. It also initializes
* commandStrategies using init() function by filling it with available CommandStrategies in
@@ -81,46 +120,88 @@ public class CommandStrategyProvider {
* command Strategy will have to be added within this function in order to initiate it within the constructor.
*/
private static void init() {
commandStrategies.put(CommandContext.resource("clients").method("POST").build(), "createClientCommandStrategy");
commandStrategies.put(CommandContext.resource("clients\\/\\d+").method("PUT").build(), "updateClientCommandStrategy");
commandStrategies.put(CommandContext.resource("loans").method("POST").build(), "applyLoanCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+").method("GET").build(), "getLoanByIdCommandStrategy");
commandStrategies.put(CommandContext.resource("loans/\\d+(\\?(\\w+(?:\\=[\\w,]+|&)+)+)").method("GET").build(),
commandStrategies.put(CommandContext.resource("clients").method(POST).build(), "createClientCommandStrategy");
commandStrategies.put(CommandContext.resource("clients\\/" + NUMBER_REGEX).method(PUT).build(), "updateClientCommandStrategy");
commandStrategies.put(CommandContext.resource("loans").method(POST).build(), "applyLoanCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + OPTIONAL_QUERY_PARAM_REGEX).method(GET).build(),
"getLoanByIdCommandStrategy");
commandStrategies.put(CommandContext.resource("savingsaccounts").method("POST").build(), "applySavingsCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/charges").method("POST").build(), "createChargeCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/charges").method("GET").build(), "collectChargesCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/charges\\/\\d+").method("GET").build(),
commandStrategies.put(
CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + OPTIONAL_QUERY_PARAM_REGEX).method(GET).build(),
"getLoanByExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("savingsaccounts").method(POST).build(), "applySavingsCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\/charges").method(POST).build(),
"createChargeCommandStrategy");
commandStrategies
.put(CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/charges" + OPTIONAL_COMMAND_PARAM_REGEX + "")
.method(POST).build(), "createChargeByLoanExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\/charges").method(GET).build(),
"collectChargesCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/charges").method(GET).build(),
"collectChargesByLoanExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\/charges\\/" + NUMBER_REGEX).method(GET).build(),
"getChargeByIdCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/transactions\\?(\\w+(\\=[\\w]+))").method("POST").build(),
commandStrategies.put(CommandContext.resource(
"loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/charges\\/external-id\\/" + UUID_PARAM_REGEX + OPTIONAL_QUERY_PARAM_REGEX)
.method(GET).build(), "getChargeByChargeExternalIdCommandStrategy");
commandStrategies.put(CommandContext
.resource("loans\\/" + NUMBER_REGEX + "\\/charges\\/" + NUMBER_REGEX + MANDATORY_COMMAND_PARAM_REGEX).method(POST).build(),
"adjustChargeCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/charges\\/external-id\\/"
+ UUID_PARAM_REGEX + MANDATORY_COMMAND_PARAM_REGEX).method(POST).build(), "adjustChargeByChargeExternalIdCommandStrategy");
commandStrategies.put(
CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\/transactions" + MANDATORY_COMMAND_PARAM_REGEX).method(POST).build(),
"createTransactionLoanCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/transactions\\/\\d+(\\?command=[\\w]+)?").method("POST").build(),
"adjustTransactionCommandStrategy");
commandStrategies.put(CommandContext.resource("clients\\/\\d+\\?command=activate").method("POST").build(),
commandStrategies.put(
CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/transactions" + MANDATORY_COMMAND_PARAM_REGEX)
.method(POST).build(),
"createTransactionByLoanExternalIdCommandStrategy");
commandStrategies
.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\/transactions\\/" + NUMBER_REGEX + OPTIONAL_COMMAND_PARAM_REGEX)
.method(POST).build(), "adjustTransactionCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/transactions\\/external-id\\/"
+ UUID_PARAM_REGEX + OPTIONAL_COMMAND_PARAM_REGEX).method(POST).build(), "adjustTransactionByExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("clients\\/" + NUMBER_REGEX + "\\?command=activate").method(POST).build(),
"activateClientCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\?command=approve").method("POST").build(),
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\?command=approve").method(POST).build(),
"approveLoanCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\?command=disburse").method("POST").build(),
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\?command=disburse").method(POST).build(),
"disburseLoanCommandStrategy");
commandStrategies.put(CommandContext.resource("rescheduleloans").method("POST").build(),
commandStrategies.put(
CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + MANDATORY_COMMAND_PARAM_REGEX).method(POST).build(),
"loanStateTransistionsByExternalIdCommandStrategy");
commandStrategies.put(CommandContext.resource("rescheduleloans").method(POST).build(),
"createLoanRescheduleRequestCommandStrategy");
commandStrategies.put(CommandContext.resource("rescheduleloans\\/\\d+\\?command=approve").method("POST").build(),
commandStrategies.put(CommandContext.resource("rescheduleloans\\/" + NUMBER_REGEX + "\\?command=approve").method(POST).build(),
"approveLoanRescheduleCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/transactions\\/\\d+").method("GET").build(),
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + "\\/transactions\\/" + NUMBER_REGEX).method(GET).build(),
"getTransactionByIdCommandStrategy");
commandStrategies.put(CommandContext.resource("datatables\\/[a-zA-Z0-9_]*\\/\\d+").method("GET").build(),
"getDatatableEntryByAppTableIdCommandStrategy");
commandStrategies.put(CommandContext.resource("datatables\\/[a-zA-Z0-9_]*\\/\\d+").method("POST").build(),
commandStrategies.put(CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + "\\/transactions\\/external-id\\/"
+ UUID_PARAM_REGEX + OPTIONAL_QUERY_PARAM_REGEX).method(GET).build(), "getTransactionByExternalIdCommandStrategy");
commandStrategies.put(
CommandContext.resource("datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/" + NUMBER_REGEX).method(POST).build(),
"createDatatableEntryCommandStrategy");
commandStrategies.put(CommandContext.resource("datatables\\/[a-zA-Z0-9_]*\\/\\d+\\/\\d+").method("PUT").build(),
commandStrategies.put(
CommandContext.resource("datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/" + NUMBER_REGEX + "\\/" + NUMBER_REGEX)
.method(PUT).build(),
"updateDatatableEntryOneToManyCommandStrategy");
commandStrategies.put(CommandContext.resource("datatables\\/[a-zA-Z0-9_]*\\/\\d+").method("PUT").build(),
commandStrategies.put(
CommandContext.resource("datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/" + NUMBER_REGEX).method(PUT).build(),
"updateDatatableEntryOneToOneCommandStrategy");
commandStrategies.put(
CommandContext.resource("datatables\\/[a-zA-Z0-9_]*\\/\\d+(\\?(\\w+(?:\\=[\\w,]+|&)+)+)").method("GET").build(),
"getDatatableEntryByAppTableIdCommandStrategy");
CommandContext.resource("datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/" + NUMBER_REGEX + "\\/" + NUMBER_REGEX)
.method(PUT).build(),
"updateDatatableEntryOneToManyCommandStrategy");
commandStrategies.put(CommandContext
.resource("datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/" + NUMBER_REGEX + OPTIONAL_QUERY_PARAM_REGEX)
.method(GET).build(), "getDatatableEntryByAppTableIdCommandStrategy");
commandStrategies.put(CommandContext.resource("loans\\/" + NUMBER_REGEX + OPTIONAL_COMMAND_PARAM_REGEX).method(PUT).build(),
"modifyLoanApplicationCommandStrategy");
commandStrategies.put(
CommandContext.resource("datatables\\/[a-zA-Z0-9_]*\\/query(\\?(\\w+(?:\\=[\\w,]+|&)+)+)").method("GET").build(),
CommandContext.resource("loans\\/external-id\\/" + UUID_PARAM_REGEX + OPTIONAL_COMMAND_PARAM_REGEX).method(PUT).build(),
"modifyLoanApplicationByExternalIdCommandStrategy");
commandStrategies.put(
CommandContext.resource("datatables\\/" + ALPHANUMBERIC_WITH_UNDERSCORE_REGEX + "\\/query" + MANDATORY_QUERY_PARAM_REGEX)
.method(GET).build(),
"getDatatableEntryByQueryCommandStrategy");
}
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -57,13 +58,13 @@ public class ActivateClientCommandStrategy implements CommandStrategy {
response.setHeaders(request.getHeaders());
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
Long clientId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
final Long clientId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
// Calls 'activate' function from 'ClientsApiResource' to activate a
// client
responseBody = clientsApiResource.activate(clientId, "activate", request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful activation of
// the client
response.setBody(responseBody);
@@ -0,0 +1,99 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to adjust a charge using external id. It passes the contents of the body from the
* BatchRequest to {@link LoanChargesApiResource} and gets back the response. This class will also catch any errors
* raised by {@link LoanChargesApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class AdjustChargeByChargeExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Expected pattern - loans\/external-id\/[\w\d_-]+\/charges\/external-id\/[\w\d_-]+(\?command=[\w]+)?
// Get the loan and charge ids for use in loanChargesApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
String loanExternalId = pathParameters.get(2);
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Matcher commandMatcher = commandPattern.matcher(pathParameters.get(5));
if (!commandMatcher.find()) {
// This would only occur if the CommandStrategyProvider is incorrectly configured.
response.setRequestId(request.getRequestId());
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
response.setBody(
"Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist");
return response;
}
final String commandQueryParam = commandMatcher.group(0);
final String command = commandQueryParam.substring(commandQueryParam.indexOf("=") + 1);
final String chargeExternalIdPathParameter = pathParameters.get(5);
String loanChargeExternalId;
if (chargeExternalIdPathParameter.contains("?")) {
loanChargeExternalId = pathParameters.get(5).substring(0, pathParameters.get(5).indexOf("?"));
} else {
loanChargeExternalId = pathParameters.get(5);
}
// Calls 'executeLoanCharge' function from 'loanChargesApiResource' using external id
responseBody = loanChargesApiResource.executeLoanCharge(loanExternalId, loanChargeExternalId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after retrieving the charge
response.setBody(responseBody);
return response;
}
}
@@ -0,0 +1,98 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to adjust a charge. It passes the contents of the body from the BatchRequest to
* {@link LoanChargesApiResource} and gets back the response. This class will also catch any errors raised by
* {@link LoanChargesApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class AdjustChargeCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Get the loan and charge ids for use in loanChargesApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final Long loanId = Long.parseLong(pathParameters.get(1));
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Matcher commandMatcher = commandPattern.matcher(pathParameters.get(3));
if (!commandMatcher.find()) {
// This would only occur if the CommandStrategyProvider is incorrectly configured.
response.setRequestId(request.getRequestId());
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
response.setBody(
"Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist");
return response;
}
final String commandQueryParam = commandMatcher.group(0);
final String command = commandQueryParam.substring(commandQueryParam.indexOf("=") + 1);
final String chargeIdPathParameter = pathParameters.get(3);
Long loanChargeId;
if (chargeIdPathParameter.contains("?")) {
loanChargeId = Long.parseLong(pathParameters.get(3).substring(0, pathParameters.get(3).indexOf("?")));
} else {
loanChargeId = Long.parseLong(pathParameters.get(3));
}
// Calls 'executeLoanCharge' function from 'loanChargesApiResource'
responseBody = loanChargesApiResource.executeLoanCharge(loanId, loanChargeId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after retrieving the charge
response.setBody(responseBody);
return response;
}
}
@@ -0,0 +1,89 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to adjust a transaction by external id. It passes the contents of the body from
* the BatchRequest to {@link LoanTransactionsApiResource} and gets back the response. This class will also catch any
* errors raised by {@link LoanTransactionsApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class AdjustTransactionByExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
*/
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Expected URL pattern - loans\/external-id\/[\w\d_-]+\/transactions\/external-id\/[\w\d_-]+(\?command=[\w]+)?
// Get the loan and transaction ids for use in loanTransactionsApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanExternalId = pathParameters.get(2);
final String transactionIdPathParameter = pathParameters.get(5);
String transactionExternalId;
if (transactionIdPathParameter.contains("?")) {
transactionExternalId = transactionIdPathParameter.substring(0, transactionIdPathParameter.indexOf("?"));
} else {
transactionExternalId = transactionIdPathParameter;
}
final Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
final String command = queryParameters.get("command");
// Calls 'adjustLoanTransaction' function from 'loanTransactionsApiResource' using external-id
responseBody = loanTransactionsApiResource.adjustLoanTransaction(loanExternalId, transactionExternalId, request.getBody(), command);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after retrieving the transaction
response.setBody(responseBody);
return response;
}
}
@@ -44,10 +44,13 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class AdjustTransactionCommandStrategy implements CommandStrategy {
/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
*/
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Override
public BatchResponse execute(final BatchRequest request, UriInfo uriInfo) {
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
@@ -58,7 +61,7 @@ public class AdjustTransactionCommandStrategy implements CommandStrategy {
// Get the loan and transaction ids for use in loanTransactionsApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
Long loanId = Long.parseLong(pathParameters.get(1));
final Long loanId = Long.parseLong(pathParameters.get(1));
final String transactionIdPathParameter = pathParameters.get(3);
Long transactionId;
@@ -68,8 +71,8 @@ public class AdjustTransactionCommandStrategy implements CommandStrategy {
transactionId = Long.parseLong(pathParameters.get(3));
}
Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
String command = queryParameters.get("command");
final Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
final String command = queryParameters.get("command");
// Calls 'adjustLoanTransaction' function from 'loanTransactionsApiResource'
responseBody = loanTransactionsApiResource.adjustLoanTransaction(loanId, transactionId, request.getBody(), command);
@@ -24,6 +24,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -58,7 +59,7 @@ public class ApplyLoanCommandStrategy implements CommandStrategy {
// Apply Loan to an existing client
responseBody = loansApiResource.calculateLoanScheduleOrSubmitLoanApplication(null, null, request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after loan is successfully applied
response.setBody(responseBody);
@@ -24,6 +24,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.savings.api.SavingsAccountsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -59,7 +60,7 @@ public class ApplySavingsCommandStrategy implements CommandStrategy {
// client
responseBody = savingsAccountsApiResource.submitApplication(request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after savings is successfully
// applied
response.setBody(responseBody);
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -57,13 +58,13 @@ public class ApproveLoanCommandStrategy implements CommandStrategy {
response.setHeaders(request.getHeaders());
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
Long loanId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
final Long loanId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
// Calls 'approve' function from 'LoansApiResource' to approve a
// loan
responseBody = loansApiResource.stateTransitions(loanId, "approve", request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful approval of a
// loan
response.setBody(responseBody);
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.api.RescheduleLoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
@Component
@@ -35,7 +36,7 @@ public class ApproveLoanRescheduleCommandStrategy implements CommandStrategy {
private final RescheduleLoansApiResource rescheduleLoansApiResource;
@Override
public BatchResponse execute(BatchRequest request, UriInfo uriInfo) {
public BatchResponse execute(BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
@@ -43,14 +44,14 @@ public class ApproveLoanRescheduleCommandStrategy implements CommandStrategy {
response.setHeaders(request.getHeaders());
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
Long scheduleId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
final Long scheduleId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
// Calls 'approve' function from 'Loans reschedule Request' to
// approve a
// loan
responseBody = rescheduleLoansApiResource.updateLoanRescheduleRequest(scheduleId, "approve", request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful approval of a
// Loans reschedule Request
response.setBody(responseBody);
@@ -0,0 +1,88 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and Collect Charges for a Loan by external id. It passes the contents of the body
* from the BatchRequest to {@link LoanChargesApiResource} and gets back the response. This class will also catch any
* errors raised by {@link LoanChargesApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class CollectChargesByLoanExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(BatchRequest request, final UriInfo uriInfo) {
final MutableUriInfo parameterizedUriInfo = new MutableUriInfo(uriInfo);
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Expected pattern - loans\/external-id\/[\w\d_-]+\/charges
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
// Pluck out the loanExternalId out of the relative path
final String loanExternalId = pathParameters.get(2);
Map<String, String> queryParameters;
if (relativeUrl.indexOf('?') > 0) {
queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
// Add the query parameters sent in the relative URL to UriInfo
CommandStrategyUtils.addQueryParametersToUriInfo(parameterizedUriInfo, queryParameters);
}
// Calls 'retrieveAllLoanCharges' function from
// 'LoanChargesApiResource' to Collect
// Charges for a loan
responseBody = loanChargesApiResource.retrieveAllLoanCharges(loanExternalId, parameterizedUriInfo);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after Charges have been
// successfully collected
response.setBody(responseBody);
return response;
}
}
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -35,8 +36,6 @@ import org.springframework.stereotype.Component;
* will also catch any errors raised by {@link org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource} and
* map those errors to appropriate status codes in BatchResponse.
*
* @author Rishabh Shukla
*
* @see org.apache.fineract.batch.command.CommandStrategy
* @see org.apache.fineract.batch.domain.BatchRequest
* @see org.apache.fineract.batch.domain.BatchResponse
@@ -45,10 +44,13 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class CollectChargesCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(BatchRequest request, UriInfo uriInfo) {
public BatchResponse execute(BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
@@ -59,14 +61,14 @@ public class CollectChargesCommandStrategy implements CommandStrategy {
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
// Pluck out the loanId out of the relative path
Long loanId = Long.parseLong(pathParameters.get(1));
final Long loanId = Long.parseLong(pathParameters.get(1));
// Calls 'retrieveAllLoanCharges' function from
// 'LoanChargesApiResource' to Collect
// Charges for a loan
responseBody = loanChargesApiResource.retrieveAllLoanCharges(loanId, uriInfo);
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after Charges have been
// successfully collected
response.setBody(responseBody);
@@ -0,0 +1,87 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and Create Charge for a Loan by external id. It passes the contents of the body
* from the BatchRequest to {@link LoanChargesApiResource} and gets back the response. This class will also catch any
* errors raised by {@link LoanChargesApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class CreateChargeByLoanExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Expected pattern - loans\/external-id\/[\w\d_-]+\/charges
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanExternalIdPathParameter = pathParameters.get(2);
String loanExternalId;
if (loanExternalIdPathParameter.contains("?")) {
loanExternalId = pathParameters.get(2).substring(0, pathParameters.get(2).indexOf("?"));
} else {
loanExternalId = pathParameters.get(2);
}
final Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
final String command = queryParameters.get("command");
// Calls 'executeLoanCharge' function from 'LoanChargesApiResource'
// to create a new charge for based on loan external id
responseBody = loanChargesApiResource.executeLoanCharge(loanExternalId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after Charge has been successfully
// created
response.setBody(responseBody);
return response;
}
}
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -57,14 +58,14 @@ public class CreateChargeCommandStrategy implements CommandStrategy {
response.setHeaders(request.getHeaders());
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
Long loanId = Long.parseLong(pathParameters.get(1));
final Long loanId = Long.parseLong(pathParameters.get(1));
// Calls 'executeLoanCharge' function from 'LoanChargesApiResource'
// to create
// a new charge for a loan
responseBody = loanChargesApiResource.executeLoanCharge(loanId, null, request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after Charge has been successfully
// created
response.setBody(responseBody);
@@ -24,6 +24,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -58,7 +59,7 @@ public class CreateClientCommandStrategy implements CommandStrategy {
// client
responseBody = clientsApiResource.create(request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful creation of
// the client
response.setBody(responseBody);
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.dataqueries.api.DatatablesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -61,7 +62,7 @@ public class CreateDatatableEntryCommandStrategy implements CommandStrategy {
// 'DatatablesApiResource' to create a datatable entry on an existing loan
responseBody = datatablesApiResource.createDatatableEntry(datatableName, loanId, request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after datatable entry is successfully
// created
response.setBody(responseBody);
@@ -24,6 +24,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.api.RescheduleLoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -55,7 +56,7 @@ public class CreateLoanRescheduleRequestCommandStrategy implements CommandStrate
// 'RescheduleLoansApiResource' to create a reschedule request on an existing loan
responseBody = rescheduleLoansApiResource.createLoanRescheduleRequest(request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after savings is successfully
// applied
response.setBody(responseBody);
@@ -0,0 +1,89 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and handles the creation of a transaction for a Loan using External Id. It passes
* the contents of the body from the BatchRequest to {@link LoanTransactionsApiResource} and gets back the response.
* This class will also catch any errors raised by {@link LoanTransactionsApiResource} and map those errors to
* appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class CreateTransactionByLoanExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
*/
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected Pattern - loans\/external-id\/[a-zA-Z0-9_-]*\/transactions\?command=[\w]+
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
final String loanExternalId = pathParameters.get(2);
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Matcher commandMatcher = commandPattern.matcher(pathParameters.get(3));
if (!commandMatcher.find()) {
// This would only occur if the CommandStrategyProvider is incorrectly configured.
response.setRequestId(request.getRequestId());
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
response.setBody(
"Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist");
return response;
}
final String commandQueryParam = commandMatcher.group(0);
final String command = commandQueryParam.substring(commandQueryParam.indexOf("=") + 1);
responseBody = loanTransactionsApiResource.executeLoanTransaction(loanExternalId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after Charge has been successfully
// created
response.setBody(responseBody);
return response;
}
}
@@ -37,8 +37,6 @@ import org.springframework.stereotype.Component;
* also catch any errors raised by {@link LoanTransactionsApiResource} and map those errors to appropriate status codes
* in BatchResponse.
*
* @author Mohit Sinha
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
@@ -47,6 +45,9 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class CreateTransactionLoanCommandStrategy implements CommandStrategy {
/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
*/
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Override
@@ -59,10 +60,10 @@ public class CreateTransactionLoanCommandStrategy implements CommandStrategy {
response.setHeaders(request.getHeaders());
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
Long loanId = Long.parseLong(pathParameters.get(1));
final Long loanId = Long.parseLong(pathParameters.get(1));
Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
Matcher commandMatcher = commandPattern.matcher(pathParameters.get(2));
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Matcher commandMatcher = commandPattern.matcher(pathParameters.get(2));
if (!commandMatcher.find()) {
// This would only occur if the CommandStrategyProvider is incorrectly configured.
@@ -72,12 +73,12 @@ public class CreateTransactionLoanCommandStrategy implements CommandStrategy {
"Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist");
return response;
}
String commandQueryParam = commandMatcher.group(0);
String command = commandQueryParam.substring(commandQueryParam.indexOf("=") + 1);
final String commandQueryParam = commandMatcher.group(0);
final String command = commandQueryParam.substring(commandQueryParam.indexOf("=") + 1);
responseBody = loanTransactionsApiResource.executeLoanTransaction(loanId, command, request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after Charge has been successfully
// created
response.setBody(responseBody);
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -57,13 +58,13 @@ public class DisburseLoanCommandStrategy implements CommandStrategy {
response.setHeaders(request.getHeaders());
final List<String> pathParameters = Splitter.on('/').splitToList(request.getRelativeUrl());
Long loanId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
final Long loanId = Long.parseLong(pathParameters.get(1).substring(0, pathParameters.get(1).indexOf("?")));
// Calls 'disburse' function from 'LoansApiResource' to disburse a
// loan
responseBody = loansApiResource.stateTransitions(loanId, "disburse", request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful disbursal of
// the loan
@@ -0,0 +1,91 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to retrieve a charge by external id. It passes the contents of the body from the
* BatchRequest to {@link LoanChargesApiResource} and gets back the response. This class will also catch any errors
* raised by {@link LoanChargesApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class GetChargeByChargeExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final MutableUriInfo parameterizedUriInfo = new MutableUriInfo(uriInfo);
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Expected pattern - loans\/external-id\/[\w\d_-]+\/charges\/external-id\/[\w\d_-]+
// Get the loan and charge external ids for use in loanChargesApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanExternalId = pathParameters.get(2);
String chargeExternalId;
if (relativeUrl.indexOf('?') > 0) {
chargeExternalId = StringUtils.substringBeforeLast(pathParameters.get(5), "?");
} else {
chargeExternalId = pathParameters.get(5);
}
Map<String, String> queryParameters;
if (relativeUrl.indexOf('?') > 0) {
queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
// Add the query parameters sent in the relative URL to UriInfo
CommandStrategyUtils.addQueryParametersToUriInfo(parameterizedUriInfo, queryParameters);
}
responseBody = loanChargesApiResource.retrieveLoanCharge(loanExternalId, chargeExternalId, parameterizedUriInfo);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(responseBody);
return response;
}
}
@@ -46,10 +46,13 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class GetChargeByIdCommandStrategy implements CommandStrategy {
/**
* Loan charges api resource {@link LoanChargesApiResource}.
*/
private final LoanChargesApiResource loanChargesApiResource;
@Override
public BatchResponse execute(final BatchRequest request, UriInfo uriInfo) {
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final MutableUriInfo parameterizedUriInfo = new MutableUriInfo(uriInfo);
final BatchResponse response = new BatchResponse();
@@ -0,0 +1,152 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and get loan by external id. It passes the contents of the body from the
* BatchRequest to {@link LoansApiResource} and gets back the response. This class will also catch any errors raised by
* {@link LoansApiResource} and map those errors to appropriate status codes in BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class GetLoanByExternalIdCommandStrategy implements CommandStrategy {
/**
* Loans api resource {@link LoansApiResource}.
*/
private final LoansApiResource loansApiResource;
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final MutableUriInfo parameterizedUriInfo = new MutableUriInfo(uriInfo);
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/external-id\/[\w\d_-]+\?associations=transactions
final String relativeUrl = request.getRelativeUrl();
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanExternalIdPathParameter = pathParameters.get(2);
String loanExternalId;
// uriInfo will contain the query parameter value(s) that are sent in the actual batch uri.
// for example: batches?enclosingTransaction=true
// But the query parameters that are sent in the batch relative url has to be sent to
// LoansApiResource.retrieveLoan
// To use the relative url query parameters
// - Parse and fetch the query parameters sent in the relative url
// (loans/external-id/ff62fc65-1bba-4bb0-b090-5f9ecf0a66f1?fields=id,principal,annualInterestRate)
// - Add them to the UriInfo query parameters list
// - Call loansApiResource.retrieveLoan(loanExternalId, false, uriInfo)
// - Remove the relative url query parameters from UriInfo in the finally (after loan details are retrieved)
Map<String, String> queryParameters = null;
if (loanExternalIdPathParameter.indexOf('?') > 0) {
loanExternalId = StringUtils.substringBefore(loanExternalIdPathParameter, "?");
queryParameters = getQueryParameters(relativeUrl);
// Add the query parameters sent in the relative URL to UriInfo
addQueryParametersToUriInfo(parameterizedUriInfo, queryParameters);
} else {
loanExternalId = loanExternalIdPathParameter;
}
// Calls 'retrieveLoan' function from 'LoansApiResource' to
// get the loan details based on the loan external id
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");
}
if (queryParameters.containsKey("staffInSelectedOfficeOnly")) {
staffInSelectedOfficeOnly = BooleanUtils.toBoolean(queryParameters.get("staffInSelectedOfficeOnly"));
}
}
responseBody = loansApiResource.retrieveLoan(loanExternalId, staffInSelectedOfficeOnly, associations, exclude, fields,
parameterizedUriInfo);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the response after retrieving the loan
response.setBody(responseBody);
return response;
}
/**
* Get query parameters from relative URL.
*
* @param relativeUrl
* the relative URL
* @return the query parameters in a map
*/
private Map<String, String> getQueryParameters(final String relativeUrl) {
final String queryParameterStr = StringUtils.substringAfter(relativeUrl, "?");
final String[] queryParametersArray = StringUtils.split(queryParameterStr, "&");
final Map<String, String> queryParametersMap = new HashMap<>();
for (String parameterStr : queryParametersArray) {
String[] keyValue = StringUtils.split(parameterStr, "=");
queryParametersMap.put(keyValue[0], keyValue[1]);
}
return queryParametersMap;
}
/**
* Add query parameters(received in the relative URL) to URI info query parameters.
*
* @param uriInfo
* the URI info
* @param queryParameters
* the query parameters
*/
private void addQueryParametersToUriInfo(final MutableUriInfo uriInfo, final Map<String, String> queryParameters) {
for (Map.Entry<String, String> entry : queryParameters.entrySet()) {
uriInfo.addAdditionalQueryParameter(entry.getKey(), entry.getValue());
}
}
}
@@ -0,0 +1,105 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to retrieve a transaction by external id. It passes the contents of the body from
* the BatchRequest to {@link LoanTransactionsApiResource} and gets back the response. This class will also catch any
* errors raised by {@link LoanTransactionsApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class GetTransactionByExternalIdCommandStrategy implements CommandStrategy {
/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
*/
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final MutableUriInfo parameterizedUriInfo = new MutableUriInfo(uriInfo);
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Expected pattern - loans\/external-id\/[\w\d_-]+\/transactions\/external-id\/[\w\d_-]+
// Get the loan and transaction ids for use in loanTransactionsApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanExternalId = pathParameters.get(2);
String transactionExternalId;
if (relativeUrl.indexOf('?') > 0) {
transactionExternalId = StringUtils.substringBeforeLast(pathParameters.get(5), "?");
} else {
transactionExternalId = pathParameters.get(5);
}
Map<String, String> queryParameters = new HashMap<>();
if (relativeUrl.indexOf('?') > 0) {
queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
// Add the query parameters sent in the relative URL to UriInfo
CommandStrategyUtils.addQueryParametersToUriInfo(parameterizedUriInfo, queryParameters);
}
String fields = null;
if (!queryParameters.isEmpty()) {
if (queryParameters.containsKey("fields")) {
fields = queryParameters.get("fields");
}
}
// Calls 'retrieveTransaction' function from 'loanTransactionsApiResource' using external id
responseBody = loanTransactionsApiResource.retrieveTransactionByLoanExternalIdAndTransactionExternalId(loanExternalId,
transactionExternalId, fields, uriInfo);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after retrieving the transaction
response.setBody(responseBody);
return response;
}
}
@@ -47,10 +47,13 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class GetTransactionByIdCommandStrategy implements CommandStrategy {
/**
* Loan transactions api resource {@link LoanTransactionsApiResource}.
*/
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Override
public BatchResponse execute(final BatchRequest request, UriInfo uriInfo) {
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final MutableUriInfo parameterizedUriInfo = new MutableUriInfo(uriInfo);
final BatchResponse response = new BatchResponse();
@@ -63,7 +66,7 @@ public class GetTransactionByIdCommandStrategy implements CommandStrategy {
// Get the loan and transaction ids for use in loanTransactionsApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
Long loanId = Long.parseLong(pathParameters.get(1));
final Long loanId = Long.parseLong(pathParameters.get(1));
Long transactionId;
if (relativeUrl.indexOf('?') > 0) {
transactionId = Long.parseLong(StringUtils.substringBeforeLast(pathParameters.get(3), "?"));
@@ -0,0 +1,93 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to handle approval of a pending loan by its external id. It passes the contents of
* the body from the BatchRequest to {@link LoansApiResource} and gets back the response. This class will also catch any
* errors raised by {@link LoansApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class LoanStateTransistionsByExternalIdCommandStrategy implements CommandStrategy {
/**
* Loans api resource {@link LoansApiResource}.
*/
private final LoansApiResource loansApiResource;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/external-id\/[\w\d_-]+\?command=***
final String relativeUrl = request.getRelativeUrl();
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanExternalIdPathParameter = pathParameters.get(2);
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Matcher commandMatcher = commandPattern.matcher(loanExternalIdPathParameter);
if (!commandMatcher.find()) {
// This would only occur if the CommandStrategyProvider is incorrectly configured.
response.setRequestId(request.getRequestId());
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
response.setBody(
"Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist");
return response;
}
final String commandQueryParam = commandMatcher.group(0);
final String command = commandQueryParam.substring(commandQueryParam.indexOf("=") + 1);
final String loanExternalId = StringUtils.substringBefore(loanExternalIdPathParameter, "?");
// Calls 'approve'/'disburse' function from 'LoansApiResource' to approve/disburse loan
responseBody = loansApiResource.stateTransitions(loanExternalId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful approval of a loan
response.setBody(responseBody);
return response;
}
}
@@ -0,0 +1,96 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} to handle any updates to the loan application. It passes the contents of the body
* from the BatchRequest to {@link LoansApiResource} and gets back the response. This class will also catch any errors
* raised by {@link LoansApiResource} and map those errors to appropriate status codes in BatchResponse.
*
* @see CommandStrategy
* @see BatchRequest
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class ModifyLoanApplicationByExternalIdCommandStrategy implements CommandStrategy {
/**
* {@link LoansApiResource} object
*/
private final LoansApiResource loansApiResource;
/**
* Returns {@link BatchResponse} object by taking in and executing {@link BatchRequest} object.
*
* @param request
* the {@link BatchRequest} object
* @param uriInfo
* the {@link UriInfo} object
* @return response the {@link BatchResponse} object
*/
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/external-id\/[\w\d_-]+\?command=adjust
final String relativeUrl = request.getRelativeUrl();
// Get the loan id for use in loansApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanIdPathParameter = pathParameters.get(2);
String loanExternalId;
if (loanIdPathParameter.contains("?")) {
loanExternalId = StringUtils.substringBefore(loanIdPathParameter, "?");
} else {
loanExternalId = loanIdPathParameter;
}
final Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
final String command = queryParameters.get("command");
responseBody = loansApiResource.modifyLoanApplication(loanExternalId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response modifying the loan application
response.setBody(responseBody);
return response;
}
}
@@ -0,0 +1,97 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyUtils;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link org.apache.fineract.batch.command.CommandStrategy} to handle any updates to the loan application.
* It passes the contents of the body from the BatchRequest to
* {@link org.apache.fineract.portfolio.loanaccount.api.LoansApiResource} and gets back the response. This class will
* also catch any errors raised by {@link org.apache.fineract.portfolio.loanaccount.api.LoansApiResource} and map those
* errors to appropriate status codes in BatchResponse.
*
* @see org.apache.fineract.batch.command.CommandStrategy
* @see org.apache.fineract.batch.domain.BatchRequest
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class ModifyLoanApplicationCommandStrategy implements CommandStrategy {
/**
* {@link LoansApiResource} object
*/
private final LoansApiResource loansApiResource;
/**
* Returns {@link org.apache.fineract.batch.domain.BatchResponse} object by taking in and executing
* {@link org.apache.fineract.batch.domain.BatchRequest} object.
*
* @param request
* the {@link org.apache.fineract.batch.domain.BatchRequest} object
* @param uriInfo
* the {@link UriInfo} object
* @return response the {@link org.apache.fineract.batch.domain.BatchResponse} object
*/
@Override
public BatchResponse execute(final BatchRequest request, final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
final String responseBody;
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
final String relativeUrl = request.getRelativeUrl();
// Get the loan id for use in loansApiResource
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
final String loanIdPathParameter = pathParameters.get(1);
Long loanId;
if (loanIdPathParameter.contains("?")) {
loanId = Long.parseLong(loanIdPathParameter.substring(0, loanIdPathParameter.indexOf("?")));
} else {
loanId = Long.parseLong(loanIdPathParameter);
}
final Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
final String command = queryParameters.get("command");
responseBody = loansApiResource.modifyLoanApplication(loanId, command, request.getBody());
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response modifying the loan application
response.setBody(responseBody);
return response;
}
}
@@ -24,6 +24,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -62,7 +63,7 @@ public class UpdateClientCommandStrategy implements CommandStrategy {
// client
responseBody = clientsApiResource.update(clientId, request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after the successful update of
// client information
response.setBody(responseBody);
@@ -26,6 +26,7 @@ import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.dataqueries.api.DatatablesApiResource;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -62,7 +63,7 @@ public class UpdateDatatableEntryOneToManyCommandStrategy implements CommandStra
// 'DatatablesApiResource' to update a datatable entry on an existing entity in a one-many relationship
responseBody = datatablesApiResource.updateDatatableEntryOneToMany(datatableName, entityId, datatableEntryId, request.getBody());
response.setStatusCode(200);
response.setStatusCode(HttpStatus.SC_OK);
// Sets the body of the response after datatable entry is successfully
// updated
response.setBody(responseBody);
@@ -107,6 +107,8 @@ final class LoanChargesApiResourceSwagger {
public LocalDate submittedOnDate;
@Schema(example = "95174ff9-1a75-4d72-a413-6f9b1cb988b7")
public String externalId;
@Schema(example = "26 March 2013")
public LocalDate dueDate;
}
@Schema(description = "GetLoansLoanIdChargesTemplateResponse")
@@ -957,6 +957,8 @@ final class LoansApiResourceSwagger {
public boolean disallowExpectedDisbursements;
@Schema(example = "1")
public Integer clientId;
@Schema(example = "5e77989e-aa11-11bc-b109-0242ac120004")
public String clientExternalId;
@Schema(example = "Kampala first Client")
public String clientName;
@Schema(example = "2")
@@ -981,6 +983,8 @@ final class LoansApiResourceSwagger {
public BigDecimal principal;
@Schema(example = "1000.000000")
public Double approvedPrincipal;
@Schema(example = "1001.000000")
public Double proposedPrincipal;
@Schema(example = "200.000000")
public Double netDisbursalAmount;
@Schema(example = "12")
@@ -996,6 +1000,8 @@ final class LoansApiResourceSwagger {
public GetLoansLoanIdInterestRateFrequencyType interestRateFrequencyType;
@Schema(example = "24")
public Integer annualInterestRate;
@Schema(example = "false")
public Boolean isFloatingInterestRate;
public GetLoansLoanIdAmortizationType amortizationType;
@Schema(example = "5.5")
public BigDecimal fixedPrincipalPercentagePerInstallment;
@@ -1057,8 +1063,8 @@ final class LoansApiResourceSwagger {
public String locale;
@Schema(example = "1")
public Integer productId;
@Schema(example = "100,000.00")
public String principal;
@Schema(example = "1000.00")
public BigDecimal principal;
@Schema(example = "12")
public Integer loanTermFrequency;
@Schema(example = "2")
@@ -1163,9 +1169,11 @@ final class LoansApiResourceSwagger {
@Schema(example = "1")
public Integer clientId;
@Schema(example = "1")
public Integer loanId;
public Long loanId;
@Schema(example = "1")
public Integer resourceId;
public Long resourceId;
@Schema(example = "95174ff9-1a75-4d72-a413-6f9b1cb988b7")
public String resourceExternalId;
}
@Schema(description = "PutLoansLoanIdRequest")
@@ -1314,9 +1322,9 @@ final class LoansApiResourceSwagger {
@Schema(example = "1")
public Integer clientId;
@Schema(example = "1")
public Integer loanId;
public Long loanId;
@Schema(example = "1")
public Integer resourceId;
public Long resourceId;
@Schema(example = "95174ff9-1a75-4d72-a413-6f9b1cb988b7")
public String resourceExternalId;
public PutLoansLoanIdChanges changes;
@@ -1332,9 +1340,9 @@ final class LoansApiResourceSwagger {
@Schema(example = "1")
public Integer clientId;
@Schema(example = "1")
public Integer loanId;
public Long loanId;
@Schema(example = "1")
public Integer resourceId;
public Long resourceId;
@Schema(example = "95174ff9-1a75-4d72-a413-6f9b1cb988b7")
public String resourceExternalId;
}
@@ -1370,7 +1378,7 @@ final class LoansApiResourceSwagger {
@Schema(example = "3e7791ce-aa10-11ec-b909-0242ac120002")
public String externalId;
@Schema(example = "5000.33")
public String transactionAmount;
public BigDecimal transactionAmount;
@Schema(example = "Description of disbursement details.")
public String note;
@Schema(example = "28 June 2022")
@@ -1380,7 +1388,7 @@ final class LoansApiResourceSwagger {
@Schema(example = "28 June 2022")
public String approvedOnDate;
@Schema(example = "1000")
public String approvedLoanAmount;
public BigDecimal approvedLoanAmount;
@Schema(example = "28 June 2022")
public String expectedDisbursementDate;
@Schema(example = "28 June 2022")