FINERACT-2326: Extract out external dependencies from Client and Group entity

This commit is contained in:
Jose Alberto Hernandez
2025-08-15 22:53:14 +02:00
committed by Arnold Gálovics
parent 37f31ecb14
commit 125c8b4db2
4 changed files with 36 additions and 95 deletions
@@ -288,7 +288,14 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
savingsProductId, savingsAccountId, dataOfBirth, gender, clientType, clientClassification, legalForm.getValue(),
isStaff);
// Account Number generation
this.clientRepository.saveAndFlush(newClient);
if (StringUtils.isBlank(accountNo)) {
AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(EntityAccountType.CLIENT);
newClient.updateAccountNo(accountNumberGenerator.generate(newClient, accountNumberFormat));
this.clientRepository.saveAndFlush(newClient);
}
boolean rollbackTransaction = false;
if (newClient.isActive()) {
validateParentGroupRulesBeforeClientActivation(newClient);
@@ -296,13 +303,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateClient(null).build();
rollbackTransaction = this.commandProcessingService.validateRollbackCommand(commandWrapper, currentUser);
}
this.clientRepository.saveAndFlush(newClient);
if (newClient.isAccountNumberRequiresAutoGeneration()) {
AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(EntityAccountType.CLIENT);
newClient.updateAccountNo(accountNumberGenerator.generate(newClient, accountNumberFormat));
this.clientRepository.saveAndFlush(newClient);
}
final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
@@ -1101,4 +1102,5 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
.withEntityExternalId(client.getExternalId()) //
.build();
}
}
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandProcessingService;
@@ -186,17 +187,18 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
rollbackTransaction = this.commandProcessingService.validateRollbackCommand(commandWrapper, currentUser);
}
// pre-save to generate id for use in group hierarchy
this.groupRepository.save(newGroup);
// Account Number generation
if (StringUtils.isBlank(accountNo)) {
generateAccountNumber(newGroup);
}
/*
* Generate hierarchy for a new center/group and all the child groups if they exist
*/
newGroup.generateHierarchy();
/* Generate account number if required */
generateAccountNumberIfRequired(newGroup);
this.groupRepository.saveAndFlush(newGroup);
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);
@@ -229,20 +231,17 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
}
}
private void generateAccountNumberIfRequired(Group newGroup) {
if (newGroup.isAccountNumberRequiresAutoGeneration()) {
EntityAccountType entityAccountType = null;
AccountNumberFormat accountNumberFormat = null;
if (newGroup.isCenter()) {
entityAccountType = EntityAccountType.CENTER;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateCenterAccountNumber(newGroup, accountNumberFormat));
} else {
entityAccountType = EntityAccountType.GROUP;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateGroupAccountNumber(newGroup, accountNumberFormat));
}
private void generateAccountNumber(Group newGroup) {
EntityAccountType entityAccountType = null;
AccountNumberFormat accountNumberFormat = null;
if (newGroup.isCenter()) {
entityAccountType = EntityAccountType.CENTER;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateCenterAccountNumber(newGroup, accountNumberFormat));
} else {
entityAccountType = EntityAccountType.GROUP;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateGroupAccountNumber(newGroup, accountNumberFormat));
}
}