FINERACT-2169: Accrual account api refactor;

This commit is contained in:
viktorpavlenko
2025-02-24 11:19:37 +01:00
committed by Adam Saghy
parent 8c2b7bd827
commit af922fe933
5 changed files with 44 additions and 17 deletions
@@ -32,6 +32,7 @@ import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.accounting.accrual.request.AccrualAccountRequest;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
@@ -54,13 +55,10 @@ public class AccrualAccountingApiResource {
@Operation(summary = "Executes Periodic Accrual Accounting", method = "POST", description = "Mandatory Fields\n" + "\n" + "tillDate\n")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = AccrualAccountingApiResourceSwagger.PostRunaccrualsRequest.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
public String executePeriodicAccrualAccounting(@Parameter(hidden = true) final String jsonRequestBody) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().excuteAccrualAccounting().withJson(jsonRequestBody).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.apiJsonSerializerService.serialize(result);
public CommandProcessingResult executePeriodicAccrualAccounting(@Parameter(hidden = true) AccrualAccountRequest accrualAccountRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().excuteAccrualAccounting()
.withJson(apiJsonSerializerService.serialize(accrualAccountRequest)).build();
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
@@ -24,9 +24,9 @@ public final class AccrualAccountingConstants {
}
public static final String accrueTillParamName = "tillDate";
public static final String localeParamName = "locale";
public static final String dateFormatParamName = "dateFormat";
public static final String ACCRUE_TILL_PARAM_NAME = "tillDate";
public static final String LOCALE_PARAM_NAME = "locale";
public static final String DATE_FORMAT_PARAM_NAME = "dateFormat";
public static final String PERIODIC_ACCRUAL_ACCOUNTING_RESOURCE_NAME = "periodicaccrual";
public static final String PERIODIC_ACCRUAL_ACCOUNTING_EXECUTION_ERROR_CODE = "execution.failed";
@@ -0,0 +1,28 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.accounting.accrual.request;
import java.io.Serial;
import java.io.Serializable;
public record AccrualAccountRequest(String locale, String dateFormat, String tillDate) implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
@@ -18,8 +18,8 @@
*/
package org.apache.fineract.accounting.accrual.serialization;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.ACCRUE_TILL_PARAM_NAME;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.PERIODIC_ACCRUAL_ACCOUNTING_RESOURCE_NAME;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.accrueTillParamName;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
@@ -46,8 +46,8 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public final class AccrualAccountingDataValidator {
private static final Set<String> LOAN_PERIODIC_REQUEST_DATA_PARAMETERS = new HashSet<>(
Arrays.asList(accrueTillParamName, AccrualAccountingConstants.localeParamName, AccrualAccountingConstants.dateFormatParamName));
private static final Set<String> LOAN_PERIODIC_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(ACCRUE_TILL_PARAM_NAME,
AccrualAccountingConstants.LOCALE_PARAM_NAME, AccrualAccountingConstants.DATE_FORMAT_PARAM_NAME));
private final FromJsonHelper fromApiJsonHelper;
@@ -63,8 +63,9 @@ public final class AccrualAccountingDataValidator {
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(PERIODIC_ACCRUAL_ACCOUNTING_RESOURCE_NAME);
final LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed(accrueTillParamName, element);
baseDataValidator.reset().parameter(accrueTillParamName).value(date).notNull().validateDateBefore(DateUtils.getBusinessLocalDate());
final LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed(ACCRUE_TILL_PARAM_NAME, element);
baseDataValidator.reset().parameter(ACCRUE_TILL_PARAM_NAME).value(date).notNull()
.validateDateBefore(DateUtils.getBusinessLocalDate());
throwExceptionIfValidationWarningsExist(dataValidationErrors);
@@ -18,9 +18,9 @@
*/
package org.apache.fineract.accounting.accrual.service;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.ACCRUE_TILL_PARAM_NAME;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.PERIODIC_ACCRUAL_ACCOUNTING_EXECUTION_ERROR_CODE;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.PERIODIC_ACCRUAL_ACCOUNTING_RESOURCE_NAME;
import static org.apache.fineract.accounting.accrual.api.AccrualAccountingConstants.accrueTillParamName;
import java.time.LocalDate;
import java.util.ArrayList;
@@ -44,7 +44,7 @@ public class AccrualAccountingWritePlatformServiceImpl implements AccrualAccount
@Override
public CommandProcessingResult executeLoansPeriodicAccrual(JsonCommand command) {
this.accountingDataValidator.validateLoanPeriodicAccrualData(command.json());
LocalDate tillDate = command.localDateValueOfParameterNamed(accrueTillParamName);
LocalDate tillDate = command.localDateValueOfParameterNamed(ACCRUE_TILL_PARAM_NAME);
try {
this.loanAccrualsProcessingService.addPeriodicAccruals(tillDate);
} catch (MultiException e) {