<commit_before>package org.esupportail.smsuapi.business.purge;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.log4j.Logger;
import org.esupportail.smsuapi.dao.DaoService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Manage the purge in table SMS.
 * @author PRQD8824
 *
 */
public class PurgeSms {

	/**
	 * Maximum day of sms seniority.
	 */
	private int seniorityDay;
	
	/**
	 * Used to manage db.
	 */
	@Autowired private DaoService daoService;

	/**
	 * A logger.
	 */
	private final Logger logger = Logger.getLogger(getClass());
	
	/**
	 * 
	 */
	public void purgeSms() {
		// compute de limite date
		final long currentTimeInMillis = System.currentTimeMillis();
		final Calendar seniorityDateAsCal = new GregorianCalendar();
		seniorityDateAsCal.setTimeInMillis(currentTimeInMillis);
		
		seniorityDateAsCal.add(Calendar.DAY_OF_YEAR, -seniorityDay);
		
		final Date seniorityDateAsDate = seniorityDateAsCal.getTime();
		
		purgeSmsOlderThan(seniorityDateAsDate);
	}
	
	/**
	 * Purge the Sms in db with date older than the specified date.
	 * @param date
	 */
	private void purgeSmsOlderThan(final Date date) {
		
			logger.debug("Starting purge of SMS table with parameter : \n" + " - date : " + date);
		
		final int nbSmsDeleted = daoService.deleteSmsOlderThan(date);
		
			logger.debug("End purge of SMS table, result : \n" + 
				     " - number of sms deleted : " + nbSmsDeleted);
	}
	
	
	/******************
	 * Mutator
	 */
	
	/**
	 * Standard setter used by spring.
	 * @param seniorityDay
	 */
	public void setSeniorityDay(final int seniorityDay) {
		this.seniorityDay = seniorityDay;
	}
	
}<commit_msg>cleanup: create helper functions and use them<commit_after>package org.esupportail.smsuapi.business.purge;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.log4j.Logger;
import org.esupportail.smsuapi.dao.DaoService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Manage the purge in table SMS.
 * @author PRQD8824
 *
 */
public class PurgeSms {

	/**
	 * Maximum day of sms seniority.
	 */
	private int seniorityDay;
	
	/**
	 * Used to manage db.
	 */
	@Autowired private DaoService daoService;

	/**
	 * A logger.
	 */
	private final Logger logger = Logger.getLogger(getClass());
	
	public void purgeSms() {
		purgeSmsOlderThan(getNowMinusDays(seniorityDay));
	}
	
	/**
	 * Purge the Sms in db with date older than the specified date.
	 * @param date
	 */
	private void purgeSmsOlderThan(final Date date) {
		
			logger.debug("Starting purge of SMS table with parameter : \n" + " - date : " + date);
		
		final int nbSmsDeleted = daoService.deleteSmsOlderThan(date);
		
			logger.debug("End purge of SMS table, result : \n" + 
				     " - number of sms deleted : " + nbSmsDeleted);
	}
    
    private Date getNowMinusDays(int days) {
		// compute de limite date
		final Calendar seniorityDateAsCal = new GregorianCalendar();
		seniorityDateAsCal.setTimeInMillis(System.currentTimeMillis());
		seniorityDateAsCal.add(Calendar.DAY_OF_YEAR, -days);
		
        return seniorityDateAsCal.getTime();
    }
	
	/******************
	 * Mutator
	 */
	
	/**
	 * Standard setter used by spring.
	 * @param seniorityDay
	 */
	public void setSeniorityDay(final int seniorityDay) {
		this.seniorityDay = seniorityDay;
	}
	
}
{'fraction_non_alphanumeric': 0.11716220194289079, 'fraction_numerical': 0.0029437739181630853, 'mean_word_length': 3.5367156208277706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5527644', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1112, 'n_words': 268}