class BudgetService {

    public List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo) {
        if (budgets != null)
            for (final Budget budget : budgets) {
                // fetch related items

                if (budget.getFinancialYear() != null && budget.getFinancialYear().getId() != null
                        && budget.getFinancialYear().getTenantId() != null) {
                    final FinancialYearSearchContract contract = new FinancialYearSearchContract();
                    contract.setId(budget.getFinancialYear().getId());
                    contract.setTenantId(budget.getFinancialYear().getTenantId());
                    final FinancialYearContract financialYear = financialYearContractRepository.findById(contract,requestInfo);
                    if (financialYear == null)
                        throw new InvalidDataException("financialYear", "financialYear.invalid",
                                " Invalid financialYear");
                    budget.setFinancialYear(financialYear);
                }

                if (budget.getParent() != null && budget.getParent().getId() != null
                        && !budget.getParent().getId().isEmpty()) {
                    final Budget parent = budgetRepository.findById(budget.getParent());
                    if (parent == null)
                        throw new InvalidDataException("parent", "parent.invalid", " Invalid parent");
                    budget.setParent(parent);
                }
                if (budget.getReferenceBudget() != null && budget.getReferenceBudget().getId() != null
                        && !budget.getReferenceBudget().getId().isEmpty()) {
                    final Budget referenceBudget = budgetRepository.findById(budget.getReferenceBudget());
                    if (referenceBudget == null)
                        throw new InvalidDataException("referenceBudget", "referenceBudget.invalid",
                                " Invalid referenceBudget");
                    budget.setReferenceBudget(referenceBudget);
                }
            }

        return budgets;
    }

    @Autowired public  BudgetService(final SmartValidator validator, final BudgetRepository budgetRepository,
            final FinancialYearContractRepository financialYearContractRepository);

}