Esempio n. 1
0
        private string GetSQLQueryForReporting(ReportingEvent reportingEvent)
        {
            string startDate = string.Format("{0:s}", reportingEvent.StartDate.AddDays(-1).ToUniversalTime());

            var queryBuilder = new StringBuilder();

            queryBuilder.Append("SELECT * FROM c WHERE");
            queryBuilder.Append("((c.EffectiveInterval.Start between '" + startDate + "' AND '" + reportingEvent.EndDateFormat + "') OR ");
            queryBuilder.Append("(c.EffectiveInterval.Start < '" + reportingEvent.StartDateFormat + "' AND (IS_NULL(c.EffectiveInterval['End']) OR  c.EffectiveInterval['End'] >='" + reportingEvent.StartDateFormat + "'))");
            queryBuilder.Append(")");
            queryBuilder.Append(" AND c.Permission.Application = '" + reportingEvent.Application + "'");
            if (!string.IsNullOrWhiteSpace(reportingEvent.Target.Context))
            {
                queryBuilder.Append($@"AND c.TargetPerson.Key.Context = ""{reportingEvent.Target.Context}""");
                queryBuilder.Append($@"AND c.TargetPerson.Key.Id = ""{reportingEvent.Target.Id}""");
            }
            else if (!string.IsNullOrWhiteSpace(reportingEvent.Source.Context))
            {
                queryBuilder.Append($@"AND c.User.Key.Context = ""{reportingEvent.Source.Context}""");
                queryBuilder.Append($@"AND c.User.Key.Id = ""{reportingEvent.Source.Id}""");
            }
            queryBuilder.Append($@"AND c.TenantId = ""{reportingEvent.TenantId}""");
            queryBuilder.Append($@"AND c.Permission.Id IN ({ "\"" + string.Join("\", \"", reportingEvent.Permissions) + "\""})");
            return(queryBuilder.ToString());
        }
 public static FileInformation Get(ReportingEvent reportingEvent, Uri url, string hash, string status)
 {
     return(new FileInformation
     {
         FileName = reportingEvent.FileName,
         FileNameTimeStamp = reportingEvent.FileNameTimeStamp,
         Url = url.ToString(),
         PartitionKey = reportingEvent.TenantId,
         RowKey = reportingEvent.Guid,
         Hash = hash,
         Status = status
     });
 }
        public void GenerateReport_ReportingEventDto_ValidationIsFailed_WhenAllApplicationNameNotProvided()
        {
            CheckPropertyValidation cpv = new CheckPropertyValidation();
            var request    = new ReportingEvent();
            var errorCount = cpv.myValidation(request);

            AreEqual((errorCount.Count), 5);
            AreEqual(errorCount.ToList()[0].ErrorMessage, "The Application field is required.");
            AreEqual(errorCount.ToList()[1].ErrorMessage, "The Permissions field is required.");
            AreEqual(errorCount.ToList()[2].ErrorMessage, "The EndDate field is required.");
            AreEqual(errorCount.ToList()[3].ErrorMessage, "The FileName field is required.");
            AreEqual(errorCount.ToList()[4].ErrorMessage, "The TenantId field is required.");
        }
        public async Task <GenerateReport> InsertAndTriggerGenerateReport(ReportingEvent reportingEventDto)
        {
            var reportingEvent = DomainAdapter.MapReportingEvent(reportingEventDto);

            _logger.LogInformation("Inserting record to the FileInformation Table");
            await _fileInformationRepository.UpdateRecord(FileInformation.Get(reportingEvent, new Uri("https://raetgdprtbldev.blob.core.windows.net"), "HashProcessing", "Processing"));

            string message = JsonConvert.SerializeObject(reportingEvent);

            _logger.LogInformation("Adding message to report-file-queue");
            _azureQueueStorageRepository.AddAsync(message);
            return(new GenerateReport()
            {
                FileName = reportingEvent.FileName, Guid = reportingEvent.Guid
            });
        }
        public async Task GenerateReport_TestAsync()
        {
            //Arrange

            _blobStorageSettingsMock.SetupProperty(e => e.MaxDataLimitForBlob, "100");

            _reportingBusiness = new ReportingBusiness(_reportingStorageMock.Object, _azureBlobStorageRepMock.Object,
                                                       _azureTableStorageRepMock.Object, _checkSumGeneratorMock.Object, _blobStorageSettingsMock.Object, _azureQueueStoragerRepMock.Object, _logger.Object);

            _reportingEvent = new ReportingEvent()
            {
                FileName = "TestFile"
            };


            //Register Mapper
            Mapper.Initialize(cfg =>
            {
                cfg.AddProfile <EffectiveIntervalCSVMapperProfile>();
            });

            _mapperMock.Setup(e =>
                              e.Map <IList <EffectiveAuthorizationInterval>, List <EffectiveIntervalCSVMapper> >(
                                  Generator.GenerateEffectiveAuthorizationIntervals()))
            .Returns(It.IsAny <List <EffectiveIntervalCSVMapper> >());

            _reportingStorageMock.Setup(e => e.FetchReportingData(It.IsAny <ReportingEvent>()))
            .ReturnsAsync(Generator.GenerateEffectiveAuthorizationIntervals);

            _checkSumGeneratorMock.Setup(x => x.Generate(It.IsAny <string>())).Returns("Generated CheckSum");

            _azureBlobStorageRepMock.Setup(e => e.UploadFileAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new Uri("http://localhost")));

            _azureTableStorageRepMock.Setup(e => e.InsertRecordToTable(It.IsAny <FileInformation>()))
            .Returns(Task.FromResult(new TableResult()));


            //Act
            var result = await _reportingBusiness.GenerateReport(_reportingEvent);

            //Assert
            Assert.Equal(_reportingEvent.FileName, result.FileName);
            Assert.Equal("Generated CheckSum", result.Hash);
        }
        public async Task GenerateReport_TestAsync_Exception()
        {
            //Arrange
            _reportingBusiness = new ReportingBusiness(_reportingStorageMock.Object, _azureBlobStorageRepMock.Object,
                                                       _azureTableStorageRepMock.Object, _checkSumGeneratorMock.Object, _blobStorageSettingsMock.Object, _azureQueueStoragerRepMock.Object, _logger.Object);

            _reportingEvent = new ReportingEvent()
            {
                FileName = "TestFile"
            };

            _reportingStorageMock.Setup(e => e.FetchReportingData(It.IsAny <ReportingEvent>()))
            .ReturnsAsync(Generator.GenerateEffectiveAuthorizationIntervals);

            //Act
            var result = await _reportingBusiness.GenerateReport(_reportingEvent);

            //Assert
            Assert.Equal("Exceeds max record count, limit is 0 and actual count is 1", result.Hash);
        }
        private ReportingEvent ReportingEventDtoSetup()
        {
            var reportingEventDto = new ReportingEvent
            {
                Application = "DummyApplication",
                Permissions = new List <string> {
                    "DummyPermission"
                },
                EndDate    = DateTime.Now.AddDays(-1),
                StartDate  = DateTime.Now.AddDays(1),
                FileName   = "DummyFile.csv",
                TenantId   = "DummyTenant",
                SourceUser = new ExternalId()
                {
                    Context = "Youforce", Id = "IC01"
                },
                TargetUser = new ExternalId()
            };

            return(reportingEventDto);
        }
Esempio n. 8
0
        public async Task <IActionResult> Generate([FromBody] ReportingEvent reportingEventDto)
        {
            try
            {
                if (!(string.IsNullOrWhiteSpace(reportingEventDto.SourceUser.Id) || string.IsNullOrWhiteSpace(reportingEventDto.SourceUser.Context)) &&
                    !(string.IsNullOrWhiteSpace(reportingEventDto.TargetUser.Id) || string.IsNullOrWhiteSpace(reportingEventDto.TargetUser.Context)))
                {
                    return(BadRequest("Both Source and Target user cannot be selected"));
                }
                if (reportingEventDto.StartDate > reportingEventDto.EndDate)
                {
                    return(BadRequest("Start Date cannot be greater than End Date!"));
                }
                _logger.LogInformation("Generate Report process started!");
                var generatedReport = await _reportingBusiness.InsertAndTriggerGenerateReport(reportingEventDto);

                return(Ok(generatedReport));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 9
0
 void OnReportingEvent(ReportingEventArgs args) => ReportingEvent?.Invoke(this, args);
 public Task <IList <EffectiveAuthorizationInterval> > FetchReportingData(ReportingEvent ReportingEvent)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
        public async Task <IList <EffectiveAuthorizationInterval> > FetchReportingData(ReportingEvent ReportingEvent)
        {
            var uri              = UriFactory.CreateDocumentCollectionUri(_dbConfig.Database, _dbConfig.Collection);
            var reportingSql     = GetSQLQueryForReporting(ReportingEvent);
            var resourceResponse = _client.CreateDocumentQuery <EffectiveAuthorizationInterval>(uri, reportingSql, _queryOptions).ToList();

            return(resourceResponse);
        }
Esempio n. 12
0
 protected virtual void OnReportingEvent(ReportingEventArgs args) => ReportingEvent?.Invoke(this, args);