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 22, 2024
1 parent 34b165a commit 3ee1755
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 397 deletions.
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("LOAN_INTEREST_RECALCULATION").order(3L), //
new BusinessStep().stepName("ADD_PERIODIC_ACCRUAL_ENTRIES").order(4L), //
new BusinessStep().stepName("ACCRUAL_ACTIVITY_POSTING").order(5L), //
new BusinessStep().stepName("CHECK_LOAN_REPAYMENT_DUE").order(6L), //
new BusinessStep().stepName("CHECK_LOAN_REPAYMENT_OVERDUE").order(7L), //
new BusinessStep().stepName("CHECK_DUE_INSTALLMENTS").order(8L), //
new BusinessStep().stepName("UPDATE_LOAN_ARREARS_AGING").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.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class TestContextKey {

public static final String ORIGINAL_COB_WORKFLOW_JOB_BUSINESS_STEP_LIST = "originalCOBWorkflowJobBusinessStepList";
public static final String CLIENT_CREATE_RESPONSE = "clientCreateResponse";
public static final String CLIENT_CREATE_SECOND_CLIENT_RESPONSE = "clientCreateSecondClientResponse";
public static final String LOAN_CREATE_RESPONSE = "loanCreateResponse";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ Feature: COBFeature

@TestRailId:C3044 @AdvancedPaymentAllocation
Scenario: Verify that LoanAccountCustomSnapshotBusinessEvent is created with proper business date when installment is due date and COB runs
Given Admin puts CHECK_DUE_INSTALLMENTS job into LOAN_CLOSE_OF_BUSINESS workflow
When Admin sets the business date to "01 January 2024"
When Admin creates a client with random data
When Admin set "LP2_DOWNPAYMENT_AUTO_ADVANCED_PAYMENT_ALLOCATION" loan product "DEFAULT" transaction type to "NEXT_INSTALLMENT" future installment allocation rule
Expand All @@ -228,6 +227,5 @@ Feature: COBFeature
When Admin sets the business date to "17 January 2024"
When Admin runs inline COB job for Loan
Then LoanAccountCustomSnapshotBusinessEvent is created with business date "17 January 2024"
Then Admin removes CHECK_DUE_INSTALLMENTS job from LOAN_CLOSE_OF_BUSINESS workflow


Loading

0 comments on commit 3ee1755

Please sign in to comment.