<commit_before>
package edu.wustl.catissuecore.bizlogic.querysuite;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;

import edu.common.dynamicextensions.domaininterface.AttributeInterface;
import edu.common.dynamicextensions.domaininterface.EntityInterface;
import edu.common.dynamicextensions.exception.DynamicExtensionsApplicationException;
import edu.common.dynamicextensions.exception.DynamicExtensionsSystemException;
import edu.wustl.catissuecore.applet.AppletConstants;
import edu.wustl.catissuecore.util.global.Constants;
import edu.wustl.common.querysuite.queryobject.ICondition;
import edu.wustl.common.querysuite.queryobject.IConstraints;
import edu.wustl.common.querysuite.queryobject.IExpression;
import edu.wustl.common.querysuite.queryobject.IExpressionId;
import edu.wustl.common.querysuite.queryobject.IExpressionOperand;
import edu.wustl.common.querysuite.queryobject.IParameterizedCondition;
import edu.wustl.common.querysuite.queryobject.IQuery;
import edu.wustl.common.querysuite.queryobject.IRule;
import edu.wustl.common.querysuite.queryobject.RelationalOperator;
import edu.wustl.common.querysuite.queryobject.impl.ParameterizedCondition;
import edu.wustl.common.util.global.ApplicationProperties;
import edu.wustl.common.util.global.Validator;
import edu.wustl.common.util.logger.Logger;

/**
 * Creates Query Object as per the data filled by the user on AddLimits section.
 * This will also validate the inputs and generate messages and they will be
 * shown to user.
 * 
 * @author deepti_shelar
 * 
 */
public class CreateQueryObjectBizLogic
{

	/**
	 * Gets the map which holds the data to create the rule object and add it to
	 * query.
	 * 
	 * @param strToCreateQueryObject
	 *            str to create query obj
	 * @param entity
	 *            name of entity
	 * @return Map rules details
	 * @throws DynamicExtensionsSystemException
	 *             DynamicExtensionsSystemException
	 * @throws DynamicExtensionsApplicationException
	 *             DynamicExtensionsApplicationException
	 */
	public Map getRuleDetailsMap(String strToCreateQueryObject, EntityInterface entity)
			throws DynamicExtensionsSystemException, DynamicExtensionsApplicationException
	{
		String errorMessage = "";
		Map ruleDetailsMap = new HashMap();
		Map conditionsMap = createConditionsMap(strToCreateQueryObject);
		if (entity != null)
		{
			Collection<AttributeInterface> attrCollection = entity.getAttributeCollection();
			if (conditionsMap != null && !conditionsMap.isEmpty() && attrCollection != null
					&& !attrCollection.isEmpty())
			{
				List<AttributeInterface> attributes = new ArrayList<AttributeInterface>();
				List<String> attributeOperators = new ArrayList<String>();
				List<String> secondAttributeValues = new ArrayList<String>();
				ArrayList<ArrayList<String>> conditionValues = new ArrayList<ArrayList<String>>();

				Iterator iterAttributes = (Iterator) attrCollection.iterator();
				while (iterAttributes.hasNext())
				{
					AttributeInterface attr = (AttributeInterface) iterAttributes.next();
					String componentId = attr.getName() + attr.getId().toString();
					String[] params = (String[]) conditionsMap.get(componentId);
					if (params != null)
					{
						attributes.add(attr);
						attributeOperators.add(params[0]);
						//firstAttributeValues.add(params[1]);
						secondAttributeValues.add(params[2]);
						ArrayList<String> attributeValues = getConditionValuesList(params);
						errorMessage = errorMessage
								+ validateAttributeValues(attr, attributeValues);
						conditionValues.add(attributeValues);
					}
					System.out.println(errorMessage);
				}
				ruleDetailsMap.put(AppletConstants.ATTRIBUTES, attributes);
				ruleDetailsMap.put(AppletConstants.ATTRIBUTE_OPERATORS, attributeOperators);
				//ruleDetailsMap.put(AppletConstants.FIRST_ATTR_VALUES, firstAttributeValues);
				ruleDetailsMap.put(AppletConstants.SECOND_ATTR_VALUES, secondAttributeValues);<commit_msg>checks if the operator is 'between' gets the limit(range) of the  operator in proper order from the utility method getAttributeValuesInProperOrder().<commit_after>
package edu.wustl.catissuecore.bizlogic.querysuite;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;

import edu.common.dynamicextensions.domaininterface.AttributeInterface;
import edu.common.dynamicextensions.domaininterface.EntityInterface;
import edu.common.dynamicextensions.exception.DynamicExtensionsApplicationException;
import edu.common.dynamicextensions.exception.DynamicExtensionsSystemException;
import edu.wustl.catissuecore.applet.AppletConstants;
import edu.wustl.catissuecore.util.global.Constants;
import edu.wustl.common.querysuite.queryobject.ICondition;
import edu.wustl.common.querysuite.queryobject.IConstraints;
import edu.wustl.common.querysuite.queryobject.IExpression;
import edu.wustl.common.querysuite.queryobject.IExpressionId;
import edu.wustl.common.querysuite.queryobject.IExpressionOperand;
import edu.wustl.common.querysuite.queryobject.IParameterizedCondition;
import edu.wustl.common.querysuite.queryobject.IQuery;
import edu.wustl.common.querysuite.queryobject.IRule;
import edu.wustl.common.querysuite.queryobject.RelationalOperator;
import edu.wustl.common.querysuite.queryobject.impl.ParameterizedCondition;
import edu.wustl.common.util.global.ApplicationProperties;
import edu.wustl.common.util.global.Validator;
import edu.wustl.common.util.logger.Logger;
import edu.wustl.catissuecore.util.global.Utility;

/**
 * Creates Query Object as per the data filled by the user on AddLimits section.
 * This will also validate the inputs and generate messages and they will be
 * shown to user.
 * 
 * @author deepti_shelar
 * 
 */
public class CreateQueryObjectBizLogic
{

	/**
	 * Gets the map which holds the data to create the rule object and add it to
	 * query.
	 * 
	 * @param strToCreateQueryObject
	 *            str to create query obj
	 * @param entity
	 *            name of entity
	 * @return Map rules details
	 * @throws DynamicExtensionsSystemException
	 *             DynamicExtensionsSystemException
	 * @throws DynamicExtensionsApplicationException
	 *             DynamicExtensionsApplicationException
	 */
	public Map getRuleDetailsMap(String strToCreateQueryObject, EntityInterface entity)
			throws DynamicExtensionsSystemException, DynamicExtensionsApplicationException
	{
		String errorMessage = "";
		Map ruleDetailsMap = new HashMap();
		Map conditionsMap = createConditionsMap(strToCreateQueryObject);
		if (entity != null)
		{
			Collection<AttributeInterface> attrCollection = entity.getAttributeCollection();
			if (conditionsMap != null && !conditionsMap.isEmpty() && attrCollection != null
					&& !attrCollection.isEmpty())
			{
				List<AttributeInterface> attributes = new ArrayList<AttributeInterface>();
				List<String> attributeOperators = new ArrayList<String>();
				List<String> secondAttributeValues = new ArrayList<String>();
				ArrayList<ArrayList<String>> conditionValues = new ArrayList<ArrayList<String>>();

				Iterator iterAttributes = (Iterator) attrCollection.iterator();
				while (iterAttributes.hasNext())
				{
					AttributeInterface attr = (AttributeInterface) iterAttributes.next();
					String componentId = attr.getName() + attr.getId().toString();
					String[] params = (String[]) conditionsMap.get(componentId);
					if (params != null)
					{
						attributes.add(attr);
						attributeOperators.add(params[0]);
						//firstAttributeValues.add(params[1]);
						secondAttributeValues.add(params[2]); 
						ArrayList<String> attributeValues = getConditionValuesList(params);
						errorMessage = errorMessage
								+ validateAttributeValues(attr, attributeValues);
						if (params[0].equalsIgnoreCase(Constants.Between))
						{
							attributeValues = Utility.getAttributeValuesInProperOrder(attr.getDataType(),
									attributeValues.get(0), attributeValues.get(1));
						}
						conditionValues.add(attributeValues);
					}
					System.out.println(errorMessage);
				}
				ruleDetailsMap.put(AppletConstants.ATTRIBUTES, attributes);
				ruleDetailsMap.put(AppletConstants.ATTRIBUTE_OPERATORS, attributeOperators);
				//ruleDetailsMap.put(AppletConstants.FIRST_ATTR_VALUES, firstAttributeValues);
				ruleDetailsMap.put(AppletConstants.SECOND_ATTR_VALUES, secondAttributeValues);
{'fraction_non_alphanumeric': 0.09427342688999547, 'fraction_numerical': 0.0010185604345857855, 'mean_word_length': 5.115570934256056, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1894918', 'n_tokens_mistral': 2772, 'n_tokens_neox': 2456, 'n_words': 474}