Example #1
0
        public static async Task <PreLoadPaymentMessage> Run(
            [QueueTrigger(QueueNames.PreLoadEarningDetailsPayment)] PreLoadPaymentMessage message,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            return(await FunctionRunner.Run <GetEarningDetailsFunction, PreLoadPaymentMessage>(writer, executionContext,
                                                                                               async (container, logger) => {
                // Get ALL EarningDetails from Payment ProviderEventsAPI for a Employer and PeriodId
                logger.Info($"Running {nameof(GetEarningDetailsFunction)} {message.EmployerAccountId}. {message.PeriodId}");

                var paymentDataService = container.GetInstance <PaymentApiDataService>();
                var hashingService = container.GetInstance <IHashingService>();
                var dataService = container.GetInstance <PreLoadPaymentDataService>();

                var earningDetails = await paymentDataService.PaymentForPeriod(message.PeriodId, message.EmployerAccountId);

                var hashedAccountId = hashingService.HashValue(message.EmployerAccountId);
                logger.Info($"Found {earningDetails.Count} for Account: {hashedAccountId}");

                foreach (var item in earningDetails)
                {
                    await dataService.StoreEarningDetails(message.EmployerAccountId, item);
                }

                logger.Info($"Sending message {nameof(message)} to {QueueNames.CreatePaymentMessage}");
                return message;
            }));
        }
Example #2
0
        public static async Task Run(
            [QueueTrigger(QueueNames.RefreshApprenticeshipsForEmployer)] RefreshApprenticeshipForAccountMessage message,
            [Queue(QueueNames.StoreApprenticeships)] ICollector <ApprenticeshipMessage> outputQueueMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            await FunctionRunner.Run <GetApprenticeshipsForEmployer>(writer, executionContext,
                                                                     async (container, logger) =>
            {
                logger.Debug($"Getting apprenticeships for employer {message.EmployerId}...");
                var employerCommitmentsApi   = container.GetInstance <IEmployerCommitmentApi>();
                var apprenticeshipValidation = new ApprenticeshipValidation();
                var mapper = new Mapper(container.GetInstance <IApprenticeshipCourseDataService>());

                var apprenticeships = await GetApprenticeshipsForAccount(message.EmployerId, employerCommitmentsApi);

                IEnumerable <long> failedValidation;

                (apprenticeships, failedValidation) = apprenticeshipValidation.BusinessValidation(apprenticeships);
                logger.Info($"{failedValidation.Count()} apprenticeships failed business validation");

                (apprenticeships, failedValidation) = apprenticeshipValidation.InputValidation(apprenticeships);
                logger.Info($"{failedValidation.Count()} apprenticeships failed input validation");

                var mappedApprenticeships = apprenticeships.Select(mapper.Map).ToList();

                logger.Info($"Sending {mappedApprenticeships.Count} apprenticeships for storing. EmployerId: {message.EmployerId} ");

                foreach (var apprenticeship in mappedApprenticeships)
                {
                    outputQueueMessage.Add(await apprenticeship);
                }
            });
        }
Example #3
0
        public static async Task <string> Run(
            [HttpTrigger(AuthorizationLevel.Function,
                         "post", Route = "AllLevyDeclarationsPreLoadHttpFunction")] HttpRequestMessage req,
            [Queue(QueueNames.LevyPreLoadRequest)] ICollector <PreLoadRequest> outputQueueMessage,
            ExecutionContext executionContext,
            TraceWriter writer
            )
        {
            return(await FunctionRunner.Run <AllLevyDeclarationsPreLoadHttpFunction, string>(writer, executionContext,
                                                                                             async (container, logger) =>
            {
                var body = await req.Content.ReadAsStringAsync();
                var preLoadRequest = JsonConvert.DeserializeObject <PreLoadAllEmployersRequest>(body);

                var levyDataService = container.GetInstance <IEmployerDataService>();
                var hashingService = container.GetInstance <IHashingService>();

                var employerIds = await levyDataService.GetAllAccounts();

                logger.Info($"Found {employerIds.Count} employer(s) for period; Year: {preLoadRequest.PeriodYear} Month: {preLoadRequest.PeriodMonth}");

                foreach (var id in employerIds)
                {
                    outputQueueMessage.Add(
                        new PreLoadRequest
                    {
                        EmployerAccountIds = new[] { hashingService.HashValue(id) },
                        PeriodYear = preLoadRequest.PeriodYear,
                        PeriodMonth = preLoadRequest.PeriodMonth,
                    });
                }

                return $"Created {employerIds.Count} {nameof(PreLoadRequest)} messages";
            }));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            await FunctionRunner.Run <InitialiseFunction>(log, async (container, logger) =>
            {
                log.Info("Initialising the Levy functions.");

                var functions = Assembly.GetExecutingAssembly()
                                .GetExportedTypes()
                                .Where(type => !type.IsAbstract && type.IsClass && typeof(IFunction).IsAssignableFrom(type))
                                .ToList();

                foreach (var function in functions)
                {
                    var triggerAttribute = function.GetMethods(BindingFlags.Public | BindingFlags.Static)
                                           .SelectMany(method => method.GetParameters())
                                           .SelectMany(paramInfo => paramInfo.GetCustomAttributes(typeof(QueueTriggerAttribute)))
                                           .Cast <QueueTriggerAttribute>()
                                           .FirstOrDefault();

                    if (triggerAttribute == null)
                    {
                        log.Verbose("No QueueTrigger found.");
                        continue;
                    }

                    logger.Debug($"Now creating queue: {triggerAttribute.QueueName}");
                    var configuration = container.GetInstance <IApplicationConfiguration>();
                    var client        = CloudStorageAccount.Parse(configuration.StorageConnectionString).CreateCloudQueueClient();
                    var queue         = client.GetQueueReference(triggerAttribute.QueueName);
                    await queue.CreateIfNotExistsAsync();
                }
            });

            return(req.CreateResponse(HttpStatusCode.OK));
        }
Example #5
0
        public static async Task <GenerateAccountProjectionCommand> Run(
            [QueueTrigger(QueueNames.AllowProjection)] LevySchemeDeclarationUpdatedMessage message,
            TraceWriter writer, ExecutionContext executionContext)
        {
            return(await FunctionRunner.Run <LevyDeclarationAllowProjectionFunction, GenerateAccountProjectionCommand>(writer, executionContext,
                                                                                                                       async (container, logger) =>
            {
                logger.Debug("Getting levy declaration handler from container.");
                var handler = container.GetInstance <AllowAccountProjectionsHandler>();
                if (handler == null)
                {
                    throw new InvalidOperationException("Faild to get levy handler from container.");
                }
                var allowProjections = await handler.Allow(message);
                if (!allowProjections)
                {
                    logger.Debug($"Cannot generate the projections, still handling levy declarations. Employer: {message.AccountId}");
                    return null;
                }

                logger.Info($"Now sending message to trigger the account projections for employer '{message.AccountId}'");
                return new GenerateAccountProjectionCommand
                {
                    EmployerAccountId = message.AccountId,
                    ProjectionSource = ProjectionSource.LevyDeclaration
                };
            }));
        }
        public static async Task Run(
            [QueueTrigger(QueueNames.RefreshEmployersForApprenticeshipUpdate)] string message,
            [Queue(QueueNames.RefreshApprenticeshipsForEmployer)] ICollector <RefreshApprenticeshipForAccountMessage> updateApprenticeshipForAccountOutputMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            await FunctionRunner.Run <RefreshEmployersForApprenticeshipUpdate, string>(writer, executionContext,
                                                                                       async (container, logger) =>
            {
                logger.Debug("Getting all employer ids...");
                var employerCommitmentsApi = container.GetInstance <IEmployerCommitmentApi>();
                var allEmployerIds         = await employerCommitmentsApi.GetAllEmployerAccountIds();

                var count = 0;
                foreach (var id in allEmployerIds)
                {
                    count++;
                    updateApprenticeshipForAccountOutputMessage.Add(new RefreshApprenticeshipForAccountMessage
                    {
                        EmployerId = id
                    });
                }
                var msg = $"Added {count} employer id messages to the queue {nameof(QueueNames.RefreshApprenticeshipsForEmployer)}.";
                logger.Info(msg);
                return(msg);
            });
        }
        public static async Task <PreLoadPaymentMessage> Run(
            [QueueTrigger(QueueNames.CreatePaymentMessageNoCommitment)] PreLoadPaymentMessage message,
            [Queue(QueueNames.PaymentValidatorNoCommitment)] ICollector <PaymentCreatedMessage> noCommitmentOutputQueueMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            return(await FunctionRunner.Run <CreatePaymentMessageNoCommitmentFunction, PreLoadPaymentMessage>(writer, executionContext,
                                                                                                              async (container, logger) =>
            {
                logger.Info($"{nameof(CreatePaymentMessageFunction)} started");

                var dataService = container.GetInstance <IEmployerDatabaseService>();

                var payments = await dataService.GetPastEmployerPayments(message.EmployerAccountId, message.PeriodYear, message.PeriodMonth);

                logger.Info($"Got {payments.Count} payments for employer '{message.EmployerAccountId}'");


                var paymentNoCommitmentCreatedMessage =
                    payments
                    .Select(p => CreatePayment(logger, p))
                    .Where(p => p != null)
                    .ToList();


                foreach (var p in paymentNoCommitmentCreatedMessage)
                {
                    noCommitmentOutputQueueMessage.Add(p);
                }

                logger.Info($"{nameof(CreatePaymentMessageNoCommitmentFunction)} finished, Past payments created: {paymentNoCommitmentCreatedMessage.Count}");

                return message;
            }));
        }
Example #8
0
        public static async Task <string> Run(
            [HttpTrigger(AuthorizationLevel.Function,
                         "post", Route = "PaymentPreLoadHttpFunction")] HttpRequestMessage req,
            [Queue(QueueNames.PreLoadPayment)] ICollector <PreLoadPaymentMessage> outputQueueMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            // Creates a msg for each EmployerAccountId
            return(await FunctionRunner.Run <PaymentPreLoadHttpFunction, string>(writer, executionContext,
                                                                                 async (container, logger) =>
            {
                var body = await req.Content.ReadAsStringAsync();
                var preLoadRequest = JsonConvert.DeserializeObject <PreLoadPaymentRequest>(body);

                if (preLoadRequest == null)
                {
                    logger.Warn($"{nameof(PreLoadPaymentRequest)} not valid. Function will exit.");
                    return "";
                }

                logger.Info($"{nameof(PaymentPreLoadHttpFunction)} started. Data: {string.Join("|", preLoadRequest.EmployerAccountIds)}, {preLoadRequest.PeriodYear}, {preLoadRequest.PeriodMonth}");

                if (preLoadRequest.SubstitutionId != null && preLoadRequest.EmployerAccountIds.Count() != 1)
                {
                    var msg = $"If {nameof(preLoadRequest.SubstitutionId)} is provded there may only be 1 EmployerAccountId.";
                    logger.Warn(msg);
                    return msg;
                }

                var hashingService = container.GetInstance <IHashingService>();

                foreach (var hashedAccountId in preLoadRequest.EmployerAccountIds)
                {
                    var accountId = hashingService.DecodeValue(hashedAccountId);
                    outputQueueMessage.Add(
                        new PreLoadPaymentMessage
                    {
                        EmployerAccountId = accountId,
                        HashedEmployerAccountId = hashedAccountId,
                        PeriodYear = preLoadRequest.PeriodYear,
                        PeriodMonth = preLoadRequest.PeriodMonth,
                        PeriodId = preLoadRequest.PeriodId,
                        SubstitutionId = preLoadRequest.SubstitutionId
                    }
                        );
                }

                if (preLoadRequest.SubstitutionId.HasValue)
                {
                    var hashedSubstitutionId = hashingService.HashValue(preLoadRequest.SubstitutionId.Value);
                    return $"HashedDubstitutionId: {hashedSubstitutionId}";
                }

                logger.Info($"Added {preLoadRequest.EmployerAccountIds.Count()} get payment messages to {QueueNames.PreLoadPayment} queue.");
                return $"Message added: {preLoadRequest.EmployerAccountIds.Count()}";
            }));
        }
 public static async Task <LevySchemeDeclarationUpdatedMessage> Run(
     [ServiceBusTrigger("LevyPeriod", "mysubscription", AccessRights.Manage)] LevySchemeDeclarationUpdatedMessage levySchemeUpdatedMessage,
     TraceWriter writer)
 {
     return(await FunctionRunner.Run <LevyDeclarationEventValidatorFunction, LevySchemeDeclarationUpdatedMessage>(writer,
                                                                                                                  async (container, logger) =>
     {
         logger.Info($"Added {nameof(LevySchemeDeclarationUpdatedMessage)} to queue: {QueueNames.ValidateDeclaration},  for EmployerAccountId: {levySchemeUpdatedMessage?.AccountId}");
         return await Task.FromResult(levySchemeUpdatedMessage);
     }));
 }
 public static async Task Run([QueueTrigger(QueueNames.StoreCourse)] ApprenticeshipCourse course,
                              TraceWriter log,
                              ExecutionContext executionContext)
 {
     await FunctionRunner.Run <StoreCourseFunction>(log, executionContext, async (container, logger) =>
     {
         logger.Debug("Received reques to store course");
         var handler = container.GetInstance <StoreCourseHandler>();
         await handler.Handle(course);
         log.Info("Finished handling the request to store the course.");
     });
 }
 public static async Task <PaymentCreatedMessage> Run(
     [ServiceBusTrigger("LevyPeriod", "mysubscription", AccessRights.Manage)] PaymentCreatedMessage paymentCreatedMessage,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     return(await FunctionRunner.Run <PaymentEventServiceBusFunction, PaymentCreatedMessage>(writer, executionContext,
                                                                                             async (container, logger) =>
     {
         logger.Info($"Added {nameof(PaymentCreatedMessage)} to queue: {QueueNames.PaymentValidator},  for EmployerAccountId: {paymentCreatedMessage?.EmployerAccountId}");
         return await Task.FromResult(paymentCreatedMessage);
     }));
 }
		public static async Task Run(
            [QueueTrigger(QueueNames.CommitmentProcessor)]PaymentCreatedMessage paymentCreatedMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            await FunctionRunner.Run<PaymentEventStoreCommitmentFunction>(writer, executionContext,
                async (container, logger) =>
                {
                    logger.Debug($"Storing commitment. Account: {paymentCreatedMessage.EmployerAccountId}, apprenticeship id: {paymentCreatedMessage.ApprenticeshipId}");
	                var handler = container.GetInstance<StoreCommitmentHandler>();
					await handler.Handle(paymentCreatedMessage, QueueNames.AllowProjection);
                    logger.Info($"Stored commitment. Apprenticeship id: {paymentCreatedMessage.ApprenticeshipId}");
                });
        }
Example #13
0
 public static RefreshCourses Run(
     [HttpTrigger(AuthorizationLevel.Function, "post", Route = "RefreshStandardsHttpFunction")] HttpRequestMessage req,
     TraceWriter writer, ExecutionContext executionContext)
 {
     return(FunctionRunner.Run <RefreshStandardsHttpFunction, RefreshCourses>(writer, executionContext,
                                                                              (container, logger) =>
     {
         logger.Info("Received refresh standards request.");
         return new RefreshCourses {
             RequestTime = DateTime.Now,
             CourseType = CourseType.Standards
         };
     }));
 }
Example #14
0
 public static async Task Run([QueueTrigger(QueueNames.GetCourses)] RefreshCourses message,
                              TraceWriter log,
                              [Queue(QueueNames.StoreCourse)] ICollector <ApprenticeshipCourse> storeCourses,
                              ExecutionContext executionContext)
 {
     await FunctionRunner.Run <GetCoursesFunction>(log, executionContext, async (container, logger) =>
     {
         logger.Debug("Starting GetCoursesFunction Function.");
         var handler = container.GetInstance <GetCoursesHandler>();
         var courses = await handler.Handle(message);
         courses.ForEach(storeCourses.Add);
         log.Info($"Finished getting courses. Got {courses.Count} courses.");
     });
 }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
                                                           ExecutionContext executionContext,
                                                           TraceWriter log)
        {
            await FunctionRunner.Run <InitialiseFunction>(log, executionContext, async (container, logger) =>
            {
                //TODO: create generic function or use custom binding
                log.Info("Initialising the Payments functions.");
                await container.GetInstance <IFunctionInitialisationService>().Initialise <InitialiseFunction>();
                log.Info("Finished initialising the Payments functions.");
            });

            return(req.CreateResponse(HttpStatusCode.OK));
        }
        public static async Task <LevySchemeDeclarationUpdatedMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "LevyDeclarationEventHttpFunction")] HttpRequestMessage req,
            TraceWriter writer, ExecutionContext executionContext)
        {
            return(await FunctionRunner.Run <LevyDeclarationEventHttpFunction, LevySchemeDeclarationUpdatedMessage>(writer, executionContext,
                                                                                                                    async (container, logger) =>
            {
                var body = await req.Content.ReadAsStringAsync();
                var levySchemeUpdatedEvent = JsonConvert.DeserializeObject <LevySchemeDeclarationUpdatedMessage>(body);

                logger.Debug($"Received levy scheme declaration event via http endpoint: {levySchemeUpdatedEvent.ToDebugJson()}");
                return levySchemeUpdatedEvent;
            }));
        }
 public static async Task Run(
     [QueueTrigger(QueueNames.PaymentNoCommitmentProcessor)] PaymentCreatedMessage paymentCreatedMessage,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     await FunctionRunner.Run <PaymentEventNoCommitmentStorePaymentFunction>(writer, executionContext,
                                                                             async (container, logger) =>
     {
         logger.Debug($"Storing the payment.  Employer: {paymentCreatedMessage.EmployerAccountId}, apprenticeship: {paymentCreatedMessage.ApprenticeshipId}.");
         var handler = container.GetInstance <ProcessEmployerPaymentHandler>();
         logger.Debug("Resolved handler");
         await handler.Handle(paymentCreatedMessage, string.Empty);
         logger.Info($"Finished storing payment. Employer: {paymentCreatedMessage.EmployerAccountId}, apprenticeship: {paymentCreatedMessage.ApprenticeshipId}.");
     });
 }
Example #18
0
        public static async Task <PaymentCreatedMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "EmployerPaymentEventHttpFunction")] HttpRequestMessage req,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            return(await FunctionRunner.Run <PaymentEventHttpFunction, PaymentCreatedMessage>(writer, executionContext,
                                                                                              async (container, logger) =>
            {
                var body = await req.Content.ReadAsStringAsync();
                var paymentEvent = JsonConvert.DeserializeObject <PaymentCreatedMessage>(body);

                logger.Info($"Added one payment to {QueueNames.PaymentProcessor} queue.");
                return await Task.FromResult(paymentEvent);
            }));
        }
 public static async Task Run(
     [QueueTrigger(QueueNames.StoreApprenticeships)] ApprenticeshipMessage message,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     await FunctionRunner.Run <StoreApprenticeships>(writer, executionContext,
                                                     async (container, logger) =>
     {
         logger.Debug($"Storing apprenticeship. Account: {message.EmployerAccountId}, apprenticeship id: {message.ApprenticeshipId}");
         var handler = container.GetInstance <StoreCommitmentHandler>();
         message.ProjectionSource = ProjectionSource.Commitment;
         await handler.Handle(message, QueueNames.AllowProjection);
         logger.Info($"Stored commitment. Apprenticeship id: {message.ApprenticeshipId}");
     });
 }
        public static async Task <string> Run(
            [HttpTrigger(AuthorizationLevel.Function,
                         "post", Route = "RefreshApprenticeshipHttpTrigger")] HttpRequestMessage req,
            [Queue(QueueNames.RefreshEmployersForApprenticeshipUpdate)] ICollector <string> message,
            ExecutionContext executionContext,
            TraceWriter writer)

        {
            return(FunctionRunner.Run <RefreshApprenticeshipsForEmployerHttpFunction, string>(writer, executionContext,
                                                                                              (container, logger) =>
            {
                logger.Debug("Triggering run of refresh apprenticeships for employers.");
                message.Add("RefreshApprenticeshipsForEmployerHttp");
                return "Triggering run of refresh apprenticeships for employers.";
            }));
        }
        public static async Task <RefreshCourses> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "RefreshCoursesHttpFunction")] HttpRequestMessage req,
            TraceWriter writer, ExecutionContext executionContext)
        {
            return(await FunctionRunner.Run <RefreshCoursesHttpFunction, RefreshCourses>(writer, executionContext,
                                                                                         async (container, logger) =>
            {
                var body = await req.Content.ReadAsStringAsync();
                var msg = JsonConvert.DeserializeObject <RefreshMessage>(body);

                logger.Info($"Received refresh for {msg.CourseType} request.");
                return new RefreshCourses {
                    RequestTime = DateTime.Now,
                    CourseType = msg.CourseType
                };
            }));
        }
Example #22
0
        public static async Task Run(
            [QueueTrigger(QueueNames.RemovePreLoadData)] PreLoadPaymentMessage message,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            await FunctionRunner.Run <DeletePaymentMessageFunction>(writer, executionContext,
                                                                    async (container, logger) =>
            {
                logger.Info($"{nameof(DeletePaymentMessageFunction)} started for account: {message.HashedEmployerAccountId}");
                var dataService = container.GetInstance <PreLoadPaymentDataService>();

                await dataService.DeletePayment(message.EmployerAccountId);
                await dataService.DeleteEarningDetails(message.EmployerAccountId);

                logger.Info($"{nameof(DeletePaymentMessageFunction)} finished for account: {message.HashedEmployerAccountId}.");
            });
        }
Example #23
0
 public static async Task Run(
     [QueueTrigger(QueueNames.StoreLevyDeclarationNoProjection)] LevySchemeDeclarationUpdatedMessage levySchemeUpdatedMessage, ExecutionContext executionContext,
     TraceWriter writer)
 {
     await FunctionRunner.Run <LevyDeclarationEventNoProjectionStoreFunction>(writer, executionContext,
                                                                              async (container, logger) =>
     {
         logger.Debug("Getting levy declaration handler from container.");
         var handler = container.GetInstance <StoreLevyDeclarationHandler>();
         if (handler == null)
         {
             throw new InvalidOperationException($"Failed to get levy handler from container.");
         }
         await handler.Handle(levySchemeUpdatedMessage, string.Empty);
         logger.Info($"Finished handling past levy declaration for EmployerAccountId: {levySchemeUpdatedMessage.AccountId}, PayrollYear: {levySchemeUpdatedMessage.PayrollYear}, month: {levySchemeUpdatedMessage.PayrollMonth}, scheme: {levySchemeUpdatedMessage.EmpRef}");
     });
 }
 public static async Task Run(
     [QueueTrigger(QueueNames.BuildProjections)] GenerateAccountProjectionCommand message,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     await FunctionRunner.Run <GenerateProjectionsFunction>(writer, executionContext, async (container, logger) =>
     {
         logger.Debug("Resolving BuildAccountProjectionHandler from container.");
         var handler = container.GetInstance <BuildAccountProjectionHandler>();
         if (handler == null)
         {
             throw new InvalidOperationException("Failed to resolve BuildAccountProjectionHandler from container.");
         }
         await handler.Handle(message);
         logger.Info($"Finished building the account projection for employer: {message.EmployerAccountId}");
     });
 }
 public static async Task <RefreshCourses> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
                                               ExecutionContext executionContext,
                                               TraceWriter log)
 {
     return(await FunctionRunner.Run <InitialiseFunction, RefreshCourses>(log, executionContext, async (container, logger) =>
     {
         //TODO: create generic function or use custom binding
         log.Info("Initialising the Apprenticeship Courses function application.");
         await container.GetInstance <IFunctionInitialisationService>()
         .Initialise <InitialiseFunction>();
         log.Info("Finished initialising the Apprenticeship Courses function application.");
         return new RefreshCourses {
             RequestTime = DateTime.Now,
             CourseType = CourseType.Standards | CourseType.Frameworks
         };
     }));
 }
Example #26
0
 public static async Task <GenerateAccountProjectionCommand> Run(
     [QueueTrigger(QueueNames.GetAccountBalance)] GenerateAccountProjectionCommand message,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     return(await FunctionRunner.Run <GetAccountBalanceFunction, GenerateAccountProjectionCommand>(writer, executionContext, async (container, logger) =>
     {
         logger.Debug("Resolving GetAccountBalanceHandler from container.");
         var handler = container.GetInstance <GetAccountBalanceHandler>();
         if (handler == null)
         {
             throw new InvalidOperationException("Failed to resolve GetAccountBalanceHandler from container.");
         }
         await handler.Handle(message);
         logger.Info($"Finished generating the account projection in response to payment run: {message.EmployerAccountId}");
         return message;
     }));
 }
Example #27
0
        public static LevySchemeDeclarationUpdatedMessage Run(
            [QueueTrigger(QueueNames.ValidateLevyDeclarationNoProjection)] LevySchemeDeclarationUpdatedMessage message,
            TraceWriter writer, ExecutionContext executionContext)
        {
            return(FunctionRunner.Run <LevyDeclarationEventNoProjectionValidatorFunction, LevySchemeDeclarationUpdatedMessage>(writer, executionContext,
                                                                                                                               (container, logger) =>
            {
                var validationResults = container.GetInstance <LevyDeclarationEventValidator>()
                                        .Validate(message);
                if (!validationResults.IsValid)
                {
                    logger.Warn($"Past levy declaration event failed superficial validation. Employer id: {message.AccountId}, Period: {message.PayrollMonth}, {message.PayrollYear}, Scheme: {message.EmpRef}.");
                    return null;
                }

                logger.Info($"Validated {nameof(LevySchemeDeclarationUpdatedMessage)} for EmployerAccountId: {message.AccountId}");
                return message;
            }));
        }
        public static PreLoadPaymentMessage Run(
            [QueueTrigger(QueueNames.CreatePaymentMessage)] PreLoadPaymentMessage message,
            [Queue(QueueNames.PaymentValidator)] ICollector <PaymentCreatedMessage> outputQueueMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            return(FunctionRunner.Run <CreatePaymentMessageFunction, PreLoadPaymentMessage>(writer, executionContext,
                                                                                            (container, logger) =>
            {
                logger.Info($"{nameof(CreatePaymentMessageFunction)} started");

                var dataService = container.GetInstance <PreLoadPaymentDataService>();
                var payments = dataService.GetPayments(message.EmployerAccountId).ToList();
                var earningDetails = dataService.GetEarningDetails(message.EmployerAccountId).ToList();
                logger.Info($"Got {payments.Count()} payments to match against {earningDetails.Count} earning details for employer '{message.EmployerAccountId}'");
                List <PaymentCreatedMessage> paymentCreatedMessage;
                if (message.SubstitutionId != null)
                {
                    paymentCreatedMessage =
                        payments
                        .Select(p => CreatePaymentSubstituteData(logger, p, earningDetails, message.SubstitutionId.Value))
                        .Where(p => p != null)
                        .ToList();
                }
                else
                {
                    paymentCreatedMessage =
                        payments
                        .Select(p => CreatePayment(logger, p, earningDetails))
                        .Where(p => p != null)
                        .ToList();
                }

                foreach (var p in paymentCreatedMessage)
                {
                    outputQueueMessage.Add(p);
                }

                logger.Info($"{nameof(CreatePaymentMessageFunction)} finished, Payments created: {paymentCreatedMessage.Count}");

                return message;
            }));
        }
        public static PaymentCreatedMessage Run(
            [QueueTrigger(QueueNames.PaymentValidatorNoCommitment)] PaymentCreatedMessage paymentCreatedMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            return(FunctionRunner.Run <PaymentEventNoCommitmentValidatorFunction, PaymentCreatedMessage>(writer, executionContext, (container, logger) =>
            {
                var validationResults = container.GetInstance <PastPaymentEventSuperficialValidator>().Validate(paymentCreatedMessage);

                if (!validationResults.IsValid)
                {
                    logger.Warn($"Past payment event failed superficial validation. Employer: {paymentCreatedMessage.EmployerAccountId} apprenticeship: {paymentCreatedMessage.ApprenticeshipId}, Errors:{validationResults.ToJson()}");
                    return null;
                }

                logger.Info($"Validated past {nameof(PaymentCreatedMessage)} for EmployerAccountId: {paymentCreatedMessage.EmployerAccountId} fundingSource:{paymentCreatedMessage.FundingSource}");

                return paymentCreatedMessage;
            }));
        }
Example #30
0
        public static async Task <string> Run(
            [HttpTrigger(AuthorizationLevel.Function,
                         "post", Route = "LevyDeclarationNoProjectionPreLoadHttpFunction")] HttpRequestMessage req,
            [Queue(QueueNames.LevyPreLoadRequestNoProjection)] ICollector <PreLoadRequest> outputQueueMessage,
            ExecutionContext executionContext,
            TraceWriter writer)
        {
            return(await FunctionRunner.Run <LevyDeclarationNoProjectionPreLoadHttpFunction, string>(writer, executionContext,
                                                                                                     async (container, logger) =>
            {
                var body = await req.Content.ReadAsStringAsync();
                var preLoadRequest = JsonConvert.DeserializeObject <PreLoadRequest>(body);

                outputQueueMessage.Add(preLoadRequest);

                var msg = $"Added {nameof(PreLoadRequest)} for levy declaration";
                logger.Info(msg);
                return msg;
            }));
        }