@Test public final void test_fetch_reference_budget() { final List<Budget> budgets = getBudgets(); final Budget expextedResult = Budget.builder().id("1").build(); expextedResult.setTenantId("tenantId"); budgets.get(0).setReferenceBudget(expextedResult); when(budgetRepository.findById(any(Budget.class))).thenReturn(expextedResult); final List<Budget> actualResult = budgetService.fetchRelated(budgets,new RequestInfo()); assertEquals(expextedResult, actualResult.get(0).getReferenceBudget()); }
public List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo) { if (budgets != null) for (final Budget budget : budgets) { 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; }
BudgetService { public List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo) { if (budgets != null) for (final Budget budget : budgets) { 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; } }
BudgetService { public List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo) { if (budgets != null) for (final Budget budget : budgets) { 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  BudgetService(final SmartValidator validator, final BudgetRepository budgetRepository,
            final FinancialYearContractRepository financialYearContractRepository); }
BudgetService { public List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo) { if (budgets != null) for (final Budget budget : budgets) { 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  BudgetService(final SmartValidator validator, final BudgetRepository budgetRepository,
            final FinancialYearContractRepository financialYearContractRepository); @Transactional List<Budget> create(List<Budget> budgets, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<Budget> update(List<Budget> budgets, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<Budget> delete(List<Budget> budgets, final BindingResult errors,
            final RequestInfo requestInfo); BindingResult validate(final List<Budget> budgets, final String method, final BindingResult errors); List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo); Pagination<Budget> search(final BudgetSearch budgetSearch); @Transactional Budget save(final Budget budget); @Transactional Budget update(final Budget budget); @Transactional Budget delete(Budget budget); }
BudgetService { public List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo) { if (budgets != null) for (final Budget budget : budgets) { 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  BudgetService(final SmartValidator validator, final BudgetRepository budgetRepository,
            final FinancialYearContractRepository financialYearContractRepository); @Transactional List<Budget> create(List<Budget> budgets, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<Budget> update(List<Budget> budgets, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<Budget> delete(List<Budget> budgets, final BindingResult errors,
            final RequestInfo requestInfo); BindingResult validate(final List<Budget> budgets, final String method, final BindingResult errors); List<Budget> fetchRelated(final List<Budget> budgets,RequestInfo requestInfo); Pagination<Budget> search(final BudgetSearch budgetSearch); @Transactional Budget save(final Budget budget); @Transactional Budget update(final Budget budget); @Transactional Budget delete(Budget budget); static final String ACTION_CREATE; static final String ACTION_UPDATE; static final String ACTION_DELETE; static final String ACTION_VIEW; static final String ACTION_EDIT; static final String ACTION_SEARCH; }