Пример #1
0
        /// <summary>
        /// Concatenating address fileds require for notification
        /// </summary>
        /// <param name="objPostalAddress">USR create event PostalAddressDTO</param>
        /// <returns>returns concatenated value of address field</returns>
        private string NotificationAddressFields(PostalAddressDataDTO objPostalAddress)
        {
            using (loggingHelper.RMTraceManager.StartTrace("Business.AddressFields"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(AddressFields);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);

                string message = objPostalAddress.OrganisationName + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.DepartmentName + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.BuildingName + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.BuildingNumber + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.SubBuildingName + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.Thoroughfare + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.DependentThoroughfare + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.DependentLocality + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.DoubleDependentLocality + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.PostTown + ThirdPartyAddressLocationConstants.Comma +
                                 objPostalAddress.Postcode;

                message = Regex.Replace(message, " *, *", ",");
                message = Regex.Replace(message, ",+", ",").Trim(',');

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
                return(message);
            }
        }
Пример #2
0
        public void ProcessPAFDetails_Delete_NegativeScenario2()
        {
            PostalAddressDataDTO postalAddressDataDTO = new PostalAddressDataDTO()
            {
                AddressType_GUID = Guid.NewGuid()
            };

            mockPostalAddressDataService.Setup(n => n.GetPostalAddress(It.IsAny <int>())).Returns(Task.FromResult(postalAddressDataDTO));
            PostalAddressDTO objPostalAddress = new PostalAddressDTO()
            {
                Time                = "7/19/2016",
                Date                = "8:37:00",
                AmendmentType       = "D",
                AmendmentDesc       = "delete",
                Postcode            = "YO23 1DQ",
                PostTown            = "York",
                UDPRN               = 54162429,
                DeliveryPointSuffix = "1A",
                AddressType_GUID    = new Guid("C08C5212-6123-4EAF-9C27-D4A8035A8974")
            };
            List <PostalAddressDTO> lstPostalAddress = new List <PostalAddressDTO>();

            lstPostalAddress.Add(objPostalAddress);
            var result = testCandidate.ProcessPAFDetails(lstPostalAddress);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result);
        }
Пример #3
0
        /// <summary>
        /// Method to update the DP location based on UDPRN.
        /// </summary>
        /// <param name="addressLocationUSRPOSTDTO"></param>
        /// <param name="notificationType">Notification Type</param>
        private async Task UpdateDPLocation(AddressLocationUSRPOSTDTO addressLocationUSRPOSTDTO, Guid notificationType)
        {
            DbGeometry spatialLocationXY = GetSpatialLocation(addressLocationUSRPOSTDTO);

            PostalAddressDataDTO postalAddressDataDTO = await addressLocationDataService.GetPostalAddressData(addressLocationUSRPOSTDTO.UDPRN.Value);

            // If Delivery Point Exists for the given Postal Address
            if (postalAddressDataDTO != null && postalAddressDataDTO.DeliveryPoints != null && postalAddressDataDTO.DeliveryPoints.Count > 0 && spatialLocationXY != null)
            {
                DeliveryPointDTO deliveryPointDTO = await thirdPartyAddressLocationIntegrationService.GetDeliveryPointByPostalAddress(postalAddressDataDTO.ID);

                if (deliveryPointDTO != null && deliveryPointDTO.LocationXY != null)
                {
                    double?toleranceDistance = spatialLocationXY.Distance(deliveryPointDTO.LocationXY);

                    deliveryPointDTO.LocationXY = spatialLocationXY;

                    // Update the location details for the delivery point
                    await thirdPartyAddressLocationIntegrationService.UpdateDeliveryPointById(deliveryPointDTO);

                    // Check Tolerance. Story: RFMO-279
                    CheckToleranceForLocation(toleranceDistance, false, notificationType, addressLocationUSRPOSTDTO.UDPRN.Value, postalAddressDataDTO);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Concatenating address fileds require for notification
        /// </summary>
        /// <param name="objPostalAddress">USR create event PostalAddressDTO</param>
        /// <returns>returns concatenated value of address field</returns>
        private string Notification_Body(PostalAddressDataDTO objPostalAddress)
        {
            using (loggingHelper.RMTraceManager.StartTrace("Business.Notification_Body"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(Notification_Body);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);
                string message = default(string);

                message = ThirdPartyAddressLocationConstants.USRDeleteNOTIFICATIONBODYPREFIX +
                          objPostalAddress.OrganisationName + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.DepartmentName + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.BuildingName + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.BuildingNumber + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.SubBuildingName + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.Thoroughfare + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.DependentThoroughfare + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.DependentLocality + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.DoubleDependentLocality + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.PostTown + ThirdPartyAddressLocationConstants.Comma +
                          objPostalAddress.Postcode + ThirdPartyAddressLocationConstants.USRDeleteNOTIFICATIONBODYSUFFIX;

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
                return(message);
            }
        }
Пример #5
0
        public void ProcessPAFDetails_DeleteDPScenario()
        {
            PostalAddressDataDTO postalAddressDataDTO = new PostalAddressDataDTO()
            {
                Postcode            = "YO23 1DQ",
                PostTown            = "York",
                UDPRN               = 54162429,
                DeliveryPointSuffix = "1A",
                AddressType_GUID    = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974"),
                DeliveryPoints      = new List <DeliveryPointDataDTO>()
                {
                    new DeliveryPointDataDTO()
                    {
                        ID = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974")
                    }
                }
            };

            mockPostalAddressDataService.Setup(n => n.GetPostalAddress(It.IsAny <int>())).Returns(Task.FromResult(postalAddressDataDTO));
            mockPostalAddressDataService.Setup(x => x.UpdatePostalAddressStatus(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(true);
            mockPostalAddressIntegrationService.Setup(x => x.DeleteDeliveryPoint(It.IsAny <Guid>())).ReturnsAsync(true);
            PostalAddressDTO objPostalAddress = new PostalAddressDTO()
            {
                Time                = "7/19/2016",
                Date                = "8:37:00",
                AmendmentType       = "D",
                AmendmentDesc       = "delete",
                Postcode            = "YO23 1DQ",
                PostTown            = "York",
                UDPRN               = 54162429,
                DeliveryPointSuffix = "1A",
                AddressType_GUID    = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974")
            };
            List <PostalAddressDTO> lstPostalAddress = new List <PostalAddressDTO>();

            lstPostalAddress.Add(objPostalAddress);
            var result = testCandidate.ProcessPAFDetails(lstPostalAddress);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result);
        }
Пример #6
0
        protected override void OnSetup()
        {
            // OnSetup to be configured
            referenceDataCategoryDTOList = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO>()
            {
                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = FileType.Nyb.ToString(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressType
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = FileType.Usr.ToString(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressType
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = FileType.Paf.ToString(),
                            ID = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974"),
                        }
                    },
                    CategoryName = PostalAddressType
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = PostCodeStatus.Live.GetDescription(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressStatus
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = PostCodeStatus.PendingDeleteInFMO.GetDescription(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressStatus
                }
            };

            AddressLocationDTO addressLocationDTO = new AddressLocationDTO()
            {
                UDPRN      = 1234,
                LocationXY = DbGeometry.PointFromText("POINT(512722.70000000019 104752.6799999997)", 27700)
            };

            PostalAddressDataDTO postalAddressDataDTO = new PostalAddressDataDTO()
            {
                Postcode            = "YO23 1DQ",
                PostTown            = "York",
                UDPRN               = 54162429,
                DeliveryPointSuffix = "1A",
                AddressType_GUID    = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974")
            };

            PostalAddressDTO postalAddressDTO = new PostalAddressDTO()
            {
                ID = Guid.Empty
            };

            mockPostalAddressDataService = CreateMock <IPostalAddressDataService>();
            // mockFileProcessingLogDataService = CreateMock<IFileProcessingLogDataService>();
            mockConfigurationHelper             = CreateMock <IConfigurationHelper>();
            mockLoggingHelper                   = CreateMock <ILoggingHelper>();
            mockHttpHandler                     = CreateMock <IHttpHandler>();
            mockPostalAddressIntegrationService = CreateMock <IPostalAddressIntegrationService>();

            var rmTraceManagerMock = new Mock <IRMTraceManager>();

            rmTraceManagerMock.Setup(x => x.StartTrace(It.IsAny <string>(), It.IsAny <Guid>()));
            mockLoggingHelper.Setup(x => x.RMTraceManager).Returns(rmTraceManagerMock.Object);
            mockPostalAddressIntegrationService.Setup(n => n.GetReferenceDataSimpleLists(It.IsAny <string>())).Returns(Task.FromResult(referenceDataCategoryDTOList[2]));
            mockPostalAddressIntegrationService.Setup(n => n.GetReferenceDataSimpleLists(It.IsAny <List <string> >())).Returns(Task.FromResult(referenceDataCategoryDTOList));
            mockPostalAddressIntegrationService.Setup(n => n.GetReferenceDataGuId(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(Guid.NewGuid()));
            mockPostalAddressIntegrationService.Setup(n => n.GetAddressLocationByUDPRN(It.IsAny <int>())).Returns(Task.FromResult(addressLocationDTO));
            mockPostalAddressDataService.Setup(n => n.DeleteNYBPostalAddress(It.IsAny <List <int> >(), It.IsAny <Guid>())).Returns(Task.FromResult(true));

            mockPostalAddressDataService.Setup(n => n.GetPostalAddresses(It.IsAny <List <Guid> >())).ReturnsAsync(new List <PostalAddressDataDTO>()
            {
                new PostalAddressDataDTO()
                {
                    Postcode = "1234"
                }
            });
            mockPostalAddressDataService.Setup(n => n.CheckForDuplicateNybRecords(It.IsAny <PostalAddressDataDTO>(), It.IsAny <Guid>())).Returns("PO1234");
            mockPostalAddressDataService.Setup(n => n.CheckForDuplicateAddressWithDeliveryPoints(It.IsAny <PostalAddressDataDTO>())).Returns(Task.FromResult(true));
            mockPostalAddressDataService.Setup(n => n.CreateAddressForDeliveryPoint(It.IsAny <PostalAddressDataDTO>())).Returns(addressTypeGUID);
            mockPostalAddressDataService.Setup(n => n.GetPostalAddress(It.IsAny <int>())).Returns(Task.FromResult(postalAddressDataDTO));
            mockPostalAddressDataService.Setup(n => n.GetPAFAddress(It.IsAny <int>(), It.IsAny <Guid>())).Returns(Task.FromResult(postalAddressDTO));

            // mockFileProcessingLogDataService.Setup(x => x.LogFileException(It.IsAny<FileProcessingLogDTO>()));

            testCandidate = new DataManagement.PostalAddress.WebAPI.BusinessService.Implementation.PostalAddressBusinessService(mockPostalAddressDataService.Object, mockLoggingHelper.Object, mockConfigurationHelper.Object, mockHttpHandler.Object, mockPostalAddressIntegrationService.Object);
        }
Пример #7
0
        // TODO : Add method when ready
        // To be implemented in parallel
        /// <summary>
        /// Method to save the list of USR data into the database.
        /// </summary>
        /// <param name="addressLocationUsrpostdtos">List of Address Locations</param>
        /// <returns>Task</returns>
        public async Task SaveUSRDetails(List <AddressLocationUSRPOSTDTO> addressLocationUsrpostdtos)
        {
            int    fileUdprn;
            string addressLocationChangeType = string.Empty;

            if (addressLocationUsrpostdtos == null)
            {
                throw new ArgumentNullException(nameof(addressLocationUsrpostdtos));
            }

            using (loggingHelper.RMTraceManager.StartTrace("Business.SaveUSRDetails"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(SaveUSRDetails);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);

                List <string> categoryNamesSimpleLists = new List <string>
                {
                    ThirdPartyAddressLocationConstants.TASKNOTIFICATION,
                    ThirdPartyAddressLocationConstants.NETWORKLINKDATAPROVIDER,
                    ThirdPartyAddressLocationConstants.DeliveryPointUseIndicator,
                    ThirdPartyAddressLocationConstants.APPROXLOCATION,
                    ReferenceDataCategoryNames.DeliveryPointOperationalStatus,
                    ReferenceDataCategoryNames.NetworkNodeType
                };

                // Get all the reference data Guids required for the below
                Guid tasktypeId                    = GetReferenceData(categoryNamesSimpleLists, ThirdPartyAddressLocationConstants.TASKNOTIFICATION, ThirdPartyAddressLocationConstants.TASKACTION);
                Guid locationProviderId            = GetReferenceData(categoryNamesSimpleLists, ThirdPartyAddressLocationConstants.NETWORKLINKDATAPROVIDER, ThirdPartyAddressLocationConstants.EXTERNAL);
                Guid operationalStatusGUIDLive     = GetReferenceData(categoryNamesSimpleLists, ReferenceDataCategoryNames.DeliveryPointOperationalStatus, ThirdPartyAddressLocationConstants.OperationalStatusGUIDLive, true);
                Guid networkNodeTypeRMGServiceNode = GetReferenceData(categoryNamesSimpleLists, ReferenceDataCategoryNames.NetworkNodeType, ThirdPartyAddressLocationConstants.NetworkNodeTypeRMGServiceNode, true);
                Guid approxLocation                = GetReferenceData(categoryNamesSimpleLists, ReferenceDataCategoryNames.DeliveryPointOperationalStatus, ThirdPartyAddressLocationConstants.APPROXLOCATION, true);
                Guid notificationTypeId_GUID       = await thirdPartyAddressLocationIntegrationService.GetReferenceDataId(ThirdPartyAddressLocationConstants.USRCATEGORY, ThirdPartyAddressLocationConstants.USRREFERENCEDATANAME);

                foreach (AddressLocationUSRPOSTDTO addressLocationUSRPOSTDTO in addressLocationUsrpostdtos)
                {
                    // Get the udprn id for each USR record.
                    fileUdprn = (int)addressLocationUSRPOSTDTO.UDPRN;
                    addressLocationChangeType = addressLocationUSRPOSTDTO.ChangeType;

                    // To save new location
                    if (addressLocationChangeType.Equals(ThirdPartyAddressLocationConstants.INSERT))
                    {
                        if (!await addressLocationDataService.AddressLocationExists(fileUdprn))
                        {
                            DbGeometry spatialLocationXY = GetSpatialLocation(addressLocationUSRPOSTDTO);

                            AddressLocationDataDTO newAddressLocationDTO = new AddressLocationDataDTO()
                            {
                                ID         = Guid.NewGuid(),
                                UDPRN      = (int)addressLocationUSRPOSTDTO.UDPRN,
                                LocationXY = spatialLocationXY,
                                Lattitude  = (decimal)addressLocationUSRPOSTDTO.Latitude,
                                Longitude  = (decimal)addressLocationUSRPOSTDTO.Longitude
                            };

                            // Save the address location data record to the database.
                            await addressLocationDataService.SaveNewAddressLocation(newAddressLocationDTO);

                            PostalAddressDataDTO postalAddressDataDTO = await addressLocationDataService.GetPostalAddressData((int)fileUdprn);

                            // Check if the delivery point exists
                            if (postalAddressDataDTO.DeliveryPoints != null && postalAddressDataDTO.DeliveryPoints.Count > 0)
                            {
                                DeliveryPointDTO deliveryPointDTO = await thirdPartyAddressLocationIntegrationService.GetDeliveryPointByPostalAddress(postalAddressDataDTO.ID);

                                // Check if the existing delivery point has an approx location.
                                if (deliveryPointDTO.OperationalStatus_GUID == approxLocation)
                                {
                                    deliveryPointDTO.LocationXY            = spatialLocationXY;
                                    deliveryPointDTO.LocationProvider_GUID = locationProviderId;
                                    deliveryPointDTO.UDPRN = fileUdprn;
                                    deliveryPointDTO.OperationalStatus_GUID = operationalStatusGUIDLive;
                                    deliveryPointDTO.NetworkNodeType_GUID   = networkNodeTypeRMGServiceNode;

                                    // Update the location details for the delivery point
                                    await thirdPartyAddressLocationIntegrationService.UpdateDeliveryPointById(deliveryPointDTO);

                                    // Check if a notification exists for the UDPRN.
                                    if (await addressLocationDataService.CheckIfNotificationExists(fileUdprn, ThirdPartyAddressLocationConstants.TASKPAFACTION))
                                    {
                                        // update the notification if it exists.
                                        await thirdPartyAddressLocationIntegrationService.UpdateNotificationByUDPRN(fileUdprn, ThirdPartyAddressLocationConstants.TASKPAFACTION, ThirdPartyAddressLocationConstants.NOTIFICATIONCLOSED);
                                    }
                                }
                                else
                                {
                                    // Calculates the straight line distance between the existing delivery
                                    // point and the new delivery point.
                                    var straightLineDistance = GetDeliveryPointDistance(deliveryPointDTO, spatialLocationXY);

                                    // Check if the new point is within the tolerance limit
                                    if (straightLineDistance <= ThirdPartyAddressLocationConstants.TOLERANCEDISTANCEINMETERS)
                                    {
                                        deliveryPointDTO.LocationXY            = spatialLocationXY;
                                        deliveryPointDTO.LocationProvider_GUID = locationProviderId;
                                        deliveryPointDTO.UDPRN = fileUdprn;
                                        deliveryPointDTO.OperationalStatus_GUID = operationalStatusGUIDLive;
                                        deliveryPointDTO.NetworkNodeType_GUID   = networkNodeTypeRMGServiceNode;

                                        // Update the delivery point location directly in case it is within
                                        // the tolerance limits.
                                        await thirdPartyAddressLocationIntegrationService.UpdateDeliveryPointById(deliveryPointDTO);

                                        // Check if the notification exists for the given UDPRN.
                                        if (await addressLocationDataService.CheckIfNotificationExists(fileUdprn, ThirdPartyAddressLocationConstants.TASKPAFACTION))
                                        {
                                            // update the notification if it exists.
                                            await thirdPartyAddressLocationIntegrationService.UpdateNotificationByUDPRN(fileUdprn, ThirdPartyAddressLocationConstants.TASKPAFACTION, ThirdPartyAddressLocationConstants.NOTIFICATIONCLOSED);
                                        }
                                    }
                                    else
                                    {
                                        // Get the Postcode Sector by UDPRN
                                        PostCodeSectorDTO postCodeSectorDTO =
                                            await thirdPartyAddressLocationIntegrationService.GetPostCodeSectorByUDPRN(fileUdprn);

                                        PostalAddressDataDTO postalAddressDTO = await addressLocationDataService.GetPostalAddressData(fileUdprn);

                                        NotificationDTO notificationDO = new NotificationDTO
                                        {
                                            ID = Guid.NewGuid(),
                                            NotificationType_GUID = notificationTypeId_GUID,
                                            NotificationDueDate   = DateTime.UtcNow.AddHours(ThirdPartyAddressLocationConstants.NOTIFICATIONDUE),
                                            NotificationSource    = ThirdPartyAddressLocationConstants.USRNOTIFICATIONSOURCE,
                                            Notification_Heading  = ThirdPartyAddressLocationConstants.USRACTION,
                                            Notification_Message  = AddressFields(postalAddressDTO),
                                            PostcodeDistrict      = (postCodeSectorDTO == null || postCodeSectorDTO.District == null)
                                                ? string.Empty
                                                : postCodeSectorDTO.District,
                                            PostcodeSector = (postCodeSectorDTO == null || postCodeSectorDTO.Sector == null)
                                                ? string.Empty
                                                : postCodeSectorDTO.Sector,
                                            NotificationActionLink = string.Format(ThirdPartyAddressLocationConstants.USRNOTIFICATIONLINK, fileUdprn)
                                        };

                                        // Insert the new notification.
                                        await thirdPartyAddressLocationIntegrationService.AddNewNotification(notificationDO);
                                    }
                                }
                            }
                        }
                    }

                    // To update existing location
                    else if (addressLocationChangeType.Equals(ThirdPartyAddressLocationConstants.UPDATE))
                    {
                        // Match to Location on UDPRN (update Location)
                        if (await addressLocationDataService.AddressLocationExists(fileUdprn))
                        {
                            // Update the  Address location.
                            await UpdateAddressLocationByUDPRN(addressLocationUSRPOSTDTO);

                            // Update the DP location. Story: RFMO-276
                            await UpdateDPLocation(addressLocationUSRPOSTDTO, notificationTypeId_GUID);
                        }

                        // No Match to Location on UDPRN - Log Error
                        else
                        {
                            loggingHelper.Log(string.Format(ThirdPartyAddressLocationConstants.NoMatchToAddressOnUDPRN, fileUdprn), TraceEventType.Error);
                        }
                    }

                    // To delete existing location
                    else if (addressLocationChangeType.Equals(ThirdPartyAddressLocationConstants.DELETE))
                    {
                        await DeleteUSRDetails(addressLocationUSRPOSTDTO);
                    }
                }

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
            }
        }
Пример #8
0
        /// <summary>
        /// Create notification if the delivery point is not within tolerance
        /// </summary>
        /// <param name="notificationType">Type of notification</param>
        /// <param name="udprn">Postal address UDPRN</param>
        /// <param name="notificationBody">Message specified in body</param>
        /// <param name="notificationReference">Notification reference</param>
        /// <param name="notificationAction">Notification action</param>
        /// <returns>Integer value one if value is saved in database</returns>
        private int CreateNotificationAfterToleranceCheck(Guid notificationType, int udprn, string notificationBody, string notificationReference, string notificationAction, PostalAddressDataDTO postalAddressDTO)
        {
            PostCodeSectorDTO postCodeSectorDTO = thirdPartyAddressLocationIntegrationService.GetPostCodeSectorByUDPRN(udprn).Result;

            NotificationDTO notificationDetails = new NotificationDTO
            {
                ID = Guid.NewGuid(),
                NotificationType_GUID  = notificationType,
                NotificationDueDate    = DateTime.UtcNow.AddHours(ThirdPartyAddressLocationConstants.NOTIFICATIONDUE),
                NotificationSource     = ThirdPartyAddressLocationConstants.USRNOTIFICATIONSOURCE,
                Notification_Heading   = notificationAction,
                Notification_Message   = string.Format(notificationBody, NotificationAddressFields(postalAddressDTO)),
                PostcodeDistrict       = (postCodeSectorDTO == null || postCodeSectorDTO.District == null) ? string.Empty : postCodeSectorDTO.District,
                NotificationActionLink = string.Format(ThirdPartyAddressLocationConstants.USRNOTIFICATIONLINK, notificationReference)
            };

            return(thirdPartyAddressLocationIntegrationService.AddNewNotification(notificationDetails).Result);
        }
Пример #9
0
        /// <summary>
        /// Check tolerance for updated DP
        /// </summary>e updation</param>
        /// <param name="toleranceDistance">tolerance Distance</param>
        /// <param name="rmgDPExists">RMG Delivery point exits</param>
        /// <param name="notificationType">Notification type</param>
        /// <param name="udprn">UDPRN</param>
        /// <param name="postalAddressDTO">Postal Address details</param>
        private void CheckToleranceForLocation(double?toleranceDistance, bool rmgDPExists, Guid notificationType, int udprn, PostalAddressDataDTO postalAddressDTO)
        {
            if (toleranceDistance > ThirdPartyAddressLocationConstants.LOACTIONTOLERANCEDISTANCEINMETERS)
            {
                var nearestToleranceDistance = Math.Round(toleranceDistance.Value);

                if (!rmgDPExists)
                {
                    CreateNotificationAfterToleranceCheck(notificationType, udprn, ThirdPartyAddressLocationConstants.USRMESSAGE, $"{nearestToleranceDistance}m", ThirdPartyAddressLocationConstants.USRACTION, postalAddressDTO);
                }
                else
                {
                    CreateNotificationAfterToleranceCheck(notificationType, udprn, ThirdPartyAddressLocationConstants.USRMESSAGEFORRMGDP, $"{nearestToleranceDistance}m", ThirdPartyAddressLocationConstants.USRACTIONRMGDP, postalAddressDTO);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Method to delete the list of Third Party Address Location data into the database.
        /// </summary>
        /// <param name="addressLocationUsrpostdtos">List of Address Locations</param>
        /// <returns>Task</returns>
        public async Task DeleteUSRDetails(AddressLocationUSRPOSTDTO addressLocationUsrpostdtos)
        {
            int fileUdprn;

            using (loggingHelper.RMTraceManager.StartTrace("Business.DeleteUSRDetails"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(DeleteUSRDetails);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);

                List <string> categoryNamesSimpleLists = new List <string>
                {
                    ThirdPartyAddressLocationConstants.TASKNOTIFICATION,
                    ThirdPartyAddressLocationConstants.NETWORKLINKDATAPROVIDER,
                    ThirdPartyAddressLocationConstants.DeliveryPointUseIndicator,
                    ThirdPartyAddressLocationConstants.APPROXLOCATION,
                    ReferenceDataCategoryNames.DeliveryPointOperationalStatus,
                    ReferenceDataCategoryNames.NetworkNodeType
                };

                // Get all the reference data Guids required for the below
                Guid locationProviderInternalId = GetReferenceData(categoryNamesSimpleLists, ThirdPartyAddressLocationConstants.NETWORKLINKDATAPROVIDER, ThirdPartyAddressLocationConstants.INTERNAL);

                Guid notificationTypeId_GUID = await thirdPartyAddressLocationIntegrationService.GetReferenceDataId(ThirdPartyAddressLocationConstants.USRCATEGORY, ThirdPartyAddressLocationConstants.USRREFERENCEDATANAME);

                // Get the udprn id for each USR record.
                fileUdprn = (int)addressLocationUsrpostdtos.UDPRN;
                var addressLocation = addressLocationDataService.GetAddressLocationByUDPRN(fileUdprn).Result;

                if (addressLocation != null)
                {
                    // Delete the address location data record to the database.
                    await addressLocationDataService.DeleteAddressLocation(addressLocation);

                    PostalAddressDataDTO postalAddressDataDTO = await addressLocationDataService.GetPostalAddressData((int)fileUdprn);

                    // Check if the delivery point exists
                    if (postalAddressDataDTO.DeliveryPoints != null && postalAddressDataDTO.DeliveryPoints.Count > 0)
                    {
                        DeliveryPointDTO deliveryPointDTO = await thirdPartyAddressLocationIntegrationService.GetDeliveryPointByPostalAddress(postalAddressDataDTO.ID);

                        deliveryPointDTO.LocationProvider_GUID = locationProviderInternalId;

                        // Update the location provider for the delivery point
                        await thirdPartyAddressLocationIntegrationService.UpdateDeliveryPointById(deliveryPointDTO);

                        // Get the Postcode Sector by UDPRN
                        PostCodeSectorDTO postCodeSectorDTO =
                            await thirdPartyAddressLocationIntegrationService.GetPostCodeSectorByUDPRN(fileUdprn);

                        PostalAddressDataDTO postalAddressDTO = await addressLocationDataService.GetPostalAddressData(fileUdprn);

                        NotificationDTO notificationDO = new NotificationDTO
                        {
                            ID = Guid.NewGuid(),
                            NotificationType_GUID = notificationTypeId_GUID,
                            NotificationDueDate   = DateTime.UtcNow.AddHours(ThirdPartyAddressLocationConstants.NOTIFICATIONDUE),
                            NotificationSource    = ThirdPartyAddressLocationConstants.USRNOTIFICATIONSOURCE,
                            Notification_Heading  = ThirdPartyAddressLocationConstants.USRDELETEACTION,
                            Notification_Message  = Notification_Body(postalAddressDTO),
                            PostcodeDistrict      = (postCodeSectorDTO == null || postCodeSectorDTO.District == null)
                                    ? string.Empty
                                    : postCodeSectorDTO.District,
                            NotificationActionLink = string.Format(ThirdPartyAddressLocationConstants.USRNOTIFICATIONLINK, fileUdprn)
                        };

                        // Insert the new notification.
                        await thirdPartyAddressLocationIntegrationService.AddNewNotification(notificationDO);
                    }
                }
                else
                {
                    // Log error
                    loggingHelper.Log(string.Format(ThirdPartyAddressLocationConstants.USRERRORLOGMESSAGE, ThirdPartyAddressLocationConstants.ErrorMessageForAddressTypeUSRNotFound, fileUdprn, null, FileType.Usr, DateTime.UtcNow), TraceEventType.Error);
                }

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
            }
        }