diff --git a/src/KPI Generator/Models/ProjectReport.cs b/src/KPI Generator/Models/ProjectReport.cs index 0c97b54f85253b458a858c6547dd258a4587e7b2..b1ab76e8bf252c649a41239efe8fe9b253dcf1d6 100644 --- a/src/KPI Generator/Models/ProjectReport.cs +++ b/src/KPI Generator/Models/ProjectReport.cs @@ -8,7 +8,7 @@ public record ProjectReport public Guid Id { get; init; } [JsonPropertyName("DateCreated")] - public DateTime DateCreated { get; init; } + public DateTime? DateCreated { get; init; } = null!; [JsonPropertyName("Organizations")] public IReadOnlyList<Organization> Organizations { get; init; } = null!; diff --git a/src/KPI Generator/Models/UserReport.cs b/src/KPI Generator/Models/UserReport.cs index 9b9efd47f7b8a647ea32659f08ea0def8c5f232a..5dba1e29da0d70d5eb33f4ece6d819b30e226bdd 100644 --- a/src/KPI Generator/Models/UserReport.cs +++ b/src/KPI Generator/Models/UserReport.cs @@ -27,5 +27,5 @@ public record UserReport public IReadOnlyList<LoginProvider> LoginProviders { get; init; } = null!; [JsonPropertyName("LatestActivity")] - public DateTime? LatestActivity { get; set; } + public DateTime? LatestActivity { get; set; } = null!; } diff --git a/src/KPI Generator/Reportings/ApplicationProfile/ApplicationProfileReporting.cs b/src/KPI Generator/Reportings/ApplicationProfile/ApplicationProfileReporting.cs index b49c8a8490e910b8c9c421b472ba4da45b76d545..b94e701ce8a9aa5fad567b1e1f0f03ac987d1f7d 100644 --- a/src/KPI Generator/Reportings/ApplicationProfile/ApplicationProfileReporting.cs +++ b/src/KPI Generator/Reportings/ApplicationProfile/ApplicationProfileReporting.cs @@ -63,14 +63,14 @@ public class ApplicationProfileReporting public async Task<bool> RunAsync(ApplicationProfileReportingOptions reportingOptions) { - _logger.LogInformation("\n\nGenerating Application Profile Reporting..."); + _logger.LogInformation("Generating Application Profile Reporting..."); Options = reportingOptions; var reportingFiles = await GenerateReportingAsync(); _logger.LogInformation("Publishing to GitLab..."); // Publish to GitLab first, if that fails, publish to local storage - var success = await _gitlabStorageService.PublishAsync("Application Profile Reporting", reportingFiles); - if (!success) + var success = Options.DummyMode || await _gitlabStorageService.PublishAsync("Application Profile Reporting", reportingFiles); + if (!success || Options.DummyMode) { _logger.LogInformation("Failed to publish to GitLab. Publishing to local storage instead."); success = await _localStorageService.PublishAsync("Application Profile Reporting", reportingFiles); @@ -88,7 +88,6 @@ public class ApplicationProfileReporting foreach (var ap in applicationProfiles) { - _logger.LogInformation("Processing {ap}...", ap.Uri); var applicationProfile = await ApplicationProfileApi.GetApplicationProfileAsync(ap.Uri, RdfFormat.TextTurtle); var g = new Graph(); diff --git a/src/KPI Generator/Reportings/Complete/CompleteReporting.cs b/src/KPI Generator/Reportings/Complete/CompleteReporting.cs index dba769d57be0768b79ea81d77b40d370c0e20592..05e489e36d3618be1c349a677107046d6ad355dc 100644 --- a/src/KPI Generator/Reportings/Complete/CompleteReporting.cs +++ b/src/KPI Generator/Reportings/Complete/CompleteReporting.cs @@ -51,8 +51,8 @@ public class CompleteReporting // Publish to GitLab first, if that fails, publish to local storage _logger.LogInformation("Publishing to GitLab..."); - var success = await _gitlabStorageService.PublishAsync("Complete Reporting", reportingFiles); - if (!success) + var success = Options.DummyMode || await _gitlabStorageService.PublishAsync("Complete Reporting", reportingFiles); + if (!success || Options.DummyMode) { _logger.LogInformation("Failed to publish to GitLab. Publishing to local storage instead."); success = await _localStorageService.PublishAsync("Complete Reporting", reportingFiles); @@ -65,15 +65,15 @@ public class CompleteReporting var reportingFiles = new List<ReportingFileObject>(); var projectReportingFiles = await _projectReporting.GenerateReportingAsync(); - _logger.LogInformation("Project Reporting generated successfully."); + _logger.LogInformation("Project Reporting generated successfully.\n\n"); var resourceReportingFiles = await _resourceReporting.GenerateReportingAsync(); - _logger.LogInformation("Resource Reporting generated successfully."); + _logger.LogInformation("Resource Reporting generated successfully.\n\n"); var userReportingFiles = await _userReporting.GenerateReportingAsync(); - _logger.LogInformation("User Reporting generated successfully."); + _logger.LogInformation("User Reporting generated successfully.\n\n"); var applicationProfileReportingFiles = await _applicationProfileReporting.GenerateReportingAsync(); - _logger.LogInformation("Application Profile Reporting generated successfully."); + _logger.LogInformation("Application Profile Reporting generated successfully.\n\n"); var systemReportingFiles = await _systemReporting.GenerateReportingAsync(); - _logger.LogInformation("System Reporting generated successfully."); + _logger.LogInformation("System Reporting generated successfully.\n\n"); reportingFiles.AddRange(projectReportingFiles); reportingFiles.AddRange(resourceReportingFiles); diff --git a/src/KPI Generator/Reportings/Project/ProjectReporting.cs b/src/KPI Generator/Reportings/Project/ProjectReporting.cs index 87bd76c814f54c41dd24212b919ee530f88b160c..a6ca057bb08484c2b9a2c7cb9140afe9a3a516ed 100644 --- a/src/KPI Generator/Reportings/Project/ProjectReporting.cs +++ b/src/KPI Generator/Reportings/Project/ProjectReporting.cs @@ -63,14 +63,14 @@ public class ProjectReporting public async Task<bool> RunAsync(ProjectReportingOptions reportingOptions) { - _logger.LogInformation("\n\nGenerating Project Reporting..."); + _logger.LogInformation("Generating Project Reporting..."); Options = reportingOptions; var reportingFiles = await GenerateReportingAsync(); _logger.LogInformation("Publishing to GitLab..."); // Publish to GitLab first, if that fails, publish to local storage - var success = await _gitlabStorageService.PublishAsync("Project Reporting", reportingFiles); - if (!success) + var success = Options.DummyMode || await _gitlabStorageService.PublishAsync("Project Reporting", reportingFiles); + if (!success || Options.DummyMode) { _logger.LogInformation("Failed to publish to GitLab. Publishing to local storage instead."); success = await _localStorageService.PublishAsync("Project Reporting", reportingFiles); @@ -114,13 +114,15 @@ public class ProjectReporting var rorUrl = entry.RorUrl.Equals("https://ror.org/", StringComparison.InvariantCultureIgnoreCase) ? _reportingConfiguration.Organization?.OtherOrganization?.RorUrl ?? "_other" : entry.RorUrl; var returnObjectsForOrganization = returnObjects.Where(ro => ro.Organizations.Select(o => o.RorUrl).Any(e => e.Contains(rorUrl))).ToList(); - - var reportingFile = new ReportingFileObject + if (returnObjectsForOrganization.Count != 0) { - Path = Helpers.GetReportingPathOrganization(entry.RorUrl, ReportingFileName), - Content = Helpers.ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) - }; - reportingFilesPerOrganization.Add(reportingFile); + var reportingFile = new ReportingFileObject + { + Path = Helpers.GetReportingPathOrganization(rorUrl, ReportingFileName), + Content = Helpers.ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) + }; + reportingFilesPerOrganization.Add(reportingFile); + } } return reportingFilesPerOrganization; diff --git a/src/KPI Generator/Reportings/Resource/ResourceReporting.cs b/src/KPI Generator/Reportings/Resource/ResourceReporting.cs index 0bcc9998269ac141926f21bc76cdb5b65c7fabb6..4e1e80fd52f248b302d699d91448617ea0f8d9e1 100644 --- a/src/KPI Generator/Reportings/Resource/ResourceReporting.cs +++ b/src/KPI Generator/Reportings/Resource/ResourceReporting.cs @@ -62,14 +62,14 @@ public class ResourceReporting public async Task<bool> RunAsync(ResourceReportingOptions reportingOptions) { - _logger.LogInformation("\n\nGenerating Resource Reporting..."); + _logger.LogInformation("Generating Resource Reporting..."); Options = reportingOptions; var reportingFiles = await GenerateReportingAsync(); _logger.LogInformation("Publishing to GitLab..."); // Publish to GitLab first, if that fails, publish to local storage - var success = await _gitlabStorageService.PublishAsync("Resources Reporting", reportingFiles); - if (!success) + var success = Options.DummyMode || await _gitlabStorageService.PublishAsync("Resources Reporting", reportingFiles); + if (!success || Options.DummyMode) { _logger.LogInformation("Failed to publish to GitLab. Publishing to local storage instead."); success = await _localStorageService.PublishAsync("Resources Reporting", reportingFiles); @@ -128,13 +128,15 @@ public class ResourceReporting foreach (var entry in organizationsFromProjects) { var returnObjectsForOrganization = returnObjects.Where(ro => ro.Organizations.Select(o => o.RorUrl).Any(e => e.Contains(entry.RorUrl))).ToList(); - - var reportingFile = new ReportingFileObject + if (returnObjectsForOrganization.Count != 0) { - Path = Helpers.GetReportingPathOrganization(entry.RorUrl, ReportingFileName), - Content = Helpers.ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) - }; - reportingFilesPerOrganization.Add(reportingFile); + var reportingFile = new ReportingFileObject + { + Path = Helpers.GetReportingPathOrganization(entry.RorUrl, ReportingFileName), + Content = Helpers.ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) + }; + reportingFilesPerOrganization.Add(reportingFile); + } } return reportingFilesPerOrganization; diff --git a/src/KPI Generator/Reportings/System/SystemReporting.cs b/src/KPI Generator/Reportings/System/SystemReporting.cs index 5033bcc647d820d3b7727be89f28f2a4913f63ea..cf14a60e2c2545b3c7f0731966157295605ae421 100644 --- a/src/KPI Generator/Reportings/System/SystemReporting.cs +++ b/src/KPI Generator/Reportings/System/SystemReporting.cs @@ -62,14 +62,14 @@ public class SystemReporting public async Task<bool> RunAsync(SystemReportingOptions reportingOptions) { - _logger.LogInformation("\n\nGenerating System Reporting..."); + _logger.LogInformation("Generating System Reporting..."); Options = reportingOptions; var reportingFiles = await GenerateReportingAsync(); _logger.LogInformation("Publishing to GitLab..."); // Publish to GitLab first, if that fails, publish to local storage - var success = await _gitlabStorageService.PublishAsync("System Reporting", reportingFiles); - if (!success) + var success = Options.DummyMode || await _gitlabStorageService.PublishAsync("System Reporting", reportingFiles); + if (!success || Options.DummyMode) { _logger.LogInformation("Failed to publish to GitLab. Publishing to local storage instead."); success = await _localStorageService.PublishAsync("System Reporting", reportingFiles); diff --git a/src/KPI Generator/Reportings/User/UserReporting.cs b/src/KPI Generator/Reportings/User/UserReporting.cs index 21ad32815c87f97db5b7dba3fff3bef782a4fed0..b46aafcd38df2859e4c1d05d5b0df4650f72a367 100644 --- a/src/KPI Generator/Reportings/User/UserReporting.cs +++ b/src/KPI Generator/Reportings/User/UserReporting.cs @@ -62,14 +62,14 @@ public class UserReporting public async Task<bool> RunAsync(UserReportingOptions reportingOptions) { - _logger.LogInformation("\n\nGenerating User Reporting..."); + _logger.LogInformation("Generating User Reporting..."); Options = reportingOptions; var reportingFiles = await GenerateReportingAsync(); _logger.LogInformation("Publishing to GitLab..."); // Publish to GitLab first, if that fails, publish to local storage - var success = await _gitlabStorageService.PublishAsync("User Reporting", reportingFiles); - if (!success) + var success = Options.DummyMode || await _gitlabStorageService.PublishAsync("User Reporting", reportingFiles); + if (!success || Options.DummyMode) { _logger.LogInformation("Failed to publish to GitLab. Publishing to local storage instead."); success = await _localStorageService.PublishAsync("User Reporting", reportingFiles); @@ -137,13 +137,15 @@ public class UserReporting foreach (var entry in organizationsFromProjects) { var returnObjectsForOrganization = returnObjects.Where(ro => ro.Organizations.Select(o => o.RorUrl).Any(e => e is not null && e.Contains(entry.RorUrl))).ToList(); - - var reportingFile = new ReportingFileObject + if (returnObjectsForOrganization.Count != 0) { - Path = Helpers.GetReportingPathOrganization(entry.RorUrl, ReportingFileName), - Content = Helpers.ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) - }; - reportingFilesPerOrganization.Add(reportingFile); + var reportingFile = new ReportingFileObject + { + Path = Helpers.GetReportingPathOrganization(entry.RorUrl, ReportingFileName), + Content = Helpers.ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) + }; + reportingFilesPerOrganization.Add(reportingFile); + } } return reportingFilesPerOrganization; diff --git a/src/KPI Generator/Utils/Helpers.cs b/src/KPI Generator/Utils/Helpers.cs index 7be868eedc70afc6f49214eb9113d8c017e69eb6..da468c39b6ac45a439e8c28814c0f400b833afad 100644 --- a/src/KPI Generator/Utils/Helpers.cs +++ b/src/KPI Generator/Utils/Helpers.cs @@ -21,24 +21,11 @@ public static class Helpers return result.DistinctBy(r => r.RorUrl); } - public static string GetReportingPathGeneral(string fileName) - { - return string.Format("General/{0}", fileName); - } + public static string GetReportingPathGeneral(string fileName) => string.Format("General/{0}", fileName); - public static string GetReportingPathOrganization(string organizationRor, string fileName) - { - return string.Format("Organizations/{0}/{1}", SanitizeOrganizationRor(organizationRor), fileName); - } + public static string GetReportingPathOrganization(string organizationRor, string fileName) => string.Format("Organizations/{0}/{1}", SanitizeOrganizationRor(organizationRor), fileName); - public static string SanitizeOrganizationRor(string organizationRor) - { - return HttpUtility.UrlEncode(organizationRor.Replace("https://ror.org/", "").ToLower()); - } + public static string SanitizeOrganizationRor(string organizationRor) => HttpUtility.UrlEncode(organizationRor.Replace("https://ror.org/", "").ToLower()); - public static Stream ConvertStringContentsToStream(string contents) - { - byte[] byteArray = Encoding.UTF8.GetBytes(contents); - return new MemoryStream(byteArray); - } + public static Stream ConvertStringContentsToStream(string contents) => new MemoryStream(Encoding.UTF8.GetBytes(contents)); }