@Test public final void test_fetch_executing_department() { final List<BudgetDetail> budgetDetails = getBudgetDetails(); budgetDetails.get(0).setExecutingDepartment(new Department()); budgetDetails.get(0).getExecutingDepartment().setId("1"); budgetDetails.get(0).getExecutingDepartment().setTenantId("tenantId"); final DepartmentRes expextedResult = new DepartmentRes(); final Department dept = Department.builder().name("Department").id("1").build(); expextedResult.setDepartment(new ArrayList<Department>()); expextedResult.getDepartment().add(dept); when(departmentRepository.getDepartmentById(any(String.class), any(String.class))).thenReturn(expextedResult); final List<BudgetDetail> actualResult = budgetDetailService.fetchRelated(budgetDetails,new RequestInfo()); assertEquals(expextedResult.getDepartment().get(0), actualResult.get(0).getExecutingDepartment()); }
public List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo) { if (budgetdetails != null) for (final BudgetDetail budgetDetail : budgetdetails) { if (budgetDetail.getBudget() != null && budgetDetail.getBudget().getId() != null && budgetDetail.getBudget().getTenantId() != null) { final Budget budget = budgetRepository.findById(budgetDetail.getBudget()); if (budget == null) throw new InvalidDataException("budget", "budget.invalid", " Invalid budget"); budgetDetail.setBudget(budget); } if (budgetDetail.getFund() != null && budgetDetail.getFund().getId() != null && budgetDetail.getFund().getTenantId() != null) { final FundSearchContract contract = new FundSearchContract(); contract.setId(budgetDetail.getFund().getId()); contract.setTenantId(budgetDetail.getFund().getTenantId()); final FundContract fund = fundContractRepository.findById(contract,requestInfo); if (fund == null) throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); budgetDetail.setFund(fund); } if (budgetDetail.getBudgetGroup() != null && budgetDetail.getBudgetGroup().getId() != null && budgetDetail.getBudgetGroup().getTenantId() != null) { final BudgetGroupSearchContract contract = new BudgetGroupSearchContract(); contract.setId(budgetDetail.getBudgetGroup().getId()); contract.setTenantId(budgetDetail.getBudgetGroup().getTenantId()); final BudgetGroupContract budgetGroup = budgetGroupContractRepository.findById(contract,requestInfo); if (budgetGroup == null) throw new InvalidDataException("budgetGroup", "budgetGroup.invalid", " Invalid budgetGroup"); budgetDetail.setBudgetGroup(budgetGroup); } if (budgetDetail.getUsingDepartment() != null && budgetDetail.getUsingDepartment().getId() != null && budgetDetail.getUsingDepartment().getTenantId() != null) { final DepartmentRes usingDepartment = departmentRepository.getDepartmentById( budgetDetail.getUsingDepartment().getId().toString(), budgetDetail.getTenantId()); if (usingDepartment == null || usingDepartment.getDepartment() == null || usingDepartment.getDepartment().isEmpty()) throw new InvalidDataException("usingDepartment", "usingDepartment.invalid", " Invalid usingDepartment"); budgetDetail.setUsingDepartment(usingDepartment.getDepartment().get(0)); } if (budgetDetail.getExecutingDepartment() != null && budgetDetail.getExecutingDepartment().getId() != null && budgetDetail.getExecutingDepartment().getTenantId() != null) { final DepartmentRes executingDepartment = departmentRepository.getDepartmentById( budgetDetail.getExecutingDepartment().getId().toString(), budgetDetail.getTenantId()); if (executingDepartment == null) throw new InvalidDataException("executingDepartment", "executingDepartment.invalid", " Invalid executingDepartment"); budgetDetail.setExecutingDepartment(executingDepartment.getDepartment().get(0)); } if (budgetDetail.getFunction() != null && budgetDetail.getFunction().getId() != null && budgetDetail.getFunction().getTenantId() != null) { final FunctionSearchContract contract = new FunctionSearchContract(); contract.setId(budgetDetail.getFunction().getId()); contract.setTenantId(budgetDetail.getFunction().getTenantId()); final FunctionContract function = functionContractRepository.findById(contract,requestInfo); if (function == null) throw new InvalidDataException("function", "function.invalid", " Invalid function"); budgetDetail.setFunction(function); } if (budgetDetail.getScheme() != null && budgetDetail.getScheme().getId() != null && budgetDetail.getScheme().getTenantId() != null) { final SchemeSearchContract contract = new SchemeSearchContract(); contract.setId(budgetDetail.getScheme().getId()); contract.setTenantId(budgetDetail.getScheme().getTenantId()); final SchemeContract scheme = schemeContractRepository.findById(contract,requestInfo); if (scheme == null) throw new InvalidDataException("scheme", "scheme.invalid", " Invalid scheme"); budgetDetail.setScheme(scheme); } if (budgetDetail.getSubScheme() != null && budgetDetail.getSubScheme().getId() != null && budgetDetail.getSubScheme().getTenantId() != null) { final SubSchemeSearchContract contract = new SubSchemeSearchContract(); contract.setId(budgetDetail.getSubScheme().getId()); contract.setTenantId(budgetDetail.getSubScheme().getTenantId()); final SubSchemeContract subScheme = subSchemeContractRepository.findById(contract,requestInfo); if (subScheme == null) throw new InvalidDataException("subScheme", "subScheme.invalid", " Invalid subScheme"); budgetDetail.setSubScheme(subScheme); } if (budgetDetail.getFunctionary() != null && budgetDetail.getFunctionary().getId() != null && budgetDetail.getFunctionary().getTenantId() != null) { final FunctionarySearchContract contract = new FunctionarySearchContract(); contract.setId(budgetDetail.getFunctionary().getId()); contract.setTenantId(budgetDetail.getFunctionary().getTenantId()); final FunctionaryContract functionary = functionaryContractRepository.findById(contract,requestInfo); if (functionary == null) throw new InvalidDataException("functionary", "functionary.invalid", " Invalid functionary"); budgetDetail.setFunctionary(functionary); } if (budgetDetail.getBoundary() != null && budgetDetail.getBoundary().getId() != null && budgetDetail.getBoundary().getTenantId() != null) { final Boundary boundary = boundaryRepository.getBoundaryById(budgetDetail.getBoundary().getId(), budgetDetail.getBoundary().getTenantId()); if (boundary == null) throw new InvalidDataException("boundary", "boundary.invalid", " Invalid boundary"); budgetDetail.setBoundary(boundary); } } return budgetdetails; }
BudgetDetailService { public List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo) { if (budgetdetails != null) for (final BudgetDetail budgetDetail : budgetdetails) { if (budgetDetail.getBudget() != null && budgetDetail.getBudget().getId() != null && budgetDetail.getBudget().getTenantId() != null) { final Budget budget = budgetRepository.findById(budgetDetail.getBudget()); if (budget == null) throw new InvalidDataException("budget", "budget.invalid", " Invalid budget"); budgetDetail.setBudget(budget); } if (budgetDetail.getFund() != null && budgetDetail.getFund().getId() != null && budgetDetail.getFund().getTenantId() != null) { final FundSearchContract contract = new FundSearchContract(); contract.setId(budgetDetail.getFund().getId()); contract.setTenantId(budgetDetail.getFund().getTenantId()); final FundContract fund = fundContractRepository.findById(contract,requestInfo); if (fund == null) throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); budgetDetail.setFund(fund); } if (budgetDetail.getBudgetGroup() != null && budgetDetail.getBudgetGroup().getId() != null && budgetDetail.getBudgetGroup().getTenantId() != null) { final BudgetGroupSearchContract contract = new BudgetGroupSearchContract(); contract.setId(budgetDetail.getBudgetGroup().getId()); contract.setTenantId(budgetDetail.getBudgetGroup().getTenantId()); final BudgetGroupContract budgetGroup = budgetGroupContractRepository.findById(contract,requestInfo); if (budgetGroup == null) throw new InvalidDataException("budgetGroup", "budgetGroup.invalid", " Invalid budgetGroup"); budgetDetail.setBudgetGroup(budgetGroup); } if (budgetDetail.getUsingDepartment() != null && budgetDetail.getUsingDepartment().getId() != null && budgetDetail.getUsingDepartment().getTenantId() != null) { final DepartmentRes usingDepartment = departmentRepository.getDepartmentById( budgetDetail.getUsingDepartment().getId().toString(), budgetDetail.getTenantId()); if (usingDepartment == null || usingDepartment.getDepartment() == null || usingDepartment.getDepartment().isEmpty()) throw new InvalidDataException("usingDepartment", "usingDepartment.invalid", " Invalid usingDepartment"); budgetDetail.setUsingDepartment(usingDepartment.getDepartment().get(0)); } if (budgetDetail.getExecutingDepartment() != null && budgetDetail.getExecutingDepartment().getId() != null && budgetDetail.getExecutingDepartment().getTenantId() != null) { final DepartmentRes executingDepartment = departmentRepository.getDepartmentById( budgetDetail.getExecutingDepartment().getId().toString(), budgetDetail.getTenantId()); if (executingDepartment == null) throw new InvalidDataException("executingDepartment", "executingDepartment.invalid", " Invalid executingDepartment"); budgetDetail.setExecutingDepartment(executingDepartment.getDepartment().get(0)); } if (budgetDetail.getFunction() != null && budgetDetail.getFunction().getId() != null && budgetDetail.getFunction().getTenantId() != null) { final FunctionSearchContract contract = new FunctionSearchContract(); contract.setId(budgetDetail.getFunction().getId()); contract.setTenantId(budgetDetail.getFunction().getTenantId()); final FunctionContract function = functionContractRepository.findById(contract,requestInfo); if (function == null) throw new InvalidDataException("function", "function.invalid", " Invalid function"); budgetDetail.setFunction(function); } if (budgetDetail.getScheme() != null && budgetDetail.getScheme().getId() != null && budgetDetail.getScheme().getTenantId() != null) { final SchemeSearchContract contract = new SchemeSearchContract(); contract.setId(budgetDetail.getScheme().getId()); contract.setTenantId(budgetDetail.getScheme().getTenantId()); final SchemeContract scheme = schemeContractRepository.findById(contract,requestInfo); if (scheme == null) throw new InvalidDataException("scheme", "scheme.invalid", " Invalid scheme"); budgetDetail.setScheme(scheme); } if (budgetDetail.getSubScheme() != null && budgetDetail.getSubScheme().getId() != null && budgetDetail.getSubScheme().getTenantId() != null) { final SubSchemeSearchContract contract = new SubSchemeSearchContract(); contract.setId(budgetDetail.getSubScheme().getId()); contract.setTenantId(budgetDetail.getSubScheme().getTenantId()); final SubSchemeContract subScheme = subSchemeContractRepository.findById(contract,requestInfo); if (subScheme == null) throw new InvalidDataException("subScheme", "subScheme.invalid", " Invalid subScheme"); budgetDetail.setSubScheme(subScheme); } if (budgetDetail.getFunctionary() != null && budgetDetail.getFunctionary().getId() != null && budgetDetail.getFunctionary().getTenantId() != null) { final FunctionarySearchContract contract = new FunctionarySearchContract(); contract.setId(budgetDetail.getFunctionary().getId()); contract.setTenantId(budgetDetail.getFunctionary().getTenantId()); final FunctionaryContract functionary = functionaryContractRepository.findById(contract,requestInfo); if (functionary == null) throw new InvalidDataException("functionary", "functionary.invalid", " Invalid functionary"); budgetDetail.setFunctionary(functionary); } if (budgetDetail.getBoundary() != null && budgetDetail.getBoundary().getId() != null && budgetDetail.getBoundary().getTenantId() != null) { final Boundary boundary = boundaryRepository.getBoundaryById(budgetDetail.getBoundary().getId(), budgetDetail.getBoundary().getTenantId()); if (boundary == null) throw new InvalidDataException("boundary", "boundary.invalid", " Invalid boundary"); budgetDetail.setBoundary(boundary); } } return budgetdetails; } }
BudgetDetailService { public List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo) { if (budgetdetails != null) for (final BudgetDetail budgetDetail : budgetdetails) { if (budgetDetail.getBudget() != null && budgetDetail.getBudget().getId() != null && budgetDetail.getBudget().getTenantId() != null) { final Budget budget = budgetRepository.findById(budgetDetail.getBudget()); if (budget == null) throw new InvalidDataException("budget", "budget.invalid", " Invalid budget"); budgetDetail.setBudget(budget); } if (budgetDetail.getFund() != null && budgetDetail.getFund().getId() != null && budgetDetail.getFund().getTenantId() != null) { final FundSearchContract contract = new FundSearchContract(); contract.setId(budgetDetail.getFund().getId()); contract.setTenantId(budgetDetail.getFund().getTenantId()); final FundContract fund = fundContractRepository.findById(contract,requestInfo); if (fund == null) throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); budgetDetail.setFund(fund); } if (budgetDetail.getBudgetGroup() != null && budgetDetail.getBudgetGroup().getId() != null && budgetDetail.getBudgetGroup().getTenantId() != null) { final BudgetGroupSearchContract contract = new BudgetGroupSearchContract(); contract.setId(budgetDetail.getBudgetGroup().getId()); contract.setTenantId(budgetDetail.getBudgetGroup().getTenantId()); final BudgetGroupContract budgetGroup = budgetGroupContractRepository.findById(contract,requestInfo); if (budgetGroup == null) throw new InvalidDataException("budgetGroup", "budgetGroup.invalid", " Invalid budgetGroup"); budgetDetail.setBudgetGroup(budgetGroup); } if (budgetDetail.getUsingDepartment() != null && budgetDetail.getUsingDepartment().getId() != null && budgetDetail.getUsingDepartment().getTenantId() != null) { final DepartmentRes usingDepartment = departmentRepository.getDepartmentById( budgetDetail.getUsingDepartment().getId().toString(), budgetDetail.getTenantId()); if (usingDepartment == null || usingDepartment.getDepartment() == null || usingDepartment.getDepartment().isEmpty()) throw new InvalidDataException("usingDepartment", "usingDepartment.invalid", " Invalid usingDepartment"); budgetDetail.setUsingDepartment(usingDepartment.getDepartment().get(0)); } if (budgetDetail.getExecutingDepartment() != null && budgetDetail.getExecutingDepartment().getId() != null && budgetDetail.getExecutingDepartment().getTenantId() != null) { final DepartmentRes executingDepartment = departmentRepository.getDepartmentById( budgetDetail.getExecutingDepartment().getId().toString(), budgetDetail.getTenantId()); if (executingDepartment == null) throw new InvalidDataException("executingDepartment", "executingDepartment.invalid", " Invalid executingDepartment"); budgetDetail.setExecutingDepartment(executingDepartment.getDepartment().get(0)); } if (budgetDetail.getFunction() != null && budgetDetail.getFunction().getId() != null && budgetDetail.getFunction().getTenantId() != null) { final FunctionSearchContract contract = new FunctionSearchContract(); contract.setId(budgetDetail.getFunction().getId()); contract.setTenantId(budgetDetail.getFunction().getTenantId()); final FunctionContract function = functionContractRepository.findById(contract,requestInfo); if (function == null) throw new InvalidDataException("function", "function.invalid", " Invalid function"); budgetDetail.setFunction(function); } if (budgetDetail.getScheme() != null && budgetDetail.getScheme().getId() != null && budgetDetail.getScheme().getTenantId() != null) { final SchemeSearchContract contract = new SchemeSearchContract(); contract.setId(budgetDetail.getScheme().getId()); contract.setTenantId(budgetDetail.getScheme().getTenantId()); final SchemeContract scheme = schemeContractRepository.findById(contract,requestInfo); if (scheme == null) throw new InvalidDataException("scheme", "scheme.invalid", " Invalid scheme"); budgetDetail.setScheme(scheme); } if (budgetDetail.getSubScheme() != null && budgetDetail.getSubScheme().getId() != null && budgetDetail.getSubScheme().getTenantId() != null) { final SubSchemeSearchContract contract = new SubSchemeSearchContract(); contract.setId(budgetDetail.getSubScheme().getId()); contract.setTenantId(budgetDetail.getSubScheme().getTenantId()); final SubSchemeContract subScheme = subSchemeContractRepository.findById(contract,requestInfo); if (subScheme == null) throw new InvalidDataException("subScheme", "subScheme.invalid", " Invalid subScheme"); budgetDetail.setSubScheme(subScheme); } if (budgetDetail.getFunctionary() != null && budgetDetail.getFunctionary().getId() != null && budgetDetail.getFunctionary().getTenantId() != null) { final FunctionarySearchContract contract = new FunctionarySearchContract(); contract.setId(budgetDetail.getFunctionary().getId()); contract.setTenantId(budgetDetail.getFunctionary().getTenantId()); final FunctionaryContract functionary = functionaryContractRepository.findById(contract,requestInfo); if (functionary == null) throw new InvalidDataException("functionary", "functionary.invalid", " Invalid functionary"); budgetDetail.setFunctionary(functionary); } if (budgetDetail.getBoundary() != null && budgetDetail.getBoundary().getId() != null && budgetDetail.getBoundary().getTenantId() != null) { final Boundary boundary = boundaryRepository.getBoundaryById(budgetDetail.getBoundary().getId(), budgetDetail.getBoundary().getTenantId()); if (boundary == null) throw new InvalidDataException("boundary", "boundary.invalid", " Invalid boundary"); budgetDetail.setBoundary(boundary); } } return budgetdetails; }  }
BudgetDetailService { public List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo) { if (budgetdetails != null) for (final BudgetDetail budgetDetail : budgetdetails) { if (budgetDetail.getBudget() != null && budgetDetail.getBudget().getId() != null && budgetDetail.getBudget().getTenantId() != null) { final Budget budget = budgetRepository.findById(budgetDetail.getBudget()); if (budget == null) throw new InvalidDataException("budget", "budget.invalid", " Invalid budget"); budgetDetail.setBudget(budget); } if (budgetDetail.getFund() != null && budgetDetail.getFund().getId() != null && budgetDetail.getFund().getTenantId() != null) { final FundSearchContract contract = new FundSearchContract(); contract.setId(budgetDetail.getFund().getId()); contract.setTenantId(budgetDetail.getFund().getTenantId()); final FundContract fund = fundContractRepository.findById(contract,requestInfo); if (fund == null) throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); budgetDetail.setFund(fund); } if (budgetDetail.getBudgetGroup() != null && budgetDetail.getBudgetGroup().getId() != null && budgetDetail.getBudgetGroup().getTenantId() != null) { final BudgetGroupSearchContract contract = new BudgetGroupSearchContract(); contract.setId(budgetDetail.getBudgetGroup().getId()); contract.setTenantId(budgetDetail.getBudgetGroup().getTenantId()); final BudgetGroupContract budgetGroup = budgetGroupContractRepository.findById(contract,requestInfo); if (budgetGroup == null) throw new InvalidDataException("budgetGroup", "budgetGroup.invalid", " Invalid budgetGroup"); budgetDetail.setBudgetGroup(budgetGroup); } if (budgetDetail.getUsingDepartment() != null && budgetDetail.getUsingDepartment().getId() != null && budgetDetail.getUsingDepartment().getTenantId() != null) { final DepartmentRes usingDepartment = departmentRepository.getDepartmentById( budgetDetail.getUsingDepartment().getId().toString(), budgetDetail.getTenantId()); if (usingDepartment == null || usingDepartment.getDepartment() == null || usingDepartment.getDepartment().isEmpty()) throw new InvalidDataException("usingDepartment", "usingDepartment.invalid", " Invalid usingDepartment"); budgetDetail.setUsingDepartment(usingDepartment.getDepartment().get(0)); } if (budgetDetail.getExecutingDepartment() != null && budgetDetail.getExecutingDepartment().getId() != null && budgetDetail.getExecutingDepartment().getTenantId() != null) { final DepartmentRes executingDepartment = departmentRepository.getDepartmentById( budgetDetail.getExecutingDepartment().getId().toString(), budgetDetail.getTenantId()); if (executingDepartment == null) throw new InvalidDataException("executingDepartment", "executingDepartment.invalid", " Invalid executingDepartment"); budgetDetail.setExecutingDepartment(executingDepartment.getDepartment().get(0)); } if (budgetDetail.getFunction() != null && budgetDetail.getFunction().getId() != null && budgetDetail.getFunction().getTenantId() != null) { final FunctionSearchContract contract = new FunctionSearchContract(); contract.setId(budgetDetail.getFunction().getId()); contract.setTenantId(budgetDetail.getFunction().getTenantId()); final FunctionContract function = functionContractRepository.findById(contract,requestInfo); if (function == null) throw new InvalidDataException("function", "function.invalid", " Invalid function"); budgetDetail.setFunction(function); } if (budgetDetail.getScheme() != null && budgetDetail.getScheme().getId() != null && budgetDetail.getScheme().getTenantId() != null) { final SchemeSearchContract contract = new SchemeSearchContract(); contract.setId(budgetDetail.getScheme().getId()); contract.setTenantId(budgetDetail.getScheme().getTenantId()); final SchemeContract scheme = schemeContractRepository.findById(contract,requestInfo); if (scheme == null) throw new InvalidDataException("scheme", "scheme.invalid", " Invalid scheme"); budgetDetail.setScheme(scheme); } if (budgetDetail.getSubScheme() != null && budgetDetail.getSubScheme().getId() != null && budgetDetail.getSubScheme().getTenantId() != null) { final SubSchemeSearchContract contract = new SubSchemeSearchContract(); contract.setId(budgetDetail.getSubScheme().getId()); contract.setTenantId(budgetDetail.getSubScheme().getTenantId()); final SubSchemeContract subScheme = subSchemeContractRepository.findById(contract,requestInfo); if (subScheme == null) throw new InvalidDataException("subScheme", "subScheme.invalid", " Invalid subScheme"); budgetDetail.setSubScheme(subScheme); } if (budgetDetail.getFunctionary() != null && budgetDetail.getFunctionary().getId() != null && budgetDetail.getFunctionary().getTenantId() != null) { final FunctionarySearchContract contract = new FunctionarySearchContract(); contract.setId(budgetDetail.getFunctionary().getId()); contract.setTenantId(budgetDetail.getFunctionary().getTenantId()); final FunctionaryContract functionary = functionaryContractRepository.findById(contract,requestInfo); if (functionary == null) throw new InvalidDataException("functionary", "functionary.invalid", " Invalid functionary"); budgetDetail.setFunctionary(functionary); } if (budgetDetail.getBoundary() != null && budgetDetail.getBoundary().getId() != null && budgetDetail.getBoundary().getTenantId() != null) { final Boundary boundary = boundaryRepository.getBoundaryById(budgetDetail.getBoundary().getId(), budgetDetail.getBoundary().getTenantId()); if (boundary == null) throw new InvalidDataException("boundary", "boundary.invalid", " Invalid boundary"); budgetDetail.setBoundary(boundary); } } return budgetdetails; }  @Transactional List<BudgetDetail> create(List<BudgetDetail> budgetDetails, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<BudgetDetail> update(List<BudgetDetail> budgetDetails, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<BudgetDetail> delete(List<BudgetDetail> budgetDetails, final BindingResult errors,
            final RequestInfo requestInfo); List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo); Pagination<BudgetDetail> search(final BudgetDetailSearch budgetDetailSearch); @Transactional BudgetDetail save(final BudgetDetail budgetDetail); @Transactional BudgetDetail update(final BudgetDetail budgetDetail); @Transactional BudgetDetail delete(final BudgetDetail budgetDetail); }
BudgetDetailService { public List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo) { if (budgetdetails != null) for (final BudgetDetail budgetDetail : budgetdetails) { if (budgetDetail.getBudget() != null && budgetDetail.getBudget().getId() != null && budgetDetail.getBudget().getTenantId() != null) { final Budget budget = budgetRepository.findById(budgetDetail.getBudget()); if (budget == null) throw new InvalidDataException("budget", "budget.invalid", " Invalid budget"); budgetDetail.setBudget(budget); } if (budgetDetail.getFund() != null && budgetDetail.getFund().getId() != null && budgetDetail.getFund().getTenantId() != null) { final FundSearchContract contract = new FundSearchContract(); contract.setId(budgetDetail.getFund().getId()); contract.setTenantId(budgetDetail.getFund().getTenantId()); final FundContract fund = fundContractRepository.findById(contract,requestInfo); if (fund == null) throw new InvalidDataException("fund", "fund.invalid", " Invalid fund"); budgetDetail.setFund(fund); } if (budgetDetail.getBudgetGroup() != null && budgetDetail.getBudgetGroup().getId() != null && budgetDetail.getBudgetGroup().getTenantId() != null) { final BudgetGroupSearchContract contract = new BudgetGroupSearchContract(); contract.setId(budgetDetail.getBudgetGroup().getId()); contract.setTenantId(budgetDetail.getBudgetGroup().getTenantId()); final BudgetGroupContract budgetGroup = budgetGroupContractRepository.findById(contract,requestInfo); if (budgetGroup == null) throw new InvalidDataException("budgetGroup", "budgetGroup.invalid", " Invalid budgetGroup"); budgetDetail.setBudgetGroup(budgetGroup); } if (budgetDetail.getUsingDepartment() != null && budgetDetail.getUsingDepartment().getId() != null && budgetDetail.getUsingDepartment().getTenantId() != null) { final DepartmentRes usingDepartment = departmentRepository.getDepartmentById( budgetDetail.getUsingDepartment().getId().toString(), budgetDetail.getTenantId()); if (usingDepartment == null || usingDepartment.getDepartment() == null || usingDepartment.getDepartment().isEmpty()) throw new InvalidDataException("usingDepartment", "usingDepartment.invalid", " Invalid usingDepartment"); budgetDetail.setUsingDepartment(usingDepartment.getDepartment().get(0)); } if (budgetDetail.getExecutingDepartment() != null && budgetDetail.getExecutingDepartment().getId() != null && budgetDetail.getExecutingDepartment().getTenantId() != null) { final DepartmentRes executingDepartment = departmentRepository.getDepartmentById( budgetDetail.getExecutingDepartment().getId().toString(), budgetDetail.getTenantId()); if (executingDepartment == null) throw new InvalidDataException("executingDepartment", "executingDepartment.invalid", " Invalid executingDepartment"); budgetDetail.setExecutingDepartment(executingDepartment.getDepartment().get(0)); } if (budgetDetail.getFunction() != null && budgetDetail.getFunction().getId() != null && budgetDetail.getFunction().getTenantId() != null) { final FunctionSearchContract contract = new FunctionSearchContract(); contract.setId(budgetDetail.getFunction().getId()); contract.setTenantId(budgetDetail.getFunction().getTenantId()); final FunctionContract function = functionContractRepository.findById(contract,requestInfo); if (function == null) throw new InvalidDataException("function", "function.invalid", " Invalid function"); budgetDetail.setFunction(function); } if (budgetDetail.getScheme() != null && budgetDetail.getScheme().getId() != null && budgetDetail.getScheme().getTenantId() != null) { final SchemeSearchContract contract = new SchemeSearchContract(); contract.setId(budgetDetail.getScheme().getId()); contract.setTenantId(budgetDetail.getScheme().getTenantId()); final SchemeContract scheme = schemeContractRepository.findById(contract,requestInfo); if (scheme == null) throw new InvalidDataException("scheme", "scheme.invalid", " Invalid scheme"); budgetDetail.setScheme(scheme); } if (budgetDetail.getSubScheme() != null && budgetDetail.getSubScheme().getId() != null && budgetDetail.getSubScheme().getTenantId() != null) { final SubSchemeSearchContract contract = new SubSchemeSearchContract(); contract.setId(budgetDetail.getSubScheme().getId()); contract.setTenantId(budgetDetail.getSubScheme().getTenantId()); final SubSchemeContract subScheme = subSchemeContractRepository.findById(contract,requestInfo); if (subScheme == null) throw new InvalidDataException("subScheme", "subScheme.invalid", " Invalid subScheme"); budgetDetail.setSubScheme(subScheme); } if (budgetDetail.getFunctionary() != null && budgetDetail.getFunctionary().getId() != null && budgetDetail.getFunctionary().getTenantId() != null) { final FunctionarySearchContract contract = new FunctionarySearchContract(); contract.setId(budgetDetail.getFunctionary().getId()); contract.setTenantId(budgetDetail.getFunctionary().getTenantId()); final FunctionaryContract functionary = functionaryContractRepository.findById(contract,requestInfo); if (functionary == null) throw new InvalidDataException("functionary", "functionary.invalid", " Invalid functionary"); budgetDetail.setFunctionary(functionary); } if (budgetDetail.getBoundary() != null && budgetDetail.getBoundary().getId() != null && budgetDetail.getBoundary().getTenantId() != null) { final Boundary boundary = boundaryRepository.getBoundaryById(budgetDetail.getBoundary().getId(), budgetDetail.getBoundary().getTenantId()); if (boundary == null) throw new InvalidDataException("boundary", "boundary.invalid", " Invalid boundary"); budgetDetail.setBoundary(boundary); } } return budgetdetails; }  @Transactional List<BudgetDetail> create(List<BudgetDetail> budgetDetails, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<BudgetDetail> update(List<BudgetDetail> budgetDetails, final BindingResult errors,
            final RequestInfo requestInfo); @Transactional List<BudgetDetail> delete(List<BudgetDetail> budgetDetails, final BindingResult errors,
            final RequestInfo requestInfo); List<BudgetDetail> fetchRelated(final List<BudgetDetail> budgetdetails,RequestInfo requestInfo); Pagination<BudgetDetail> search(final BudgetDetailSearch budgetDetailSearch); @Transactional BudgetDetail save(final BudgetDetail budgetDetail); @Transactional BudgetDetail update(final BudgetDetail budgetDetail); @Transactional BudgetDetail delete(final BudgetDetail budgetDetail); 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; }