private void HandleUnionZeroedValueCases(SearchRequestDto unionDto) { unionDto.GetParameters(); foreach (var entry in unionDto.ValuesDictionary) { if (entry.Key.Contains("zeroed")) { //HAP-1026 difficult bug to solve generically --> if attribute is zeroed, like will fix the issue and keep it working. entry.Value.Value = "%" + entry.Value.Value + "%"; entry.Value.SearchOperator = SearchOperator.CONTAINS; } } }
public static IDictionary <String, object> GetParameters(SearchRequestDto listDto) { IDictionary <String, object> resultDictionary = new Dictionary <string, object>(); var searchParameters = listDto.GetParameters(); if (searchParameters == null) { return(resultDictionary); } foreach (var searchParameter in searchParameters) { var parameter = searchParameter.Value; if (parameter.IsDate) { var dt = parameter.GetAsDate; HandleDateParameter(parameter, resultDictionary, searchParameter, dt); } else if (parameter.IsNumber && (parameter.Value is string)) { try { var int32 = Convert.ToInt32(parameter.Value); resultDictionary.Add(searchParameter.Key, int32); } catch { //its declared as a number, but the client passed a string like %10%, for contains, or even SR123 resultDictionary.Add(searchParameter.Key, parameter.Value); } } else if (parameter.Value != null && parameter.Value.ToString().StartsWith("@")) { resultDictionary.Add(searchParameter.Key, DefaultValuesBuilder.GetDefaultValue(parameter.Value.ToString(), null, DefaultValuesBuilder.DBDateTimeFormat)); } else { resultDictionary.Add(searchParameter.Key, parameter.Value); } } return(resultDictionary); }
private static string HandleSearchParams(SearchRequestDto listDto, string entityName) { var sb = new StringBuilder(); var sbReplacingIdx = 0; sb.Append(listDto.SearchParams).Replace("#", ""); var searchParameters = listDto.GetParameters(); var parameters = getParametersOnTheRightOrder(searchParameters, listDto); var j = 0; foreach (var parameter in parameters) { var searchParameter = searchParameters[parameter]; if (parameter.StartsWith("null")) { if (searchParameter.SearchOperator == SearchOperator.BLANK) { //HAP-1106-- > if blank operator, then all null union fields are acceptable, otherwise none sb.Replace(parameter, "1=1"); } else { sb.Replace(parameter, "1!=1"); } //ignore null parameters, as of union grids continue; } //need to fetch from here to keep order correct var param = parameter; var statement = new StringBuilder(); var parameterData = GetParameterData(entityName, searchParameter, param); var operatorPrefix = searchParameter.SearchOperator.OperatorPrefix(); if (searchParameter.SearchOperator == SearchOperator.BETWEEN) { statement.Append("( " + parameterData.Item1 + " >= :" + param + "_start" + "&&" + parameterData.Item1 + " <= :" + param + "_end" + ")"); } else if (searchParameter.SearchOperator == SearchOperator.ORCONTAINS) { var values = (searchParameter.Value as IEnumerable).Cast <string>().ToList(); if (values != null) { statement.Append("( "); for (var i = 0; i < values.Count; i++) { statement.Append(parameterData.Item1); // this next line would be the ideal, but it will be complicade passing this parameters to BaseHibernateDAO. //statement.Append(GetDefaultParam(operatorPrefix, param + i)); // TODO: refactor later statement.Append(operatorPrefix + "'%" + values[i] + "%'"); statement.Append(" OR "); } statement.Remove(statement.Length - 4, 4); // remove the last " OR " statement.Append(" )"); } } else { searchParameter.IsNumber = parameterData.Item2 == ParameterType.Number; statement.Append("( " + parameterData.Item1); if (searchParameter.IsList) { statement.Append(operatorPrefix).Append(String.Format(HibernateUtil.ListParameterPrefixPattern, param)); } else if (searchParameter.IsDate || parameterData.Item2 == ParameterType.Date) { statement.Append(HandleDateAttribute(param, searchParameter, operatorPrefix)); } else if (searchParameter.SearchOperator == SearchOperator.BLANK && (searchParameter.IsNumber || searchParameter.IsDate)) { statement.Append(" IS NULL "); } else { statement.Append(GetDefaultParam(operatorPrefix, param)); } if (searchParameter.SearchOperator == SearchOperator.NOTEQ) { statement.Append(" OR " + parameterData.Item1 + " IS NULL " + " )"); } else { statement.Append(" )"); } } var idxToReplace = sb.ToString().IndexOf(param, sbReplacingIdx, StringComparison.Ordinal); if (idxToReplace == -1 && param.IndexOf(j.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) != -1) { //if the parameter contains a number, let´s try now replacing it //this is used on scenarios where we have a fixed query and grid query where we constrain one of the parameters of the original query with a gridfilter value //then we would have two parameters with the same name. To vaoid it, we rename it to the position+ name (ex: 5status;) param = param.Replace(j.ToString(CultureInfo.InvariantCulture), ""); idxToReplace = sb.ToString().IndexOf(param, sbReplacingIdx, StringComparison.Ordinal); } if (idxToReplace != -1) { //there´s just one case which was done as a workaround for fetching the commodities. see HapagImacDataSet#GetAssetCommodities sb.Replace(param, statement.ToString(), idxToReplace, param.Length); sbReplacingIdx += statement.ToString().Length; } j++; } sb.Replace("&&", " AND "); sb.Replace("||,", " OR "); return(sb.ToString()); }