class InstrumentAccountCodeService {

    public List<InstrumentAccountCode> fetchRelated(List<InstrumentAccountCode> instrumentaccountcodes, RequestInfo requestInfo) {

        if (instrumentaccountcodes != null)
            for (InstrumentAccountCode instrumentAccountCode : instrumentaccountcodes) {

                // fetch related items

                if (instrumentAccountCode.getInstrumentType() != null
                        && instrumentAccountCode.getInstrumentType().getName() != null) {
                    InstrumentTypeSearch instrumentTypeSearch = new InstrumentTypeSearch();
                    instrumentTypeSearch.setName(instrumentAccountCode.getInstrumentType().getName());
                    instrumentTypeSearch.setTenantId(instrumentAccountCode.getInstrumentType().getTenantId());
                    Pagination<InstrumentType> response = instrumentTypeRepository.search(instrumentTypeSearch);
                    if (response == null || response.getPagedData() == null || response.getPagedData().isEmpty())
                        throw new InvalidDataException("instrumentTypeSearchResult", ErrorCode.INVALID_REF_VALUE.getCode(), null);
                    instrumentAccountCode.setInstrumentType(response.getPagedData().get(0));
                }

                if (instrumentAccountCode.getAccountCode() != null
                        && instrumentAccountCode.getAccountCode().getGlcode() != null) {

                    instrumentAccountCode.getAccountCode().setTenantId(instrumentAccountCode.getTenantId());
                    ChartOfAccountContract accountCode = chartOfAccountContractRepository
                            .findByGlcode(instrumentAccountCode.getAccountCode(), requestInfo);

                    if (accountCode == null)
                        throw new InvalidDataException("accountCode", ErrorCode.INVALID_REF_VALUE.getCode(), null);

                    instrumentAccountCode.setAccountCode(accountCode);
                }

            }

        return instrumentaccountcodes;
    }

    @Autowired public  InstrumentAccountCodeService(SmartValidator validator,
            InstrumentAccountCodeRepository instrumentAccountCodeRepository,
            ChartOfAccountContractRepository chartOfAccountContractRepository,
            InstrumentTypeRepository instrumentTypeRepository);

}