Lombok refactoring continued

This commit is contained in:
Arnold Galovics
2022-04-09 13:23:57 +02:00
committed by Arnold Gálovics
parent ddd97f274e
commit ab80cc0477
24 changed files with 79 additions and 309 deletions
@@ -37,13 +37,13 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.serialization.BatchRequestJsonHelper; import org.apache.fineract.batch.serialization.BatchRequestJsonHelper;
import org.apache.fineract.batch.service.BatchApiService; import org.apache.fineract.batch.service.BatchApiService;
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer; import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -70,6 +70,7 @@ import org.springframework.stereotype.Component;
+ "Batch API uses Json Path to handle dependent parameters. For example, if request '2' is referencing request '1' and in the \"body\" or in \"relativeUrl\" of request '2', there is a dependent parameter (which will look like \"$.parameter_name\"), then Batch API will internally substitute this dependent parameter from the response body of request '1'.\n" + "Batch API uses Json Path to handle dependent parameters. For example, if request '2' is referencing request '1' and in the \"body\" or in \"relativeUrl\" of request '2', there is a dependent parameter (which will look like \"$.parameter_name\"), then Batch API will internally substitute this dependent parameter from the response body of request '1'.\n"
+ "\n" + "\n"
+ "Batch API is able to handle deeply nested dependent requests as well nested parameters. As shown in the example, requests are dependent on each other as, 1<--2<--6, i.e a nested dependency, where request '6' is not directly dependent on request '1' but still it is one of the nested child of request '1'. In the same way Batch API could handle a deeply nested dependent value, such as {..[..{..,$.parameter_name,..}..]}.") + "Batch API is able to handle deeply nested dependent requests as well nested parameters. As shown in the example, requests are dependent on each other as, 1<--2<--6, i.e a nested dependency, where request '6' is not directly dependent on request '1' but still it is one of the nested child of request '1'. In the same way Batch API could handle a deeply nested dependent value, such as {..[..{..,$.parameter_name,..}..]}.")
@RequiredArgsConstructor
public class BatchApiResource { public class BatchApiResource {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
@@ -77,24 +78,6 @@ public class BatchApiResource {
private final BatchApiService service; private final BatchApiService service;
private final BatchRequestJsonHelper batchRequestJsonHelper; private final BatchRequestJsonHelper batchRequestJsonHelper;
/**
* Constructs a 'BatchApiService' with context, toApiJsonSerializer, service and batchRequestJsonHelper.
*
* @param context
* @param toApiJsonSerializer
* @param service
* @param batchRequestJsonHelper
*/
@Autowired
public BatchApiResource(final PlatformSecurityContext context, final ToApiJsonSerializer<BatchResponse> toApiJsonSerializer,
final BatchApiService service, final BatchRequestJsonHelper batchRequestJsonHelper) {
this.context = context;
this.toApiJsonSerializer = toApiJsonSerializer;
this.service = service;
this.batchRequestJsonHelper = batchRequestJsonHelper;
}
/** /**
* Rest assured POST method to get {@link BatchRequest} and returns back the consolidated {@link BatchResponse} * Rest assured POST method to get {@link BatchRequest} and returns back the consolidated {@link BatchResponse}
* *
@@ -21,7 +21,6 @@ package org.apache.fineract.batch.command;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.fineract.batch.command.internal.UnknownCommandStrategy; import org.apache.fineract.batch.command.internal.UnknownCommandStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -46,7 +45,6 @@ public class CommandStrategyProvider {
* *
* @param applicationContext * @param applicationContext
*/ */
@Autowired
public CommandStrategyProvider(final ApplicationContext applicationContext) { public CommandStrategyProvider(final ApplicationContext applicationContext) {
// calls init() function of this class. // calls init() function of this class.
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.client.api.ClientsApiResource; import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class ActivateClientCommandStrategy implements CommandStrategy { public class ActivateClientCommandStrategy implements CommandStrategy {
private final ClientsApiResource clientsApiResource; private final ClientsApiResource clientsApiResource;
@Autowired
public ActivateClientCommandStrategy(final ClientsApiResource clientsApiResource) {
this.clientsApiResource = clientsApiResource;
}
@Override @Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal; package org.apache.fineract.batch.command.internal;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource; import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class ApplyLoanCommandStrategy implements CommandStrategy { public class ApplyLoanCommandStrategy implements CommandStrategy {
private final LoansApiResource loansApiResource; private final LoansApiResource loansApiResource;
@Autowired
public ApplyLoanCommandStrategy(final LoansApiResource loansApiResource) {
this.loansApiResource = loansApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal; package org.apache.fineract.batch.command.internal;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.savings.api.SavingsAccountsApiResource; import org.apache.fineract.portfolio.savings.api.SavingsAccountsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class ApplySavingsCommandStrategy implements CommandStrategy { public class ApplySavingsCommandStrategy implements CommandStrategy {
private final SavingsAccountsApiResource savingsAccountsApiResource; private final SavingsAccountsApiResource savingsAccountsApiResource;
@Autowired
public ApplySavingsCommandStrategy(final SavingsAccountsApiResource savingsAccountsApiResource) {
this.savingsAccountsApiResource = savingsAccountsApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource; import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class ApproveLoanCommandStrategy implements CommandStrategy { public class ApproveLoanCommandStrategy implements CommandStrategy {
private final LoansApiResource loansApiResource; private final LoansApiResource loansApiResource;
@Autowired
public ApproveLoanCommandStrategy(final LoansApiResource loansApiResource) {
this.loansApiResource = loansApiResource;
}
@Override @Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -21,25 +21,21 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.api.RescheduleLoansApiResource; import org.apache.fineract.portfolio.loanaccount.rescheduleloan.api.RescheduleLoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@RequiredArgsConstructor
public class ApproveLoanRescheduleCommandStrategy implements CommandStrategy { public class ApproveLoanRescheduleCommandStrategy implements CommandStrategy {
private final RescheduleLoansApiResource rescheduleLoansApiResource; private final RescheduleLoansApiResource rescheduleLoansApiResource;
@Autowired
public ApproveLoanRescheduleCommandStrategy(final RescheduleLoansApiResource rescheduleLoansApiResource) {
this.rescheduleLoansApiResource = rescheduleLoansApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, UriInfo uriInfo) {
final BatchResponse response = new BatchResponse(); final BatchResponse response = new BatchResponse();
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource; import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class CollectChargesCommandStrategy implements CommandStrategy { public class CollectChargesCommandStrategy implements CommandStrategy {
private final LoanChargesApiResource loanChargesApiResource; private final LoanChargesApiResource loanChargesApiResource;
@Autowired
public CollectChargesCommandStrategy(final LoanChargesApiResource loanChargesApiResource) {
this.loanChargesApiResource = loanChargesApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, UriInfo uriInfo) {
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource; import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class CreateChargeCommandStrategy implements CommandStrategy { public class CreateChargeCommandStrategy implements CommandStrategy {
private final LoanChargesApiResource loanChargesApiResource; private final LoanChargesApiResource loanChargesApiResource;
@Autowired
public CreateChargeCommandStrategy(final LoanChargesApiResource loanChargesApiResource) {
this.loanChargesApiResource = loanChargesApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal; package org.apache.fineract.batch.command.internal;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.client.api.ClientsApiResource; import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class CreateClientCommandStrategy implements CommandStrategy { public class CreateClientCommandStrategy implements CommandStrategy {
private final ClientsApiResource clientsApiResource; private final ClientsApiResource clientsApiResource;
@Autowired
public CreateClientCommandStrategy(final ClientsApiResource clientsApiResource) {
this.clientsApiResource = clientsApiResource;
}
@Override @Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource; import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class DisburseLoanCommandStrategy implements CommandStrategy { public class DisburseLoanCommandStrategy implements CommandStrategy {
private final LoansApiResource loansApiResource; private final LoansApiResource loansApiResource;
@Autowired
public DisburseLoanCommandStrategy(final LoansApiResource loansApiResource) {
this.loansApiResource = loansApiResource;
}
@Override @Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource; import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see BatchResponse * @see BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class RepayLoanCommandStrategy implements CommandStrategy { public class RepayLoanCommandStrategy implements CommandStrategy {
private final LoanTransactionsApiResource loanTransactionsApiResource; private final LoanTransactionsApiResource loanTransactionsApiResource;
@Autowired
public RepayLoanCommandStrategy(final LoanTransactionsApiResource loanTransactionsApiResource) {
this.loanTransactionsApiResource = loanTransactionsApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal; package org.apache.fineract.batch.command.internal;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.client.api.ClientsApiResource; import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse * @see org.apache.fineract.batch.domain.BatchResponse
*/ */
@Component @Component
@RequiredArgsConstructor
public class UpdateClientCommandStrategy implements CommandStrategy { public class UpdateClientCommandStrategy implements CommandStrategy {
private final ClientsApiResource clientsApiResource; private final ClientsApiResource clientsApiResource;
@Autowired
public UpdateClientCommandStrategy(final ClientsApiResource clientsApiResource) {
this.clientsApiResource = clientsApiResource;
}
@Override @Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) { public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -26,6 +26,7 @@ import java.util.List;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandContext; import org.apache.fineract.batch.command.CommandContext;
import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.command.CommandStrategyProvider; import org.apache.fineract.batch.command.CommandStrategyProvider;
@@ -35,7 +36,6 @@ import org.apache.fineract.batch.exception.ClientDetailsNotFoundException;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode; import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.NonTransientDataAccessException; import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionException; import org.springframework.transaction.TransactionException;
@@ -54,28 +54,13 @@ import org.springframework.transaction.support.TransactionTemplate;
* @see org.apache.fineract.batch.command.CommandStrategyProvider * @see org.apache.fineract.batch.command.CommandStrategyProvider
*/ */
@Service @Service
@RequiredArgsConstructor
public class BatchApiServiceImpl implements BatchApiService { public class BatchApiServiceImpl implements BatchApiService {
private final CommandStrategyProvider strategyProvider; private final CommandStrategyProvider strategyProvider;
private final ResolutionHelper resolutionHelper; private final ResolutionHelper resolutionHelper;
private final TransactionTemplate transactionTemplate; private final TransactionTemplate transactionTemplate;
/**
* Constructs a 'BatchApiServiceImpl' with an argument of
* {@link org.apache.fineract.batch.command.CommandStrategyProvider} type.
*
* @param strategyProvider
* @param resolutionHelper
* @param transactionTemplate
*/
@Autowired
public BatchApiServiceImpl(final CommandStrategyProvider strategyProvider, final ResolutionHelper resolutionHelper,
final TransactionTemplate transactionTemplate) {
this.strategyProvider = strategyProvider;
this.resolutionHelper = resolutionHelper;
this.transactionTemplate = transactionTemplate;
}
/** /**
* Returns the response list by getting a proper {@link org.apache.fineract.batch.command.CommandStrategy}. * Returns the response list by getting a proper {@link org.apache.fineract.batch.command.CommandStrategy}.
* execute() method of acquired commandStrategy is then provided with the separate Request. * execute() method of acquired commandStrategy is then provided with the separate Request.
@@ -27,10 +27,10 @@ import com.jayway.jsonpath.ReadContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -41,6 +41,7 @@ import org.springframework.stereotype.Component;
* @see BatchApiServiceImpl * @see BatchApiServiceImpl
*/ */
@Component @Component
@RequiredArgsConstructor
public class ResolutionHelper { public class ResolutionHelper {
/** /**
@@ -76,12 +77,7 @@ public class ResolutionHelper {
} }
private FromJsonHelper fromJsonHelper; private final FromJsonHelper fromJsonHelper;
@Autowired
public ResolutionHelper(final FromJsonHelper fromJsonHelper) {
this.fromJsonHelper = fromJsonHelper;
}
/** /**
* Returns a map containing requests that are divided in accordance of dependency relations among them. Each * Returns a map containing requests that are divided in accordance of dependency relations among them. Each
@@ -39,6 +39,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.data.AuditData; import org.apache.fineract.commands.data.AuditData;
import org.apache.fineract.commands.data.AuditSearchData; import org.apache.fineract.commands.data.AuditSearchData;
import org.apache.fineract.commands.service.AuditReadPlatformService; import org.apache.fineract.commands.service.AuditReadPlatformService;
@@ -49,7 +50,6 @@ import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSer
import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.security.utils.SQLBuilder; import org.apache.fineract.infrastructure.security.utils.SQLBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -61,6 +61,7 @@ import org.springframework.stereotype.Component;
+ "Permissions: To search and look at audit entries a user needs to be attached to a role that has one of the ALL_FUNCTIONS, ALL_FUNCTIONS_READ or READ_AUDIT permissions.\n" + "Permissions: To search and look at audit entries a user needs to be attached to a role that has one of the ALL_FUNCTIONS, ALL_FUNCTIONS_READ or READ_AUDIT permissions.\n"
+ "\n" + "\n"
+ "Data Scope: A user can only see audits that are within their data scope. However, 'head office' users can see all audits including those that aren't office/branch related e.g. Loan Product changes.\")") + "Data Scope: A user can only see audits that are within their data scope. However, 'head office' users can see all audits including those that aren't office/branch related e.g. Loan Product changes.\")")
@RequiredArgsConstructor
public class AuditsApiResource { public class AuditsApiResource {
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId", private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId",
@@ -75,17 +76,6 @@ public class AuditsApiResource {
private final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializer; private final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializer;
private final DefaultToApiJsonSerializer<AuditSearchData> toApiJsonSerializerSearchTemplate; private final DefaultToApiJsonSerializer<AuditSearchData> toApiJsonSerializerSearchTemplate;
@Autowired
public AuditsApiResource(final PlatformSecurityContext context, final AuditReadPlatformService auditReadPlatformService,
final ApiRequestParameterHelper apiRequestParameterHelper, final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializer,
final DefaultToApiJsonSerializer<AuditSearchData> toApiJsonSerializerSearchTemplate) {
this.context = context;
this.auditReadPlatformService = auditReadPlatformService;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.toApiJsonSerializer = toApiJsonSerializer;
this.toApiJsonSerializerSearchTemplate = toApiJsonSerializerSearchTemplate;
}
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@@ -41,6 +41,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.data.AuditData; import org.apache.fineract.commands.data.AuditData;
import org.apache.fineract.commands.data.AuditSearchData; import org.apache.fineract.commands.data.AuditSearchData;
@@ -52,7 +53,6 @@ import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamE
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.utils.SQLBuilder; import org.apache.fineract.infrastructure.security.utils.SQLBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -60,6 +60,7 @@ import org.springframework.stereotype.Component;
@Component @Component
@Scope("singleton") @Scope("singleton")
@Tag(name = "Maker Checker (or 4-eye) functionality") @Tag(name = "Maker Checker (or 4-eye) functionality")
@RequiredArgsConstructor
public class MakercheckersApiResource { public class MakercheckersApiResource {
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId", private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId",
@@ -72,19 +73,6 @@ public class MakercheckersApiResource {
private final ApiRequestParameterHelper apiRequestParameterHelper; private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService writePlatformService; private final PortfolioCommandSourceWritePlatformService writePlatformService;
@Autowired
public MakercheckersApiResource(final AuditReadPlatformService readPlatformService,
final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializerAudit,
final DefaultToApiJsonSerializer<AuditSearchData> toApiJsonSerializerSearchTemplate,
final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService writePlatformService) {
this.readPlatformService = readPlatformService;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.toApiJsonSerializerAudit = toApiJsonSerializerAudit;
this.toApiJsonSerializerSearchTemplate = toApiJsonSerializerSearchTemplate;
this.writePlatformService = writePlatformService;
}
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@@ -19,88 +19,36 @@
package org.apache.fineract.commands.data; package org.apache.fineract.commands.data;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
/** /**
* Immutable data object representing client data. * Immutable data object representing client data.
*/ */
@AllArgsConstructor
@Getter
public final class AuditData { public final class AuditData {
@SuppressWarnings("unused")
private final Long id; private final Long id;
@SuppressWarnings("unused")
private final String actionName; private final String actionName;
private final String entityName; private final String entityName;
@SuppressWarnings("unused")
private final Long resourceId; private final Long resourceId;
@SuppressWarnings("unused")
private final Long subresourceId; private final Long subresourceId;
@SuppressWarnings("unused")
private final String maker; private final String maker;
@SuppressWarnings("unused")
private final ZonedDateTime madeOnDate; private final ZonedDateTime madeOnDate;
@SuppressWarnings("unused")
private final String checker; private final String checker;
@SuppressWarnings("unused")
private final ZonedDateTime checkedOnDate; private final ZonedDateTime checkedOnDate;
@SuppressWarnings("unused")
private final String processingResult; private final String processingResult;
@Setter
private String commandAsJson; private String commandAsJson;
@SuppressWarnings("unused")
private final String officeName; private final String officeName;
@SuppressWarnings("unused")
private final String groupLevelName; private final String groupLevelName;
@SuppressWarnings("unused")
private final String groupName; private final String groupName;
@SuppressWarnings("unused")
private final String clientName; private final String clientName;
@SuppressWarnings("unused")
private final String loanAccountNo; private final String loanAccountNo;
@SuppressWarnings("unused")
private final String savingsAccountNo; private final String savingsAccountNo;
@SuppressWarnings("unused")
private final Long clientId; private final Long clientId;
@SuppressWarnings("unused")
private final Long loanId; private final Long loanId;
@SuppressWarnings("unused")
private final String url; private final String url;
public AuditData(final Long id, final String actionName, final String entityName, final Long resourceId, final Long subresourceId,
final String maker, final ZonedDateTime madeOnDate, final String checker, final ZonedDateTime checkedOnDate,
final String processingResult, final String commandAsJson, final String officeName, final String groupLevelName,
final String groupName, final String clientName, final String loanAccountNo, final String savingsAccountNo, final Long clientId,
final Long loanId, final String url) {
this.id = id;
this.actionName = actionName;
this.entityName = entityName;
this.resourceId = resourceId;
this.subresourceId = subresourceId;
this.maker = maker;
this.madeOnDate = madeOnDate;
this.checker = checker;
this.checkedOnDate = checkedOnDate;
this.commandAsJson = commandAsJson;
this.processingResult = processingResult;
this.officeName = officeName;
this.groupLevelName = groupLevelName;
this.groupName = groupName;
this.clientName = clientName;
this.loanAccountNo = loanAccountNo;
this.savingsAccountNo = savingsAccountNo;
this.clientId = clientId;
this.loanId = loanId;
this.url = url;
}
public void setCommandAsJson(final String commandAsJson) {
this.commandAsJson = commandAsJson;
}
public String getCommandAsJson() {
return this.commandAsJson;
}
public String getEntityName() {
return this.entityName;
}
} }
@@ -20,27 +20,19 @@ package org.apache.fineract.commands.data;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.useradministration.data.AppUserData; import org.apache.fineract.useradministration.data.AppUserData;
/** /**
* Immutable data object representing audit search results. * Immutable data object representing audit search results.
*/ */
@RequiredArgsConstructor
@Getter
public final class AuditSearchData { public final class AuditSearchData {
@SuppressWarnings("unused")
private final Collection<AppUserData> appUsers; private final Collection<AppUserData> appUsers;
@SuppressWarnings("unused")
private final List<String> actionNames; private final List<String> actionNames;
@SuppressWarnings("unused")
private final List<String> entityNames; private final List<String> entityNames;
@SuppressWarnings("unused")
private final Collection<ProcessingResultLookup> processingResults; private final Collection<ProcessingResultLookup> processingResults;
public AuditSearchData(final Collection<AppUserData> appUsers, final List<String> apiOperations, final List<String> resources,
final Collection<ProcessingResultLookup> processingResults) {
this.appUsers = appUsers;
this.actionNames = apiOperations;
this.entityNames = resources;
this.processingResults = processingResults;
}
} }
@@ -18,25 +18,17 @@
*/ */
package org.apache.fineract.commands.data; package org.apache.fineract.commands.data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/** /**
* Immutable data object for application user data. * Immutable data object for application user data.
*/ */
@RequiredArgsConstructor
@Getter
public class ProcessingResultLookup { public class ProcessingResultLookup {
private final Long id; private final Long id;
private final String processingResult; private final String processingResult;
public ProcessingResultLookup(final Long id, final String processingResult) {
this.id = id;
this.processingResult = processingResult;
}
public Long getId() {
return this.id;
}
public String getProcessingResult() {
return this.processingResult;
}
} }
@@ -20,17 +20,16 @@ package org.apache.fineract.commands.provider;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.HashMap; import java.util.HashMap;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.exception.UnsupportedCommandException; import org.apache.fineract.commands.exception.UnsupportedCommandException;
import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -46,18 +45,13 @@ import org.springframework.stereotype.Component;
* @see CommandType * @see CommandType
*/ */
@Component @Component
@Scope("singleton") @NoArgsConstructor
@Slf4j
public class CommandHandlerProvider implements ApplicationContextAware { public class CommandHandlerProvider implements ApplicationContextAware {
private static final Logger LOGGER = LoggerFactory.getLogger(CommandHandlerProvider.class);
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
private HashMap<String, String> registeredHandlers; private HashMap<String, String> registeredHandlers;
CommandHandlerProvider() {
}
/** /**
* Returns a handler for the given entity and action.<br> * Returns a handler for the given entity and action.<br>
* <br> * <br>
@@ -87,12 +81,12 @@ public class CommandHandlerProvider implements ApplicationContextAware {
final String[] commandHandlerBeans = this.applicationContext.getBeanNamesForAnnotation(CommandType.class); final String[] commandHandlerBeans = this.applicationContext.getBeanNamesForAnnotation(CommandType.class);
if (ArrayUtils.isNotEmpty(commandHandlerBeans)) { if (ArrayUtils.isNotEmpty(commandHandlerBeans)) {
for (final String commandHandlerName : commandHandlerBeans) { for (final String commandHandlerName : commandHandlerBeans) {
LOGGER.info("Register command handler '{}' ...", commandHandlerName); log.info("Register command handler '{}' ...", commandHandlerName);
final CommandType commandType = this.applicationContext.findAnnotationOnBean(commandHandlerName, CommandType.class); final CommandType commandType = this.applicationContext.findAnnotationOnBean(commandHandlerName, CommandType.class);
try { try {
this.registeredHandlers.put(commandType.entity() + "|" + commandType.action(), commandHandlerName); this.registeredHandlers.put(commandType.entity() + "|" + commandType.action(), commandHandlerName);
} catch (final Throwable th) { } catch (final Throwable th) {
LOGGER.error("Unable to register command handler '{}'!", commandHandlerName, th); log.error("Unable to register command handler '{}'!", commandHandlerName, th);
} }
} }
} }
@@ -31,6 +31,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.data.AuditData; import org.apache.fineract.commands.data.AuditData;
import org.apache.fineract.commands.data.AuditSearchData; import org.apache.fineract.commands.data.AuditSearchData;
@@ -64,17 +66,15 @@ import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformS
import org.apache.fineract.useradministration.data.AppUserData; import org.apache.fineract.useradministration.data.AppUserData;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.apache.fineract.useradministration.service.AppUserReadPlatformService; import org.apache.fineract.useradministration.service.AppUserReadPlatformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@RequiredArgsConstructor
@Slf4j
public class AuditReadPlatformServiceImpl implements AuditReadPlatformService { public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
private static final Logger LOG = LoggerFactory.getLogger(AuditReadPlatformServiceImpl.class);
private static final Set<String> supportedOrderByValues = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId", private static final Set<String> supportedOrderByValues = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId",
"subresourceId", "madeOnDate", "checkedOnDate", "officeName", "groupName", "clientName", "loanAccountNo", "savingsAccountNo", "subresourceId", "madeOnDate", "checkedOnDate", "officeName", "groupName", "clientName", "loanAccountNo", "savingsAccountNo",
"clientId", "loanId", "maker", "checker", "processingResult")); "clientId", "loanId", "maker", "checker", "processingResult"));
@@ -94,31 +94,6 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
private final DepositProductReadPlatformService depositProductReadPlatformService; private final DepositProductReadPlatformService depositProductReadPlatformService;
private final ColumnValidator columnValidator; private final ColumnValidator columnValidator;
@Autowired
public AuditReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate,
final FromJsonHelper fromApiJsonHelper, final AppUserReadPlatformService appUserReadPlatformService,
final OfficeReadPlatformService officeReadPlatformService, final ClientReadPlatformService clientReadPlatformService,
final LoanProductReadPlatformService loanProductReadPlatformService, final StaffReadPlatformService staffReadPlatformService,
final PaginationParametersDataValidator paginationParametersDataValidator,
final SavingsProductReadPlatformService savingsProductReadPlatformService,
final DepositProductReadPlatformService depositProductReadPlatformService, final ColumnValidator columnValidator,
DatabaseSpecificSQLGenerator sqlGenerator, PaginationHelper paginationHelper) {
this.context = context;
this.jdbcTemplate = jdbcTemplate;
this.fromApiJsonHelper = fromApiJsonHelper;
this.appUserReadPlatformService = appUserReadPlatformService;
this.officeReadPlatformService = officeReadPlatformService;
this.clientReadPlatformService = clientReadPlatformService;
this.loanProductReadPlatformService = loanProductReadPlatformService;
this.staffReadPlatformService = staffReadPlatformService;
this.paginationParametersDataValidator = paginationParametersDataValidator;
this.savingsProductReadPlatformService = savingsProductReadPlatformService;
this.depositProductReadPlatformService = depositProductReadPlatformService;
this.columnValidator = columnValidator;
this.paginationHelper = paginationHelper;
this.sqlGenerator = sqlGenerator;
}
private static final class AuditMapper implements RowMapper<AuditData> { private static final class AuditMapper implements RowMapper<AuditData> {
public String schema(final boolean includeJson, final String hierarchy) { public String schema(final boolean includeJson, final String hierarchy) {
@@ -218,7 +193,7 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
this.columnValidator.validateSqlInjection(sqlBuilder.toString(), parameters.limitSql()); this.columnValidator.validateSqlInjection(sqlBuilder.toString(), parameters.limitSql());
} }
LOG.info("sql: {}", sqlBuilder); log.info("sql: {}", sqlBuilder);
return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlBuilder.toString(), extraCriteria.getArguments(), rm); return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlBuilder.toString(), extraCriteria.getArguments(), rm);
} }
@@ -257,7 +232,7 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
} }
sql += extraCriteria.getSQLTemplate(); sql += extraCriteria.getSQLTemplate();
sql += groupAndOrderBySQL; sql += groupAndOrderBySQL;
LOG.info("sql: {}", sql); log.info("sql: {}", sql);
return this.jdbcTemplate.query(sql, rm, extraCriteria.getArguments()); return this.jdbcTemplate.query(sql, rm, extraCriteria.getArguments());
} }
@@ -22,6 +22,8 @@ import com.google.gson.JsonElement;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.commands.domain.CommandSource; import org.apache.fineract.commands.domain.CommandSource;
import org.apache.fineract.commands.domain.CommandSourceRepository; import org.apache.fineract.commands.domain.CommandSourceRepository;
import org.apache.fineract.commands.domain.CommandWrapper; import org.apache.fineract.commands.domain.CommandWrapper;
@@ -36,35 +38,23 @@ import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.infrastructure.jobs.service.SchedulerJobRunnerReadService; import org.apache.fineract.infrastructure.jobs.service.SchedulerJobRunnerReadService;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.CannotAcquireLockException;
import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
@RequiredArgsConstructor
@Slf4j
public class PortfolioCommandSourceWritePlatformServiceImpl implements PortfolioCommandSourceWritePlatformService { public class PortfolioCommandSourceWritePlatformServiceImpl implements PortfolioCommandSourceWritePlatformService {
private static final SecureRandom RANDOM = new SecureRandom();
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final CommandSourceRepository commandSourceRepository; private final CommandSourceRepository commandSourceRepository;
private final FromJsonHelper fromApiJsonHelper; private final FromJsonHelper fromApiJsonHelper;
private final CommandProcessingService processAndLogCommandService; private final CommandProcessingService processAndLogCommandService;
private final SchedulerJobRunnerReadService schedulerJobRunnerReadService; private final SchedulerJobRunnerReadService schedulerJobRunnerReadService;
private static final Logger LOG = LoggerFactory.getLogger(PortfolioCommandSourceWritePlatformServiceImpl.class);
private static final SecureRandom random = new SecureRandom();
@Autowired
public PortfolioCommandSourceWritePlatformServiceImpl(final PlatformSecurityContext context,
final CommandSourceRepository commandSourceRepository, final FromJsonHelper fromApiJsonHelper,
final CommandProcessingService processAndLogCommandService, final SchedulerJobRunnerReadService schedulerJobRunnerReadService) {
this.context = context;
this.commandSourceRepository = commandSourceRepository;
this.fromApiJsonHelper = fromApiJsonHelper;
this.processAndLogCommandService = processAndLogCommandService;
this.schedulerJobRunnerReadService = schedulerJobRunnerReadService;
}
@Override @Override
@SuppressWarnings("AvoidHidingCauseException") @SuppressWarnings("AvoidHidingCauseException")
@@ -90,9 +80,9 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
final String json = wrapper.getJson(); final String json = wrapper.getJson();
CommandProcessingResult result = null; CommandProcessingResult result = null;
JsonCommand command = null; JsonCommand command = null;
Integer numberOfRetries = 0; int numberOfRetries = 0;
Integer maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock(); int maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock();
Integer maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries(); int maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries();
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json);
command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(), command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(),
wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(),
@@ -103,12 +93,12 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker);
numberOfRetries = maxNumberOfRetries + 1; numberOfRetries = maxNumberOfRetries + 1;
} catch (CannotAcquireLockException | ObjectOptimisticLockingFailureException exception) { } catch (CannotAcquireLockException | ObjectOptimisticLockingFailureException exception) {
LOG.info("The following command {} has been retried {} time(s)", command.json(), numberOfRetries); log.info("The following command {} has been retried {} time(s)", command.json(), numberOfRetries);
/*** /***
* Fail if the transaction has been retired for maxNumberOfRetries * Fail if the transaction has been retired for maxNumberOfRetries
**/ **/
if (numberOfRetries >= maxNumberOfRetries) { if (numberOfRetries >= maxNumberOfRetries) {
LOG.warn("The following command {} has been retried for the max allowed attempts of {} and will be rolled back", log.warn("The following command {} has been retried for the max allowed attempts of {} and will be rolled back",
command.json(), numberOfRetries); command.json(), numberOfRetries);
throw exception; throw exception;
} }
@@ -116,7 +106,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
* Else sleep for a random time (between 1 to 10 seconds) and continue * Else sleep for a random time (between 1 to 10 seconds) and continue
**/ **/
try { try {
int randomNum = random.nextInt(maxIntervalBetweenRetries + 1); int randomNum = RANDOM.nextInt(maxIntervalBetweenRetries + 1);
Thread.sleep(1000 + (randomNum * 1000)); Thread.sleep(1000 + (randomNum * 1000));
numberOfRetries = numberOfRetries + 1; numberOfRetries = numberOfRetries + 1;
} catch (InterruptedException e) { } catch (InterruptedException e) {
@@ -25,6 +25,8 @@ import java.time.Instant;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.commands.domain.CommandSource; import org.apache.fineract.commands.domain.CommandSource;
@@ -45,42 +47,23 @@ import org.apache.fineract.infrastructure.hooks.event.HookEvent;
import org.apache.fineract.infrastructure.hooks.event.HookEventSource; import org.apache.fineract.infrastructure.hooks.event.HookEventSource;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
@Slf4j
@RequiredArgsConstructor
public class SynchronousCommandProcessingService implements CommandProcessingService { public class SynchronousCommandProcessingService implements CommandProcessingService {
private static final Logger LOG = LoggerFactory.getLogger(SynchronousCommandProcessingService.class); private final PlatformSecurityContext context;
private PlatformSecurityContext context;
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final ToApiJsonSerializer<Map<String, Object>> toApiJsonSerializer; private final ToApiJsonSerializer<Map<String, Object>> toApiJsonSerializer;
private final ToApiJsonSerializer<CommandProcessingResult> toApiResultJsonSerializer; private final ToApiJsonSerializer<CommandProcessingResult> toApiResultJsonSerializer;
private CommandSourceRepository commandSourceRepository; private final CommandSourceRepository commandSourceRepository;
private final ConfigurationDomainService configurationDomainService; private final ConfigurationDomainService configurationDomainService;
private final CommandHandlerProvider commandHandlerProvider; private final CommandHandlerProvider commandHandlerProvider;
@Autowired
public SynchronousCommandProcessingService(final PlatformSecurityContext context, final ApplicationContext applicationContext,
final ToApiJsonSerializer<Map<String, Object>> toApiJsonSerializer,
final ToApiJsonSerializer<CommandProcessingResult> toApiResultJsonSerializer,
final CommandSourceRepository commandSourceRepository, final ConfigurationDomainService configurationDomainService,
final CommandHandlerProvider commandHandlerProvider) {
this.context = context;
this.context = context;
this.applicationContext = applicationContext;
this.toApiJsonSerializer = toApiJsonSerializer;
this.toApiResultJsonSerializer = toApiResultJsonSerializer;
this.commandSourceRepository = commandSourceRepository;
this.commandSourceRepository = commandSourceRepository;
this.configurationDomainService = configurationDomainService;
this.commandHandlerProvider = commandHandlerProvider;
}
@Transactional @Transactional
@Override @Override
public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command, public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command,
@@ -286,7 +269,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
applicationContext.publishEvent(applicationEvent); applicationContext.publishEvent(applicationEvent);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error", e); log.error("Error", e);
} }
} }