private AccountWrapper validateAndGetAccount()

in service/src/main/java/org/apache/fineract/cn/deposit/service/internal/service/TransactionService.java [261:282]


    private AccountWrapper validateAndGetAccount(@NotNull TransactionRequestData request, String accountId, TransactionTypeEnum txnType) {
        //TODO: error handling
        Account account = ledgerManager.findAccount(accountId);
        validateAccount(request.getAmount(), account);

        ProductInstanceEntity instance = productInstanceRepository.findByAccountIdentifier(accountId).orElseThrow(
                () -> ServiceException.notFound("Account {0} not found", accountId)
        );
        ProductDefinition productDefinition = productDefinitionService.findProductDefinition(instance.getProductDefinition().getIdentifier()).get();

        Currency currency = productDefinition.getCurrency();
        if (!currency.getCode().equals(request.getAmount().getCurrency()))
            throw new UnsupportedOperationException();

        request.normalizeAmounts(currency);

        Double withdrawableBalance = getWithdrawableBalance(account, productDefinition);
        if (txnType == TransactionTypeEnum.WITHDRAWAL && withdrawableBalance < request.getAmount().getAmount().doubleValue())
            throw new UnsupportedOperationException();

        return new AccountWrapper(account, instance, productDefinition, withdrawableBalance);
    }