Exemplo n.º 1
0
        private EntitySchemaQueryColumn AddAggregatedColumn(JObject yAxisConfig)
        {
            AggregationType columnAggregationType = AggregationType.Count;
            string          aggregationType       = SerieParameters.Value <string>("func");

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            EntitySchemaQueryExpression columnExpression = EntitySchemaQuery.CreateSchemaColumnExpression(
                Esq.RootSchema, GroupColumnPath);

            columnExpression.UId = Guid.NewGuid();
            var queryFunction = new EntitySchemaAggregationQueryFunction(columnAggregationType.ToStrict(),
                                                                         columnExpression, Esq);

            if (columnAggregationType == AggregationType.Count)
            {
                queryFunction.AggregationEvalType = AggregationEvalType.Distinct;
            }
            EntitySchemaQueryColumn column = Esq.AddColumn(queryFunction);
            var columnMap = new Dictionary <string, object>();

            columnMap["valueAlias"]           = column.ValueExpression.Function.QueryAlias;
            columnMap["dataValueType"]        = columnExpression.SchemaColumn.DataValueType;
            entityColumnsMap[GroupColumnPath] = columnMap;
            yAxisConfig["dataValueType"]      = GetColumnDataValueType(columnExpression);
            return(column);
        }
Exemplo n.º 2
0
        public override Select Build()
        {
            string columnPath = Parameters.Value <string>("columnName");

            if (string.IsNullOrEmpty(columnPath))
            {
                columnPath = Esq.RootSchema.PrimaryColumn.ColumnValueName;
            }
            EntitySchemaQueryExpression columnExpression = EntitySchemaQuery.CreateSchemaColumnExpression(
                Esq.RootSchema, columnPath);

            columnExpression.UId = Guid.NewGuid();
            AggregationType columnAggregationType = AggregationType.Count;
            string          aggregationType       = Parameters.Value <string>("aggregationType");

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            var queryFunction = new EntitySchemaAggregationQueryFunction(columnAggregationType.ToStrict(),
                                                                         columnExpression, Esq);

            ColumnDataValueType = GetColumnDataValueType(columnExpression);
            Esq.AddColumn(queryFunction);
            EntityColumnMap = new Dictionary <string, object>();
            EntityColumnMap["valueAlias"]    = queryFunction.QueryAlias;
            EntityColumnMap["dataValueType"] = columnExpression.SchemaColumn.DataValueType;
            string filterData = Parameters.Value <string>("filterData");

            AddFilterByJson(filterData);
            return(base.Build());
        }
Exemplo n.º 3
0
        private void AddDateTimeColumnsByFormat(string dateTimeFormat)
        {
            SortedDictionary <int, string> dateTimeFormats = GetSortedDateTimeFormats(dateTimeFormat);
            int index = 0;

            foreach (int key in dateTimeFormats.Keys)
            {
                var    format = dateTimeFormats[key];
                string alias  = "DatePart" + index;
                EntitySchemaDatePartQueryFunctionInterval interval = DashboardDataUtils.GetDatePartInterval(format);
                EntitySchemaQueryExpression columnExpression       =
                    EntitySchemaQuery.CreateSchemaColumnExpression(Esq.RootSchema, ColumnPath);
                columnExpression.UId = Guid.NewGuid();
                var queryFunction = new EntitySchemaDatePartQueryFunction(Esq, interval, columnExpression);
                queryFunction.SpecifyQueryAlias(alias);
                columnExpression.ParentQuery = queryFunction.ParentQuery;
                var esqExpression = new EntitySchemaQueryExpression(queryFunction)
                {
                    UId = Guid.NewGuid()
                };
                EntitySchemaQueryColumn column = Esq.AddColumn(esqExpression.Function);
                var map = new Dictionary <string, object>();
                map["format"]           = format;
                map["valueAlias"]       = alias;
                entityColumnsMap[alias] = map;
                if (OrderByGroupField)
                {
                    ApplyColumnOrder(column);
                }
                index++;
            }
        }
Exemplo n.º 4
0
        private void SetRigthExpression(EntitySchemaQueryFilter filter, object value)
        {
            filter.RightExpressions.Clear();
            EntitySchemaQueryExpression parameter =
                EntitySchemaQuery.CreateParameterExpression(value, filter.LeftExpression.SchemaColumn.DataValueType);

            filter.RightExpressions.Add(parameter);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns column's data value type.
        /// </summary>
        protected int?GetColumnDataValueType(EntitySchemaQueryExpression expression)
        {
            if (expression.SchemaColumn == null)
            {
                return(null);
            }
            DataValueType columnValueType = expression.SchemaColumn.DataValueType;

            return((int)Terrasoft.Nui.ServiceModel.Extensions.DataValueTypeExtension.ToEnum(columnValueType));
        }
Exemplo n.º 6
0
        private EntitySchemaQueryFilter GetDatePartFilter(EntitySchemaQueryExpression columnExpression, int datePartValue, EntitySchemaDatePartQueryFunctionInterval interval)
        {
            var queryFunction = new EntitySchemaDatePartQueryFunction(Esq, interval, columnExpression);
            var filter        = new EntitySchemaQueryFilter(FilterComparisonType.Equal)
            {
                LeftExpression = new EntitySchemaQueryExpression(queryFunction)
            };
            EntitySchemaQueryExpression rightExpression = EntitySchemaQuery.CreateParameterExpression(datePartValue);

            filter.RightExpressions.Add(rightExpression);
            return(filter);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds filter(s) for column date part(s).
        /// </summary>
        /// <param name="filterColumn">Column for filtration</param>
        /// <param name="filterValue">Stringified JSON object with values</param>
        /// <param name="dateTimeFormat">Date parts separated by ';'</param>
        public void AddDatePartFilter(string filterColumn, string filterValue, string dateTimeFormat)
        {
            string[] dateTimeFormats = dateTimeFormat.Split(';');
            var      filterValueObj  = (JObject)Json.Deserialize(filterValue);
            EntitySchemaQueryExpression columnExpression = Esq.CreateSchemaColumnExpression(filterColumn);

            foreach (var format in dateTimeFormats)
            {
                var datePartValue = filterValueObj.Value <int>(format);
                EntitySchemaDatePartQueryFunctionInterval interval = DashboardDataUtils.GetDatePartInterval(format);
                var filter = GetDatePartFilter(columnExpression, datePartValue, interval);
                Esq.Filters.Add(filter);
            }
        }
Exemplo n.º 8
0
        private static bool IsFilterRightExressionsEmpty(EntitySchemaQueryFilter filter)
        {
            EntitySchemaQueryExpressionCollection rightExpressions = filter.RightExpressions;
            bool isEmpty = (rightExpressions.Count == 0 && filter.ComparisonType != FilterComparisonType.IsNull &&
                            filter.ComparisonType != FilterComparisonType.IsNotNull);

            if (!isEmpty && rightExpressions.Count == 1)
            {
                EntitySchemaQueryExpression rightExpression = rightExpressions[0];
                DataValueType expressionType = rightExpression.ParameterValueForcedType;
                isEmpty = (expressionType is TextDataValueType || expressionType is DateTimeDataValueType) &&
                          (rightExpression.ParameterValue == null) &&
                          (rightExpression.ExpressionType == EntitySchemaQueryExpressionType.Parameter);
            }

            return(isEmpty);
        }
Exemplo n.º 9
0
 private bool IsDateMacrosFilter(EntitySchemaQueryFilterCollection filterCollection)
 {
     if (filterCollection.Count == 2)
     {
         var firstFilter  = filterCollection[0] as EntitySchemaQueryFilter;
         var secondFilter = filterCollection[1] as EntitySchemaQueryFilter;
         if (firstFilter != null && firstFilter.RightExpressions.Count == 1 &&
             secondFilter != null && secondFilter.RightExpressions.Count == 1)
         {
             EntitySchemaQueryExpression firstExpression  = firstFilter.RightExpressions[0];
             EntitySchemaQueryExpression secondExpression = secondFilter.RightExpressions[0];
             var firstFunction  = firstExpression.Function as EntitySchemaBaseCurrentDateQueryFunction;
             var secondFunction = secondExpression.Function as EntitySchemaBaseCurrentDateQueryFunction;
             if (firstFunction != null && secondFunction != null)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 10
0
        private void ApplyFilterParameterByDateQueryFunction(DateTime currentDate, EntitySchemaQueryFilterCollection filters)
        {
            EntitySchemaQueryFilter     firstFilter      = (EntitySchemaQueryFilter)filters[0];
            EntitySchemaQueryFilter     secondFilter     = (EntitySchemaQueryFilter)filters[1];
            EntitySchemaQueryExpression firstExpression  = firstFilter.RightExpressions[0];
            EntitySchemaQueryExpression secondExpression = secondFilter.RightExpressions[0];
            var firstFunction  = firstExpression.Function as EntitySchemaBaseCurrentDateQueryFunction;
            var secondFunction = secondExpression.Function as EntitySchemaBaseCurrentDateQueryFunction;

            if (firstExpression.Function.GetType() == typeof(EntitySchemaCurrentDateQueryFunction))
            {
                SetRigthExpression(firstFilter, DateTimeUtilities.DateTimeToDate(currentDate, firstFunction.Offset));
                SetRigthExpression(secondFilter, DateTimeUtilities.DateTimeToDate(currentDate, secondFunction.Offset));
            }
            else if (firstExpression.Function.GetType() == typeof(EntitySchemaStartOfCurrentWeekQueryFunction))
            {
                SetRigthExpression(firstFilter, DateTimeUtilities.StartOfWeek(currentDate, firstFunction.Offset));
                SetRigthExpression(secondFilter, DateTimeUtilities.StartOfWeek(currentDate, secondFunction.Offset));
            }
            else if (firstExpression.Function.GetType() == typeof(EntitySchemaStartOfCurrentMonthQueryFunction))
            {
                SetRigthExpression(firstFilter, DateTimeUtilities.StartOfMonth(currentDate, firstFunction.Offset));
                SetRigthExpression(secondFilter, DateTimeUtilities.StartOfMonth(currentDate, secondFunction.Offset));
            }
            else if (firstExpression.Function.GetType() == typeof(EntitySchemaStartOfCurrentQuarterQueryFunction))
            {
                SetRigthExpression(firstFilter, DateTimeUtilities.StartOfQuarter(currentDate, firstFunction.Offset));
                SetRigthExpression(secondFilter, DateTimeUtilities.StartOfQuarter(currentDate, secondFunction.Offset));
            }
            else if (firstExpression.Function.GetType() == typeof(EntitySchemaStartOfCurrentHalfYearQueryFunction))
            {
                SetRigthExpression(firstFilter, DateTimeUtilities.StartOfHalfYear(currentDate, firstFunction.Offset));
                SetRigthExpression(secondFilter, DateTimeUtilities.StartOfHalfYear(currentDate, secondFunction.Offset));
            }
            else if (firstExpression.Function.GetType() == typeof(EntitySchemaStartOfCurrentYearQueryFunction))
            {
                SetRigthExpression(firstFilter, DateTimeUtilities.StartOfYear(currentDate, firstFunction.Offset));
                SetRigthExpression(secondFilter, DateTimeUtilities.StartOfYear(currentDate, secondFunction.Offset));
            }
        }