FINERACT-2332: SavingCOB infrastructure
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
356dd07ca0
commit
8d560a1f7c
+117
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 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.cob.savings;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.COBIdAndExternalIdAndAccountNo;
|
||||
import org.apache.fineract.cob.data.COBIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.cob.data.COBParameter;
|
||||
import org.apache.fineract.cob.data.COBPartition;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
|
||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RetrieveSavingsIdServiceImpl implements RetrieveSavingsIdService {
|
||||
|
||||
private static final Collection<Integer> NON_CLOSED_SAVINGS_STATUSES = new ArrayList<>(
|
||||
Arrays.asList(SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.getValue(), SavingsAccountStatusType.APPROVED.getValue(),
|
||||
SavingsAccountStatusType.ACTIVE.getValue(), SavingsAccountStatusType.TRANSFER_IN_PROGRESS.getValue(),
|
||||
SavingsAccountStatusType.TRANSFER_ON_HOLD.getValue()));
|
||||
|
||||
private final SavingsAccountRepository savingsAccountRepository;
|
||||
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
@Override
|
||||
public List<COBPartition> retrieveSavingsCOBPartitions(Long numberOfDays, LocalDate businessDate, boolean isCatchUp,
|
||||
int partitionSize) {
|
||||
String sql = """
|
||||
select min(id) as min, max(id) as max, page, count(id) as count from
|
||||
(select floor(((row_number() over(order by id))-1) / :pageSize) as page, t.* from
|
||||
(select id from m_savings_account where status_enum in (:statusIds) and
|
||||
""";
|
||||
if (isCatchUp) {
|
||||
sql = sql + " last_closed_business_date = :businessDate ";
|
||||
} else {
|
||||
sql = sql + " (last_closed_business_date = :businessDate or last_closed_business_date is null) ";
|
||||
}
|
||||
sql = sql + " order by id) t) t2 group by page order by page";
|
||||
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("pageSize", partitionSize);
|
||||
parameters.addValue("statusIds", NON_CLOSED_SAVINGS_STATUSES);
|
||||
parameters.addValue("businessDate", businessDate.minusDays(numberOfDays));
|
||||
return namedParameterJdbcTemplate.query(sql.toString(), parameters, RetrieveSavingsIdServiceImpl::mapRow);
|
||||
}
|
||||
|
||||
private static COBPartition mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return new COBPartition(rs.getLong("min"), rs.getLong("max"), rs.getLong("page"), rs.getLong("count"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COBIdAndLastClosedBusinessDate> retrieveSavingsIdsBehindDate(LocalDate businessDate, List<Long> savingsIds) {
|
||||
return savingsAccountRepository.findAllSavingsIdsBehindDate(businessDate, savingsIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COBIdAndLastClosedBusinessDate> retrieveSavingsIdsBehindDateOrNull(LocalDate businessDate, List<Long> savingsIds) {
|
||||
return savingsAccountRepository.findAllSavingsIdsBehindDateOrNull(businessDate, savingsIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COBIdAndLastClosedBusinessDate> retrieveSavingsIdsOldestCobProcessed(LocalDate businessDate) {
|
||||
return savingsAccountRepository.findAllSavingsIdsOldestCobProcessed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> retrieveAllNonClosedSavingsByLastClosedBusinessDateAndMinAndMaxSavingsId(COBParameter savingsCOBParameter,
|
||||
boolean isCatchUp) {
|
||||
LocalDate cobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)
|
||||
.minusDays(SavingsCOBConstant.NUMBER_OF_DAYS_BEHIND);
|
||||
|
||||
if (isCatchUp) {
|
||||
return savingsAccountRepository.findAllSavingsByLastClosedBusinessDateNotNullAndMinAndMaxSavingsIdAndStatuses(
|
||||
savingsCOBParameter.getMinAccountId(), savingsCOBParameter.getMaxAccountId(), cobBusinessDate,
|
||||
NON_CLOSED_SAVINGS_STATUSES);
|
||||
} else {
|
||||
return savingsAccountRepository.findAllSavingsByLastClosedBusinessDateAndMinAndMaxSavingsIdAndStatuses(
|
||||
savingsCOBParameter.getMinAccountId(), savingsCOBParameter.getMaxAccountId(), cobBusinessDate,
|
||||
NON_CLOSED_SAVINGS_STATUSES);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COBIdAndExternalIdAndAccountNo> findAllStayedLockedByCobBusinessDate(LocalDate cobBusinessDate) {
|
||||
// This will be implemented when we add the query to join with SavingsAccountLock
|
||||
// For now, return empty list as the lock table doesn't exist yet
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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.infrastructure.event.external.service.serialization.mapper.savings;
|
||||
|
||||
import org.apache.fineract.avro.savings.v1.SavingsAccountStayedLockedDataV1;
|
||||
import org.apache.fineract.avro.savings.v1.SavingsAccountsStayedLockedDataV1;
|
||||
import org.apache.fineract.cob.data.COBIdAndExternalIdAndAccountNo;
|
||||
import org.apache.fineract.cob.savings.SavingsAccountsStayedLockedData;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroMapperConfig;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(config = AvroMapperConfig.class)
|
||||
public interface SavingsAccountsStayedLockedDataMapper {
|
||||
|
||||
SavingsAccountsStayedLockedDataV1 map(SavingsAccountsStayedLockedData savingsAccountsStayedLockedData);
|
||||
|
||||
SavingsAccountStayedLockedDataV1 map(COBIdAndExternalIdAndAccountNo cobIdAndExternalIdAndAccountNo);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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.infrastructure.event.external.service.serialization.serializer.savings;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.avro.generic.GenericContainer;
|
||||
import org.apache.fineract.avro.generator.ByteBufferSerializable;
|
||||
import org.apache.fineract.avro.savings.v1.SavingsAccountsStayedLockedDataV1;
|
||||
import org.apache.fineract.cob.savings.SavingsAccountsStayedLockedBusinessEvent;
|
||||
import org.apache.fineract.cob.savings.SavingsAccountsStayedLockedData;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.savings.SavingsAccountsStayedLockedDataMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SavingsAccountsStayedLockedBusinessEventSerializer implements BusinessEventSerializer {
|
||||
|
||||
private final SavingsAccountsStayedLockedDataMapper mapper;
|
||||
|
||||
@Override
|
||||
public <T> boolean canSerialize(BusinessEvent<T> event) {
|
||||
return event instanceof SavingsAccountsStayedLockedBusinessEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ByteBufferSerializable toAvroDTO(BusinessEvent<T> rawEvent) {
|
||||
SavingsAccountsStayedLockedBusinessEvent event = (SavingsAccountsStayedLockedBusinessEvent) rawEvent;
|
||||
SavingsAccountsStayedLockedData savingsAccounts = event.get();
|
||||
return mapper.map(savingsAccounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GenericContainer> getSupportedSchema() {
|
||||
return SavingsAccountsStayedLockedDataV1.class;
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -112,7 +112,8 @@ public class ExternalEventConfigurationValidationServiceTest {
|
||||
"LoanCapitalizedIncomeTransactionCreatedBusinessEvent", "LoanUndoContractTerminationBusinessEvent",
|
||||
"LoanBuyDownFeeTransactionCreatedBusinessEvent", "LoanBuyDownFeeAdjustmentTransactionCreatedBusinessEvent",
|
||||
"LoanBuyDownFeeAmortizationTransactionCreatedBusinessEvent",
|
||||
"LoanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent", "LoanApprovedAmountChangedBusinessEvent");
|
||||
"LoanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent", "LoanApprovedAmountChangedBusinessEvent",
|
||||
"SavingsAccountsStayedLockedBusinessEvent");
|
||||
|
||||
List<FineractPlatformTenant> tenants = Arrays
|
||||
.asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null));
|
||||
@@ -149,6 +150,7 @@ public class ExternalEventConfigurationValidationServiceTest {
|
||||
|
||||
// then
|
||||
String expectedMessage = "No external events configured";
|
||||
|
||||
String actualMessage = exceptionThrown.getMessage();
|
||||
|
||||
assertTrue(actualMessage.contains(expectedMessage));
|
||||
@@ -206,7 +208,8 @@ public class ExternalEventConfigurationValidationServiceTest {
|
||||
"LoanCapitalizedIncomeTransactionCreatedBusinessEvent", "LoanUndoContractTerminationBusinessEvent",
|
||||
"LoanBuyDownFeeTransactionCreatedBusinessEvent", "LoanBuyDownFeeAdjustmentTransactionCreatedBusinessEvent",
|
||||
"LoanBuyDownFeeAmortizationTransactionCreatedBusinessEvent",
|
||||
"LoanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent", "LoanApprovedAmountChangedBusinessEvent");
|
||||
"LoanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent", "LoanApprovedAmountChangedBusinessEvent",
|
||||
"SavingsAccountsStayedLockedBusinessEvent");
|
||||
|
||||
List<FineractPlatformTenant> tenants = Arrays
|
||||
.asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null));
|
||||
|
||||
Reference in New Issue
Block a user