示例#1
0
        public async Task <long> RunReport(string reportName, int collectionYear, int collectionPeriod, string createdBy, CancellationToken cancellationToken = default(CancellationToken))
        {
            long jobId = -1;

            var report = _reports.Single(x => x.ReportName.Equals(reportName));

            var job = new FileUploadJob
            {
                CollectionYear   = collectionYear,
                PeriodNumber     = collectionPeriod,
                CollectionName   = report.CollectionName.Replace(Constants.CollectionYearToken, collectionYear.ToString()),
                StorageReference = report.ContainerName.Replace(Constants.CollectionYearToken, collectionYear.ToString()),
                Status           = Jobs.Model.Enums.JobStatusType.Ready,
                JobId            = 0,
                CreatedBy        = createdBy
            };

            string url = $"{_baseUrl}/api/job";

            var result = await _httpClientService.SendDataAsync(url, job, cancellationToken);

            long.TryParse(result, out jobId);

            return(jobId);
        }
        public async Task <long> SubmitJob(Models.Job.JobSubmission submittedJobSubmission, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(submittedJobSubmission?.FileName))
            {
                throw new ArgumentException("submission message should have file name");
            }

            var job = new FileUploadJob
            {
                Ukprn            = submittedJobSubmission.Ukprn,
                Priority         = 1,
                Status           = JobStatusType.Ready,
                CreatedBy        = submittedJobSubmission.SubmittedBy,
                FileName         = submittedJobSubmission.FileName,
                IsFirstStage     = true,
                StorageReference = submittedJobSubmission.StorageReference,
                FileSize         = submittedJobSubmission.FileSizeBytes,
                CollectionName   = submittedJobSubmission.CollectionName,
                PeriodNumber     = submittedJobSubmission.Period,
                NotifyEmail      = submittedJobSubmission.NotifyEmail,
                TermsAccepted    = submittedJobSubmission.TermsAccepted,
            };

            var response = await _httpClientService.SendDataAsync($"{_baseUrl}/api/job", job, cancellationToken);

            long.TryParse(response, out var result);

            return(result);
        }
示例#3
0
        public async Task GetConfirmation_Success()
        {
            var dateTime = new DateTime(2018, 10, 10, 10, 20, 30);

            var job = new FileUploadJob()
            {
                JobId                = 10,
                JobType              = EnumJobType.IlrSubmission,
                FileName             = "test.xml",
                PeriodNumber         = 1,
                SubmittedBy          = "test user",
                DateTimeSubmittedUtc = dateTime
            };

            var serializationServiceMock = new Mock <IJsonSerializationService>();

            serializationServiceMock.Setup(x => x.Deserialize <FileUploadJob>(string.Empty)).Returns(job);

            var submisisionService = GetService(null, serializationServiceMock.Object);
            var confirmation       = await submisisionService.GetConfirmation(It.IsAny <long>(), It.IsAny <long>());

            confirmation.Should().NotBeNull();
            confirmation.FileName.Should().Be("TEST.XML");
            confirmation.PeriodName.Should().Be("R01");
            confirmation.SubmittedBy.Should().Be("test user");
            confirmation.SubmittedAtDateTime.Should().Be("10:20am on Wednesday 10 October 2018");
        }
        public void JobMetaDataEntityToJobMetaData_Test()
        {
            var entity = new FileUploadJobMetaData
            {
                FileName         = "test.xml",
                JobId            = 1,
                StorageReference = "test-ref",
                Ukprn            = 1000,
                CollectionName   = "ILR1819",
                PeriodNumber     = 10,
                FileSize         = 1000,
                Job = new Data.Entities.Job {
                    JobId = 1
                }
            };

            var job = new FileUploadJob();

            JobConverter.Convert(entity, job);

            job.JobId.Should().Be(1);
            job.FileName.Should().Be("test.xml");
            job.StorageReference.Should().Be("test-ref");
            job.Ukprn.Should().Be(1000);
            job.CollectionName.Should().Be("ILR1819");
            job.PeriodNumber.Should().Be(10);
            job.FileSize.Should().Be(1000);
        }
        public void JobMetaDataToEntity_Test()
        {
            var job = new FileUploadJob
            {
                FileName         = "test.xml",
                JobId            = 1,
                StorageReference = "test-ref",
                Ukprn            = 1000,
                CollectionName   = "ILR1819",
                PeriodNumber     = 10,
                FileSize         = 1000
            };

            var entity = new FileUploadJobMetaData();

            JobConverter.Convert(job, entity);

            entity.JobId.Should().Be(1);
            entity.FileName.Should().Be("test.xml");
            entity.StorageReference.Should().Be("test-ref");
            entity.Ukprn.Should().Be(1000);
            entity.CollectionName.Should().Be("ILR1819");
            entity.PeriodNumber.Should().Be(10);
            entity.FileSize.Should().Be(1000);
        }
        private IlrMessageFactory GetFactory(bool isFirstStage = true, FileUploadJob job = null)
        {
            var mockIFileUploadJobManager = new Mock <IFileUploadJobManager>();

            mockIFileUploadJobManager.Setup(x => x.GetJobById(It.IsAny <long>())).ReturnsAsync(
                job ?? new FileUploadJob
            {
                IsFirstStage = isFirstStage,
                JobId        = 10,
                Ukprn        = 1000
            });

            var mockTopicConfiguration = new Mock <ITopicConfiguration>();

            mockTopicConfiguration.SetupGet(x => x.SubscriptionName).Returns("Validation");

            var jobTopicTaskService = new Mock <IJobTopicTaskService>();

            jobTopicTaskService.Setup(x => x.GetTopicItems(It.IsAny <JobType>(), It.IsAny <bool>(), default(CancellationToken))).ReturnsAsync(
                new List <ITopicItem>()
            {
                new TopicItem("A", "B", new List <ITaskItem>())
            });

            var factory = new IlrMessageFactory(
                new Mock <ILogger>().Object,
                mockIFileUploadJobManager.Object,
                mockTopicConfiguration.Object,
                jobTopicTaskService.Object);

            return(factory);
        }
        public async Task <MessageParameters> CreateMessageParametersAsync(long jobId)
        {
            FileUploadJob job = await _fileUploadJobManager.GetJobById(jobId);

            List <ITopicItem> topics = (await _jobTopicTaskService.GetTopicItems(job.JobType, job.IsFirstStage)).ToList();

            JobContextMessage contextMessage = new JobContextMessage(
                job.JobId,
                topics,
                job.Ukprn.ToString(),
                job.StorageReference,
                job.FileName,
                job.SubmittedBy,
                0,
                job.DateTimeSubmittedUtc);

            contextMessage.KeyValuePairs.Add("CollectionName", job.CollectionName);
            contextMessage.KeyValuePairs.Add("ReturnPeriod", job.PeriodNumber);

            AddExtraKeys(contextMessage, job);

            MessageParameters message = new MessageParameters(job.JobType)
            {
                JobContextMessage = contextMessage,
                SubscriptionLabel = topics[0].SubscriptionName,
                TopicParameters   = new Dictionary <string, object>
                {
                    {
                        "To", topics[0].SubscriptionName
                    }
                }
            };

            return(message);
        }
示例#8
0
        public async Task <long> SubmitJob(SubmissionMessageViewModel submissionMessage)
        {
            if (string.IsNullOrEmpty(submissionMessage?.FileName))
            {
                throw new ArgumentException("submission message should have file name");
            }

            var job = new FileUploadJob()
            {
                Ukprn = submissionMessage.Ukprn,
                DateTimeSubmittedUtc = _dateTimeProvider.GetNowUtc(),
                Priority             = 1,
                Status           = JobStatusType.Ready,
                SubmittedBy      = submissionMessage.SubmittedBy,
                FileName         = submissionMessage.FileName,
                IsFirstStage     = true,
                StorageReference = submissionMessage.StorageReference,
                FileSize         = submissionMessage.FileSizeBytes,
                CollectionName   = submissionMessage.CollectionName,
                PeriodNumber     = submissionMessage.Period,
                NotifyEmail      = submissionMessage.NotifyEmail,
                JobType          = submissionMessage.JobType,
                TermsAccepted    = submissionMessage.JobType == EnumJobType.EasSubmission ? true : (bool?)null,
                CollectionYear   = submissionMessage.CollectionYear
            };

            var response = await _httpClient.SendDataAsync($"{_apiBaseUrl}", job);

            long.TryParse(response, out var result);

            return(result);
        }
        public override void AddExtraKeys(IJobContextMessage message, FileUploadJob metaData)
        {
            message.KeyValuePairs.Add(JobContextMessageKey.FileSizeInBytes, metaData.FileSize);

            if (metaData.IsFirstStage)
            {
                message.KeyValuePairs.Add(JobContextMessageKey.PauseWhenFinished, "1");
            }

            if (metaData.Ukprn == 0)
            {
                return;
            }

            message.KeyValuePairs.Add(JobContextMessageKey.InvalidLearnRefNumbers, GenerateKey(metaData.Ukprn, metaData.JobId, "ValidationInvalidLearners", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.ValidLearnRefNumbers, GenerateKey(metaData.Ukprn, metaData.JobId, "ValidationValidLearners", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.ValidationErrors, GenerateKey(metaData.Ukprn, metaData.JobId, "ValidationErrors", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.ValidationErrorLookups, GenerateKey(metaData.Ukprn, metaData.JobId, "ValidationErrorsLookup", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.FundingAlbOutput, GenerateKey(metaData.Ukprn, metaData.JobId, "FundingAlbOutput", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.FundingFm35Output, GenerateKey(metaData.Ukprn, metaData.JobId, "FundingFm35Output", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.FundingFm25Output, GenerateKey(metaData.Ukprn, metaData.JobId, "FundingFm25Output", "json"));
            message.KeyValuePairs.Add(JobContextMessageKey.FundingFm36Output, GenerateKey(metaData.Ukprn, metaData.JobId, JobContextMessageKey.FundingFm36Output, "json"));
            message.KeyValuePairs.Add("FundingFm70Output", GenerateKey(metaData.Ukprn, metaData.JobId, "FundingFm70Output", "json"));
            message.KeyValuePairs.Add("FundingFm81Output", GenerateKey(metaData.Ukprn, metaData.JobId, "FundingFm81Output", "json"));
            message.KeyValuePairs.Add("OriginalFilename", metaData.FileName);
            message.KeyValuePairs.Add("CollectionYear", metaData.CollectionYear);
        }
示例#10
0
        public void PostJob_NewJob_InvalidStatus_Failed_Test()
        {
            var job        = new FileUploadJob();
            var controller = GetController();

            var result = (BadRequestObjectResult)controller.Post(job);

            result.StatusCode.Should().Be(400);
        }
示例#11
0
        public IEnumerable <FileUploadJob> ConvertJobs(IEnumerable <FileUploadJobMetaData> entities)
        {
            var items = new List <FileUploadJob>();

            foreach (var entity in entities)
            {
                var model = new FileUploadJob();
                JobConverter.Convert(entity, model);
                items.Add(model);
            }

            return(items);
        }
示例#12
0
 public static void Convert(JobQueueManager.Data.Entities.Job source, FileUploadJob destination)
 {
     destination.DateTimeSubmittedUtc = source.DateTimeSubmittedUtc;
     destination.Priority             = source.Priority;
     destination.Status             = (JobStatus.Interface.JobStatusType)source.Status;
     destination.DateTimeUpdatedUtc = source.DateTimeUpdatedUtc;
     destination.JobId              = source.JobId;
     destination.RowVersion         = source.RowVersion == null ? null : System.Convert.ToBase64String(source.RowVersion);
     destination.SubmittedBy        = source.SubmittedBy;
     destination.NotifyEmail        = source.NotifyEmail;
     destination.JobType            = (Jobs.Model.Enums.JobType)source.JobType;
     destination.CrossLoadingStatus = source.CrossLoadingStatus.HasValue ? (JobStatus.Interface.JobStatusType)source.CrossLoadingStatus.Value : (JobStatus.Interface.JobStatusType?)null;
 }
示例#13
0
        public void PostJob_UpdateJob_InvalidStatus_Failed_Test(JobStatusType status)
        {
            var job = new FileUploadJob()
            {
                JobId  = 100,
                Status = status,
                Ukprn  = 1000,
            };

            var controller = GetController();

            var result = controller.Post(job);

            result.Should().BeAssignableTo <BadRequestObjectResult>();
            ((BadRequestObjectResult)result).StatusCode.Should().Be(400);
        }
        public async Task GenerateKeysAsync()
        {
            var job = new FileUploadJob()
            {
                JobType = JobType.IlrSubmission,
                JobId   = 10,
                Ukprn   = 123456
            };

            IlrMessageFactory factory = GetFactory(false, job);

            MessageParameters result = await factory.CreateMessageParametersAsync(It.IsAny <long>());

            result.JobContextMessage.KeyValuePairs[JobContextMessageKey.InvalidLearnRefNumbers].Should()
            .Be($"{job.Ukprn}/{job.JobId}/ValidationInvalidLearners.json");
        }
示例#15
0
        public async Task AddJobMetaData_Success_Values()
        {
            IContainer    container = Registrations();
            FileUploadJob savedJob;

            using (var scope = container.BeginLifetimeScope())
            {
                // Create the schema in the database
                var options = scope.Resolve <DbContextOptions <JobQueueDataContext> >();
                using (var context = new JobQueueDataContext(options))
                {
                    context.Database.EnsureCreated();
                }

                FileUploadJob job = new FileUploadJob()
                {
                    JobId            = 1,
                    Ukprn            = 1000,
                    FileName         = "test.xml",
                    StorageReference = "test-ref",
                    FileSize         = 10.5m,
                    IsFirstStage     = true,
                    CollectionName   = "ILR1718",
                    PeriodNumber     = 10,
                    TermsAccepted    = true,
                    CollectionYear   = 1819
                };

                IFileUploadJobManager manager = scope.Resolve <IFileUploadJobManager>();
                await manager.AddJob(job);

                savedJob = await manager.GetJobById(1);
            }

            savedJob.Should().NotBeNull();
            savedJob.JobId.Should().Be(1);
            savedJob.Ukprn.Should().Be(1000);
            savedJob.FileName.Should().Be("test.xml");
            savedJob.FileSize.Should().Be(10.5m);
            savedJob.StorageReference.Should().Be("test-ref");
            savedJob.IsFirstStage.Should().Be(true);
            savedJob.CollectionName.Should().Be("ILR1718");
            savedJob.PeriodNumber.Should().Be(10);
            savedJob.TermsAccepted.Should().Be(true);
            savedJob.CollectionYear.Should().Be(1819);
        }
示例#16
0
        public async Task <long> AddJob(FileUploadJob job)
        {
            if (job == null)
            {
                throw new ArgumentNullException();
            }

            using (var context = _contextFactory())
            {
                var entity = new Job
                {
                    DateTimeSubmittedUtc = _dateTimeProvider.GetNowUtc(),
                    JobType            = (short)job.JobType,
                    Priority           = job.Priority,
                    Status             = (short)job.Status,
                    SubmittedBy        = job.SubmittedBy,
                    NotifyEmail        = job.NotifyEmail,
                    CrossLoadingStatus = (await IsCrossLoadingEnabled(job.JobType)) ? (short)JobStatusType.Ready : (short?)null
                };

                var metaEntity = new FileUploadJobMetaData()
                {
                    FileName         = job.FileName,
                    FileSize         = job.FileSize,
                    IsFirstStage     = true,
                    StorageReference = job.StorageReference,
                    Job            = entity,
                    CollectionName = job.CollectionName,
                    PeriodNumber   = job.PeriodNumber,
                    Ukprn          = job.Ukprn,
                    TermsAccepted  = job.TermsAccepted,
                    CollectionYear = job.CollectionYear
                };
                context.Job.Add(entity);
                context.FileUploadJobMetaData.Add(metaEntity);
                await context.SaveChangesAsync();

                //send email on create for esf and eas
                if (job.JobType != JobType.IlrSubmission)
                {
                    await SendEmailNotification(entity.JobId);
                }

                return(entity.JobId);
            }
        }
示例#17
0
        public FileUploadJob GetLatestJobByUkprn(long ukprn, string collectionName)
        {
            var result = new FileUploadJob();

            using (var context = _contextFactory())
            {
                var entity = context.FileUploadJobMetaData
                             .Include(x => x.Job)
                             .Where(x => x.Ukprn == ukprn && x.CollectionName.Equals(collectionName, StringComparison.CurrentCultureIgnoreCase))
                             .OrderByDescending(x => x.Job.DateTimeSubmittedUtc)
                             .FirstOrDefault();

                JobConverter.Convert(entity, result);
            }

            return(result);
        }
示例#18
0
        public void PostJob_NewJob_SaveFailed_Test()
        {
            var job = new FileUploadJob()
            {
                Status  = JobStatusType.Ready,
                JobType = JobType.IlrSubmission,
            };
            var jobqueServiceMock = new Mock <IFileUploadJobManager>();

            jobqueServiceMock.Setup(x => x.AddJob(It.IsAny <FileUploadJob>())).Returns(0);

            var controller = GetController(null, jobqueServiceMock.Object);

            var result = (BadRequestResult)controller.Post(job);

            result.StatusCode.Should().Be(400);
        }
        public void AddExtraKeys_Test(bool isFirstStage)
        {
            var message = new JobContextMessage()
            {
                KeyValuePairs = new Dictionary <string, object>()
            };

            var job = new FileUploadJob()
            {
                FileSize             = 123,
                Ukprn                = 999,
                JobId                = 100,
                StorageReference     = "ref",
                FileName             = "filename.xml",
                SubmittedBy          = "test user",
                DateTimeSubmittedUtc = new DateTime(2018, 10, 10),
                IsFirstStage         = isFirstStage,
            };

            message.KeyValuePairs.Add("Filename", job.FileName);

            var factory = GetFactory(isFirstStage, job);

            factory.AddExtraKeys(message, job);

            message.KeyValuePairs[JobContextMessageKey.FileSizeInBytes].Should().Be(123);

            if (isFirstStage)
            {
                message.KeyValuePairs[JobContextMessageKey.PauseWhenFinished].Should().Be("1");
            }
            else
            {
                message.KeyValuePairs.ContainsKey(JobContextMessageKey.PauseWhenFinished).Should().Be(false);
            }

            message.KeyValuePairs.ContainsKey(JobContextMessageKey.InvalidLearnRefNumbers).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.ValidLearnRefNumbers).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.ValidationErrors).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.ValidationErrorLookups).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.FundingAlbOutput).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.FundingFm35Output).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.FundingFm25Output).Should().BeTrue();
        }
示例#20
0
        public JobBase GetFileUploadJobByCode(Guid code)
        {
            var job = (FileUploadJob)JobQueue.Instance.FindJobByCode(code);

            if (job == null)
            {
                IUcbManagementInformationRepository <UploadJobQueue> uploadJobQueueRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <UploadJobQueue> >();
                var uploadjob = uploadJobQueueRepository.Find(x => x.Code == code, "JobSteps").FirstOrDefault();
                if (uploadjob != null)
                {
                    var           descSplit   = uploadjob.JobDescription.Split('|');
                    FileUploadJob jobToReturn = new FileUploadJob()
                    {
                        Code           = uploadjob.Code,
                        ProviderKey    = descSplit[1],
                        Status         = (JobStatus)Enum.Parse(typeof(JobStatus), uploadjob.Status),
                        UniqueFileName = descSplit[3],
                        UserId         = uploadjob.UserId,
                        JobSteps       = new List <MIFileUpload.JobQueue.JobStep>()
                    };
                    foreach (UcbManagementInformation.Server.DataAccess.JobStep step in uploadjob.JobSteps.OrderBy(x => x.StepOrder))
                    {
                        jobToReturn.JobSteps.Add(new MIFileUpload.JobQueue.JobStep(step.StartTime, step.EndTime, (JobStepStatus)Enum.Parse(typeof(JobStepStatus), step.Status))
                        {
                            Code      = step.Code,
                            Category  = step.Category,
                            Name      = step.Name,
                            ParentJob = jobToReturn,
                            Order     = step.StepOrder
                        });
                    }
                    return(jobToReturn);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(job);
            }
        }
        private async Task <FileUploadJob> JobStatusCompletionState(long ukprn, long jobId, bool secondStageRequired)
        {
            var completed = false;
            var result    = new FileUploadJob();

            while (!completed)
            {
                FileUploadJob status;
                try
                {
                    status = await jobService.GetJob(ukprn, jobId);
                }
                catch (HttpRequestException exception)
                {
                    var message =
                        $"The Job Api has raised an internal server error when getting job for Ukprn: {ukprn} with JobId: {jobId} which needs to be followed up with DCT.";
                    throw new HttpRequestException(message, exception);
                }

                if (status.Status == JobStatusType.Waiting ||
                    status.Status == JobStatusType.Completed)
                {
                    completed = true;
                    result    = status;
                    if (secondStageRequired)
                    {
                        await jobService.UpdateJobStatus(jobId, JobStatusType.Ready);
                    }
                }
                else if (status.Status == JobStatusType.Failed ||
                         status.Status == JobStatusType.FailedRetry)
                {
                    completed = true;
                    result    = status;
                }
                else
                {
                    await Task.Delay(configuration.DcJobEventCheckDelay);
                }
            }

            return(result);
        }
        public void CreateMessageParameters_Success()
        {
            var job = new FileUploadJob()
            {
                JobType = JobType.IlrSubmission,
                JobId   = 10
            };

            var factory = GetFactory(false, job);

            MessageParameters result = new JoinableTaskContext().Factory.Run(() => factory.CreateMessageParametersAsync(It.IsAny <long>()));

            result.Should().NotBeNull();
            result.JobType.Should().Be(JobType.IlrSubmission);
            result.JobContextMessage.JobId.Should().Be(10);
            result.SubscriptionLabel.Should().Be("A");
            result.JobContextMessage.Topics[0].SubscriptionName.Should().Be("A");
            result.JobContextMessage.Topics[0].SubscriptionSqlFilterValue.Should().Be("B");
            result.TopicParameters.ContainsKey("To").Should().Be(true);
        }
示例#23
0
        public async Task GetJob_Success()
        {
            var job = new FileUploadJob()
            {
                JobId    = 10,
                JobType  = EnumJobType.IlrSubmission,
                FileName = "test.xml"
            };

            var serializationServiceMock = new Mock <IJsonSerializationService>();

            serializationServiceMock.Setup(x => x.Deserialize <FileUploadJob>(string.Empty)).Returns(job);

            var submisisionService = GetService(null, serializationServiceMock.Object);
            var confirmation       = await submisisionService.GetJob(It.IsAny <long>(), It.IsAny <long>());

            confirmation.Should().NotBeNull();
            confirmation.FileName.Should().Be("test.xml");
            confirmation.JobType.Should().Be(EnumJobType.IlrSubmission);
            confirmation.JobId.Should().Be(10);
        }
示例#24
0
        public async Task <FileUploadJob> GetJobById(long jobId)
        {
            if (jobId == 0)
            {
                throw new ArgumentException("Job id can not be 0");
            }

            using (var context = _contextFactory())
            {
                var entity = await context.FileUploadJobMetaData.Include(x => x.Job).SingleOrDefaultAsync(x => x.JobId == jobId);

                if (entity == null)
                {
                    throw new ArgumentException($"Job id {jobId} does not exist");
                }

                var job = new FileUploadJob();
                JobConverter.Convert(entity, job);
                return(job);
            }
        }
示例#25
0
        public FileUploadConfirmationViewModel ConvertToViewModel(FileUploadJob job)
        {
            if (job?.JobId == 0)
            {
                return(null);
            }

            var localTime = _dateTimeProvider.ConvertUtcToUk(job.DateTimeSubmittedUtc);

            return(new FileUploadConfirmationViewModel()
            {
                FileName = job.FileName.FileNameWithoutUkprn(),
                JobId = job.JobId,
                PeriodName = string.Concat("R", job.PeriodNumber.ToString("00")),
                SubmittedAtDate = localTime.ToString("dddd dd MMMM yyyy"),
                SubmittedAtDateTime = string.Concat(localTime.ToString("h:mmtt").ToLower(), " on ", localTime.ToString("dddd dd MMMM yyyy")),
                SubmittedBy = job.SubmittedBy,
                HeaderMessage = GetHeader(job.JobType, job.PeriodNumber),
                JobType = job.JobType,
                CollectionName = job.CollectionName,
            });
        }
示例#26
0
        public async Task <FileUploadJob> GetLatestJobByUkprnAndContractReference(long ukprn, string contractReference,
                                                                                  string collectionName)
        {
            var result = new FileUploadJob();
            var fileNameSearchQuery = $"{ukprn}/SUPPDATA-{ukprn}-{contractReference}-";

            using (var context = _contextFactory())
            {
                var entity = await context.FileUploadJobMetaData
                             .Include(x => x.Job)
                             .Where(
                    x => x.Ukprn == ukprn &&
                    x.CollectionName.Equals(collectionName, StringComparison.CurrentCultureIgnoreCase) &&
                    x.FileName.StartsWith(fileNameSearchQuery))
                             .OrderByDescending(x => x.Job.DateTimeSubmittedUtc)
                             .FirstOrDefaultAsync();

                JobConverter.Convert(entity, result);
            }

            return(result);
        }
示例#27
0
        public void PostJob_NewJob_Success_Test()
        {
            var job = new FileUploadJob
            {
                Status      = JobStatusType.Ready,
                SubmittedBy = "test",
                JobType     = JobType.IlrSubmission,
                JobId       = 0,
                Ukprn       = 1000,
                FileName    = "test",
            };

            var jobqueMetaServiceMock = new Mock <IFileUploadJobManager>();

            jobqueMetaServiceMock.Setup(x => x.AddJob(job)).Returns(1);

            var controller = GetController(null, jobqueMetaServiceMock.Object);

            var result = (OkObjectResult)controller.Post(job);

            result.StatusCode.Should().Be(200);
            result.Value.Should().Be(1);
        }
示例#28
0
        public static void Convert(FileUploadJob source, FileUploadJobMetaData destination)
        {
            if (source == null)
            {
                return;
            }

            if (destination == null)
            {
                destination = new FileUploadJobMetaData();
            }

            destination.FileName         = source.FileName;
            destination.FileSize         = source.FileSize;
            destination.StorageReference = source.StorageReference;
            destination.JobId            = source.JobId;
            destination.IsFirstStage     = source.IsFirstStage;
            destination.CollectionName   = source.CollectionName;
            destination.PeriodNumber     = source.PeriodNumber;
            destination.Ukprn            = source.Ukprn;
            destination.TermsAccepted    = source.TermsAccepted;
            destination.CollectionYear   = source.CollectionYear;
        }
示例#29
0
        public override void ExecuteCmdlet()
        {
            // Step 1: Validate source file.
            FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.Source));

            if (!localFile.Exists)
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.Source));
            }

            // Step 2: Build the CloudFile object which pointed to the
            // destination cloud file.
            this.RunTask(async taskId =>
            {
                bool isDirectory;
                string[] path             = NamingUtil.ValidatePath(this.Path, out isDirectory);
                var cloudFileToBeUploaded = await this.BuildCloudFileInstanceFromPathAsync(localFile.Name, path, isDirectory);

                var uploadJob = new FileUploadJob()
                {
                    SourcePath = localFile.FullName,
                    DestFile   = cloudFileToBeUploaded,
                };

                var progressRecord = new ProgressRecord(
                    this.OutputStream.GetProgressId(taskId),
                    string.Format(CultureInfo.CurrentCulture, Resources.SendAzureFileActivity, localFile.Name, cloudFileToBeUploaded.GetFullPath(), cloudFileToBeUploaded.Share.Name),
                    Resources.PrepareUploadingFile);

                await this.RunTransferJob(uploadJob, progressRecord);

                if (this.PassThru)
                {
                    this.OutputStream.WriteObject(taskId, cloudFileToBeUploaded);
                }
            });
        }
        string getJobId(string result)
        {
            FileUploadJob jobresult = JsonConvert.DeserializeObject <FileUploadJob>(result);

            return(jobresult.jobId);
        }
        public override void ExecuteCmdlet()
        {
            // Step 1: Validate source file.
            FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.Source));
            if (!localFile.Exists)
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.Source));
            }

            // Step 2: Build the CloudFile object which pointed to the
            // destination cloud file.
            this.RunTask(async taskId =>
            {
                bool isDirectory;
                string[] path = NamingUtil.ValidatePath(this.Path, out isDirectory);
                var cloudFileToBeUploaded = await this.BuildCloudFileInstanceFromPathAsync(localFile.Name, path, isDirectory);

                var uploadJob = new FileUploadJob()
                {
                    SourcePath = localFile.FullName,
                    DestFile = cloudFileToBeUploaded,
                };

                var progressRecord = new ProgressRecord(
                    this.OutputStream.GetProgressId(taskId),
                    string.Format(CultureInfo.CurrentCulture, Resources.SendAzureFileActivity, localFile.Name, cloudFileToBeUploaded.GetFullPath(), cloudFileToBeUploaded.Share.Name),
                    Resources.PrepareUploadingFile);

                await this.RunTransferJob(uploadJob, progressRecord);

                if (this.PassThru)
                {
                    this.OutputStream.WriteObject(taskId, cloudFileToBeUploaded);
                }
            });
        }