package eu.dnetlib.data.utility.cleaner;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import eu.dnetlib.data.utility.cleaner.rmi.CleanerException;
import eu.dnetlib.enabling.resultset.rmi.ResultSetException;
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;

public class ProviderConsumerImpl implements ProviderConsumer {
	protected ResultSetService provider;
	protected String bdId;

	private static final Log log = LogFactory.getLog(ProviderConsumerImpl.class); // NOPMD by marko on 11/24/08 5:02 PM

	public ProviderConsumerImpl(ResultSetService provider, String bdId) {
		this.provider = provider;
		this.bdId = bdId;
	}

	public int getSize() throws CleanerException {
		try {
			return provider.getNumberOfElements(bdId);
		} catch (ResultSetException e) {
			log.error("Error calling getSize of the dataProvider, bdid = " + bdId, e);
			throw new CleanerException("Error calling getSize of the dataProvider, bdid = " + bdId, e);
		}
	}

	public List<String> getElements(int from, int to) throws CleanerException {
		try {
			return provider.getResult(bdId, from, to, "WAITING");
		} catch (ResultSetException e) {
			log.error("Error calling getResult of the dataProvider, bdid = " + bdId, e);
			throw new CleanerException("Error calling getResult of the dataProvider, bdid = " + bdId, e);
		}
	}

}
