/**
 *
 */
package com.zi.mwms.solution.event.user;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Element;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.cim.idm.framework.exception.ext.FrameworkErrorSignal;
import com.cim.idm.framework.exception.ext.NotFoundSignal;
import com.cim.idm.wmspackage.user.UserServiceProxy;
import com.cim.idm.wmspackage.user.management.data.UserInfo;
import com.cim.idm.wmspackage.user.management.data.UserInfoKey;


/**
 * @author sjlee
 *
 */
public class UserProfileServiceUtil implements ApplicationContextAware {

	/**
	 * @uml.property  name="applicationContext"
	 * @uml.associationEnd
	 */
	private ApplicationContext     	applicationContext;
	private static Log 				log = LogFactory.getLog(UserProfileServiceImpl.class);


	/* (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	/**
	 * @param arg0
	 * @throws BeansException
	 * @uml.property  name="applicationContext"
	 */
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		// TODO Auto-generated method stub
		applicationContext = arg0;
	}

	public Element createUserProfileElement(String userId) throws FrameworkErrorSignal, NotFoundSignal
	{
		if(log.isInfoEnabled()){
			log.info("userId = " + userId);
		}

		UserInfoKey userProfileKey = new UserInfoKey();
		userProfileKey.setUserId( userId );

		UserInfo userProfileData = null;
		userProfileData  = UserServiceProxy.getUserInfoService().selectByKey( userProfileKey );

		Element element = null;
		String node = null;

		node = "USERPROFILE";
		element = new Element(node);

		Element elmUserId = new Element("USERID");
		elmUserId.setText(userProfileData.getKey().getUserId());
		element.addContent(elmUserId);

		Element elmUserName = new Element("USERNAME");
		elmUserName.setText(userProfileData.getUserName());
		element.addContent(elmUserName);

		Element elmUserGroupName = new Element("USERGROUPNAME");
		elmUserGroupName.setText(userProfileData.getUserGroupName());
		element.addContent(elmUserGroupName);

		Element elmDepartMentName = new Element("DEPARTMENT");
		elmDepartMentName.setText(userProfileData.getDepartment());
		element.addContent(elmDepartMentName);

		Element elmSpecialPassword = new Element("SPECIALPASSWORD");
		elmSpecialPassword.setText(userProfileData.getSpecialPassword());
		element.addContent(elmSpecialPassword);

		return element;
	}

}
