Exemple #1
0
        public async Task AddChangeRequestIndexerAsync(long changeRequestId)
        {
            var brakeConfigRepositoryService =
                _vcdbUnitOfWork.GetRepositoryService <BrakeConfig>() as
                IVcdbSqlServerEfRepositoryService <BrakeConfig>;

            if (brakeConfigRepositoryService == null)
            {
                return;
            }

            var addedBrakeConfigs =
                await
                brakeConfigRepositoryService.GetAsync(
                    item => item.ChangeRequestId == changeRequestId, 100000,
                    "BrakeABS",
                    "BrakeSystem",
                    "FrontBrakeType",
                    "RearBrakeType");

            if (addedBrakeConfigs == null || !addedBrakeConfigs.Any())
            {
                throw new InvalidOperationException(
                          "Brake Config Index cannot be updated before the transactional table is updated");
            }

            var addedBrakeConfig = addedBrakeConfigs.First();
            var vehicleToBrakeConfigSearchResult =
                await
                _vehicletoBrakeConfigSearchService.SearchAsync(null,
                                                               $"brakeConfigId eq {addedBrakeConfig.Id}");

            var existingVehicleToBrakeConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;

            if (existingVehicleToBrakeConfigDocuments != null && existingVehicleToBrakeConfigDocuments.Any())
            {
                throw new InvalidOperationException(
                          "BrakeConfig already exisit in VehicleToBrakeConfigIndex. So, this change request cannot be an add request");
            }

            //brake config is new and therefore not yet available in "vehicletobrakeconfigs" azure search index
            VehicleToBrakeConfigDocument newVehicleToBrakeConfigDocument = new VehicleToBrakeConfigDocument
            {
                VehicleToBrakeConfigId = Guid.NewGuid().ToString(),
                BrakeConfigId          = addedBrakeConfig.Id,
                FrontBrakeTypeId       = addedBrakeConfig.FrontBrakeTypeId,
                FrontBrakeTypeName     = addedBrakeConfig.FrontBrakeType.Name,
                RearBrakeTypeId        = addedBrakeConfig.RearBrakeTypeId,
                RearBrakeTypeName      = addedBrakeConfig.RearBrakeType.Name,
                BrakeABSId             = addedBrakeConfig.BrakeABSId,
                BrakeABSName           = addedBrakeConfig.BrakeABS.Name,
                BrakeSystemId          = addedBrakeConfig.BrakeSystemId,
                BrakeSystemName        = addedBrakeConfig.BrakeSystem.Name,
            };

            await this._vehicleToBrakeConfigIndexingService.UploadDocumentAsync(newVehicleToBrakeConfigDocument);
        }
        public async Task AddChangeRequestIndexerAsync(long changeRequestId)
        {
            var vehicletoBrakeConfigRepositoryService =
                _vcdbUnitOfWork.GetRepositoryService <VehicleToBrakeConfig>() as
                IVcdbSqlServerEfRepositoryService <VehicleToBrakeConfig>;

            if (vehicletoBrakeConfigRepositoryService == null)
            {
                return;
            }

            var addedVehicleToBrakeConfigs =
                await
                vehicletoBrakeConfigRepositoryService.GetAsync(item => item.ChangeRequestId == changeRequestId, 100000,
                                                               "BrakeConfig.BrakeABS",
                                                               "BrakeConfig.BrakeSystem",
                                                               "BrakeConfig.FrontBrakeType",
                                                               "BrakeConfig.RearBrakeType",
                                                               "Vehicle.BaseVehicle.Make",
                                                               "Vehicle.BaseVehicle.Model",
                                                               "Vehicle.BaseVehicle.Model.VehicleType",
                                                               "Vehicle.BaseVehicle.Model.VehicleType.VehicleTypeGroup",
                                                               "Vehicle.SubModel",
                                                               "Vehicle.Region");

            if (addedVehicleToBrakeConfigs == null || !addedVehicleToBrakeConfigs.Any())
            {
                throw new InvalidOperationException(
                          "Vehicle To Brake Config Index cannot be updated before the transactional table is updated");
            }

            //delete document with vehicleToBrakeConfigId of Guid and brakeConfigId of addedVehicleToBrakeConfigs.BrakeConfigId
            var vehicleToBrakeConfigSearchResult =
                await
                _vehicleToBrakeConfigSearchService.SearchAsync(null,
                                                               $"brakeConfigId eq {addedVehicleToBrakeConfigs.First().BrakeConfigId}");

            var existingVehicleToBrakeConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;

            if (existingVehicleToBrakeConfigDocuments != null && existingVehicleToBrakeConfigDocuments.Any())
            {
                Guid guid;
                foreach (var existingVehicleToBrakeConfigDocument in existingVehicleToBrakeConfigDocuments)
                {
                    if (Guid.TryParse(existingVehicleToBrakeConfigDocument.VehicleToBrakeConfigId, out guid))
                    {
                        await
                        this._vehicleToBrakeConfigIndexingService.DeleteDocumentByVehicleToBrakeConfigIdAsync(
                            existingVehicleToBrakeConfigDocument.VehicleToBrakeConfigId);
                    }
                }
            }

            await InsertOrUpdateVehicleToBrakeConfigDocuments(addedVehicleToBrakeConfigs);
        }
Exemple #3
0
        private async Task UpdateVehicleToBrakeConfigDocuments(VehicleType updatedVehicleType)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                var vehicleToBrakeConfigSearchResult =
                    await
                    _vehicletoBrakeConfigSearchService.SearchAsync(null,
                                                                   $"vehicleTypeId eq {updatedVehicleType.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToBrakeConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;
                if (existingVehicleToBrakeConfigDocuments != null && existingVehicleToBrakeConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBrakeConfigDocument in existingVehicleToBrakeConfigDocuments)
                    {
                        existingVehicleToBrakeConfigDocument.VehicleTypeName = updatedVehicleType.Name;
                    }

                    await
                    this._vehicleToBrakeConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBrakeConfigDocuments.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
        private async Task UpdateVehicleToBrakeConfigDocuments(List <Vehicle> updatedVehicles)
        {
            if (updatedVehicles == null)
            {
                return;
            }

            foreach (var updatedVehicle in updatedVehicles)
            //NOTE: updatedVehicles will contain more than 1 item when processing base vehicle replace
            //Pushkar: azure search: length of the request URL may exceed the limit of 8 KB limit may exceed if $filter=vehicleId eq '1' or vehicleId eq '2' or vehicleId eq '3' is used to avoid this foreach loop
            {
                var vehicleToBrakeConfigSearchResult =
                    await
                    _vehicletoBrakeConfigSearchService.SearchAsync(null, $"vehicleId eq {updatedVehicle.Id}");

                var existingVehicleToBrakeConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;

                if (existingVehicleToBrakeConfigDocuments != null && existingVehicleToBrakeConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBrakeConfigDocument in existingVehicleToBrakeConfigDocuments)
                    {
                        existingVehicleToBrakeConfigDocument.SubModelId   = updatedVehicle.SubModelId;
                        existingVehicleToBrakeConfigDocument.SubModelName = updatedVehicle.SubModel.Name;
                        existingVehicleToBrakeConfigDocument.RegionId     = updatedVehicle.RegionId;
                        existingVehicleToBrakeConfigDocument.RegionName   = updatedVehicle.Region.Name;
                    }

                    await
                    this._vehicleToBrakeConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBrakeConfigDocuments.ToList());
                }
            }
        }
Exemple #5
0
        private async Task UpdateVehicleToBrakeConfigDocuments(BrakeType updatedBrakeType)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                // get front brake type result
                var vehicleToBrakeConfigSearchResultFront =
                    await
                    _vehicletoBrakeConfigSearchService.SearchAsync(null,
                                                                   $"frontBrakeTypeId eq {updatedBrakeType.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToBrakeConfigDocumentsFront = vehicleToBrakeConfigSearchResultFront.Documents;

                if (existingVehicleToBrakeConfigDocumentsFront != null &&
                    existingVehicleToBrakeConfigDocumentsFront.Any())
                {
                    foreach (
                        var existingVehicleToBrakeConfigDocument in
                        existingVehicleToBrakeConfigDocumentsFront)
                    {
                        existingVehicleToBrakeConfigDocument.FrontBrakeTypeName = updatedBrakeType.Name;
                    }

                    await
                    this._vehicleToBrakeConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBrakeConfigDocumentsFront.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);

            // get rear brake type result
            isEndReached = false;
            pageNumber   = 1;
            do
            {
                var vehicleToBrakeConfigSearchResultRear =
                    await
                    _vehicletoBrakeConfigSearchService.SearchAsync(null,
                                                                   $"rearBrakeTypeId eq {updatedBrakeType.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToBrakeConfigDocumentsRear = vehicleToBrakeConfigSearchResultRear.Documents;

                if (existingVehicleToBrakeConfigDocumentsRear != null &&
                    existingVehicleToBrakeConfigDocumentsRear.Any())
                {
                    foreach (
                        var existingVehicleToBrakeConfigDocument in
                        existingVehicleToBrakeConfigDocumentsRear)
                    {
                        existingVehicleToBrakeConfigDocument.RearBrakeTypeName = updatedBrakeType.Name;
                    }

                    await
                    this._vehicleToBrakeConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBrakeConfigDocumentsRear.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
        public async Task <VehicleToBrakeConfigSearchViewModel> Search(VehicleToBrakeConfigSearchInputModel vehicleToBrakeConfigSearchInputModel)
        {
            var applyFilters = new VehicleToBrakeConfigSearchFilters()
            {
                BrakeConfigId     = vehicleToBrakeConfigSearchInputModel.BrakeConfigId,
                StartYear         = Convert.ToInt32(vehicleToBrakeConfigSearchInputModel.StartYear),
                EndYear           = Convert.ToInt32(vehicleToBrakeConfigSearchInputModel.EndYear),
                Makes             = vehicleToBrakeConfigSearchInputModel.Makes,
                Models            = vehicleToBrakeConfigSearchInputModel.Models,
                SubModels         = vehicleToBrakeConfigSearchInputModel.SubModels,
                VehicleTypes      = vehicleToBrakeConfigSearchInputModel.VehicleTypes,
                VehicleTypeGroups = vehicleToBrakeConfigSearchInputModel.VehicleTypeGroups,
                Regions           = vehicleToBrakeConfigSearchInputModel.Regions,
                FrontBrakeTypes   = vehicleToBrakeConfigSearchInputModel.FrontBrakeTypes,
                RearBrakeTypes    = vehicleToBrakeConfigSearchInputModel.RearBrakeTypes,
                BrakeAbs          = vehicleToBrakeConfigSearchInputModel.BrakeAbs,
                BrakeSystem       = vehicleToBrakeConfigSearchInputModel.BrakeSystems
            };

            var result = await _vehicleToBrakeConfigSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(),
                                                                              new SearchOptions
            {
                FacetsToInclude = new List <string>
                {
                    "frontBrakeTypeName,count:1000",
                    "rearBrakeTypeName,count:1000",
                    "brakeABSName,count:1000",
                    "brakeSystemName,count:1000",
                    "regionName,count:1000",
                    "vehicleTypeName,count:1000",
                    "vehicleTypeGroupName,count:1000",
                    "makeName,count:1000",
                    "modelName,count:1000",
                    "subModelName,count:1000",
                },
                RecordCount      = 1000,
                ReturnTotalCount = true,
            });

            var viewModel = _vehicleToBrakeConfigSearchViewModelMapper.Map(result);

            return(viewModel);
        }
Exemple #7
0
        public override async Task <long> SubmitUpdateChangeRequestAsync <TId>(BrakeConfig entity, TId id,
                                                                               string requestedBy,
                                                                               ChangeType changeType = ChangeType.None,
                                                                               List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null,
                                                                               List <AttachmentsModel> attachments = null, string changeContent = null)
        {
            if (entity.BrakeSystemId.Equals(default(int)) ||
                entity.BrakeABSId.Equals(default(int)) ||
                entity.FrontBrakeTypeId.Equals(default(int)) ||
                entity.RearBrakeTypeId.Equals(default(int)))
            {
                throw new ArgumentException(nameof(entity));
            }

            if (id.Equals(default(TId)))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (!entity.Id.Equals(id))
            {
                throw new ArgumentException("Invalid Brake Config Id");
            }

            var brakeConfigFromDb = await FindAsync(id);

            if (brakeConfigFromDb == null)
            {
                throw new NoRecordFound("No Brake Config exist");
            }

            var existingEntity = new BrakeConfig()
            {
                Id                        = brakeConfigFromDb.Id,
                BrakeABSId                = brakeConfigFromDb.BrakeABSId,
                BrakeSystemId             = brakeConfigFromDb.BrakeSystemId,
                FrontBrakeTypeId          = brakeConfigFromDb.FrontBrakeTypeId,
                RearBrakeTypeId           = brakeConfigFromDb.RearBrakeTypeId,
                ChangeRequestId           = brakeConfigFromDb.ChangeRequestId,
                DeleteDate                = brakeConfigFromDb.DeleteDate,
                InsertDate                = brakeConfigFromDb.InsertDate,
                LastUpdateDate            = brakeConfigFromDb.LastUpdateDate,
                VehicleToBrakeConfigCount = brakeConfigFromDb.VehicleToBrakeConfigCount
            };

            changeRequestItemStagings = new List <ChangeRequestItemStaging>();

            // Validation check for update of existing brake config
            await ValidateConfigurationDoesNotMatchWithExistingBrakeConfig(entity);
            await ValidateNoChangeRequestExistsWithSameConfiguration(entity);
            await ValidateBrakeConfigLookUpHasNoChangeRequest(entity);
            await ValidateBrakeConfigDependentHasNoChangeRequest(entity);

            entity.InsertDate = brakeConfigFromDb.InsertDate;

            changeRequestItemStagings.Add(new ChangeRequestItemStaging()
            {
                ChangeType      = ChangeType.Modify,
                EntityId        = entity.Id.ToString(),
                CreatedDateTime = DateTime.UtcNow,
                Entity          = typeof(BrakeConfig).Name,
                Payload         = base.Serializer.Serialize(entity),
                ExistingPayload = base.Serializer.Serialize(existingEntity)
            });

            changeContent = string.Format("{0} / {1} / {2} / {3}"
                                          , brakeConfigFromDb.FrontBrakeType.Name
                                          , brakeConfigFromDb.RearBrakeType.Name
                                          , brakeConfigFromDb.BrakeABS.Name
                                          , brakeConfigFromDb.BrakeSystem.Name);

            // NOTE: change-request-comments-staging perfomed on base
            var changeRequestId = await base.SubmitUpdateChangeRequestAsync(entity, id, requestedBy, ChangeType.Modify, changeRequestItemStagings, comment, attachments, changeContent);

            brakeConfigFromDb.ChangeRequestId = changeRequestId;
            _brakeConfigRepositoryService.Update(brakeConfigFromDb);
            Repositories.SaveChanges();

            //NOTE: updating change request id in child dependent tables is not valid

            IList <VehicleToBrakeConfig> existingVehicleToBrakeConfigs =
                await
                base.Repositories.GetRepositoryService <VehicleToBrakeConfig>()
                .GetAsync(item => item.BrakeConfigId.Equals(brakeConfigFromDb.Id) && item.DeleteDate == null);

            if (existingVehicleToBrakeConfigs == null || existingVehicleToBrakeConfigs.Count == 0)
            {
                var vehicleToBrakeConfigSearchResult = await _vehicletoBrakeConfigSearchService.SearchAsync(null, $"brakeConfigId eq {brakeConfigFromDb.Id}");

                var existingVehicleToBrakeConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;
                if (existingVehicleToBrakeConfigDocuments != null && existingVehicleToBrakeConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBrakeConfigDocument in existingVehicleToBrakeConfigDocuments)
                    {
                        //existingVehicleDocument.VehicleId must be a GUID string
                        await _vehicleToBrakeConfigIndexingService.UpdateBrakeConfigChangeRequestIdAsync(existingVehicleToBrakeConfigDocument.VehicleToBrakeConfigId, changeRequestId);
                    }
                }
            }
            else
            {
                //NOTE: brakeConfigFromDb.VehicleToBrakeConfigs will be null because it is not lazy loaded
                foreach (var vehicleToBrakeConfig in existingVehicleToBrakeConfigs)
                {
                    await _vehicleToBrakeConfigIndexingService.UpdateBrakeConfigChangeRequestIdAsync(vehicleToBrakeConfig.Id.ToString(), changeRequestId);
                }
            }

            return(changeRequestId);
        }