francisguchie commented on a change in pull request #738:
URL: https://github.com/apache/fineract/pull/738#discussion_r411429911
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
##########
@@ -86,470 +93,715 @@
import org.springframework.transaction.annotation.Transactional;
@Service
-public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl
implements SavingsApplicationProcessWritePlatformService {
-
- private final static Logger logger =
LoggerFactory.getLogger(SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.class);
-
- private final PlatformSecurityContext context;
- private final SavingsAccountRepositoryWrapper savingAccountRepository;
- private final SavingsAccountAssembler savingAccountAssembler;
- private final SavingsAccountDataValidator savingsAccountDataValidator;
- private final AccountNumberGenerator accountNumberGenerator;
- private final ClientRepositoryWrapper clientRepository;
- private final GroupRepository groupRepository;
- private final SavingsProductRepository savingsProductRepository;
- private final NoteRepository noteRepository;
- private final StaffRepositoryWrapper staffRepository;
- private final SavingsAccountApplicationTransitionApiJsonValidator
savingsAccountApplicationTransitionApiJsonValidator;
- private final SavingsAccountChargeAssembler savingsAccountChargeAssembler;
- private final CommandProcessingService commandProcessingService;
- private final SavingsAccountDomainService savingsAccountDomainService;
- private final SavingsAccountWritePlatformService
savingsAccountWritePlatformService;
- private final AccountNumberFormatRepositoryWrapper
accountNumberFormatRepository;
- private final BusinessEventNotifierService businessEventNotifierService;
- private final EntityDatatableChecksWritePlatformService
entityDatatableChecksWritePlatformService;
-
- @Autowired
- public
SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl(final
PlatformSecurityContext context,
- final SavingsAccountRepositoryWrapper savingAccountRepository,
final SavingsAccountAssembler savingAccountAssembler,
- final SavingsAccountDataValidator savingsAccountDataValidator,
final AccountNumberGenerator accountNumberGenerator,
- final ClientRepositoryWrapper clientRepository, final
GroupRepository groupRepository,
- final SavingsProductRepository savingsProductRepository, final
NoteRepository noteRepository,
- final StaffRepositoryWrapper staffRepository,
- final SavingsAccountApplicationTransitionApiJsonValidator
savingsAccountApplicationTransitionApiJsonValidator,
- final SavingsAccountChargeAssembler savingsAccountChargeAssembler,
final CommandProcessingService commandProcessingService,
- final SavingsAccountDomainService savingsAccountDomainService,
- final SavingsAccountWritePlatformService
savingsAccountWritePlatformService,
- final AccountNumberFormatRepositoryWrapper
accountNumberFormatRepository,
- final BusinessEventNotifierService businessEventNotifierService,
- final EntityDatatableChecksWritePlatformService
entityDatatableChecksWritePlatformService) {
- this.context = context;
- this.savingAccountRepository = savingAccountRepository;
- this.savingAccountAssembler = savingAccountAssembler;
- this.accountNumberGenerator = accountNumberGenerator;
- this.savingsAccountDataValidator = savingsAccountDataValidator;
- this.clientRepository = clientRepository;
- this.groupRepository = groupRepository;
- this.savingsProductRepository = savingsProductRepository;
- this.noteRepository = noteRepository;
- this.staffRepository = staffRepository;
- this.savingsAccountApplicationTransitionApiJsonValidator =
savingsAccountApplicationTransitionApiJsonValidator;
- this.savingsAccountChargeAssembler = savingsAccountChargeAssembler;
- this.commandProcessingService = commandProcessingService;
- this.savingsAccountDomainService = savingsAccountDomainService;
- this.accountNumberFormatRepository = accountNumberFormatRepository;
- this.savingsAccountWritePlatformService =
savingsAccountWritePlatformService;
- this.businessEventNotifierService = businessEventNotifierService ;
- this.entityDatatableChecksWritePlatformService =
entityDatatableChecksWritePlatformService;
- }
-
/*
* Guaranteed to throw an exception no matter what the data integrity issue
* is.
*/
- private void handleDataIntegrityIssues(final JsonCommand command, final
Throwable realCause, final Exception dve) {
-
- final StringBuilder errorCodeBuilder = new
StringBuilder("error.msg.").append(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);
-
- if (realCause.getMessage().contains("sa_account_no_UNIQUE")) {
- final String accountNo =
command.stringValueOfParameterNamed("accountNo");
- errorCodeBuilder.append(".duplicate.accountNo");
- throw new
PlatformDataIntegrityException(errorCodeBuilder.toString(), "Savings account
with accountNo " + accountNo
- + " already exists", "accountNo", accountNo);
-
- } else if (realCause.getMessage().contains("sa_externalid_UNIQUE")) {
-
- final String externalId =
command.stringValueOfParameterNamed("externalId");
- errorCodeBuilder.append(".duplicate.externalId");
- throw new
PlatformDataIntegrityException(errorCodeBuilder.toString(), "Savings account
with externalId " + externalId
- + " already exists", "externalId", externalId);
- }
-
- errorCodeBuilder.append(".unknown.data.integrity.issue");
- logger.error("Error occured.", dve);
- throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
"Unknown data integrity issue with savings account.");
- }
-
- @Transactional
- @Override
- public CommandProcessingResult submitApplication(final JsonCommand
command) {
- try {
- this.savingsAccountDataValidator.validateForSubmit(command.json());
- final AppUser submittedBy = this.context.authenticatedUser();
-
- final SavingsAccount account =
this.savingAccountAssembler.assembleFrom(command, submittedBy);
- this.savingAccountRepository.save(account);
-
- generateAccountNumber(account);
-
- final Long savingsId = account.getId();
- if(command.parameterExists(SavingsApiConstants.datatables)){
-
this.entityDatatableChecksWritePlatformService.saveDatatables(StatusEnum.CREATE.getCode().longValue(),
- EntityTables.SAVING.getName(), savingsId,
account.productId(),
-
command.arrayOfParameterNamed(SavingsApiConstants.datatables));
- }
-
this.entityDatatableChecksWritePlatformService.runTheCheckForProduct(savingsId,
- EntityTables.SAVING.getName(),
StatusEnum.CREATE.getCode().longValue(),
- EntityTables.SAVING.getForeignKeyColumnNameOnDatatable(),
account.productId());
-
-
this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_CREATE,
- constructEntityMap(BUSINESS_ENTITY.SAVING, account));
-
- return new CommandProcessingResultBuilder() //
- .withCommandId(command.commandId()) //
+public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl
+ implements SavingsApplicationProcessWritePlatformService {
+
+ private final static Logger logger = LoggerFactory
+
.getLogger(SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.class);
+
+ private final PlatformSecurityContext context;
+ private final SavingsAccountRepositoryWrapper savingAccountRepository;
+ private final SavingsAccountAssembler savingAccountAssembler;
+ private final SavingsAccountDataValidator savingsAccountDataValidator;
+ private final AccountNumberGenerator accountNumberGenerator;
+ private final ClientRepositoryWrapper clientRepository;
+ private final GroupRepository groupRepository;
+ private final SavingsProductRepository savingsProductRepository;
+ private final NoteRepository noteRepository;
+ private final StaffRepositoryWrapper staffRepository;
+ private final SavingsAccountApplicationTransitionApiJsonValidator
savingsAccountApplicationTransitionApiJsonValidator;
+ private final SavingsAccountChargeAssembler savingsAccountChargeAssembler;
+ private final CommandProcessingService commandProcessingService;
+ private final SavingsAccountDomainService savingsAccountDomainService;
+ private final SavingsAccountWritePlatformService
savingsAccountWritePlatformService;
+ private final AccountNumberFormatRepositoryWrapper
accountNumberFormatRepository;
+ private final BusinessEventNotifierService businessEventNotifierService;
+ private final EntityDatatableChecksWritePlatformService
entityDatatableChecksWritePlatformService;
+ private final GSIMRepositoy gsimRepository;
+ private final GroupRepositoryWrapper groupRepositoryWrapper;
+ private final GroupSavingsIndividualMonitoringWritePlatformService
gsimWritePlatformService;
+
+ @Autowired
+ public
SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl(final
PlatformSecurityContext context,
+ final SavingsAccountRepositoryWrapper savingAccountRepository,
+ final SavingsAccountAssembler savingAccountAssembler,
+ final SavingsAccountDataValidator savingsAccountDataValidator,
+ final AccountNumberGenerator accountNumberGenerator, final
ClientRepositoryWrapper clientRepository,
+ final GroupRepository groupRepository, final
SavingsProductRepository savingsProductRepository,
+ final NoteRepository noteRepository, final
StaffRepositoryWrapper staffRepository,
+ final SavingsAccountApplicationTransitionApiJsonValidator
savingsAccountApplicationTransitionApiJsonValidator,
+ final SavingsAccountChargeAssembler
savingsAccountChargeAssembler,
+ final CommandProcessingService commandProcessingService,
+ final SavingsAccountDomainService savingsAccountDomainService,
+ final SavingsAccountWritePlatformService
savingsAccountWritePlatformService,
+ final AccountNumberFormatRepositoryWrapper
accountNumberFormatRepository,
+ final BusinessEventNotifierService businessEventNotifierService,
+ final EntityDatatableChecksWritePlatformService
entityDatatableChecksWritePlatformService,
+ final GSIMRepositoy gsimRepository, final
GroupRepositoryWrapper groupRepositoryWrapper,
+ final GroupSavingsIndividualMonitoringWritePlatformService
gsimWritePlatformService) {
+ this.context = context;
+ this.savingAccountRepository = savingAccountRepository;
+ this.savingAccountAssembler = savingAccountAssembler;
+ this.accountNumberGenerator = accountNumberGenerator;
+ this.savingsAccountDataValidator = savingsAccountDataValidator;
+ this.clientRepository = clientRepository;
+ this.groupRepository = groupRepository;
+ this.savingsProductRepository = savingsProductRepository;
+ this.noteRepository = noteRepository;
+ this.staffRepository = staffRepository;
+ this.savingsAccountApplicationTransitionApiJsonValidator =
savingsAccountApplicationTransitionApiJsonValidator;
+ this.savingsAccountChargeAssembler = savingsAccountChargeAssembler;
+ this.commandProcessingService = commandProcessingService;
+ this.savingsAccountDomainService = savingsAccountDomainService;
+ this.accountNumberFormatRepository = accountNumberFormatRepository;
+ this.savingsAccountWritePlatformService =
savingsAccountWritePlatformService;
+ this.businessEventNotifierService = businessEventNotifierService;
+ this.entityDatatableChecksWritePlatformService =
entityDatatableChecksWritePlatformService;
+ this.gsimRepository = gsimRepository;
+ this.groupRepositoryWrapper = groupRepositoryWrapper;
+ this.gsimWritePlatformService = gsimWritePlatformService;
+ }
+
+ /*
+ * Guaranteed to throw an exception no matter what the data integrity
issue
+ * is.
+ */
+ private void handleDataIntegrityIssues(final JsonCommand command, final
Throwable realCause, final Exception dve) {
+
+ final StringBuilder errorCodeBuilder = new
StringBuilder("error.msg.")
+ .append(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);
+
+ if (realCause.getMessage().contains("sa_account_no_UNIQUE")) {
+ final String accountNo =
command.stringValueOfParameterNamed("accountNo");
+ errorCodeBuilder.append(".duplicate.accountNo");
+ throw new
PlatformDataIntegrityException(errorCodeBuilder.toString(),
+ "Savings account with accountNo " + accountNo + "
already exists", "accountNo", accountNo);
+
+ } else if (realCause.getMessage().contains("sa_externalid_UNIQUE")) {
+
+ final String externalId =
command.stringValueOfParameterNamed("externalId");
+ errorCodeBuilder.append(".duplicate.externalId");
+ throw new
PlatformDataIntegrityException(errorCodeBuilder.toString(),
+ "Savings account with externalId " + externalId + "
already exists", "externalId", externalId);
+ }
+
+ errorCodeBuilder.append(".unknown.data.integrity.issue");
+ logger.error("{}", dve.getMessage(), dve);
+ throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
+ "Unknown data integrity issue with savings account.");
+ }
+
+ @Transactional
+ @Override
+ public CommandProcessingResult submitGSIMApplication(final JsonCommand
command) {
+
+ CommandProcessingResult result = null;
+
+ JsonArray gsimApplications =
command.arrayOfParameterNamed("clientArray");
+
+ for (JsonElement gsimApplication : gsimApplications) {
+ //
result=submitApplication(JsonCommand.fromExistingCommand(command,
+ // gsimApplication));
+ result =
submitApplication(JsonCommand.fromExistingCommand(command, gsimApplication,
+
gsimApplication.getAsJsonObject().get("clientId").getAsLong()));
+ }
+
+ return result;
+ }
+
+ @Transactional
+ @Override
+ public CommandProcessingResult submitApplication(final JsonCommand
command) {
+ try {
+
this.savingsAccountDataValidator.validateForSubmit(command.json());
+ final AppUser submittedBy = this.context.authenticatedUser();
+
+ final SavingsAccount account =
this.savingAccountAssembler.assembleFrom(command, submittedBy);
+ this.savingAccountRepository.save(account);
+ String accountNumber = "";
+ GroupSavingsIndividualMonitoring gsimAccount = null;
+ BigDecimal applicationId = BigDecimal.ZERO;
+ Boolean isLastChildApplication = false;
+
+ // gsim
+ if (account.isAccountNumberRequiresAutoGeneration()) {
+
+ final AccountNumberFormat accountNumberFormat =
this.accountNumberFormatRepository
+ .findByAccountType(EntityAccountType.SAVINGS);
+ // if application is of GSIM type
+ if (account.getAccountTypes() == 5) {
+ final Long groupId =
command.longValueOfParameterNamed("groupId");
+ // GSIM specific parameters
+ if
(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("applicationId") !=
null) {
+ applicationId =
command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("applicationId");
+ }
+
+ if
(command.booleanObjectValueOfParameterNamed("lastApplication") != null) {
+ isLastChildApplication =
command.booleanPrimitiveValueOfParameterNamed("lastApplication");
+ }
+
+ Group group =
this.groupRepositoryWrapper.findOneWithNotFoundDetection(groupId);
+
+ if
(command.booleanObjectValueOfParameterNamed("isParentAccount") != null)
+ {
+ // empty table check
+ if (gsimRepository.count() != 0) {
+ // Parent-Not an empty table
+
+ accountNumber =
this.accountNumberGenerator.generate(account, accountNumberFormat);
+ account.updateAccountNo(accountNumber +
"-1");
Review comment:
@nikpawar89
Without hyphens the user can easily generate BBANs, issue check books to
account holders
standard account numbers should be 10 digits
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]