class AccountEntityRepository {

    @Transactional
    public List<AccountEntity> save(List<AccountEntity> accountEntities, RequestInfo requestInfo) {

        ModelMapper mapper = new ModelMapper();
        AccountEntityContract contract;

        if (persistThroughKafka != null && !persistThroughKafka.isEmpty()
                && persistThroughKafka.equalsIgnoreCase("yes")) {

            AccountEntityRequest request = new AccountEntityRequest();
            request.setRequestInfo(requestInfo);
            request.setAccountEntities(new ArrayList<>());

            for (AccountEntity f : accountEntities) {

                contract = new AccountEntityContract();
                contract.setCreatedDate(new Date());
                mapper.map(f, contract);
                request.getAccountEntities().add(contract);

            }

            addToQue(request);

            return accountEntities;
        } else {

            List<AccountEntity> resultList = new ArrayList<AccountEntity>();

            for (AccountEntity f : accountEntities) {

                resultList.add(save(f));
            }

            AccountEntityRequest request = new AccountEntityRequest();
            request.setRequestInfo(requestInfo);
            request.setAccountEntities(new ArrayList<>());

            for (AccountEntity f : resultList) {

                contract = new AccountEntityContract();
                contract.setCreatedDate(new Date());
                mapper.map(f, contract);
                request.getAccountEntities().add(contract);

            }

            addToSearchQueue(request);

            return resultList;
        }

    }

    @Autowired public  AccountEntityRepository(AccountEntityJdbcRepository accountEntityJdbcRepository,
                                   MastersQueueRepository accountEntityQueueRepository, FinancialConfigurationService financialConfigurationService,
                                   AccountEntityESRepository accountEntityESRepository, @Value("${persist.through.kafka}") String persistThroughKafka);

}