<commit_before>package edu.wustl.query.util.querysuite;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import edu.wustl.common.beans.SessionDataBean;
import edu.wustl.common.querysuite.queryobject.IParameterizedQuery;
import edu.wustl.common.querysuite.queryobject.impl.ParameterizedQuery;
import edu.wustl.common.security.PrivilegeCache;
import edu.wustl.common.security.PrivilegeManager;
import edu.wustl.common.security.PrivilegeUtility;
import edu.wustl.common.util.Permissions;
import edu.wustl.common.util.dbManager.HibernateUtility;
import edu.wustl.query.util.global.Constants;
import gov.nih.nci.security.authorization.domainobjects.ProtectionElement;
import gov.nih.nci.security.authorization.domainobjects.ProtectionGroup;
import gov.nih.nci.security.authorization.domainobjects.User;
import gov.nih.nci.security.dao.ProtectionElementSearchCriteria;
import gov.nih.nci.security.exceptions.CSException;
import gov.nih.nci.security.exceptions.CSObjectNotFoundException;

public class CsmUtility {
	
	private PrivilegeCache setPrivilegeCache(SessionDataBean sessionDataBean ) throws CSException
	{
		User user = new PrivilegeUtility().getUserProvisioningManager().getUser(sessionDataBean.getUserName());
		sessionDataBean.setCsmUserId(user.getUserId().toString());
		PrivilegeCache privilegeCache = PrivilegeManager.getInstance().getPrivilegeCache(sessionDataBean.getUserName());
		return privilegeCache;

	}
	public void  checkExecuteQueryPrivilege(
			Collection<IParameterizedQuery> authorizedQueryCollection,
			Collection<IParameterizedQuery> sharedQueryCollection,<commit_msg>added a method to check weather the given query is shared or not.<commit_after>package edu.wustl.query.util.querysuite;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import edu.wustl.common.beans.SessionDataBean;
import edu.wustl.common.querysuite.queryobject.IParameterizedQuery;
import edu.wustl.common.querysuite.queryobject.impl.ParameterizedQuery;
import edu.wustl.common.security.PrivilegeCache;
import edu.wustl.common.security.PrivilegeManager;
import edu.wustl.common.security.PrivilegeUtility;
import edu.wustl.common.util.Permissions;
import edu.wustl.common.util.dbManager.HibernateUtility;
import edu.wustl.query.util.global.Constants;
import gov.nih.nci.security.authorization.domainobjects.ProtectionElement;
import gov.nih.nci.security.authorization.domainobjects.ProtectionGroup;
import gov.nih.nci.security.authorization.domainobjects.User;
import gov.nih.nci.security.dao.ProtectionElementSearchCriteria;
import gov.nih.nci.security.exceptions.CSException;
import gov.nih.nci.security.exceptions.CSObjectNotFoundException;

public class CsmUtility {
	
	private PrivilegeCache setPrivilegeCache(SessionDataBean sessionDataBean ) throws CSException
	{
		User user = new PrivilegeUtility().getUserProvisioningManager().getUser(sessionDataBean.getUserName());
		sessionDataBean.setCsmUserId(user.getUserId().toString());
		PrivilegeCache privilegeCache = PrivilegeManager.getInstance().getPrivilegeCache(sessionDataBean.getUserName());
		return privilegeCache;

	}
	
	/**
	 * It will check weather the object with the given objectId is shared or not.
	 * I will check weather yhe 
	 * @param objectId of the object which is to be checked for sharing.
	 * @return true if object with given objectId has associated public Protection Group 
	 * @throws CSObjectNotFoundException
	 * @throws CSException
	 */
	public boolean checkIsSharedQuery(String objectId) throws CSObjectNotFoundException, CSException
	{
		ProtectionElement pe = new ProtectionElement();
		List<ProtectionElement> peList = new ArrayList<ProtectionElement>();
		PrivilegeUtility privilegeUtility = new PrivilegeUtility();
		pe.setObjectId(objectId);
		boolean sharedQuery=false;
		//ProtectionGroupSearchCriteria groupSearchCriteria = new ProtectionGroupSearchCriteria
		ProtectionElementSearchCriteria searchCriteria = new ProtectionElementSearchCriteria(pe);
		peList = privilegeUtility.getUserProvisioningManager().getObjects(searchCriteria);
		if (peList != null && !peList.isEmpty())
		{
			pe = peList.get(0);
			Set<ProtectionGroup> pgSet = privilegeUtility.getUserProvisioningManager()
					.getProtectionGroups(pe.getProtectionElementId().toString());
			for (ProtectionGroup pg : pgSet)
			{
				if (pg.getProtectionGroupName().equals(Constants.PUBLIC_QUERY_PROTECTION_GROUP))
				{
					sharedQuery = true;
				}
			}
		}
		return sharedQuery;
		
	}
	public void  checkExecuteQueryPrivilege(
			Collection<IParameterizedQuery> authorizedQueryCollection,
			Collection<IParameterizedQuery> sharedQueryCollection,
{'fraction_non_alphanumeric': 0.09005947323704333, 'fraction_numerical': 0.00021240441801189465, 'mean_word_length': 6.522364217252396, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '4439217', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1420, 'n_words': 242}