<commit_before>package ee.pardiralli.service;

import ee.pardiralli.db.*;
import ee.pardiralli.domain.*;
import ee.pardiralli.dto.InsertionDTO;
import ee.pardiralli.util.BanklinkUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InsertionServiceImpl implements InsertionService {

    private final DuckRepository duckRepository;
    private final RaceRepository raceRepository;
    private final OwnerRepository ownerRepository;
    private final BuyerRepository buyerRepository;
    private final TransactionRepository transactionRepository;
    private final MailService mailService;
    private final SerialNumberService numberService;

    @Autowired
    public InsertionServiceImpl(DuckRepository duckRepository,
                                RaceRepository raceRepository,
                                OwnerRepository ownerRepository,
                                BuyerRepository buyerRepository,
                                TransactionRepository transactionRepository,
                                MailService mailService, SerialNumberService numberService) {

        this.duckRepository = duckRepository;
        this.raceRepository = raceRepository;
        this.ownerRepository = ownerRepository;
        this.buyerRepository = buyerRepository;
        this.transactionRepository = transactionRepository;
        this.mailService = mailService;
        this.numberService = numberService;
    }


    @Override
    public Boolean saveInsertion(InsertionDTO insertionDTO) {
        List<Duck> duckList = new ArrayList<>();

        Race race = raceRepository.findRaceByIsOpen(true);

        DuckBuyer duckBuyer = new DuckBuyer();
        duckBuyer.setEmail(insertionDTO.getBuyerEmail());
        duckBuyer = buyerRepository.save(duckBuyer);

        DuckOwner duckOwner = new DuckOwner();
        duckOwner.setFirstName(insertionDTO.getOwnerFirstName());
        duckOwner.setLastName(insertionDTO.getOwnerLastName());
        duckOwner.setPhoneNumber(insertionDTO.getOwnerPhoneNumber());
        duckOwner = ownerRepository.save(duckOwner);

        Transaction transaction = new Transaction();
        transaction.setIsPaid(true);
        transaction.setTimeOfPayment(BanklinkUtils.getCurrentTimeStamp());
        transaction = transactionRepository.save(transaction);

        for (int i = 0; i < insertionDTO.getNumberOfDucks(); i++) {
            Duck duck = new Duck();
            duck.setDateOfPurchase(BanklinkUtils.getCurrentDate());
            duck.setDuckBuyer(duckBuyer);
            duck.setDuckOwner(duckOwner);
            duck.setRace(race);
            duck.setTransaction(transaction);
            duck.setPriceCents(insertionDTO.getPriceOfOneDuck() * 100);
            duck.setTimeOfPurchase(BanklinkUtils.getCurrentTimeStamp());
            duck.setSerialNumber(numberService.getSerial());

            duckList.add(duckRepository.save(duck));
        }
        return mailService.sendConfirmationEmail(duckBuyer, duckList);
    }

    @Override
    public boolean existsOpenRace() {
        return raceRepository.countOpenedRaces() == 1;
    }
}
<commit_msg>Added logging to InsertionService<commit_after>package ee.pardiralli.service;

import ee.pardiralli.db.*;
import ee.pardiralli.domain.*;
import ee.pardiralli.dto.InsertionDTO;
import ee.pardiralli.util.BanklinkUtils;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Log4j
public class InsertionServiceImpl implements InsertionService {

    private final DuckRepository duckRepository;
    private final RaceRepository raceRepository;
    private final OwnerRepository ownerRepository;
    private final BuyerRepository buyerRepository;
    private final TransactionRepository transactionRepository;
    private final MailService mailService;
    private final SerialNumberService numberService;

    @Autowired
    public InsertionServiceImpl(DuckRepository duckRepository,
                                RaceRepository raceRepository,
                                OwnerRepository ownerRepository,
                                BuyerRepository buyerRepository,
                                TransactionRepository transactionRepository,
                                MailService mailService, SerialNumberService numberService) {

        this.duckRepository = duckRepository;
        this.raceRepository = raceRepository;
        this.ownerRepository = ownerRepository;
        this.buyerRepository = buyerRepository;
        this.transactionRepository = transactionRepository;
        this.mailService = mailService;
        this.numberService = numberService;
    }


    @Override
    public Boolean saveInsertion(InsertionDTO insertionDTO) {
        log.info("Inserting ducks from " + insertionDTO);
        List<Duck> duckList = new ArrayList<>();

        Race race = raceRepository.findRaceByIsOpen(true);

        DuckBuyer duckBuyer = new DuckBuyer();
        duckBuyer.setEmail(insertionDTO.getBuyerEmail());
        duckBuyer = buyerRepository.save(duckBuyer);

        DuckOwner duckOwner = new DuckOwner();
        duckOwner.setFirstName(insertionDTO.getOwnerFirstName());
        duckOwner.setLastName(insertionDTO.getOwnerLastName());
        duckOwner.setPhoneNumber(insertionDTO.getOwnerPhoneNumber());
        duckOwner = ownerRepository.save(duckOwner);

        Transaction transaction = new Transaction();
        transaction.setIsPaid(true);
        transaction.setTimeOfPayment(BanklinkUtils.getCurrentTimeStamp());
        transaction = transactionRepository.save(transaction);

        for (int i = 0; i < insertionDTO.getNumberOfDucks(); i++) {
            Duck duck = new Duck();
            duck.setDateOfPurchase(BanklinkUtils.getCurrentDate());
            duck.setDuckBuyer(duckBuyer);
            duck.setDuckOwner(duckOwner);
            duck.setRace(race);
            duck.setTransaction(transaction);
            duck.setPriceCents(insertionDTO.getPriceOfOneDuck() * 100);
            duck.setTimeOfPurchase(BanklinkUtils.getCurrentTimeStamp());
            duck.setSerialNumber(numberService.getSerial());

            log.info("Saving duck " + duck);
            duckList.add(duckRepository.save(duck));
        }

        Boolean sentMail = mailService.sendConfirmationEmail(duckBuyer, duckList);
        if (sentMail) {
            log.info("Confirmation email sent");
        } else {
            log.error("Failed to send confirmation email");
        }

        return sentMail;
    }

    @Override
    public boolean existsOpenRace() {
        return raceRepository.countOpenedRaces() == 1; // TODO: 11/01/2017 this should be done by RaceService
    }
}

{'fraction_non_alphanumeric': 0.07894736842105263, 'fraction_numerical': 0.003036437246963563, 'mean_word_length': 2.9730040206777715, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '14079', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1766, 'n_words': 333}