private void HandleOrderParameter(QueryParameter parameter)
 {
     if (Equals(parameter.Name, "orderBy"))
     {
         _orderField = Enumeration.GetByDisplayName <EpcisField>(parameter.Values.Single());
     }
     else if (Equals(parameter.Name, "orderDirection"))
     {
         _orderDirection = Enumeration.GetByDisplayName <OrderDirection>(parameter.Values.Single());
     }
 }
        private static void ApplyTimeParameter(EpcisField field, QueryParameter parameter, IUnitOfWork unitOfWork)
        {
            var filterOperator = Enumeration.GetByDisplayName <FilterComparator>(parameter.Name.Substring(0, 2));

            unitOfWork.EventManager.WhereSimpleFieldMatches(field, filterOperator, parameter.GetValue <DateTime>());
        }
Example #3
0
 public void WhereSimpleFieldIn <T>(EpcisField field, T[] values) => _query = _query.Where($"{field.ToPgSql()} = ANY({_parameters.Add(values)})");
Example #4
0
 public void WhereSimpleFieldMatches(EpcisField field, FilterComparator filterOperator, object value) => _query = _query.Where($"{field.ToPgSql()} {filterOperator.ToSql()} {_parameters.Add(value)}");
Example #5
0
 public void WhereMasterDataHierarchyContains(EpcisField field, string[] values)
 => _query = _query.Where($"({field.ToPgSql()} = ANY({_parameters.Add(values)}) OR EXISTS(SELECT h.parent_id FROM cbv.masterdata_hierarchy h WHERE h.parent_id = ANY({_parameters.Last}) AND h.children_id = {field.ToPgSql()} AND h.type = '{field.ToCbvType()}'))");
Example #6
0
 public void WhereMasterdataAttributeValueIn(EpcisField attribute, string id, string[] values)
 => _query = _query.Where($"EXISTS(SELECT a.id FROM cbv.attribute a WHERE a.masterdata_type = {_parameters.Add(attribute.ToCbvType())} AND a.masterdata_id = {attribute.ToPgSql()} AND a.id = {_parameters.Add(id)} AND a.value = ANY({_parameters.Add(values)}))");
Example #7
0
 public void OrderBy(EpcisField field, OrderDirection direction) => _query.OrderBy($"{field.ToPgSql()} {direction.ToPgSql()}");
 public static string ToCbvType(this EpcisField field) => GetValue(field, CbvTypes) ?? throw new Exception($"Cannot convert to CBV type: '{field.DisplayName}'");
 public static string ToPgSql(this EpcisField field) => GetValue(field, SimpleFields) ?? throw new Exception($"Unknown simple EPCIS event field: '{field.DisplayName}'");
Example #10
0
        public async Task <IEnumerable <IEntity> > Execute(IEnumerable <QueryParameter> parameters, IUnitOfWork unitOfWork, CancellationToken cancellationToken)
        {
            parameters = parameters ?? new QueryParameter[0];

            foreach (var parameter in parameters)
            {
                if (Equals(parameter.Name, "eventType"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.EventType, parameter.Values.Select(Enumeration.GetByDisplayName <EventType>).ToArray());
                }
                else if (Equals(parameter.Name, "eventCountLimit"))
                {
                    unitOfWork.EventManager.SetLimit(parameter.GetValue <int>());
                }
                else if (Equals(parameter.Name, "maxEventCount"))
                {
                    unitOfWork.EventManager.SetLimit(parameter.GetValue <int>() + 1);
                }
                else if (Equals(parameter.Name, "EQ_action"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.Action, parameter.Values.Select(Enumeration.GetByDisplayName <EventAction>).ToArray());
                }
                else if (Equals(parameter.Name, "EQ_bizLocation"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.BusinessLocation, parameter.Values);
                }
                else if (Equals(parameter.Name, "EQ_bizStep"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.BusinessStep, parameter.Values);
                }
                else if (Equals(parameter.Name, "EQ_disposition"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.Disposition, parameter.Values);
                }
                else if (Equals(parameter.Name, "EQ_eventID"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.EventId, parameter.Values);
                }
                else if (Equals(parameter.Name, "EQ_transformationID"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.TransformationId, parameter.Values);
                }
                else if (Equals(parameter.Name, "EQ_readPoint"))
                {
                    unitOfWork.EventManager.WhereSimpleFieldIn(EpcisField.ReadPoint, parameter.Values);
                }
                else if (Equals(parameter.Name, "EXISTS_errorDeclaration"))
                {
                    unitOfWork.EventManager.WhereExistsErrorDeclaration();
                }
                else if (Equals(parameter.Name, "EQ_errorReason"))
                {
                    unitOfWork.EventManager.WhereErrorReasonIn(parameter.Values);
                }
                else if (Equals(parameter.Name, "EQ_correctiveEventID"))
                {
                    unitOfWork.EventManager.WhereCorrectiveEventIdIn(parameter.Values);
                }
                else if (Equals(parameter.Name, "WD_readPoint"))
                {
                    unitOfWork.EventManager.WhereMasterDataHierarchyContains(EpcisField.ReadPoint, parameter.Values);
                }
                else if (Equals(parameter.Name, "WD_bizLocation"))
                {
                    unitOfWork.EventManager.WhereMasterDataHierarchyContains(EpcisField.BusinessLocation, parameter.Values);
                }

                else if (Equals(parameter.Name, "orderBy"))
                {
                    _orderField = Enumeration.GetByDisplayName <EpcisField>(parameter.Values.Single());
                }
                else if (Equals(parameter.Name, "orderDirection"))
                {
                    _orderDirection = Enumeration.GetByDisplayName <OrderDirection>(parameter.Values.Single());
                }

                // Family of parameters (regex name)
                else if (Regex.IsMatch(parameter.Name, "^EQ_(source|destination)_"))
                {
                    ApplySourceDestinationParameter(parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^EQ_bizTransaction_"))
                {
                    ApplyBusinessTransactionParameter(parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(GE|LT)_eventTime"))
                {
                    ApplyTimeParameter(EpcisField.CaptureTime, parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(GE|LT)_recordTime"))
                {
                    ApplyTimeParameter(EpcisField.RecordTime, parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^MATCH_"))
                {
                    ApplyEpcMatchParameter(parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(EQ|GT|LT|GE|LE)_quantity$"))
                {
                    ApplyQuantityParameter(parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(EQ|GT|LT|GE|LE)_INNER_ILMD_"))
                {
                    ApplyCustomFieldParameter(parameter, true, FieldType.Ilmd, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(EQ|GT|LT|GE|LE)_ILMD_"))
                {
                    ApplyCustomFieldParameter(parameter, false, FieldType.Ilmd, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^EXISTS_INNER_ILMD_"))
                {
                    ApplyExistCustomFieldParameter(parameter, true, FieldType.Ilmd, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^EXISTS_ILMD_"))
                {
                    ApplyExistCustomFieldParameter(parameter, false, FieldType.Ilmd, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(EQ|GT|LT|GE|LE)_INNER_"))
                {
                    ApplyCustomFieldParameter(parameter, true, FieldType.EventExtension, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^(EQ|GT|LT|GE|LE)_"))
                {
                    ApplyCustomFieldParameter(parameter, false, FieldType.EventExtension, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^EXISTS_INNER"))
                {
                    ApplyExistCustomFieldParameter(parameter, true, FieldType.EventExtension, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^EQATTR_"))
                {
                    ApplyExistAttributeParameter(parameter, unitOfWork);
                }
                else if (Regex.IsMatch(parameter.Name, "^HASATTR_"))
                {
                    ApplyHasAttributeParameter(parameter, unitOfWork);
                }

                else
                {
                    throw new NotImplementedException($"Query parameter unexpected or not implemented: '{parameter.Name}'");
                }
            }

            unitOfWork.EventManager.OrderBy(_orderField, _orderDirection); // Set order by filter

            var results = await unitOfWork.EventManager.ToList(cancellationToken);

            // Check for the maxEventCount parameter
            if (parameters.Any(x => x.Name == "maxEventCount") && results.Count() == parameters.Last(x => x.Name == "maxEventCount").GetValue <int>() + 1)
            {
                throw new EpcisException(ExceptionType.QueryTooLargeException, "Too many results returned by the request");
            }

            return(results);
        }
Example #11
0
 public void Apply(OrderFilter filter) => _orderField = filter.Field;