FINERACT-1678-Config-Bulk-Event-Loan-COB

This commit is contained in:
Ruchi Dhamankar
2023-01-05 06:14:24 -08:00
committed by taskain7
parent a62d0578d5
commit 4269e3e8f1
10 changed files with 244 additions and 9 deletions
@@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.cob.domain.BatchBusinessStep;
import org.apache.fineract.cob.domain.BatchBusinessStepRepository;
import org.apache.fineract.cob.exceptions.BusinessStepException;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.domain.ActionContext;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
@@ -45,15 +46,19 @@ public class COBBusinessStepServiceImpl implements COBBusinessStepService {
private final ApplicationContext applicationContext;
private final ListableBeanFactory beanFactory;
private final BusinessEventNotifierService businessEventNotifierService;
private final ConfigurationDomainService configurationDomainService;
@Override
public <T extends COBBusinessStep<S>, S extends AbstractPersistableCustom> S run(TreeMap<Long, String> executionMap, S item) {
if (executionMap == null || executionMap.isEmpty()) {
throw new BusinessStepException("Execution map is empty! COB Business step execution skipped!");
}
boolean bulkEventEnabled = configurationDomainService.isCOBBulkEventEnabled();
// Extra safety net to avoid event leaking
try {
businessEventNotifierService.startExternalEventRecording();
if (bulkEventEnabled) {
businessEventNotifierService.startExternalEventRecording();
}
for (String businessStep : executionMap.values()) {
try {
@@ -67,9 +72,13 @@ public class COBBusinessStepServiceImpl implements COBBusinessStepService {
ThreadLocalContextUtil.setActionContext(ActionContext.COB);
}
}
businessEventNotifierService.stopExternalEventRecording();
if (bulkEventEnabled) {
businessEventNotifierService.stopExternalEventRecording();
}
} catch (Exception e) {
businessEventNotifierService.resetEventRecording();
if (bulkEventEnabled) {
businessEventNotifierService.resetEventRecording();
}
throw e;
}
return item;
@@ -131,4 +131,6 @@ public interface ConfigurationDomainService {
boolean isAddressEnabled();
boolean isCOBBulkEventEnabled();
}
@@ -47,6 +47,7 @@ public class ConfigurationDomainServiceJpa implements ConfigurationDomainService
private static final String DAYS_AFTER_REPAYMENT_IS_OVERDUE = "days-after-repayment-is-overdue";
private static final String ENABLE_EXTERNAL_ID_AUTO_GENERATION = "enable-auto-generated-external-id";
private static final String ENABLE_ADDRESS = "Enable-Address";
private static final String ENABLE_COB_BULK_EVENT = "enable-cob-bulk-event";
private final PermissionRepository permissionRepository;
private final GlobalConfigurationRepositoryWrapper globalConfigurationRepository;
@@ -498,4 +499,10 @@ public class ConfigurationDomainServiceJpa implements ConfigurationDomainService
return property.isEnabled();
}
@Override
public boolean isCOBBulkEventEnabled() {
final GlobalConfigurationPropertyData property = getGlobalConfigurationPropertyData(ENABLE_COB_BULK_EVENT);
return property.isEnabled();
}
}
@@ -97,4 +97,5 @@
<include file="parts/0075_add_processed_commands_purge_job.xml" relativeToChangelogFile="true" />
<include file="parts/0076_add_loan_transaction_enum_values.xml" relativeToChangelogFile="true" />
<include file="parts/0077_add_overpaid_date_for_loan.xml" relativeToChangelogFile="true" />
<include file="parts/0078_add_configuration_cob_bulk_event.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
<changeSet author="fineract" id="1" context="postgresql">
<sql>
SELECT SETVAL('c_configuration_id_seq', COALESCE(MAX(id), 0)+1, false ) FROM c_configuration;
</sql>
</changeSet>
<changeSet author="fineract" id="2">
<insert tableName="c_configuration">
<column name="name" value="enable-cob-bulk-event"/>
<column name="value"/>
<column name="date_value"/>
<column name="string_value"/>
<column name="enabled" valueBoolean="false"/>
<column name="is_trap_door" valueBoolean="false"/>
<column name="description" value="Whether bulk event for COB is enabled in the system"/>
</insert>
</changeSet>
</databaseChangeLog>