Пример #1
0
        public CustomValidationResult ValidateClashHasNoChildClashes(string clashExternalReference)
        {
            var lookupClashes = _clashRepository.GetAll()
                                .Where(c => c.ParentExternalidentifier == clashExternalReference);

            return(lookupClashes.Any()
                ? CustomValidationResult.Failed()
                : CustomValidationResult.Success());
        }
Пример #2
0
        public IEnumerable <ClashModel> Get()
        {
            var clashes = _clashRepository.GetAll()?.ToList();

            if (clashes != null && clashes.Any())
            {
                return(clashes.Select(clash =>
                {
                    var parentclash = string.IsNullOrWhiteSpace(clash.ParentExternalidentifier)
                       ? null
                       : clashes.FirstOrDefault(c => c.Externalref.Equals(clash.ParentExternalidentifier,
                                                                          StringComparison.OrdinalIgnoreCase));

                    return _mapper.Map <ClashModel>(Tuple.Create(clash, parentclash));
                }).ToList());
            }
            return(null);
        }
Пример #3
0
        /// <summary>Prepares the related data.</summary>
        /// <param name="campaigns">The campaigns.</param>
        protected override void PrepareRelatedData(IReadOnlyCollection <Campaign> campaigns)
        {
            var productExternalIds = campaigns.Select(c => c.Product).Where(s => !string.IsNullOrWhiteSpace(s))
                                     .Distinct(StringComparer.OrdinalIgnoreCase).ToList().ToList();

            _products = _productRepository.FindByExternal(productExternalIds).ToDictionary(x => x.Externalidentifier);

            var allClashes = _clashRepository.GetAll().IndexListByExternalRef();

            _clashRoots = ClashHelper.CalculateClashTopParents(allClashes);
        }
Пример #4
0
        public Dictionary <string, int> Get()
        {
            var breakcount     = _breakrepo.GetAll().Count();
            var spotCountcount = _spotrepo.GetAll().Count();
            var progcount      = _programmerepo.GetAll().Count();
            var campaigncount  = _campaignrepo.GetAll().Count();
            var productcount   = _productRepository.GetAll().Count();
            var clashcount     = _clashRepository.GetAll().Count();

            var items = new Dictionary <string, int> {
                { "Breaks", breakcount }, { "Spots", spotCountcount }, { "Programmes", progcount }, { "Campaigns", campaigncount }, { "Product", productcount }, { "Clash", clashcount }
            };

            return(items);
        }
Пример #5
0
        protected override void PrepareRelatedCampaignData(IReadOnlyCollection <Campaign> campaigns)
        {
            var productRefs     = new HashSet <string>();
            var demographicRefs = new HashSet <string>();

            foreach (var campaign in campaigns)
            {
                productRefs.Add(campaign.Product);
                demographicRefs.Add(campaign.DemoGraphic);
            }

            _products = _productRepository
                        .FindByExternal(productRefs.ToList())
                        .ToDictionary(r => r.Externalidentifier);

            _demographics = _demographicRepository
                            .GetByExternalRef(demographicRefs.ToList())
                            .ToDictionary(r => r.ExternalRef);

            _clashes = _clashRepository.GetAll()
                       .ToDictionary(r => r.Externalref);
        }
Пример #6
0
        public override bool CompareTargetDataToDb(string key, string fileName = null, Table tableData = null,
                                                   TestDataResultOperationType operationType = default)
        {
            var featureTestData = GenerateDataFromTable(tableData);
            var fileTestData    = GenerateDataFromFile(fileName, key);
            var allClashes      = _clashRepository.GetAll().ToList();

            switch (operationType)
            {
            case TestDataResultOperationType.Add:
            {
                featureTestData.AddRange(fileTestData);
                if (allClashes.Count != featureTestData.Count)
                {
                    return(false);
                }

                foreach (var entity in featureTestData)
                {
                    if (allClashes.Count(c => c.Externalref == entity.Externalref) != 1)
                    {
                        return(false);
                    }

                    var storedClash = allClashes.FirstOrDefault(c => c.Externalref == entity.Externalref);
                    if (!CompareClash(entity, storedClash))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            default:
                return(false);
            }
        }
Пример #7
0
        public static void CheckClashParents(this IClashRepository repository, IReadOnlyCollection <Clash> newClashes)
        {
            if (repository is null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            var parentDoesNotExistMessages = new List <string>();
            var exposureCountGreaterThanParentsMessages = new List <string>();
            var existingClashes = repository.GetAll();

            newClashes = newClashes.OrderBy(c => c.ParentExternalidentifier).ThenBy(c => c.Externalref).ToList();

            newClashes.Where(c => c.Externalref.Equals(c.ParentExternalidentifier, StringComparison.OrdinalIgnoreCase))
            .ToList().ForEach(
                c => parentDoesNotExistMessages.Add($"Clash code {c.Externalref} has invalid parent clash code {c.ParentExternalidentifier}"));

            var allClashes = newClashes.Union(existingClashes ?? Enumerable.Empty <Clash>());

            newClashes.Where(c => !string.IsNullOrWhiteSpace(c.ParentExternalidentifier)).ToList().ForEach(c =>
            {
                var parentClash = allClashes.FirstOrDefault(e => e.Externalref.Equals(c.ParentExternalidentifier,
                                                                                      StringComparison.OrdinalIgnoreCase));
                if (parentClash != null)
                {
                    if (parentClash.DefaultPeakExposureCount < c.DefaultPeakExposureCount)
                    {
                        exposureCountGreaterThanParentsMessages.Add("Clash code " + c.Externalref +
                                                                    " default peak exposure count should be less than or equal to " +
                                                                    parentClash.DefaultPeakExposureCount);
                    }

                    if (parentClash.DefaultOffPeakExposureCount < c.DefaultOffPeakExposureCount)
                    {
                        exposureCountGreaterThanParentsMessages.Add("Clash code " + c.Externalref +
                                                                    " default non-peak exposure count should be less than or equal to " +
                                                                    parentClash.DefaultOffPeakExposureCount);
                    }
                }
                else
                {
                    parentDoesNotExistMessages.Add("Clash code " + c.Externalref + " has invalid parent clash code " +
                                                   c.ParentExternalidentifier);
                }
            });

            newClashes.Where(c => allClashes.Any(ch => ch.ParentExternalidentifier == c.Externalref)).ToList().ForEach(c =>
            {
                var childClashes = allClashes.Where(ch => ch.ParentExternalidentifier == c.Externalref);

                foreach (var childClash in childClashes)
                {
                    if (c.DefaultPeakExposureCount < childClash.DefaultPeakExposureCount)
                    {
                        exposureCountGreaterThanParentsMessages.Add("Clash code " + c.Externalref +
                                                                    " default peak exposure count should be higher than or equal to " +
                                                                    childClash.DefaultPeakExposureCount);
                    }

                    if (c.DefaultOffPeakExposureCount < childClash.DefaultOffPeakExposureCount)
                    {
                        exposureCountGreaterThanParentsMessages.Add("Clash code " + c.Externalref +
                                                                    " default non-peak exposure count should be higher than or equal to " +
                                                                    childClash.DefaultOffPeakExposureCount);
                    }
                }
            });

            if (parentDoesNotExistMessages.Any())
            {
                throw new DataSyncException(DataSyncErrorCode.Clash_ParentDoesNotExist,
                                            string.Join(", ", parentDoesNotExistMessages));
            }

            if (exposureCountGreaterThanParentsMessages.Any())
            {
                throw new DataSyncException(DataSyncErrorCode.Clash_ExposureCountGreaterThenParents,
                                            string.Join(", ", exposureCountGreaterThanParentsMessages));
            }
        }
Пример #8
0
 public override IEnumerable <Clash> GetAll() => _repository.GetAll();