class BankAccountService {

	public List<BankAccount> fetchRelated(List<BankAccount> bankaccounts) {
		for (BankAccount bankAccount : bankaccounts) {
			// fetch related items
			bankAccount.setTenantId(ApplicationThreadLocals.getTenantId().get());
			if (bankAccount.getBankBranch() != null) {
				BankBranch bankBranch = bankBranchRepository.findById(bankAccount.getBankBranch());
				if (bankBranch == null) {
					throw new InvalidDataException("bankBranch", "bankBranch.invalid", " Invalid bankBranch");
				}
				bankAccount.setBankBranch(bankBranch);
			}
			if (bankAccount.getChartOfAccount() != null) {
				ChartOfAccount chartOfAccount = chartOfAccountRepository.findById(bankAccount.getChartOfAccount());
				if (chartOfAccount == null) {
					throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid",
							" Invalid chartOfAccount");
				}
				bankAccount.setChartOfAccount(chartOfAccount);
			}
			if (bankAccount.getFund() != null) {
				Fund fund = fundRepository.findById(bankAccount.getFund());
				if (fund == null) {
					throw new InvalidDataException("fund", "fund.invalid", " Invalid fund");
				}
				bankAccount.setFund(fund);
			}

		}

		return bankaccounts;
	}

}