<commit_before>/*
 * Created on Jan 20, 2006
 *
 * Listener for cleanup after session invalidates.
 * 
 */
package edu.wustl.catissuecore.util.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import edu.wustl.catissuecore.util.global.Constants;
import edu.wustl.common.beans.SessionDataBean;
import edu.wustl.common.dao.DAOFactory;
import edu.wustl.common.dao.JDBCDAO;
import edu.wustl.common.security.PrivilegeManager;
import edu.wustl.common.util.dbManager.DAOException;
import edu.wustl.common.util.logger.Logger;

/**
 * @author poornima_govindrao
 *
 * Listener for cleanup after session invalidates.
 */
public class CatissueCoreSessionListener implements HttpSessionListener{

	public void sessionCreated(HttpSessionEvent arg0) {
		
	}

	//Cleanup after session invalidates.
	public void sessionDestroyed(HttpSessionEvent arg0) {
		HttpSession session = arg0.getSession();
		SessionDataBean sessionData= (SessionDataBean)session.getAttribute(Constants.SESSION_DATA);
				
		if(sessionData!=null)
			cleanUp(sessionData,(String)session.getAttribute(Constants.RANDOM_NUMBER));
		
		// To remove PrivilegeCache from the session, requires user LoginName
		// Singleton instance of PrivilegeManager	
		PrivilegeManager privilegeManager = PrivilegeManager.getInstance();
		privilegeManager.removePrivilegeCache(sessionData.getUserName());
		System.out.println("Privilege Cache removed..");
	}
    private void cleanUp(SessionDataBean sessionData,String randomNumber)
    {
		//Delete Advance Query table if exists
	 	//Advance Query table name with userID attached
		String tempTableName = Constants.QUERY_RESULTS_TABLE+"_"+sessionData.getUserId();
		try
		{
			JDBCDAO jdbcDao = (JDBCDAO)DAOFactory.getInstance().getDAO(Constants.JDBC_DAO);
			jdbcDao.openSession(sessionData);
			jdbcDao.delete(tempTableName);
			jdbcDao.closeSession();
		}
		catch(DAOException ex)
		{
			Logger.out.error("Could not delete the Advance Search temporary table."+ex.getMessage(),ex);
		}
		String tempTableNameForQuery = Constants.TEMP_OUPUT_TREE_TABLE_NAME + sessionData.getUserId()+randomNumber;
		try
		{
			JDBCDAO jdbcDao = (JDBCDAO)DAOFactory.getInstance().getDAO(Constants.JDBC_DAO);
			jdbcDao.openSession(sessionData);
			jdbcDao.delete(tempTableNameForQuery);
			jdbcDao.closeSession();
		}
		catch(DAOException ex)
		{<commit_msg>*** empty log message ***<commit_after>/*
 * Created on Jan 20, 2006
 *
 * Listener for cleanup after session invalidates.
 * 
 */
package edu.wustl.catissuecore.util.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import edu.wustl.catissuecore.util.global.Constants;
import edu.wustl.common.beans.SessionDataBean;
import edu.wustl.common.dao.DAOFactory;
import edu.wustl.common.dao.JDBCDAO;
import edu.wustl.common.security.PrivilegeManager;
import edu.wustl.common.util.dbManager.DAOException;
import edu.wustl.common.util.logger.Logger;

/**
 * @author poornima_govindrao
 *
 * Listener for cleanup after session invalidates.
 */
public class CatissueCoreSessionListener implements HttpSessionListener{

	public void sessionCreated(HttpSessionEvent arg0) {
		
	}

	//Cleanup after session invalidates.
	public void sessionDestroyed(HttpSessionEvent arg0) {
		HttpSession session = arg0.getSession();
		SessionDataBean sessionData= (SessionDataBean)session.getAttribute(Constants.SESSION_DATA);
				
		if(sessionData!=null)
			cleanUp(sessionData,(String)session.getAttribute(Constants.RANDOM_NUMBER));
		
		// To remove PrivilegeCache from the session, requires user LoginName
		// Singleton instance of PrivilegeManager	
		PrivilegeManager privilegeManager = PrivilegeManager.getInstance();
		privilegeManager.removePrivilegeCache(sessionData.getUserName());
	}
    private void cleanUp(SessionDataBean sessionData,String randomNumber)
    {
		//Delete Advance Query table if exists
	 	//Advance Query table name with userID attached
		String tempTableName = Constants.QUERY_RESULTS_TABLE+"_"+sessionData.getUserId();
		try
		{
			JDBCDAO jdbcDao = (JDBCDAO)DAOFactory.getInstance().getDAO(Constants.JDBC_DAO);
			jdbcDao.openSession(sessionData);
			jdbcDao.delete(tempTableName);
			jdbcDao.closeSession();
		}
		catch(DAOException ex)
		{
			Logger.out.error("Could not delete the Advance Search temporary table."+ex.getMessage(),ex);
		}
		String tempTableNameForQuery = Constants.TEMP_OUPUT_TREE_TABLE_NAME + sessionData.getUserId()+randomNumber;
		try
		{
			JDBCDAO jdbcDao = (JDBCDAO)DAOFactory.getInstance().getDAO(Constants.JDBC_DAO);
			jdbcDao.openSession(sessionData);
			jdbcDao.delete(tempTableNameForQuery);
			jdbcDao.closeSession();
		}
		catch(DAOException ex)
		{
{'fraction_non_alphanumeric': 0.09893772130806082, 'fraction_numerical': 0.0037492189127265154, 'mean_word_length': 5.38563829787234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743791', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1519, 'n_words': 277}