Skip to content

Commit

Permalink
FINERACT-2070: COB business step order
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Nov 24, 2024
1 parent 34b165a commit 0c7ef32
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class FineractProperties {
private String idempotencyKeyHeaderName;

private Boolean insecureHttpClient;
private long clientConnectTimeout;
private long clientReadTimeout;
private long clientWriteTimeout;

private FineractTenantProperties tenant;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public class ApiProperties {
private String strongPassword;
@Value("${fineract-test.api.tenant-id}")
private String tenantId;
@Value("${fineract-test.client-read-timeout}")
private long readTimeout;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.test.api;

import java.time.Duration;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.util.FineractClient;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -37,11 +38,10 @@ public FineractClient fineractClient() {
String username = apiProperties.getUsername();
String password = apiProperties.getPassword();
String tenantId = apiProperties.getTenantId();

long readTimeout = apiProperties.getReadTimeout();
String apiBaseUrl = baseUrl + "/fineract-provider/api/";

log.info("Using base URL '{}'", apiBaseUrl);

return FineractClient.builder().basicAuth(username, password).tenant(tenantId).baseURL(apiBaseUrl).insecure(true).build();
return FineractClient.builder().readTimeout(Duration.ofSeconds(readTimeout)).basicAuth(username, password).tenant(tenantId)
.baseURL(apiBaseUrl).insecure(true).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,57 @@
import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.BusinessStep;
import org.apache.fineract.client.models.GetBusinessStepConfigResponse;
import org.apache.fineract.client.models.UpdateBusinessStepConfigRequest;
import org.apache.fineract.client.services.BusinessStepConfigurationApi;
import org.apache.fineract.test.support.TestContext;
import org.apache.fineract.test.support.TestContextKey;
import org.springframework.stereotype.Component;
import retrofit2.Response;

@RequiredArgsConstructor
@Component
@Slf4j
public class WorkFlowJobHelper {

private static final String WORKFLOW_NAME_LOAN_CLOSE_OF_BUSINESS = "LOAN_CLOSE_OF_BUSINESS";

private final BusinessStepConfigurationApi businessStepConfigurationApi;

public void saveOriginalCOBWorkflowJobBusinessStepList() throws IOException {
Response<GetBusinessStepConfigResponse> businessStepConfigResponse = businessStepConfigurationApi
public void setWorkflowJobs() throws IOException {
List<BusinessStep> businessSteps = List.of(new BusinessStep().stepName("APPLY_CHARGE_TO_OVERDUE_LOANS").order(1L), //
new BusinessStep().stepName("LOAN_DELINQUENCY_CLASSIFICATION").order(2L), //
new BusinessStep().stepName("CHECK_LOAN_REPAYMENT_DUE").order(3L), //
new BusinessStep().stepName("CHECK_LOAN_REPAYMENT_OVERDUE").order(4L), //
new BusinessStep().stepName("CHECK_DUE_INSTALLMENTS").order(5L), //
new BusinessStep().stepName("UPDATE_LOAN_ARREARS_AGING").order(6L), //
new BusinessStep().stepName("ADD_PERIODIC_ACCRUAL_ENTRIES").order(7L), //
new BusinessStep().stepName("ACCRUAL_ACTIVITY_POSTING").order(8L), //
new BusinessStep().stepName("LOAN_INTEREST_RECALCULATION").order(9L), //
new BusinessStep().stepName("EXTERNAL_ASSET_OWNER_TRANSFER").order(10L)//
);
UpdateBusinessStepConfigRequest request = new UpdateBusinessStepConfigRequest().businessSteps(businessSteps);
Response<Void> response = businessStepConfigurationApi.updateJobBusinessStepConfig(WORKFLOW_NAME_LOAN_CLOSE_OF_BUSINESS, request)
.execute();
ErrorHelper.checkSuccessfulApiCall(response);
// --- log changes ---
logChanges();
}

private void logChanges() throws IOException {
// --- log changes ---
Response<GetBusinessStepConfigResponse> changesResponse = businessStepConfigurationApi
.retrieveAllConfiguredBusinessStep(WORKFLOW_NAME_LOAN_CLOSE_OF_BUSINESS).execute();
ErrorHelper.checkSuccessfulApiCall(businessStepConfigResponse);
List<BusinessStep> businessSteps = businessStepConfigResponse.body().getBusinessSteps();
businessSteps.sort(Comparator.comparingLong(BusinessStep::getOrder));
TestContext.GLOBAL.set(TestContextKey.ORIGINAL_COB_WORKFLOW_JOB_BUSINESS_STEP_LIST, businessSteps);
List<BusinessStep> businessStepsChanged = changesResponse.body().getBusinessSteps();
List<String> changes = businessStepsChanged//
.stream()//
.sorted(Comparator.comparingLong(BusinessStep::getOrder))//
.map(BusinessStep::getStepName)//
.collect(Collectors.toList());//

log.debug("Business steps has been CHANGED to the following:");
changes.forEach(e -> log.debug(e));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import org.apache.fineract.test.config.CacheConfiguration;
import org.apache.fineract.test.helper.BusinessDateHelper;
import org.apache.fineract.test.helper.WorkFlowJobHelper;
import org.apache.fineract.test.initializer.global.FineractGlobalInitializerStep;
import org.apache.fineract.test.initializer.scenario.FineractScenarioInitializerStep;
import org.apache.fineract.test.initializer.suite.FineractSuiteInitializerStep;
Expand All @@ -40,8 +39,7 @@ public class BaseFineractInitializerConfiguration {
@Bean
public FineractInitializer fineractInitializer(List<FineractGlobalInitializerStep> globalInitializerSteps,
List<FineractSuiteInitializerStep> suiteInitializerSteps, List<FineractScenarioInitializerStep> scenarioInitializerSteps,
BusinessDateHelper businessDateHelper, WorkFlowJobHelper workFlowJobHelper) {
return new FineractInitializer(globalInitializerSteps, suiteInitializerSteps, scenarioInitializerSteps, businessDateHelper,
workFlowJobHelper);
BusinessDateHelper businessDateHelper) {
return new FineractInitializer(globalInitializerSteps, suiteInitializerSteps, scenarioInitializerSteps, businessDateHelper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.test.helper.BusinessDateHelper;
import org.apache.fineract.test.helper.WorkFlowJobHelper;
import org.apache.fineract.test.initializer.global.FineractGlobalInitializerStep;
import org.apache.fineract.test.initializer.scenario.FineractScenarioInitializerStep;
import org.apache.fineract.test.initializer.suite.FineractSuiteInitializerStep;
Expand All @@ -39,7 +38,6 @@ public class FineractInitializer implements InitializingBean {
private final List<FineractSuiteInitializerStep> suiteInitializerSteps;
private final List<FineractScenarioInitializerStep> scenarioInitializerSteps;
private final BusinessDateHelper businessDateHelper;
private final WorkFlowJobHelper workFlowJobHelper;

@Override
public void afterPropertiesSet() throws Exception {
Expand All @@ -63,32 +61,27 @@ public void setupGlobalDefaults() throws Exception {
for (FineractGlobalInitializerStep initializerStep : globalInitializerSteps) {
initializerStep.initialize();
}

businessDateHelper.setBusinessDateToday();
}

public void setupDefaultsForSuite() throws Exception {
for (FineractSuiteInitializerStep initializerStep : suiteInitializerSteps) {
initializerStep.initializeForSuite();
}

businessDateHelper.setBusinessDateToday();
workFlowJobHelper.saveOriginalCOBWorkflowJobBusinessStepList();
}

public void setupDefaultsForScenario() throws Exception {
for (FineractScenarioInitializerStep scenarioInitializerStep : scenarioInitializerSteps) {
scenarioInitializerStep.initializeForScenario();
}

businessDateHelper.setBusinessDateToday();
}

public void resetDefaultsAfterSuite() throws Exception {
for (FineractSuiteInitializerStep initializerStep : suiteInitializerSteps) {
initializerStep.resetAfterSuite();
}

businessDateHelper.setBusinessDateToday();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,18 @@
*/
package org.apache.fineract.test.initializer.global;

import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.client.models.BusinessStep;
import org.apache.fineract.client.models.GetBusinessStepConfigResponse;
import org.apache.fineract.client.models.UpdateBusinessStepConfigRequest;
import org.apache.fineract.client.services.BusinessStepConfigurationApi;
import org.apache.fineract.test.helper.ErrorHelper;
import org.apache.fineract.test.helper.WorkFlowJobHelper;
import org.springframework.stereotype.Component;
import retrofit2.Response;

@RequiredArgsConstructor
@Component
public class CobBusinessStepInitializerStep implements FineractGlobalInitializerStep {

private static final String WORKFLOW_NAME_LOAN_CLOSE_OF_BUSINESS = "LOAN_CLOSE_OF_BUSINESS";
private static final String BUSINESS_STEP_NAME_ACCRUAL_ACTIVITY_POSTING = "ACCRUAL_ACTIVITY_POSTING";
private final BusinessStepConfigurationApi businessStepConfigurationApi;
private final WorkFlowJobHelper workFlowJobHelper;

@Override
public void initialize() throws Exception {
// --- Adding ACCRUAL_ACTIVITY_POSTING to default COB steps ---
Response<GetBusinessStepConfigResponse> businessStepConfigResponse = businessStepConfigurationApi
.retrieveAllConfiguredBusinessStep(WORKFLOW_NAME_LOAN_CLOSE_OF_BUSINESS).execute();
ErrorHelper.checkSuccessfulApiCall(businessStepConfigResponse);
List<BusinessStep> businessSteps = businessStepConfigResponse.body().getBusinessSteps();
businessSteps.sort(Comparator.comparingLong(BusinessStep::getOrder));
Long lastOrder = businessSteps.get(businessSteps.size() - 1).getOrder();

BusinessStep accrualActivityPosting = new BusinessStep().stepName(BUSINESS_STEP_NAME_ACCRUAL_ACTIVITY_POSTING).order(lastOrder + 1);
businessSteps.add(accrualActivityPosting);

UpdateBusinessStepConfigRequest request = new UpdateBusinessStepConfigRequest().businessSteps(businessSteps);

Response<Void> response = businessStepConfigurationApi.updateJobBusinessStepConfig(WORKFLOW_NAME_LOAN_CLOSE_OF_BUSINESS, request)
.execute();
ErrorHelper.checkSuccessfulApiCall(response);
workFlowJobHelper.setWorkflowJobs();
}
}

This file was deleted.

Loading

0 comments on commit 0c7ef32

Please sign in to comment.