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.MediaType;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.serialization.BatchRequestJsonHelper;
import org.apache.fineract.batch.service.BatchApiService;
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
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"
+ "\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,..}..]}.")
@RequiredArgsConstructor
public class BatchApiResource {
private final PlatformSecurityContext context;
@@ -77,24 +78,6 @@ public class BatchApiResource {
private final BatchApiService service;
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}
*
@@ -21,7 +21,6 @@ package org.apache.fineract.batch.command;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.fineract.batch.command.internal.UnknownCommandStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
@@ -46,7 +45,6 @@ public class CommandStrategyProvider {
*
* @param applicationContext
*/
@Autowired
public CommandStrategyProvider(final ApplicationContext applicationContext) {
// calls init() function of this class.
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class ActivateClientCommandStrategy implements CommandStrategy {
private final ClientsApiResource clientsApiResource;
@Autowired
public ActivateClientCommandStrategy(final ClientsApiResource clientsApiResource) {
this.clientsApiResource = clientsApiResource;
}
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class ApplyLoanCommandStrategy implements CommandStrategy {
private final LoansApiResource loansApiResource;
@Autowired
public ApplyLoanCommandStrategy(final LoansApiResource loansApiResource) {
this.loansApiResource = loansApiResource;
}
@Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.savings.api.SavingsAccountsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class ApplySavingsCommandStrategy implements CommandStrategy {
private final SavingsAccountsApiResource savingsAccountsApiResource;
@Autowired
public ApplySavingsCommandStrategy(final SavingsAccountsApiResource savingsAccountsApiResource) {
this.savingsAccountsApiResource = savingsAccountsApiResource;
}
@Override
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 java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class ApproveLoanCommandStrategy implements CommandStrategy {
private final LoansApiResource loansApiResource;
@Autowired
public ApproveLoanCommandStrategy(final LoansApiResource loansApiResource) {
this.loansApiResource = loansApiResource;
}
@Override
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 java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.api.RescheduleLoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class ApproveLoanRescheduleCommandStrategy implements CommandStrategy {
private final RescheduleLoansApiResource rescheduleLoansApiResource;
@Autowired
public ApproveLoanRescheduleCommandStrategy(final RescheduleLoansApiResource rescheduleLoansApiResource) {
this.rescheduleLoansApiResource = rescheduleLoansApiResource;
}
@Override
public BatchResponse execute(BatchRequest request, UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
@@ -21,13 +21,13 @@ package org.apache.fineract.batch.command.internal;
import com.google.common.base.Splitter;
import java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class CollectChargesCommandStrategy implements CommandStrategy {
private final LoanChargesApiResource loanChargesApiResource;
@Autowired
public CollectChargesCommandStrategy(final LoanChargesApiResource loanChargesApiResource) {
this.loanChargesApiResource = loanChargesApiResource;
}
@Override
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 java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class CreateChargeCommandStrategy implements CommandStrategy {
private final LoanChargesApiResource loanChargesApiResource;
@Autowired
public CreateChargeCommandStrategy(final LoanChargesApiResource loanChargesApiResource) {
this.loanChargesApiResource = loanChargesApiResource;
}
@Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class CreateClientCommandStrategy implements CommandStrategy {
private final ClientsApiResource clientsApiResource;
@Autowired
public CreateClientCommandStrategy(final ClientsApiResource clientsApiResource) {
this.clientsApiResource = clientsApiResource;
}
@Override
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 java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -44,15 +44,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class DisburseLoanCommandStrategy implements CommandStrategy {
private final LoansApiResource loansApiResource;
@Autowired
public DisburseLoanCommandStrategy(final LoansApiResource loansApiResource) {
this.loansApiResource = loansApiResource;
}
@Override
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 java.util.List;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see BatchResponse
*/
@Component
@RequiredArgsConstructor
public class RepayLoanCommandStrategy implements CommandStrategy {
private final LoanTransactionsApiResource loanTransactionsApiResource;
@Autowired
public RepayLoanCommandStrategy(final LoanTransactionsApiResource loanTransactionsApiResource) {
this.loanTransactionsApiResource = loanTransactionsApiResource;
}
@Override
public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") UriInfo uriInfo) {
@@ -19,13 +19,13 @@
package org.apache.fineract.batch.command.internal;
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.batch.exception.ErrorHandler;
import org.apache.fineract.batch.exception.ErrorInfo;
import org.apache.fineract.portfolio.client.api.ClientsApiResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -42,15 +42,11 @@ import org.springframework.stereotype.Component;
* @see org.apache.fineract.batch.domain.BatchResponse
*/
@Component
@RequiredArgsConstructor
public class UpdateClientCommandStrategy implements CommandStrategy {
private final ClientsApiResource clientsApiResource;
@Autowired
public UpdateClientCommandStrategy(final ClientsApiResource clientsApiResource) {
this.clientsApiResource = clientsApiResource;
}
@Override
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.Status;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandContext;
import org.apache.fineract.batch.command.CommandStrategy;
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.ErrorInfo;
import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.NonTransientDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionException;
@@ -54,28 +54,13 @@ import org.springframework.transaction.support.TransactionTemplate;
* @see org.apache.fineract.batch.command.CommandStrategyProvider
*/
@Service
@RequiredArgsConstructor
public class BatchApiServiceImpl implements BatchApiService {
private final CommandStrategyProvider strategyProvider;
private final ResolutionHelper resolutionHelper;
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}.
* 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.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -41,6 +41,7 @@ import org.springframework.stereotype.Component;
* @see BatchApiServiceImpl
*/
@Component
@RequiredArgsConstructor
public class ResolutionHelper {
/**
@@ -76,12 +77,7 @@ public class ResolutionHelper {
}
private FromJsonHelper fromJsonHelper;
@Autowired
public ResolutionHelper(final FromJsonHelper fromJsonHelper) {
this.fromJsonHelper = fromJsonHelper;
}
private final FromJsonHelper fromJsonHelper;
/**
* 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.MediaType;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.data.AuditData;
import org.apache.fineract.commands.data.AuditSearchData;
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.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.security.utils.SQLBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
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"
+ "\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.\")")
@RequiredArgsConstructor
public class AuditsApiResource {
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<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
@Consumes({ 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.MediaType;
import javax.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.data.AuditData;
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.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.utils.SQLBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -60,6 +60,7 @@ import org.springframework.stereotype.Component;
@Component
@Scope("singleton")
@Tag(name = "Maker Checker (or 4-eye) functionality")
@RequiredArgsConstructor
public class MakercheckersApiResource {
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 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
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@@ -19,88 +19,36 @@
package org.apache.fineract.commands.data;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
/**
* Immutable data object representing client data.
*/
@AllArgsConstructor
@Getter
public final class AuditData {
@SuppressWarnings("unused")
private final Long id;
@SuppressWarnings("unused")
private final String actionName;
private final String entityName;
@SuppressWarnings("unused")
private final Long resourceId;
@SuppressWarnings("unused")
private final Long subresourceId;
@SuppressWarnings("unused")
private final String maker;
@SuppressWarnings("unused")
private final ZonedDateTime madeOnDate;
@SuppressWarnings("unused")
private final String checker;
@SuppressWarnings("unused")
private final ZonedDateTime checkedOnDate;
@SuppressWarnings("unused")
private final String processingResult;
@Setter
private String commandAsJson;
@SuppressWarnings("unused")
private final String officeName;
@SuppressWarnings("unused")
private final String groupLevelName;
@SuppressWarnings("unused")
private final String groupName;
@SuppressWarnings("unused")
private final String clientName;
@SuppressWarnings("unused")
private final String loanAccountNo;
@SuppressWarnings("unused")
private final String savingsAccountNo;
@SuppressWarnings("unused")
private final Long clientId;
@SuppressWarnings("unused")
private final Long loanId;
@SuppressWarnings("unused")
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.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.useradministration.data.AppUserData;
/**
* Immutable data object representing audit search results.
*/
@RequiredArgsConstructor
@Getter
public final class AuditSearchData {
@SuppressWarnings("unused")
private final Collection<AppUserData> appUsers;
@SuppressWarnings("unused")
private final List<String> actionNames;
@SuppressWarnings("unused")
private final List<String> entityNames;
@SuppressWarnings("unused")
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;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* Immutable data object for application user data.
*/
@RequiredArgsConstructor
@Getter
public class ProcessingResultLookup {
private final Long id;
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 java.util.HashMap;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.exception.UnsupportedCommandException;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
@@ -46,18 +45,13 @@ import org.springframework.stereotype.Component;
* @see CommandType
*/
@Component
@Scope("singleton")
@NoArgsConstructor
@Slf4j
public class CommandHandlerProvider implements ApplicationContextAware {
private static final Logger LOGGER = LoggerFactory.getLogger(CommandHandlerProvider.class);
private ApplicationContext applicationContext;
private HashMap<String, String> registeredHandlers;
CommandHandlerProvider() {
}
/**
* Returns a handler for the given entity and action.<br>
* <br>
@@ -87,12 +81,12 @@ public class CommandHandlerProvider implements ApplicationContextAware {
final String[] commandHandlerBeans = this.applicationContext.getBeanNamesForAnnotation(CommandType.class);
if (ArrayUtils.isNotEmpty(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);
try {
this.registeredHandlers.put(commandType.entity() + "|" + commandType.action(), commandHandlerName);
} 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.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.data.AuditData;
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.domain.AppUser;
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.RowMapper;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@Slf4j
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",
"subresourceId", "madeOnDate", "checkedOnDate", "officeName", "groupName", "clientName", "loanAccountNo", "savingsAccountNo",
"clientId", "loanId", "maker", "checker", "processingResult"));
@@ -94,31 +94,6 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
private final DepositProductReadPlatformService depositProductReadPlatformService;
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> {
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());
}
LOG.info("sql: {}", sqlBuilder);
log.info("sql: {}", sqlBuilder);
return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlBuilder.toString(), extraCriteria.getArguments(), rm);
}
@@ -257,7 +232,7 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
}
sql += extraCriteria.getSQLTemplate();
sql += groupAndOrderBySQL;
LOG.info("sql: {}", sql);
log.info("sql: {}", sql);
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 java.security.SecureRandom;
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.CommandSourceRepository;
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.security.service.PlatformSecurityContext;
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.orm.ObjectOptimisticLockingFailureException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@Slf4j
public class PortfolioCommandSourceWritePlatformServiceImpl implements PortfolioCommandSourceWritePlatformService {
private static final SecureRandom RANDOM = new SecureRandom();
private final PlatformSecurityContext context;
private final CommandSourceRepository commandSourceRepository;
private final FromJsonHelper fromApiJsonHelper;
private final CommandProcessingService processAndLogCommandService;
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
@SuppressWarnings("AvoidHidingCauseException")
@@ -90,9 +80,9 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
final String json = wrapper.getJson();
CommandProcessingResult result = null;
JsonCommand command = null;
Integer numberOfRetries = 0;
Integer maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock();
Integer maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries();
int numberOfRetries = 0;
int maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock();
int maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries();
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json);
command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(),
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);
numberOfRetries = maxNumberOfRetries + 1;
} 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
**/
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);
throw exception;
}
@@ -116,7 +106,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
* Else sleep for a random time (between 1 to 10 seconds) and continue
**/
try {
int randomNum = random.nextInt(maxIntervalBetweenRetries + 1);
int randomNum = RANDOM.nextInt(maxIntervalBetweenRetries + 1);
Thread.sleep(1000 + (randomNum * 1000));
numberOfRetries = numberOfRetries + 1;
} catch (InterruptedException e) {
@@ -25,6 +25,8 @@ import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.HashMap;
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.ErrorInfo;
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.security.service.PlatformSecurityContext;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@RequiredArgsConstructor
public class SynchronousCommandProcessingService implements CommandProcessingService {
private static final Logger LOG = LoggerFactory.getLogger(SynchronousCommandProcessingService.class);
private PlatformSecurityContext context;
private final PlatformSecurityContext context;
private final ApplicationContext applicationContext;
private final ToApiJsonSerializer<Map<String, Object>> toApiJsonSerializer;
private final ToApiJsonSerializer<CommandProcessingResult> toApiResultJsonSerializer;
private CommandSourceRepository commandSourceRepository;
private final CommandSourceRepository commandSourceRepository;
private final ConfigurationDomainService configurationDomainService;
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
@Override
public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command,
@@ -286,7 +269,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
applicationContext.publishEvent(applicationEvent);
}
} catch (Exception e) {
LOG.error("Error", e);
log.error("Error", e);
}
}