Beispiel #1
0
        public async Task Execute(SQSEvent sqsEvent)
        {
            Console.WriteLine("Received message from SQS");
            // expected Records count = 1, per batchSize configured in serverless.yml
            // Messages will be removed from the queue upon successful response of this lambda.
            // If no successful response within 30sec then they will be available to pick up from the queue again.

            Console.WriteLine("Getting document configuration");
            var documentConfig     = ParsingHelpers.GetDocumentConfig();
            var automaticApprovals = documentConfig.AutomaticApprovals;

            var record    = sqsEvent.Records.First();
            var timestamp = record.Body;

            Console.WriteLine($"Received from queue [{record.EventSourceArn}] document timestamp = {timestamp}");

            var document = await _getDocumentDetails.Execute(timestamp);

            Console.WriteLine($"Received Document {JsonConvert.SerializeObject(document)}");

            if (document == null)
            {
                Console.WriteLine($"Could not find document for ID {timestamp} waiting to be processed in Dynamo");
                return;
            }

            await _logger.LogMessage(timestamp, "Picked up document from queue - Processing");

            Console.WriteLine($"Retrieved from dynamo, getting Html for documentId = {document.CominoDocumentNumber}");

            var html = await TryGetDocumentAsHtml(document, timestamp);

            Console.WriteLine($"Received HTML: {(html == null ? "" : (html.Length < 100 ? html : html.Substring(0, 100)))}");

            await TryConvertToPdf(html, document, timestamp);
            await TryStoreInS3(document, timestamp);

            if (automaticApprovals != null && automaticApprovals.Contains(document.LetterType))
            {
                await _localDatabaseGateway.UpdateStatus(document.Id, LetterStatusEnum.ReadyForGovNotify);
            }
            else
            {
                await _localDatabaseGateway.UpdateStatus(document.Id, LetterStatusEnum.WaitingForApproval);
            }
        }
Beispiel #2
0
        public List <DocumentDetails> GetDocumentsAfterStartDate(DateTime time)
        {
            var documentConfig = ParsingHelpers.GetDocumentConfig();
            var categories     = documentConfig.Categories;
            var descriptions   = documentConfig.Descriptions;
            var startTime      = $"{time.Month}/{time.Day}/{time.Year} {time.Hour}:{time.Minute}:{time.Second}";

            var query =
                $@"SELECT DocNo AS DocumentNumber,
                StoreDate AS Date,
                strDescription AS LetterType,
                strUser AS UserName,
                RefType AS DocumentType
                FROM W2BatchPrint
                JOIN CCDocument on DocNo = nDocNo
                WHERE CCDocument.DocCategory IN ('{string.Join("','", categories)}')
                AND CCDocument.DocDesc IN ('{string.Join("','", descriptions)}')
                AND CCDocument.DirectionFg = 'O'
                AND CCDocument.DocSource = 'O'
                AND W2BatchPrint.StoreDate > '{startTime}'
                ORDER BY W2BatchPrint.StoreDate DESC;
                ";

            List <DocumentDetails> queryResults;

            try
            {
                queryResults = _database.Query <W2BatchPrintRow>(query).Select(row =>
                                                                               new DocumentDetails {
                    Id = row.Date.ToString("O"),
                    CominoDocumentNumber = row.DocumentNumber,
                    DocumentCreator      = row.UserName,
                    LetterType           = row.LetterType,
                    DocumentType         = row.DocumentType,
                    Date = row.Date.ToString("O")
                }).ToList();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(queryResults);
        }