package eu.dnetlib.common.ws.subscription;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.ws.wsaddressing.W3CEndpointReference;

import eu.dnetlib.common.utils.EprUtils;
import eu.dnetlib.enabling.is.sn.rmi.ISSNException;

public class HarvestingManagerSubscription extends AbstractSubscription{


	public HarvestingManagerSubscription() {
		super();
	}
	
	public void initSubscriptions() {
		initServiceResource();
	}
	
	private void initServiceResource(){
		String[] topics = {
				NotificationConstants.PREFIX_SUBSCR_TOPIC_UPDATE_HARVESTING_SERVICE_LASTRESPONSE,
				NotificationConstants.PREFIX_SUBSCR_TOPIC_CREATE_HARVESTING_SERVICE,
				NotificationConstants.PREFIX_SUBSCR_TOPIC_DELETE_HARVESTING_SERVICE
		}; 
	
		try {
			W3CEndpointReference W3CEPR = EprUtils.buildW3CEPR(this.serviceHost,
					this.serviceHost+"?wsdl");
			for (String topic: topics){
				String subscrId;
				try {
					subscrId = snService.subscribe(W3CEPR, topic,
							NotificationConstants.TERMINATION_TIME_INFINITE);
					log.debug("subscribed to " + topic + " with subscrId:" + subscrId);				
				} catch (ISSNException e) {
					log.error("couldn't subscribe with topic " + topic, e);
				}
			}
		} catch (ParserConfigurationException e){
			log.error("Problem during creating W3CEPR ", e);
		}

	}

	
}
