コード例 #1
0
        public void Create(Guid candidateGuid)
        {
            var candidateUser = GetCandidateUser(candidateGuid);

            var candidateWithHistory = _candidateMappers.MapCandidateWithHistory(candidateUser, new Dictionary <Guid, CandidateSummary>(), _vacancyLocalAuthorities.Value, _localAuthorityCountyIds.Value, new Dictionary <int, int>(), new Dictionary <int, Dictionary <int, int> >(), _anonymiseData);

            Create(candidateWithHistory);
        }
コード例 #2
0
        private void ProcessCandidates(IAsyncCursor <Candidate> cursor, long expectedCount, IDictionary <string, int> vacancyLocalAuthorities, IDictionary <int, int> localAuthorityCountyIds, SyncType syncType, CancellationToken cancellationToken)
        {
            var count = 0;

            while (cursor.MoveNextAsync(cancellationToken).Result&& !cancellationToken.IsCancellationRequested)
            {
                var batch = cursor.Current.ToDictionary(c => c.Id, c => c);
                if (batch.Count == 0)
                {
                    continue;
                }
                var candidateUsers = new List <CandidateUser>(batch.Count);

                _logService.Info($"Loading {batch.Count} users");
                var usersCursor = _userRepository.GetUsersByIds(batch.Keys, cancellationToken).Result;
                while (usersCursor.MoveNextAsync(cancellationToken).Result&& !cancellationToken.IsCancellationRequested)
                {
                    candidateUsers.AddRange(usersCursor.Current.Select(user => new CandidateUser {
                        Candidate = batch[user.Id], User = user
                    }));
                }

                _logService.Info($"Processing {candidateUsers.Count} candidates");

                var maxDateCreated = candidateUsers.Max(c => c.Candidate.DateCreated);
                var maxDateUpdated = candidateUsers.Max(c => c.Candidate.DateUpdated) ?? DateTime.MinValue;

                var candidateSummaries    = _candidateRepository.GetCandidateSummariesByGuid(candidateUsers.Select(c => c.Candidate.Id));
                var schoolAttendedIds     = _schoolAttendedRepository.GetSchoolAttendedIdsByCandidateIds(candidateSummaries.Values.Select(cs => cs.CandidateId));
                var candidateHistoryIds   = _candidateHistoryRepository.GetCandidateHistoryIdsByCandidateIds(candidateSummaries.Values.Select(cs => cs.CandidateId).Distinct());
                var candidatesWithHistory = candidateUsers.Select(c => _candidateMappers.MapCandidateWithHistory(c, candidateSummaries, vacancyLocalAuthorities, localAuthorityCountyIds, schoolAttendedIds, candidateHistoryIds, _anonymiseData)).Where(c => c != null).ToList();

                count += candidatesWithHistory.Count;
                _logService.Info($"Processing {candidatesWithHistory.Count} mapped candidates");
                BulkUpsert(candidatesWithHistory, candidateSummaries);

                var syncParams = _syncRepository.GetSyncParams();
                if (syncType == SyncType.Full)
                {
                    syncParams.CandidateLastCreatedDate = maxDateCreated > syncParams.CandidateLastCreatedDate ? maxDateCreated : syncParams.CandidateLastCreatedDate;
                    //Deliberate as date updated could skip some updates post full sync
                    syncParams.CandidateLastUpdatedDate = syncParams.CandidateLastCreatedDate;
                }
                if (syncType == SyncType.PartialByDateCreated)
                {
                    syncParams.CandidateLastCreatedDate = maxDateCreated > syncParams.CandidateLastCreatedDate ? maxDateCreated : syncParams.CandidateLastCreatedDate;
                }
                if (syncType == SyncType.PartialByDateUpdated)
                {
                    syncParams.CandidateLastUpdatedDate = maxDateUpdated > syncParams.CandidateLastUpdatedDate ? maxDateUpdated : syncParams.CandidateLastUpdatedDate;
                }
                _syncRepository.SetCandidateSyncParams(syncParams);

                var percentage = ((double)count / expectedCount) * 100;
                _logService.Info($"Processed batch of {candidatesWithHistory.Count} candidates and {count} candidates out of {expectedCount} in total. {Math.Round(percentage, 2)}% complete. LastCreatedDate: {syncParams.CandidateLastCreatedDate} LastUpdatedDate: {syncParams.CandidateLastUpdatedDate}");
            }
        }
コード例 #3
0
        public void ActivatedCandidateWithHistoryTest()
        {
            //Arrange
            var candidateUser = new CandidateUserBuilder().WithStatus(20).Build();

            //Act
            var candidateWithHistory = _candidateMappers.MapCandidateWithHistory(candidateUser, new Dictionary <Guid, CandidateSummary>(), new Dictionary <string, int>(), new Dictionary <int, int>(), new Dictionary <int, int>(), new Dictionary <int, Dictionary <int, int> >(), false);

            //Assert
            var candidatePerson = candidateWithHistory.CandidatePerson;

            candidatePerson.Candidate.CandidateStatusTypeId.Should().Be(2);
            var candidateHistory = candidateWithHistory.CandidateHistory;

            candidateHistory.Should().NotBeNullOrEmpty();
            candidateHistory.Count.Should().Be(3);
            var createdHistory = candidateHistory[0];

            createdHistory.CandidateHistoryEventTypeId.Should().Be(1);
            createdHistory.CandidateHistorySubEventTypeId.Should().Be(1);
            var activatedHistory = candidateHistory[1];

            activatedHistory.CandidateId.Should().Be(candidateUser.Candidate.LegacyCandidateId);
            activatedHistory.CandidateHistoryEventTypeId.Should().Be(1);
            activatedHistory.CandidateHistorySubEventTypeId.Should().Be(2);
            // ReSharper disable once PossibleInvalidOperationException
            activatedHistory.EventDate.Should().Be(candidateUser.User.ActivationDate.Value);
            activatedHistory.Comment.Should().BeNull();
            activatedHistory.UserName.Should().Be("NAS Gateway");
            var noteHistory = candidateHistory[2];

            noteHistory.CandidateId.Should().Be(candidateUser.Candidate.LegacyCandidateId);
            noteHistory.CandidateHistoryEventTypeId.Should().Be(3);
            noteHistory.CandidateHistorySubEventTypeId.Should().Be(0);
            noteHistory.EventDate.Should().Be(candidateUser.User.ActivationDate.Value);
            noteHistory.Comment.Should().Be("NAS Exemplar registered Candidate.");
            noteHistory.UserName.Should().Be("NAS Gateway");
        }