public string BuildFlowFilter(FlowFilterFromBody filterData)
        {
            var filter        = $"{FilterKey.Source.Value} eq '{filterData.Source}' and {FilterKey.Operation.Value} eq '{filterData.Operation}' and {FilterKey.Site.Value} eq '{filterData.Site}' and {FilterKey.OperationalDepartment.Value} eq '{filterData.OperationalDepartment}' and {FilterKey.TypePlanning.Value} eq '{filterData.TypePlanning}' and {FilterKey.CustomerName.Value} eq '{filterData.Customer}' and {FilterKey.ProductionSite.Value} eq '{filterData.ProductionSite}' and {FilterKey.TransportType.Value} eq '{filterData.TransportType}' and {FilterKey.DriverWait.Value} eq '{filterData.DriverWait}'";
            var escapedFilter = Uri.EscapeDataString(filter);

            return(escapedFilter);
        }
        public FlowModel GetMostSpecificFlow(List <FlowModel> flows, FlowFilterFromBody filter)
        {
            var matches = new List <FlowMatch>();

            foreach (var flow in flows)
            {
                double level = 0;

                level += (GetMatchLevel(flow.Filter.Sources, filter.Source) +
                          GetMatchLevel(flow.Filter.Operations, filter.Operation) +
                          GetMatchLevel(flow.Filter.Customers, filter.Customer) +
                          GetMatchLevel(flow.Filter.Sites, filter.Site) +
                          GetMatchLevel(flow.Filter.OperationalDepartments, filter.OperationalDepartment) +
                          GetMatchLevel(flow.Filter.ProductionSites, filter.ProductionSite) +
                          GetMatchLevel(flow.Filter.TransportTypes, filter.TransportType) +
                          GetMatchLevel(flow.Filter.TypePlannings, filter.TypePlanning));

                if (flow.Filter.DriverWait == filter.DriverWait)
                {
                    level += 100;
                }

                matches.Add(new FlowMatch
                {
                    Id    = flow.Id,
                    Level = level
                });
            }

            var orderedMatches    = matches.OrderBy(x => x.Level);
            var mostSpecificMatch = orderedMatches.LastOrDefault();
            var mostSpecificFlow  = flows.Where(x => x.Id == mostSpecificMatch.Id).First();

            return(mostSpecificFlow);
        }
Пример #3
0
        public async Task <Result <FlowDataModel> > GetFlow(FlowFilterFromBody filterData)
        {
            var filter   = _filterBuildService.BuildFlowFilter(filterData);
            var response = await _eccSetupRestApi.GetFlow($"{UrlsConfig.EccSetup}{UrlsConfig.EccSetupOperations.ListFlows(_apiVersion, filter)}");

            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                return(Result.Fail <FlowDataModel>("Bad request to EccSetup.API"));
            }
            else
            {
                var responseAsString = await response.Content.ReadAsStringAsync();

                var flowsModel = JsonConvert.DeserializeObject <FlowsModel>(responseAsString);

                if (flowsModel.Count == 0)
                {
                    return(Result.Fail <FlowDataModel>("No flow found for current order, please contact the administrator!"));
                }

                var flows            = flowsModel.Value;
                var mostSpecificFlow = _filterBuildService.GetMostSpecificFlow(flows.ToList(), filterData);

                var result = _mapper.Map <FlowDataModel>(mostSpecificFlow);

                return(Result.Ok(result));
            }
        }
        public void BuildFlowFilterShouldSucceed()
        {
            //Arrange
            var service    = new FilterBuildService();
            var filterData = new FlowFilterFromBody()
            {
                Source                = "source",
                Operation             = "operation",
                Site                  = "site",
                OperationalDepartment = "operational department",
                TypePlanning          = "Type planning",
                Customer              = "Customer",
                ProductionSite        = "Production site",
                TransportType         = "Transport type",
                DriverWait            = "Yes"
            };
            var expectedFilter = $"source eq '{filterData.Source}' and operation eq '{filterData.Operation}' and site eq '{filterData.Site}' and department eq '{filterData.OperationalDepartment}' and type-planning eq '{filterData.TypePlanning}' and customer eq '{filterData.Customer}' and prodsite eq '{filterData.ProductionSite}' and transport-type eq '{filterData.TransportType}' and driver-wait eq '{filterData.DriverWait}'";

            expectedFilter = Uri.EscapeDataString(expectedFilter);


            //Act
            var filter = service.BuildFlowFilter(filterData);

            //Assert
            filter.Should().Be(expectedFilter);
        }
        public FlowFilterFromBody BuildFlowFilterFromBody(WorkOrderModel workOrder)
        {
            var flowFilterFromBody = new FlowFilterFromBody
            {
                Source                = workOrder.Order.Origin.Source,
                Operation             = workOrder.Order.Operation.Name,
                Site                  = workOrder.Order.Operation.Site,
                Customer              = workOrder.Order.Customer.Code,
                OperationalDepartment = workOrder.Order.Operation.OperationalDepartment,
                TypePlanning          = workOrder.Order.Operation.TypePlanning,
                TransportType         = workOrder.Order.Transport.Type,
                ProductionSite        = workOrder.Order.Customer.ProductionSite,
                DriverWait            = workOrder.Order.Transport.Driver.Wait
            };

            return(flowFilterFromBody);
        }
Пример #6
0
        public async Task <IActionResult> GetFlow([FromBody] FlowFilterFromBody filterData)
        {
            var result = await _mobileService.GetFlow(filterData);

            if (result.IsSuccess)
            {
                if (result.Value == null)
                {
                    var responseNoContent = new NoContentResult();
                    return(responseNoContent);
                }
                var data     = result.Value;
                var response = Envelope.Ok(data);
                return(Ok(response));
            }
            else
            {
                var responseBadRequest = new BadRequestResult();
                return(responseBadRequest);
            }
        }
        public void GetMostSpecificFlowShouldReturnTheRightOne()
        {
            //Arrange
            var flows = new List <FlowModel> {
                new FlowModel {
                    Id     = new Guid("9db74a82-8d56-4008-bd6e-37c6f39db6df"),
                    Filter = new FlowFilterModel {
                        Sources = new List <FlowSourceModel>()
                        {
                            new FlowSourceModel {
                                Name = "Source1"
                            },
                            new FlowSourceModel {
                                Name = "Source2"
                            }
                        },
                        Operations = new List <FlowOperationModel> {
                            new FlowOperationModel {
                                Name = "Load from warehouse"
                            }
                        },
                        Customers = new List <FlowCustomerModel> {
                            new FlowCustomerModel {
                                Name = "Exxon"
                            },
                            new FlowCustomerModel {
                                Name = "Shell"
                            },
                        },
                        Sites = new List <FlowSiteModel> {
                            new FlowSiteModel {
                                Name = "LB1227"
                            },
                            new FlowSiteModel {
                                Name = "LB3456"
                            }
                        },
                        OperationalDepartments = new List <FlowOperationalDepartmentModel> {
                            new FlowOperationalDepartmentModel {
                                Name = "BSG"
                            },
                            new FlowOperationalDepartmentModel {
                                Name = "ASG"
                            }
                        },
                        ProductionSites = new List <FlowProductionSiteModel> {
                            new FlowProductionSiteModel {
                                Name = "Site1"
                            },
                            new FlowProductionSiteModel {
                                Name = "Site2"
                            }
                        },
                        TransportTypes = new List <FlowTransportTypeModel> {
                            new FlowTransportTypeModel {
                                Name = "Truck"
                            },
                            new FlowTransportTypeModel {
                                Name = "Train"
                            }
                        },
                        TypePlannings = new List <FlowTypePlanningModel> {
                            new FlowTypePlanningModel {
                                Name = "Type1"
                            }
                        },
                        DriverWait = "No"
                    }
                },
                new FlowModel {
                    Id     = new Guid("6fcd7e30-8dac-4619-8be2-b5a7b15ee12e"),
                    Filter = new FlowFilterModel {
                        Sources = new List <FlowSourceModel>()
                        {
                            new FlowSourceModel {
                                Name = "Source1"
                            },
                            new FlowSourceModel {
                                Name = "Source2"
                            },
                            new FlowSourceModel {
                                Name = "Source3"
                            }
                        },
                        Operations = new List <FlowOperationModel> {
                            new FlowOperationModel {
                                Name = "Load from warehouse"
                            }
                        },
                        Customers = new List <FlowCustomerModel> {
                            new FlowCustomerModel {
                                Name = "Exxon"
                            },
                            new FlowCustomerModel {
                                Name = "Shell"
                            },
                        },
                        Sites = new List <FlowSiteModel> {
                            new FlowSiteModel {
                                Name = "LB1227"
                            },
                            new FlowSiteModel {
                                Name = "LB3456"
                            },
                            new FlowSiteModel {
                                Name = "LB3457"
                            }
                        },
                        OperationalDepartments = new List <FlowOperationalDepartmentModel> {
                            new FlowOperationalDepartmentModel {
                                Name = "BSG"
                            },
                            new FlowOperationalDepartmentModel {
                                Name = "ASG"
                            }
                        },
                        ProductionSites = new List <FlowProductionSiteModel> {
                            new FlowProductionSiteModel {
                                Name = "Site1"
                            },
                            new FlowProductionSiteModel {
                                Name = "Site2"
                            },
                            new FlowProductionSiteModel {
                                Name = "Site3"
                            }
                        },
                        TransportTypes = new List <FlowTransportTypeModel> {
                            new FlowTransportTypeModel {
                                Name = "Truck"
                            },
                            new FlowTransportTypeModel {
                                Name = "Train"
                            }
                        },
                        TypePlannings = new List <FlowTypePlanningModel> {
                            new FlowTypePlanningModel {
                                Name = "Type1"
                            }
                        },
                        DriverWait = "Yes"
                    }
                },
                new FlowModel {
                    Id     = new Guid("40753e95-9bc3-46a3-860b-6e6c1ebdfdd3"),
                    Filter = new FlowFilterModel {
                        Sources = new List <FlowSourceModel>()
                        {
                            new FlowSourceModel {
                                Name = "Source1"
                            },
                            new FlowSourceModel {
                                Name = "Source2"
                            },
                            new FlowSourceModel {
                                Name = "Source3"
                            }
                        },
                        Operations = new List <FlowOperationModel> {
                            new FlowOperationModel {
                                Name = "Load from warehouse"
                            }
                        },
                        Customers = new List <FlowCustomerModel> {
                            new FlowCustomerModel {
                                Name = "x"
                            },
                        },
                        Sites = new List <FlowSiteModel> {
                            new FlowSiteModel {
                                Name = "LB1227"
                            },
                            new FlowSiteModel {
                                Name = "LB3456"
                            },
                            new FlowSiteModel {
                                Name = "LB3457"
                            }
                        },
                        OperationalDepartments = new List <FlowOperationalDepartmentModel> {
                            new FlowOperationalDepartmentModel {
                                Name = "BSG"
                            },
                            new FlowOperationalDepartmentModel {
                                Name = "ASG"
                            }
                        },
                        ProductionSites = new List <FlowProductionSiteModel> {
                            new FlowProductionSiteModel {
                                Name = "x"
                            }
                        },
                        TransportTypes = new List <FlowTransportTypeModel> {
                            new FlowTransportTypeModel {
                                Name = "Truck"
                            },
                            new FlowTransportTypeModel {
                                Name = "Train"
                            }
                        },
                        TypePlannings = new List <FlowTypePlanningModel> {
                            new FlowTypePlanningModel {
                                Name = "Type1"
                            }
                        },
                        DriverWait = "Yes"
                    }
                }
            };
            var filter = new FlowFilterFromBody
            {
                Source                = "Source1",
                Operation             = "Load from warehouse",
                Customer              = "Exxon",
                Site                  = "LB1227",
                OperationalDepartment = "BSG",
                ProductionSite        = "Site1",
                TransportType         = "Truck",
                TypePlanning          = "Type1",
                DriverWait            = "No"
            };
            var service = new FilterBuildService();

            //Act
            var result = service.GetMostSpecificFlow(flows, filter);

            //Assert
            result.Id.Should().Be(new Guid("9db74a82-8d56-4008-bd6e-37c6f39db6df"));
        }