package eu.dnetlib.data.collective.harvest;

import java.util.List;

import javax.xml.ws.wsaddressing.W3CEndpointReference;

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

import eu.dnetlib.data.collective.worker.harvesting.HarvestingServiceException;
import eu.dnetlib.data.collective.worker.harvesting.IHarvestingService;
import eu.dnetlib.data.collective.worker.harvesting.RepositoryInformation;

/**
 * 
 * @author claudio
 *
 */
public class GenericHarversterServiceImpl implements IHarvestingService {

	/**
	 * logger
	 */
	private static final Log log = LogFactory.getLog(GenericHarversterServiceImpl.class);
	
	/**
	 * notification handler used to process incoming notifications
	 */
	private GenericHarvesterNotificationHandler notificationHandler;
	
	@Override
	public W3CEndpointReference getMetadataFormats(String baseURL,
			String recordIdentifier, String repositorId)
			throws HarvestingServiceException {
		
		throw new RuntimeException("Operation not supported"); 
	}
	
	@Override
	public W3CEndpointReference getRecords(OAI_PMH_METHOD methodName,
			String metadataPrefix, String fromDate, String toDate,
			List<String> setRestrictions, String baseURL,
			String oaiRecordIdentifier, String repositoryId,
			boolean supportVeryLargeRecords) throws HarvestingServiceException {
		
		throw new RuntimeException("Operation not supported");
	}

	@Override
	public RepositoryInformation getRepositoryInformation(String baseURL,
			String repositorId) throws HarvestingServiceException {
		
		throw new RuntimeException("Operation not supported");
	}

	@Override
	public W3CEndpointReference getResult(String msgId)
			throws HarvestingServiceException {
		
		throw new RuntimeException("Operation not supported");
	}

	@Override
	public W3CEndpointReference getSetInformation(String baseURL,
			String repositorId) throws HarvestingServiceException {
		
		throw new RuntimeException("Operation not supported");
	}

	@Override
	public String getStatusInformation(String rsId)
			throws HarvestingServiceException {
		
		throw new RuntimeException("Operation not supported");
	}

	@Override
	public String identify() {

		return getClass().getName();
	}

	@Override
	public boolean notify(String subscrId, String topic, String isId, String message) {
		log.info("---- service got notification ----");
		log.info("subscrId: " + subscrId);
		log.info("topic " + topic);
		log.info("isId " + isId);
		log.info("msg: " + message);
		log.info("____ now processing the notification ____");
		notificationHandler.notified(subscrId, topic, isId, message);
		return true;
	}

	@Required
	public void setNotificationHandler(GenericHarvesterNotificationHandler notificationHandler) {
		this.notificationHandler = notificationHandler;
	}

	public GenericHarvesterNotificationHandler getNotificationHandler() {
		return notificationHandler;
	}

}
