From 7b05dc8e081dc5cfab6e63b40e4056185b42be28 Mon Sep 17 00:00:00 2001 From: Petar Hristov <hristov@itc.rwth-aachen.de> Date: Fri, 6 Jan 2023 15:10:16 +0100 Subject: [PATCH] Fix: Other Organization handling and DateTime for System Maintenance --- src/KPI Generator/KPI Generator.csproj | 2 +- .../Reportings/Project/ProjectReporting.cs | 12 ++---------- .../Reportings/Resource/ResourceReporting.cs | 11 ++--------- .../Reportings/System/MaintenanceReturnObject.cs | 4 ++-- src/KPI Generator/Reportings/User/UserReporting.cs | 4 ++-- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/KPI Generator/KPI Generator.csproj b/src/KPI Generator/KPI Generator.csproj index 42602aa..1aed9c4 100644 --- a/src/KPI Generator/KPI Generator.csproj +++ b/src/KPI Generator/KPI Generator.csproj @@ -13,7 +13,7 @@ <PropertyGroup> <Authors>RWTH Aachen University</Authors> <Company>IT Center, RWTH Aachen University</Company> - <Copyright>©2022 IT Center, RWTH Aachen University</Copyright> + <Copyright>©2023 IT Center, RWTH Aachen University</Copyright> <Description>KPI Generator is a part of the Coscine group.</Description> </PropertyGroup> diff --git a/src/KPI Generator/Reportings/Project/ProjectReporting.cs b/src/KPI Generator/Reportings/Project/ProjectReporting.cs index 9e539f5..349bd35 100644 --- a/src/KPI Generator/Reportings/Project/ProjectReporting.cs +++ b/src/KPI Generator/Reportings/Project/ProjectReporting.cs @@ -85,23 +85,15 @@ public class ProjectReporting : Reporting<ProjectReportingOptions> var organizationsFromProjects = GetTopLevelOrganizationsFromEntries(returnObjects.SelectMany(ro => ro.Organizations)); foreach (var entry in organizationsFromProjects) { - var organization = Organizations.Find(o => o.RorUrl.Equals(entry.RorUrl)); - if (organization is null) - { - organization = _otherOrganization; - Console.WriteLine($" WARNING!: Organization \"{entry.RorUrl}\" could not be correctly identified. Will use \"{_otherOrganization.RorUrl}\"."); - _logger.LogWarning("Organization {ror} could not be correctly identified.", entry.RorUrl); - } - var returnObjectsForOrganization = returnObjects.Where(ro => ro.Organizations.Select(o => o.RorUrl).Any(e => e.Contains(entry.RorUrl))).ToList(); var reportingFile = new ReportingFileObject { - Path = GetReportingPathOrganization(organization.RorUrl, ReportingFileName), + Path = GetReportingPathOrganization(entry.RorUrl, ReportingFileName), Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) }; reportingFilesPerOrganization.Add(reportingFile); - Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(organization.RorUrl, ReportingFileName)}\" generated successfully"); + Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(entry.RorUrl, ReportingFileName)}\" generated successfully"); _logger.LogInformation("{Name}: Generated successfully {ReportingFile}.", GetType().Name, reportingFile); } diff --git a/src/KPI Generator/Reportings/Resource/ResourceReporting.cs b/src/KPI Generator/Reportings/Resource/ResourceReporting.cs index 966a3ec..da2ba40 100644 --- a/src/KPI Generator/Reportings/Resource/ResourceReporting.cs +++ b/src/KPI Generator/Reportings/Resource/ResourceReporting.cs @@ -84,22 +84,15 @@ public class ResourceReporting : Reporting<ResourceReportingOptions> var organizationsFromResources = GetTopLevelOrganizationsFromEntries(returnObjects.SelectMany(ro => ro.Organizations)); foreach (var entry in organizationsFromResources) { - var organization = Organizations.Find(o => o.RorUrl.Equals(entry.RorUrl)); - if (organization is null) - { - organization = _otherOrganization; - Console.WriteLine($" WARNING!: Organization \"{entry.RorUrl}\" could not be correctly identified. Will use \"{_otherOrganization.RorUrl}\"."); - _logger.LogWarning("Organization {ror} could not be correctly identified.", entry.RorUrl); - } var returnObjectsForOrganization = returnObjects.Where(ro => ro.Organizations.Select(o => o.RorUrl).Any(e => e.Equals(entry.RorUrl))).ToList(); var reportingFile = new ReportingFileObject { - Path = GetReportingPathOrganization(organization.RorUrl, ReportingFileName), + Path = GetReportingPathOrganization(entry.RorUrl, ReportingFileName), Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented)) }; reportingFilesPerOrganization.Add(reportingFile); - Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(organization.RorUrl, ReportingFileName)}\" generated successfully"); + Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(entry.RorUrl, ReportingFileName)}\" generated successfully"); _logger.LogInformation("{Name}: Generated successfully {ReportingFile}.", GetType().Name, reportingFile); } return reportingFilesPerOrganization; diff --git a/src/KPI Generator/Reportings/System/MaintenanceReturnObject.cs b/src/KPI Generator/Reportings/System/MaintenanceReturnObject.cs index 2d71f8c..7af2780 100644 --- a/src/KPI Generator/Reportings/System/MaintenanceReturnObject.cs +++ b/src/KPI Generator/Reportings/System/MaintenanceReturnObject.cs @@ -15,8 +15,8 @@ public class MaintenanceBannerObject [JsonProperty("status")] public string Status { get; set; } = null!; [JsonProperty("start_at")] - public DateTime StartAt { get; set; } + public DateTime? StartAt { get; set; } = null!; [JsonProperty("end_at")] - public DateTime EndAt { get; set; } + public DateTime? EndAt { get; set; } = null!; } diff --git a/src/KPI Generator/Reportings/User/UserReporting.cs b/src/KPI Generator/Reportings/User/UserReporting.cs index 237e84c..c06d7f6 100644 --- a/src/KPI Generator/Reportings/User/UserReporting.cs +++ b/src/KPI Generator/Reportings/User/UserReporting.cs @@ -230,12 +230,12 @@ public class UserReporting : Reporting<UserReportingOptions> private List<Organization> CleanUpOther(List<Organization> affiliations) { // Special case until `https://ror.org/%20https://ror.org/` is moved to `https://ror.org/_other` - if (affiliations.Any(o => o.RorUrl.Equals("https://ror.org/%20https://ror.org/"))) + if (affiliations.Any(o => o.RorUrl.Equals("https://ror.org/%20https://ror.org/") || o.RorUrl.Equals("https://ror.org/"))) { var cleanedUpAffiliations = affiliations; foreach (var entry in cleanedUpAffiliations) { - if (entry.RorUrl.Equals("https://ror.org/%20https://ror.org/")) + if (entry.RorUrl.Equals("https://ror.org/%20https://ror.org/") || entry.RorUrl.Equals("https://ror.org/")) { cleanedUpAffiliations[cleanedUpAffiliations.IndexOf(entry)] = new() { -- GitLab