Example #1
0
        /// <summary>
        /// New service.
        /// </summary>
        /// <returns>a <seealso cref="LookupDetailsProvider"/></returns>
        public LookupDetailsProvider NewService()
        {
            var cacheFactory = new Mock <ICreateInternalDataCache>();
            var cache        = new InternalDataCache();
            var finTypes     = new List <int>()
            {
                1, 2, 4, 5, 6, 9, 24, 25, 29, 45
            };
            var codedTypes = new List <string>()
            {
                "TNP", "PMR", "AEC", "UI", "OT", "ME", "YOU"
            };
            var tTAccomItems = new Dictionary <int, ValidityPeriods>()
            {
                [1] = new ValidityPeriods(validFrom: DateTime.Parse("2013-06-14"), validTo: DateTime.Parse("2020-06-14")),
                [2] = new ValidityPeriods(validFrom: DateTime.Parse("2009-04-28"), validTo: DateTime.Parse("2020-06-14")),
                [4] = new ValidityPeriods(validFrom: DateTime.Parse("2012-09-06"), validTo: DateTime.Parse("2015-02-28")),
                [5] = new ValidityPeriods(validFrom: DateTime.Parse("2010-11-21"), validTo: DateTime.Parse("2020-06-14")),
                [6] = new ValidityPeriods(validFrom: DateTime.Parse("2018-07-02"), validTo: DateTime.Parse("2020-06-14")),
                [9] = new ValidityPeriods(validFrom: DateTime.Parse("2000-02-01"), validTo: DateTime.Parse("2008-08-26")),
            };

            cache.SimpleLookups.Add(LookupSimpleKey.FINTYPE, finTypes);
            cache.CodedLookups.Add(LookupCodedKey.AppFinRecord, codedTypes);
            cache.LimitedLifeLookups.Add(LookupTimeRestrictedKey.TTAccom, tTAccomItems);

            cacheFactory
            .Setup(c => c.Create())
            .Returns(cache);

            return(new LookupDetailsProvider(cacheFactory.Object));
        }
Example #2
0
        /// <summary>
        /// Builds the cache.
        /// </summary>
        /// <param name="cache">The cache.</param>
        public void Build(InternalDataCache cache)
        {
            var assembly = Assembly.GetAssembly(typeof(InternalDataCachePopulationService));

            using (var stream = assembly.GetManifestResourceStream(resourceName))
            {
                var lookups = XElement.Load(stream);

                cache.AcademicYear = BuildAcademicYear();

                // these are defunct; whilst i won't remove them, don't add to them either.
                cache.AimTypes     = new HashSet <int>(BuildSimpleLookupEnumerable <int>(lookups, "AimType"));
                cache.CompStatuses = new HashSet <int>(BuildSimpleLookupEnumerable <int>(lookups, "CompStatus"));
                cache.EmpOutcomes  = new HashSet <int>(BuildSimpleLookupEnumerable <int>(lookups, "EmpOutcome"));
                cache.FundModels   = new HashSet <int>(BuildSimpleLookupEnumerable <int>(lookups, "FundModel"));
                cache.LLDDCats     = new Dictionary <int, ValidityPeriods>(BuildLookupWithValidityPeriods(lookups, "LLDDCat"));
                cache.QUALENT3s    = new HashSet <string>(BuildSimpleLookupEnumerable <string>(lookups, "QualEnt3"));
                cache.TTAccoms     = new Dictionary <int, ValidityPeriods>(BuildLookupWithValidityPeriods(lookups, "TTAccom"));

                Enum.GetValues(typeof(LookupSimpleKey))
                .OfType <LookupSimpleKey>()
                .ToList()
                .ForEach(x => AddLookups(x, lookups, cache));
                Enum.GetValues(typeof(LookupCodedKey))
                .OfType <LookupCodedKey>()
                .ToList()
                .ForEach(x => AddLookups(x, lookups, cache));
                Enum.GetValues(typeof(LookupTimeRestrictedKey))
                .OfType <LookupTimeRestrictedKey>()
                .ToList()
                .ForEach(x => AddLookups(x, lookups, cache));
            }
        }
        /// <summary>
        /// Builds this instance.
        /// </summary>
        /// <returns>an internal data cache</returns>
        public IInternalDataCache Create()
        {
            var internalDataCache = new InternalDataCache();

            Build(internalDataCache);

            return(internalDataCache);
        }
        /// <summary>
        /// New service.
        /// </summary>
        /// <returns>a <seealso cref="LookupDetailsProvider"/></returns>
        public LookupDetailsProvider NewService()
        {
            var aimTypes = new HashSet <int> {
                1, 2, 4, 5, 6, 9, 24, 25, 29, 45
            };

            var tTAccomItems = new Dictionary <string, ValidityPeriods>()
            {
                ["1"] = new ValidityPeriods(DateTime.Parse("2013-06-14"), DateTime.Parse("2020-06-14")),
                ["2"] = new ValidityPeriods(DateTime.Parse("2009-04-28"), DateTime.Parse("2020-06-14")),
                ["4"] = new ValidityPeriods(DateTime.Parse("2012-09-06"), DateTime.Parse("2015-02-28")),
                ["5"] = new ValidityPeriods(DateTime.Parse("2010-11-21"), DateTime.Parse("2020-06-14")),
                ["6"] = new ValidityPeriods(DateTime.Parse("2018-07-02"), DateTime.Parse("2020-06-14")),
                ["9"] = new ValidityPeriods(DateTime.Parse("2000-02-01"), DateTime.Parse("2008-08-26")),
            };

            var esmTypes = new Dictionary <string, ValidityPeriods>()
            {
                ["BSI1"] = new ValidityPeriods(DateTime.Parse("2000-06-14"), DateTime.Parse("2020-06-14")),
                ["BSI2"] = new ValidityPeriods(DateTime.Parse("2000-04-28"), DateTime.Parse("2020-06-14")),
                ["LOE1"] = new ValidityPeriods(DateTime.Parse("2000-09-06"), DateTime.Parse("2015-02-28")),
                ["LOE2"] = new ValidityPeriods(DateTime.Parse("2000-11-21"), DateTime.Parse("2020-06-14")),
                ["LOE3"] = new ValidityPeriods(DateTime.Parse("2000-07-02"), DateTime.Parse("2020-06-14")),
                ["LOE4"] = new ValidityPeriods(DateTime.Parse("2000-02-01"), DateTime.Parse("2008-08-26")),
            };

            var famTypes = new Dictionary <string, ValidityPeriods>()
            {
                ["ECF5"] = new ValidityPeriods(DateTime.Parse("2000-06-14"), DateTime.Parse("2018-06-14")),
                ["MCF5"] = new ValidityPeriods(DateTime.Parse("2000-06-14"), null),
            };

            var cache = new InternalDataCache
            {
                IntegerLookups = new Dictionary <TypeOfIntegerCodedLookup, IReadOnlyCollection <int> >
                {
                    { TypeOfIntegerCodedLookup.AimType, aimTypes }
                },
                StringLookups = new Dictionary <TypeOfStringCodedLookup, IReadOnlyCollection <string> >
                {
                    { TypeOfStringCodedLookup.AppFinType, new List <string> {
                          "PMR1", "PMR2", "PMR3", "TNP1", "TNP2", "TNP3", "TNP4"
                      } },
                    { TypeOfStringCodedLookup.OutGrade, new List <string> {
                          "A", "A*"
                      } }
                },
                LimitedLifeLookups = new Dictionary <TypeOfLimitedLifeLookup, IReadOnlyDictionary <string, ValidityPeriods> >
                {
                    { TypeOfLimitedLifeLookup.TTAccom, tTAccomItems },
                    { TypeOfLimitedLifeLookup.ESMType, esmTypes },
                    { TypeOfLimitedLifeLookup.LearnFAMType, famTypes },
                },
                ListItemLookups = new Dictionary <TypeOfListItemLookup, IReadOnlyDictionary <string, IReadOnlyCollection <string> > >()
            };

            return(new LookupDetailsProvider(cache));
        }
Example #5
0
        public async Task Populate_AcademicYear()
        {
            var internalDataCache = new InternalDataCache();

            await NewService(internalDataCache).PopulateAsync(CancellationToken.None);

            var yearStart = new DateTime(2018, 8, 1);

            internalDataCache.AcademicYear.Start.Should().BeSameDateAs(yearStart);
        }
Example #6
0
        public async Task ItemLookupsArePresentAndMatchExpectedCount(TypeOfListItemLookup thisKey, int expectedCount)
        {
            // arrange
            var internalDataCache = new InternalDataCache();

            // act
            await NewService(internalDataCache).PopulateAsync(CancellationToken.None);

            Assert.True(internalDataCache.ListItemLookups.ContainsKey(thisKey));
            Assert.Equal(expectedCount, internalDataCache.ListItemLookups[thisKey].Count);
        }
        public async Task TimeLimitedLookupsArePresentAndMatchExpectedCount(LookupTimeRestrictedKey thisKey, int expectedCount)
        {
            // arrange
            var internalDataCache = new InternalDataCache();

            // act
            await NewService(internalDataCache).PopulateAsync(CancellationToken.None);

            // assert
            Assert.True(internalDataCache.LimitedLifeLookups.ContainsKey(thisKey));
            Assert.Equal(expectedCount, internalDataCache.LimitedLifeLookups[thisKey].Count);
        }
        public async Task Populate()
        {
            var internalDataCache = new InternalDataCache();

            await NewService(internalDataCache).PopulateAsync(CancellationToken.None);

            var yearStart  = new DateTime(2018, 8, 1);
            var fundModels = new List <int> {
                10, 25, 35, 36, 70, 81, 82, 99
            };

            internalDataCache.AcademicYear.Start.Should().BeSameDateAs(yearStart);
            internalDataCache.FundModels.Should().BeEquivalentTo(fundModels);
            internalDataCache.QUALENT3s.Count.Should().Be(61);
        }
Example #9
0
        /// <summary>
        /// New service.
        /// </summary>
        /// <returns>a <seealso cref="LookupDetailsProvider"/></returns>
        public LookupDetailsProvider NewService()
        {
            var cacheFactory = new Mock <ICreateInternalDataCache>();
            var cache        = new InternalDataCache();
            var finTypes     = new DistinctKeySet <int> {
                1, 2, 4, 5, 6, 9, 24, 25, 29, 45
            };
            var codedTypes = new CaseInsensitiveDistinctKeySet {
                "TNP", "PMR", "AEC", "UI", "OT", "ME", "YOU"
            };

            var tTAccomItems = new Dictionary <string, ValidityPeriods>()
            {
                ["1"] = new ValidityPeriods(DateTime.Parse("2013-06-14"), DateTime.Parse("2020-06-14")),
                ["2"] = new ValidityPeriods(DateTime.Parse("2009-04-28"), DateTime.Parse("2020-06-14")),
                ["4"] = new ValidityPeriods(DateTime.Parse("2012-09-06"), DateTime.Parse("2015-02-28")),
                ["5"] = new ValidityPeriods(DateTime.Parse("2010-11-21"), DateTime.Parse("2020-06-14")),
                ["6"] = new ValidityPeriods(DateTime.Parse("2018-07-02"), DateTime.Parse("2020-06-14")),
                ["9"] = new ValidityPeriods(DateTime.Parse("2000-02-01"), DateTime.Parse("2008-08-26")),
            };

            var qualent3s = new Dictionary <string, ValidityPeriods>()
            {
                ["C20"] = new ValidityPeriods(DateTime.MinValue, DateTime.MaxValue),
                ["P69"] = new ValidityPeriods(DateTime.MinValue, DateTime.Parse("2013-07-31")),
                ["P70"] = new ValidityPeriods(DateTime.MinValue, DateTime.Parse("2013-07-31"))
            };

            var apprenticeshipFinancialRecords = new CaseInsensitiveDistinctKeySet {
                "TNP1", "TNP2", "TNP3", "TNP4", "PMR1", "PMR2", "PMR3"
            };

            cache.IntegerLookups.Add(TypeOfIntegerCodedLookup.FINTYPE, finTypes);
            cache.StringLookups.Add(TypeOfStringCodedLookup.AppFinRecord, codedTypes);
            cache.StringLookups.Add(TypeOfStringCodedLookup.ApprenticeshipFinancialRecord, apprenticeshipFinancialRecords);
            cache.LimitedLifeLookups.Add(TypeOfLimitedLifeLookup.TTAccom, tTAccomItems);
            cache.LimitedLifeLookups.Add(TypeOfLimitedLifeLookup.QualEnt3, qualent3s);

            cacheFactory
            .Setup(c => c.Create())
            .Returns(cache);

            return(new LookupDetailsProvider(cacheFactory.Object));
        }
Example #10
0
        public async Task Populate()
        {
            IInternalDataCache internalDataCache = new InternalDataCache();

            await NewService(internalDataCache).PopulateAsync(CancellationToken.None);

            internalDataCache.Period1.Should().Be(new DateTime(2018, 8, 1));
            internalDataCache.Period2.Should().Be(new DateTime(2018, 9, 1));
            internalDataCache.Period3.Should().Be(new DateTime(2018, 10, 1));
            internalDataCache.Period4.Should().Be(new DateTime(2018, 11, 1));
            internalDataCache.Period5.Should().Be(new DateTime(2018, 12, 1));
            internalDataCache.Period6.Should().Be(new DateTime(2019, 1, 1));
            internalDataCache.Period7.Should().Be(new DateTime(2019, 2, 1));
            internalDataCache.Period8.Should().Be(new DateTime(2019, 3, 1));
            internalDataCache.Period9.Should().Be(new DateTime(2019, 4, 1));
            internalDataCache.Period10.Should().Be(new DateTime(2019, 5, 1));
            internalDataCache.Period11.Should().Be(new DateTime(2019, 6, 1));
            internalDataCache.Period12.Should().Be(new DateTime(2019, 7, 1));
        }
        /// <summary>
        /// Builds the cache.
        /// </summary>
        /// <param name="cache">The cache.</param>
        public void Build(InternalDataCache cache)
        {
            var assembly = Assembly.GetAssembly(typeof(InternalDataCachePopulationService));

            using (var stream = assembly.GetManifestResourceStream(resourceName))
            {
                var lookups = XElement.Load(stream);

                cache.AcademicYear = BuildAcademicYear();

                Enum.GetValues(typeof(TypeOfIntegerCodedLookup))
                .OfType <TypeOfIntegerCodedLookup>()
                .ForEach(x => AddLookups(x, lookups, cache));
                Enum.GetValues(typeof(TypeOfStringCodedLookup))
                .OfType <TypeOfStringCodedLookup>()
                .ForEach(x => AddLookups(x, lookups, cache));
                Enum.GetValues(typeof(TypeOfLimitedLifeLookup))
                .OfType <TypeOfLimitedLifeLookup>()
                .ForEach(x => AddLookups(x, lookups, cache));
                Enum.GetValues(typeof(TypeOfListItemLookup))
                .OfType <TypeOfListItemLookup>()
                .ForEach(x => AddLookups(x, lookups, cache));
            }
        }
Example #12
0
        /// <summary>
        /// Adds lookups.
        /// </summary>
        /// <param name="forThisKey">For this key.</param>
        /// <param name="usingSource">using source.</param>
        /// <param name="addToCache">add to cache.</param>
        public void AddLookups(LookupCodedKey forThisKey, XElement usingSource, InternalDataCache addToCache)
        {
            var lookups = BuildSimpleLookupEnumerable <string>(usingSource, $"{forThisKey}");

            addToCache.CodedLookups.Add(forThisKey, lookups.ToList());
        }
Example #13
0
        private async Task <IEnumerable <IValidationError> > RunValidation(ValidationActorModel actorModel, CancellationToken cancellationToken)
        {
            if (_executionContext is ExecutionContext executionContextObj)
            {
                executionContextObj.JobId   = "-1";
                executionContextObj.TaskKey = _actorId.ToString();
            }

            ILogger logger = _parentLifeTimeScope.Resolve <ILogger>();

            InternalDataCache internalDataCacheGet;
            InternalDataCache internalDataCache;
            ExternalDataCache externalDataCacheGet;
            ExternalDataCache externalDataCache;
            FileDataCache     fileDataCache;
            Message           message;
            IEnumerable <IValidationError> errors;

            try
            {
                logger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} starting");

                internalDataCacheGet = _jsonSerializationService.Deserialize <InternalDataCache>(actorModel.InternalDataCache);
                externalDataCacheGet = _jsonSerializationService.Deserialize <ExternalDataCache>(actorModel.ExternalDataCache);
                fileDataCache        = _jsonSerializationService.Deserialize <FileDataCache>(actorModel.FileDataCache);
                message = _jsonSerializationService.Deserialize <Message>(actorModel.Message);

                internalDataCache = new InternalDataCache
                {
                    AcademicYear       = internalDataCacheGet.AcademicYear,
                    IntegerLookups     = internalDataCacheGet.IntegerLookups,
                    LimitedLifeLookups = BuildLimitedLifeLookups(internalDataCacheGet.LimitedLifeLookups),
                    ListItemLookups    = BuildListItemLookups(internalDataCacheGet.ListItemLookups),
                    StringLookups      = BuildStringLookups(internalDataCacheGet.StringLookups),
                };

                externalDataCache = new ExternalDataCache
                {
                    LearningDeliveries = externalDataCacheGet.LearningDeliveries.ToCaseInsensitiveDictionary(),
                    EPAOrganisations   = externalDataCacheGet.EPAOrganisations.ToCaseInsensitiveDictionary(),
                    ERNs = externalDataCacheGet.ERNs,
                    FCSContractAllocations = externalDataCacheGet.FCSContractAllocations,
                    Organisations          = externalDataCacheGet.Organisations,
                    Postcodes          = externalDataCacheGet.Postcodes.ToCaseInsensitiveHashSet(),
                    ONSPostcodes       = externalDataCacheGet.ONSPostcodes,
                    DevolvedPostcodes  = externalDataCacheGet.DevolvedPostcodes,
                    Standards          = externalDataCacheGet.Standards,
                    StandardValidities = externalDataCacheGet.StandardValidities,
                    ULNs              = externalDataCacheGet.ULNs,
                    ValidationErrors  = externalDataCacheGet.ValidationErrors.ToCaseInsensitiveDictionary(),
                    CampusIdentifiers = externalDataCacheGet.CampusIdentifiers,
                    ValidationRules   = externalDataCacheGet.ValidationRules,
                    ReturnPeriod      = externalDataCacheGet.ReturnPeriod
                };

                logger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} finished getting input data");

                cancellationToken.ThrowIfCancellationRequested();
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString());
                logger.LogError($"Error while processing {nameof(ValidationActor)}", ex);
                throw;
            }

            using (var childLifeTimeScope = _parentLifeTimeScope.BeginLifetimeScope(c =>
            {
                c.RegisterInstance(new Cache <IMessage> {
                    Item = message
                }).As <ICache <IMessage> >();
                c.RegisterInstance(internalDataCache).As <IInternalDataCache>();
                c.RegisterInstance(externalDataCache).As <IExternalDataCache>();
                c.RegisterInstance(fileDataCache).As <IFileDataCache>();
            }))
            {
                ExecutionContext executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>();
                executionContext.JobId   = actorModel.JobId;
                executionContext.TaskKey = _actorId.ToString();
                ILogger jobLogger = childLifeTimeScope.Resolve <ILogger>();
                try
                {
                    jobLogger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} started learners: {message.Learners.Count}");
                    IRuleSetOrchestrationService <IRule <ILearner>, ILearner> preValidationOrchestrationService = childLifeTimeScope
                                                                                                                  .Resolve <IRuleSetOrchestrationService <IRule <ILearner>, ILearner> >();

                    errors = await preValidationOrchestrationService.ExecuteAsync(message.Learners, cancellationToken);

                    jobLogger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} validation done");
                }
                catch (Exception ex)
                {
                    ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString());
                    jobLogger.LogError($"Error while processing {nameof(ValidationActor)}", ex);
                    throw;
                }
            }

            internalDataCache = null;
            externalDataCache = null;
            fileDataCache     = null;
            message           = null;

            return(errors);
        }
        /// <summary>
        /// Adds lookups.
        /// </summary>
        /// <param name="forThisKey">For this key.</param>
        /// <param name="usingSource">using source.</param>
        /// <param name="addToCache">add to cache.</param>
        public void AddLookups(TypeOfLimitedLifeLookup forThisKey, XElement usingSource, InternalDataCache addToCache)
        {
            var lookups = BuildDictionaryLookupsWithValidityPeriods(usingSource, $"{forThisKey}");

            addToCache.LimitedLifeLookups.Add(forThisKey, lookups);
        }
        /// <summary>
        /// Adds lookups.
        /// </summary>
        /// <param name="forThisKey">For this key.</param>
        /// <param name="usingSource">using source.</param>
        /// <param name="addToCache">add to cache.</param>
        public void AddLookups(TypeOfListItemLookup forThisKey, XElement usingSource, InternalDataCache addToCache)
        {
            var lookups = BuildStringDictionaryLookups(usingSource, $"{forThisKey}");

            addToCache.ListItemLookups.Add(forThisKey, lookups);
        }
        /// <summary>
        /// Adds lookups.
        /// </summary>
        /// <param name="forThisKey">For this key.</param>
        /// <param name="usingSource">using source.</param>
        /// <param name="addToCache">add to cache.</param>
        public void AddLookups(TypeOfStringCodedLookup forThisKey, XElement usingSource, InternalDataCache addToCache)
        {
            var lookups = BuildStringListLookups(usingSource, $"{forThisKey}");

            addToCache.StringLookups.Add(forThisKey, lookups);
        }
        /// <summary>
        /// Adds lookups.
        /// </summary>
        /// <param name="forThisKey">For this key.</param>
        /// <param name="usingSource">using source.</param>
        /// <param name="addToCache">add to cache.</param>
        public void AddLookups(TypeOfIntegerCodedLookup forThisKey, XElement usingSource, InternalDataCache addToCache)
        {
            var lookups = BuildListLookups <int>(usingSource, $"{forThisKey}");

            addToCache.IntegerLookups.Add(forThisKey, lookups);
        }
Example #18
0
        /// <summary>
        /// Adds lookups.
        /// </summary>
        /// <param name="forThisKey">For this key.</param>
        /// <param name="usingSource">using source.</param>
        /// <param name="addToCache">add to cache.</param>
        public void AddLookups(LookupTimeRestrictedKey forThisKey, XElement usingSource, InternalDataCache addToCache)
        {
            var lookups = BuildLookupWithValidityPeriods(usingSource, $"{forThisKey}");

            addToCache.LimitedLifeLookups.Add(forThisKey, lookups);
        }