FINERACT-2169: Refactor standing instruction history api controller;

This commit is contained in:
viktorpavlenko
2025-04-08 16:38:11 +02:00
committed by Adam Saghy
parent 2ba7e28108
commit 056a20f58e
5 changed files with 22 additions and 41 deletions
@@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.account.data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Optional;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -69,7 +70,7 @@ public class PortfolioAccountData implements Serializable {
this.amtForTransfer = null;
}
public String getCurrencyCode() {
return this.currency.getCode();
public String getCurrencyCodeFromCurrency() {
return Optional.ofNullable(getCurrency()).map(CurrencyData::getCode).orElse(null);
}
}
@@ -30,17 +30,12 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.api.DateParam;
import org.apache.fineract.infrastructure.core.data.DateFormat;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -57,8 +52,6 @@ import org.springframework.stereotype.Component;
public class StandingInstructionHistoryApiResource {
private final PlatformSecurityContext context;
private final DefaultToApiJsonSerializer<StandingInstructionHistoryData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final StandingInstructionHistoryReadPlatformService standingInstructionHistoryReadPlatformService;
private final SqlValidator sqlValidator;
@@ -70,7 +63,7 @@ public class StandingInstructionHistoryApiResource {
+ "standinginstructionrunhistory?orderBy=name&sortOrder=DESC\n" + "\n" + "standinginstructionrunhistory?offset=10&limit=50")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StandingInstructionHistoryApiResourceSwagger.GetStandingInstructionRunHistoryResponse.class))) })
public String retrieveAll(@Context final UriInfo uriInfo,
public Page<StandingInstructionHistoryData> retrieveAll(
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(description = "limit") final Integer limit,
@@ -107,10 +100,6 @@ public class StandingInstructionHistoryApiResource {
StandingInstructionDTO standingInstructionDTO = new StandingInstructionDTO(searchParameters, transferType, clientName, clientId,
fromAccount, fromAccountType, startDateRange, endDateRange);
final Page<StandingInstructionHistoryData> history = this.standingInstructionHistoryReadPlatformService
.retrieveAll(standingInstructionDTO);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, history);
return standingInstructionHistoryReadPlatformService.retrieveAll(standingInstructionDTO);
}
}
@@ -18,14 +18,23 @@
*/
package org.apache.fineract.portfolio.account.data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.portfolio.client.data.ClientData;
@Getter
@SuppressWarnings("unused")
public class StandingInstructionHistoryData {
@RequiredArgsConstructor
public class StandingInstructionHistoryData implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private final Long standingInstructionId;
private final String name;
@@ -42,24 +51,4 @@ public class StandingInstructionHistoryData {
private final LocalDate executionTime;
private final String errorLog;
public StandingInstructionHistoryData(final Long standingInstructionId, final String name, final OfficeData fromOffice,
final ClientData fromClient, final EnumOptionData fromAccountType, final PortfolioAccountData fromAccount,
final EnumOptionData toAccountType, final PortfolioAccountData toAccount, final OfficeData toOffice, final ClientData toClient,
final BigDecimal amount, final String status, final LocalDate executionTime, final String errorLog) {
this.standingInstructionId = standingInstructionId;
this.name = name;
this.fromOffice = fromOffice;
this.fromClient = fromClient;
this.fromAccountType = fromAccountType;
this.toAccountType = toAccountType;
this.fromAccount = fromAccount;
this.toAccount = toAccount;
this.toOffice = toOffice;
this.toClient = toClient;
this.amount = amount;
this.errorLog = errorLog;
this.status = status;
this.executionTime = executionTime;
}
}
@@ -146,7 +146,7 @@ public class AccountTransfersReadPlatformServiceImpl implements AccountTransfers
if (toAccountId != null && fromAccount != null) {
toAccount = this.portfolioAccountReadPlatformService.retrieveOne(toAccountId, mostRelevantToAccountType,
fromAccount.getCurrencyCode());
fromAccount.getCurrencyCodeFromCurrency());
mostRelevantToClientId = toAccount.getClientId();
}
@@ -179,7 +179,8 @@ public class AccountTransfersReadPlatformServiceImpl implements AccountTransfers
private Collection<PortfolioAccountData> retrieveToAccounts(final PortfolioAccountData excludeThisAccountFromOptions,
final Integer toAccountType, final Long toClientId) {
final String currencyCode = excludeThisAccountFromOptions != null ? excludeThisAccountFromOptions.getCurrencyCode() : null;
final String currencyCode = excludeThisAccountFromOptions != null ? excludeThisAccountFromOptions.getCurrencyCodeFromCurrency()
: null;
PortfolioAccountDTO portfolioAccountDTO = new PortfolioAccountDTO(toAccountType, toClientId, currencyCode, null, null);
Collection<PortfolioAccountData> accountOptions = this.portfolioAccountReadPlatformService
@@ -379,7 +380,7 @@ public class AccountTransfersReadPlatformServiceImpl implements AccountTransfers
if (toAccountId != null && fromAccount != null) {
toAccount = this.portfolioAccountReadPlatformService.retrieveOne(toAccountId, mostRelevantToAccountType,
fromAccount.getCurrencyCode());
fromAccount.getCurrencyCodeFromCurrency());
mostRelevantToClientId = toAccount.getClientId();
}
@@ -188,7 +188,7 @@ public class StandingInstructionReadPlatformServiceImpl implements StandingInstr
if (toAccountId != null && fromAccount != null) {
toAccount = this.portfolioAccountReadPlatformService.retrieveOne(toAccountId, mostRelevantToAccountType,
fromAccount.getCurrencyCode());
fromAccount.getCurrencyCodeFromCurrency());
mostRelevantToClientId = toAccount.getClientId();
}
@@ -239,7 +239,8 @@ public class StandingInstructionReadPlatformServiceImpl implements StandingInstr
private Collection<PortfolioAccountData> retrieveToAccounts(final PortfolioAccountData excludeThisAccountFromOptions,
final Integer toAccountType, final Long toClientId) {
final String currencyCode = excludeThisAccountFromOptions != null ? excludeThisAccountFromOptions.getCurrencyCode() : null;
final String currencyCode = excludeThisAccountFromOptions != null ? excludeThisAccountFromOptions.getCurrencyCodeFromCurrency()
: null;
PortfolioAccountDTO portfolioAccountDTO = new PortfolioAccountDTO(toAccountType, toClientId, currencyCode, null, null);
Collection<PortfolioAccountData> accountOptions = this.portfolioAccountReadPlatformService