package eu.dnetlib.dlms.epub;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Required;

/**
 * Class that composes methods of EPubSamplesGenerator so that ingestion is done in transaction chunks.
 * 
 * @author lexis
 * 
 */
public class SamplesIngestor {

	/** Logger. */
	private static final Log log = LogFactory.getLog(SamplesIngestor.class);
	/** Samples generator. */
	private EPubSamplesGenerator samplesGenerator;
	/** True to generate samples and start the ingestion, false otherwise. Default is true. */
	private boolean generateSamplesOn = true;

	/**
	 * Ingests samples calling ePubSamplesGenerator's methods.
	 */
	public void ingestion() {
		if (this.generateSamplesOn) {
			log.info("PLEASE WAIT: GENERATING SAMPLES");
			for (int i = 0; i < this.samplesGenerator.getNumOfePrints(); i++)
				this.samplesGenerator.createEPrints(i);
			for (int i = 0; i < this.samplesGenerator.getNumOfEPubs(); i++)
				this.samplesGenerator.createEPub(i);
			log.info("SAMPLES GENERATED");
			this.samplesGenerator.printResultInfo();
		} else {
			log.info("SAMPLES NOT GENERATED");
		}
	}

	@Required
	public void setSamplesGenerator(final EPubSamplesGenerator ePubSamplesGenerator) {
		this.samplesGenerator = ePubSamplesGenerator;
	}

	public EPubSamplesGenerator getSamplesGenerator() {
		return this.samplesGenerator;
	}

	public void setGenerateSamplesOn(final boolean generateSamplesOn) {
		this.generateSamplesOn = generateSamplesOn;
	}

	public boolean isGenerateSamplesOn() {
		return this.generateSamplesOn;
	}

}
