<commit_before>package devopsdistilled.operp.server.data.service.stock.impl;

import java.util.Date;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import devopsdistilled.operp.server.data.entity.stock.Stock;
import devopsdistilled.operp.server.data.entity.stock.StockKeeper;
import devopsdistilled.operp.server.data.repo.stock.StockKeeperRepository;
import devopsdistilled.operp.server.data.repo.stock.StockRepository;
import devopsdistilled.operp.server.data.service.impl.AbstractEntityService;
import devopsdistilled.operp.server.data.service.stock.StockKeeperService;

@Service
public class StockKeeperServiceImpl extends
		AbstractEntityService<StockKeeper, Long, StockKeeperRepository>
		implements StockKeeperService {

	private static final long serialVersionUID = -1311042040845285500L;

	@Inject
	private StockKeeperRepository repo;

	@Inject
	private StockRepository stockRepository;

	@Override
	protected StockKeeperRepository getRepo() {
		return repo;
	}

	@Override
	protected StockKeeper findByEntityName(String entityName) {
		return null;
	}

	@Override
	@Transactional
	public <S extends StockKeeper> S save(S stockKeeper) {
		Stock stock = stockRepository.findByItemAndWarehouse(stockKeeper
				.getStock().getItem(), stockKeeper.getStock().getWarehouse());

		if (stock != null) {
			stock.setQuantity(stock.getQuantity() + stockKeeper.getQuantity());
		} else {
			stock = stockKeeper.getStock();
			stock.setQuantity(stockKeeper.getQuantity());
		}
		stock = stockRepository.save(stock);
		stockKeeper.setStock(stock);
		stockKeeper.setStockUpdateDate(new Date());

		return super.save(stockKeeper);

	}
}<commit_msg>Revert the Stock value when deleting StockKeeper<commit_after>package devopsdistilled.operp.server.data.service.stock.impl;

import java.util.Date;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import devopsdistilled.operp.server.data.entity.stock.Stock;
import devopsdistilled.operp.server.data.entity.stock.StockKeeper;
import devopsdistilled.operp.server.data.repo.stock.StockKeeperRepository;
import devopsdistilled.operp.server.data.repo.stock.StockRepository;
import devopsdistilled.operp.server.data.service.impl.AbstractEntityService;
import devopsdistilled.operp.server.data.service.stock.StockKeeperService;

@Service
public class StockKeeperServiceImpl extends
		AbstractEntityService<StockKeeper, Long, StockKeeperRepository>
		implements StockKeeperService {

	private static final long serialVersionUID = -1311042040845285500L;

	@Inject
	private StockKeeperRepository repo;

	@Inject
	private StockRepository stockRepository;

	@Override
	protected StockKeeperRepository getRepo() {
		return repo;
	}

	@Override
	protected StockKeeper findByEntityName(String entityName) {
		return null;
	}

	@Override
	@Transactional
	public <S extends StockKeeper> S save(S stockKeeper) {
		Stock stock = stockRepository.findByItemAndWarehouse(stockKeeper
				.getStock().getItem(), stockKeeper.getStock().getWarehouse());

		if (stock != null) {
			stock.setQuantity(stock.getQuantity() + stockKeeper.getQuantity());
		} else {
			stock = stockKeeper.getStock();
			stock.setQuantity(stockKeeper.getQuantity());
		}
		stock = stockRepository.save(stock);
		stockKeeper.setStock(stock);
		stockKeeper.setStockUpdateDate(new Date());

		return super.save(stockKeeper);

	}

	@Override
	@Transactional
	public void delete(StockKeeper stockKeeper) {
		Stock stock = stockKeeper.getStock();
		stock.setQuantity(stock.getQuantity() - stockKeeper.getQuantity());
		stock = stockRepository.save(stock);
		stockKeeper.setStock(stock);

		super.delete(stockKeeper);
	}
}
{'fraction_non_alphanumeric': 0.09823544903871477, 'fraction_numerical': 0.010007900974453516, 'mean_word_length': 6.125703564727955, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6992840', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1149, 'n_words': 199}