private void createAccounts()

in service/src/main/java/org/apache/fineract/cn/individuallending/internal/command/handler/IndividualLoanCommandHandler.java [731:771]


  private void createAccounts(
      final DataContextOfAction dataContextOfAction,
      final DesignatorToAccountIdentifierMapper designatorToAccountIdentifierMapper,
      final Map<String, BigDecimal> currentBalances) throws InterruptedException
  {
    //Create the needed account assignments for groups and persist them for the case.
    try {
      designatorToAccountIdentifierMapper.getGroupsNeedingLedgers()
          .map(groupNeedingLedger -> {
            try {
              final String createdLedgerIdentifier = accountingAdapter.createLedger(
                  dataContextOfAction.getCaseParametersEntity().getCustomerIdentifier(),
                  groupNeedingLedger.getGroupName(),
                  groupNeedingLedger.getParentLedger());
              return new AccountAssignment(groupNeedingLedger.getGroupName(), createdLedgerIdentifier);
            } catch (InterruptedException e) {
              throw new InterruptedInALambdaException(e);
            }
          })
          .map(accountAssignment -> CaseMapper.map(accountAssignment, dataContextOfAction.getCustomerCaseEntity()))
          .forEach(caseAccountAssignmentEntity -> dataContextOfAction.getCustomerCaseEntity().getAccountAssignments().add(caseAccountAssignmentEntity));
    }
    catch (final InterruptedInALambdaException e) {
      e.throwWrappedException();
    }

    //Create the needed account assignments and persist them for the case.
    designatorToAccountIdentifierMapper.getLedgersNeedingAccounts()
        .map(ledger -> {
          final BigDecimal currentBalance = currentBalances.getOrDefault(ledger.getDesignator(), BigDecimal.ZERO);
          return new AccountAssignment(ledger.getDesignator(),
              accountingAdapter.createOrFindCaseAccountForLedgerAssignment(
                  dataContextOfAction.getCaseParametersEntity().getCustomerIdentifier(),
                  ledger,
                  currentBalance));})
        .map(accountAssignment -> CaseMapper.map(accountAssignment, dataContextOfAction.getCustomerCaseEntity()))
        .forEach(caseAccountAssignmentEntity ->
            dataContextOfAction.getCustomerCaseEntity().getAccountAssignments().add(caseAccountAssignmentEntity)
        );
    caseRepository.save(dataContextOfAction.getCustomerCaseEntity());
  }