package com.cim.idm.mwmsextend.event.consumable;

import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.mwmsextend.generic.util.CommonValidation;
import com.cim.idm.wmsextend.generic.util.SMessageUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
import org.jdom.Element;

import java.util.HashMap;
import java.util.Map;

public class PortalUserDeleteEvent {
	
	private static Log log = LogFactory.getLog(PortalUserDeleteEvent.class);
	public void event(EventInfo eventInfo, Document message) throws Exception {
		Element root = message.getDocument().getRootElement();
		Element body = root.getChild("Body");
		String sendSubjectName = root.getChild("Header").getChildText("ORIGINALSOURCESUBJECTNAME");
		
		String id = SMessageUtil.getElementValueByName(body, "ID");
		String clientID = SMessageUtil.getElementValueByName(body, "CLIENTID");
		
		CommonValidation.checkNotNull("ID", id);
		
		String deleteSql = "DELETE FROM USERINFO WHERE PORTALID =:ID";
		Map<String, String> bindMap = new HashMap<>();
		bindMap.put("ID", id);
		
		log.info("CIM PORTAL delete cimportalid:"+id);
		IDMFrameServiceProxy.getSqlTemplate().update(deleteSql, bindMap);
	}
	
}

