Skip to content

Commit

Permalink
FINERACT-2081: Fetch configurations by name
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Sep 13, 2024
1 parent 0e08903 commit ce6aa1c
Show file tree
Hide file tree
Showing 65 changed files with 889 additions and 1,537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,29 @@ public String updateConfiguration(@PathParam("configId") @Parameter(description

return this.toApiJsonSerializer.serialize(result);
}

@PUT
@Path("/name/{configName}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update Global Configuration by name", description = "Updates an enable/disable global configuration item by name")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = GlobalConfigurationApiResourceSwagger.PutGlobalConfigurationsRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GlobalConfigurationApiResourceSwagger.PutGlobalConfigurationsResponse.class))) })
public String updateConfigurationByName(@PathParam("configName") @Parameter(description = "configName") final String configName,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {

// TODO: Would be better to support string based identifier in Commands and resolve the entity by name in the
// service
final GlobalConfigurationPropertyData configurationData = this.readPlatformService.retrieveGlobalConfiguration(configName);

final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.updateGlobalConfiguration(configurationData.getId()) //
.withJson(apiRequestBodyAsJson) //
.build();

final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);

return this.toApiJsonSerializer.serialize(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
Expand All @@ -37,7 +35,6 @@
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

@Profile(FineractProfiles.TEST)
@Component
Expand All @@ -61,24 +58,22 @@ public void afterPropertiesSet() throws Exception {

}

@POST
@Path("{configId}/value/{configValue}")
@PUT
@Path("name/{configName}/value/{configValue}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
public Response updateGlobalConfiguration(@Context final UriInfo uriInfo, @PathParam("configId") Long configId,
@PathParam("configValue") Long configValue, @RequestBody(required = false) String error) {
public Response updateGlobalConfiguration(@PathParam("configName") String configName, @PathParam("configValue") Long configValue) {
log.warn("------------------------------------------------------------");
log.warn(" ");
log.warn("Update trap-door config: {}", configId);
log.warn("Update trap-door config: {}", configName);
log.warn(" ");
log.warn("------------------------------------------------------------");

final GlobalConfigurationProperty config = repository.findOneWithNotFoundDetection(configId);
log.warn("Config to be updated {} original value {}", config.getName(), config.getValue());
final GlobalConfigurationProperty config = repository.findOneByNameWithNotFoundDetection(configName);
config.setValue(configValue);
repository.save(config);
log.warn("Config to be updated to {}", config.getValue());
log.warn("Config {} updated to {}", config.getName(), config.getValue());
repository.removeFromCache(config.getName());
MoneyHelper.fetchRoundingModeFromGlobalConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</sql>
</changeSet>
<changeSet author="fineract" id="2">
<validCheckSum>9:64863870bbd61795b1a8ced20a6dd7a3</validCheckSum>
<insert tableName="c_configuration">
<column name="id" valueNumeric="60"/>
<column name="name" value="enable-payment-hub-integration"/>
<column name="value" valueNumeric="0"/>
<column name="date_value"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.LoanRescheduleRequestHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.accounting.Account;
Expand Down Expand Up @@ -4070,15 +4069,15 @@ public void uc136() {
AtomicLong createdLoanId = new AtomicLong();
runAt("23 March 2024", () -> {
// Rounding mode - HALF_DOWN
GlobalConfigurationHelper.updateValueForGlobalConfigurationInternal(requestSpec, responseSpec, "23", 5);
globalConfigurationHelper.updateGlobalConfigurationInternal("rounding-mode", 5L);
createLoanForRoundingMethodValidation(true);

// Rounding mode - HALF_UP
GlobalConfigurationHelper.updateValueForGlobalConfigurationInternal(requestSpec, responseSpec, "23", 4);
globalConfigurationHelper.updateGlobalConfigurationInternal("rounding-mode", 4L);
createLoanForRoundingMethodValidation(false);

// Rounding mode - HALF_EVEN - Default
GlobalConfigurationHelper.updateValueForGlobalConfigurationInternal(requestSpec, responseSpec, "23", 6);
globalConfigurationHelper.updateGlobalConfigurationInternal("rounding-mode", 6L);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.fineract.integrationtests;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE;
import static org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder.DUE_PENALTY_INTEREST_PRINCIPAL_FEE_IN_ADVANCE_PENALTY_INTEREST_PRINCIPAL_FEE_STRATEGY;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -70,6 +68,7 @@
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdRequest;
import org.apache.fineract.client.models.PostLoansRequest;
import org.apache.fineract.client.models.PostLoansResponse;
import org.apache.fineract.client.models.PutGlobalConfigurationsRequest;
import org.apache.fineract.client.models.PutLoansLoanIdResponse;
import org.apache.fineract.client.util.CallFailedRuntimeException;
import org.apache.fineract.integrationtests.common.BatchHelper;
Expand Down Expand Up @@ -150,6 +149,7 @@ public abstract class BaseLoanIntegrationTest {
createResponseSpecification(Matchers.is(202)));
protected BusinessDateHelper businessDateHelper = new BusinessDateHelper();
protected DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATETIME_PATTERN);
protected GlobalConfigurationHelper globalConfigurationHelper = new GlobalConfigurationHelper();

protected static void validateRepaymentPeriod(GetLoansLoanIdResponse loanDetails, Integer index, LocalDate dueDate, double principalDue,
double principalPaid, double principalOutstanding, double paidInAdvance, double paidLate) {
Expand Down Expand Up @@ -658,14 +658,17 @@ protected void verifyRepaymentSchedule(Long loanId, Installment... installments)

protected void runAt(String date, Runnable runnable) {
try {
GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, 42, true);
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, TRUE);
// globalConfigurationHelper.updateGlobalConfiguration("is-interest-to-be-recovered-first-when-greater-than-emi",
// new PutGlobalConfigurationsRequest().enabled(TRUE));
globalConfigurationHelper.updateGlobalConfiguration("enable_business_date", new PutGlobalConfigurationsRequest().enabled(true));
businessDateHelper.updateBusinessDate(
new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en"));
runnable.run();
} finally {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, FALSE);
GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, 42, false);
globalConfigurationHelper.updateGlobalConfiguration("enable_business_date",
new PutGlobalConfigurationsRequest().enabled(false));
// globalConfigurationHelper.updateGlobalConfiguration("is-interest-to-be-recovered-first-when-greater-than-emi",
// new PutGlobalConfigurationsRequest().enabled(FALSE));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@
import org.apache.fineract.batch.command.internal.GetDatatableEntryByAppTableIdAndDataTableIdCommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.client.models.PutGlobalConfigurationsRequest;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.integrationtests.common.BatchHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
import org.apache.fineract.integrationtests.common.error.ErrorResponse;
import org.apache.fineract.integrationtests.common.loans.LoanAccountLockHelper;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
Expand All @@ -73,12 +72,10 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ExtendWith(LoanTestLifecycleExtension.class)
public class BatchApiTest {
public class BatchApiTest extends BaseLoanIntegrationTest {

private static final Logger LOG = LoggerFactory.getLogger(BatchApiTest.class);

Expand Down Expand Up @@ -113,12 +110,14 @@ public void setup() {
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.datatableHelper = new DatatableHelper(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.updateIsAutomaticExternalIdGenerationEnabled(this.requestSpec, this.responseSpec, true);
globalConfigurationHelper.updateGlobalConfiguration("enable-auto-generated-external-id",
new PutGlobalConfigurationsRequest().enabled(true));
}

@AfterEach
public void postActions() {
GlobalConfigurationHelper.updateIsAutomaticExternalIdGenerationEnabled(this.requestSpec, this.responseSpec, false);
globalConfigurationHelper.updateGlobalConfiguration("enable-auto-generated-external-id",
new PutGlobalConfigurationsRequest().enabled(false));
}

/**
Expand Down
Loading

0 comments on commit ce6aa1c

Please sign in to comment.