The provided code defines a private method named `mappingTransaction` that...

August 22, 2025 at 06:04 PM

private List<AccountTransaction> mappingTransaction(List<TransactionListDetails> transactions, Map<String, String> transTextCodeMap, String accountNumber, String mainCategory, String subCategory,String caseId) { List<AccountTransaction> accountTransactions = new ArrayList<>(); if (transactions != null && transactions.size() > 0) { // Fetching disputed transactions from ARS Date fetchFromDate = complaintsCommon.fetchFromDate(resourceAPI.getInteger(ComplaintsConstants.TRANSACTIONS_FETCH_MONTH)); List<DailyBankTransInfo> transArsInfos = arsDailyBankTransService.fetchArsTrans(accountNumber, "0", String.valueOf(accountTransactions.size()), fetchFromDate); int i = 0; for (TransactionListDetails transaction : transactions) { if (transTextCodeMap == null || (transaction.getTextCode() != null && transTextCodeMap.get(transaction.getTextCode()) != null && transaction.getBookedDate() != null)) { if (("unknowntrans".equals(subCategory) || "goodspurchased".equals(subCategory) || "internationalpayments".equals(mainCategory) || "fees".equals(mainCategory)) && transaction.getAmount() != null && transaction.getAmount().signum() != -1) { continue; } AccountTransaction bankTransaction = new AccountTransaction(); bankTransaction.setTransAmount(transaction.getAmount()); bankTransaction.setTransCurrency("NOK"); //cardTrans.setOriginalCurrency(transaction.getOriginalCurrency()); bankTransaction.setTextCode(transaction.getTextCode()); bankTransaction.setOriginalAmount(transaction.getAmount()); bankTransaction.setDescription(transaction.getDescription()); bankTransaction.setTransRef(String.valueOf(i)); bankTransaction.setRefNo(transaction.getTextLine2()); bankTransaction.setMerchantName((transaction.getTextLine1() != null ? transaction.getTextLine1() + " " : "") + (transaction.getTextLine2() != null ? transaction.getTextLine2() + " " : "") + (transaction.getTextLine3() != null ? transaction.getTextLine3() : "")); try { bankTransaction.setTransDate(transaction.getBookedDate()); bankTransaction.setUsageDate(transaction.getAccountingDate()); bankTransaction.setTransDateFormat(format(bankTransaction.getTransDate(), MEDIUMDATE)); bankTransaction.setUsageDateFormat(format(bankTransaction.getUsageDate(), MEDIUMDATE)); bankTransaction.setTransAmountFormat(format(transaction.getAmount(), CURRENCY)); } catch (Exception e) { LOGGER_INFO.log("Account formatting error : " + e.getMessage()); } // Updating already raised transaction complaints are true if (transArsInfos.size() > 0) { for (DailyBankTransInfo transArsInfo : transArsInfos) { LOGGER_INFO.log("Banking transaction = " + bankTransaction + ". ARS Transaction = " + transArsInfo + ". account equals check " + transArsInfo.getBruksdato()+ "=" + bankTransaction.getTransDate() +" : "+ transArsInfo.getRegDato()+ "=" + bankTransaction.getUsageDate() +" : "+ bankTransaction.getTransAmount()+ "=" + transArsInfo.getNOK() +" : "+ transArsInfo.getDescription()+"="+((bankTransaction.getDescription() != null ? bankTransaction.getDescription() + ", " : StringUtils.EMPTY) + (bankTransaction.getMerchantName() != null ? bankTransaction.getMerchantName() : StringUtils.EMPTY)).trim()); if ((transArsInfo.getReqIDCase() != null && !transArsInfo.getReqIDCase().trim().equalsIgnoreCase(caseId)) && (transArsInfo.getBruksdato()!= null && bankTransaction.getTransDate() != null && transArsInfo.getBruksdato().compareTo(bankTransaction.getTransDate()) == 0) && (transArsInfo.getRegDato()!= null && bankTransaction.getUsageDate()!=null && transArsInfo.getRegDato().compareTo(bankTransaction.getUsageDate()) == 0) && (bankTransaction.getTransAmount()!= null && transArsInfo.getNOK()!= null && bankTransaction.getTransAmount().compareTo(new BigDecimal(transArsInfo.getNOK())) == 0) && (transArsInfo.getDescription() != null && transArsInfo.getDescription().trim() .equals(((bankTransaction.getDescription() != null ? bankTransaction.getDescription() + ", " : StringUtils.EMPTY) + (bankTransaction.getMerchantName() != null ? bankTransaction.getMerchantName() : StringUtils.EMPTY)).trim()))) { bankTransaction.setComplaintRaised(true); break; } } } accountTransactions.add(bankTransaction); i++; } } } return accountTransactions; }

The provided code defines a private method named mappingTransaction that processes a list of transactions (transactions) and maps them into a new list of AccountTransaction objects based on various constraints and business logic. Here's a detailed breakdown of what the code does:


Inputs to the Function:

  • transactions: A list of TransactionListDetails objects, each representing a banking transaction.
  • transTextCodeMap: A map containing transaction text codes and associated values.
  • accountNumber: The account number associated with the transactions.
  • mainCategory and subCategory: Strings representing categories of the transactions (e.g., "fees", "unknowntrans").
  • caseId: A unique identifier for a particular case.

Outputs of the Function:

  • Returns a list of AccountTransaction objects (accountTransactions), which are processed and filtered based on predefined rules.

What the Code Does:

  1. Initialization:

    • Creates a new list to hold AccountTransaction instances (accountTransactions).
    • Checks if the transactions list is non-null and contains elements. If not, an empty list is returned immediately.
  2. Fetch Additional Data:

    • Retrieves a fetchFromDate, which represents the date from which disputed transactions are fetched.
    • Retrieves a list of disputed transactions (transArsInfos) from an external service (arsDailyBankTransService) using the account number and date.
  3. Iterate Through Transactions:

    • Loops through each TransactionListDetails object in the transactions list.
    • For each transaction:
      • Validates certain conditions:
        • Checks whether transTextCodeMap is null or verifies the presence of a valid textCode in the map and that the bookedDate is not null.
        • Filters out certain transactions based on mainCategory, subCategory, and the transaction's amount (e.g., negative or null amounts are skipped for specific categories).
      • Creates a new AccountTransaction object (bankTransaction) for valid records:
        • Maps properties of TransactionListDetails (e.g., amount, textCode, description) to AccountTransaction.
        • Concatenates transaction text lines (textLine1, textLine2, textLine3) to derive the merchant's name.
        • Attempts to format and set dates (transDate, usageDate) and amounts with specific formats. Logs any exceptions that occur during formatting.
      • Updates AccountTransaction to mark whether it has an already-raised complaint:
        • Compares date, amount, and description fields with the disputed transactions fetched from arsDailyBankTransService.
        • If a match is found and the caseId is different, sets complaintRaised to true.
  4. Add to Resultant List:

    • Adds the bankTransaction object to the accountTransactions list if it satisfies all conditions.
    • Increments the reference number ("i") used for transRef.
  5. Return:

    • The method returns the processed accountTransactions list.

Business Logic Summary:

  • Maps transactions (TransactionListDetails) to formatted account transaction objects (AccountTransaction).
  • Filters, validates, and skips transactions based on categories (mainCategory, subCategory) and conditions like negative amounts or null fields.
  • Flags transactions for which complaints are already raised based on a comparison with disputed transactions.
  • Formats transaction dates and amounts, handling any exceptions during formatting.

Example Use Case:

This method can be used in a financial service application to process raw transaction data for an account, transform it into a structured format, and flag transactions that have existing complaints or disputes. The output list would then be used for further customer-facing rendering, analysis, or reporting.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node