Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Fix/xxxx-indexOutOfRange
  • Fix/xxxx-minorFixes
  • Fix/xxxx-organization
  • Fix/xxxx-wrap
  • Hotfix/2332-userInstitutesInReporting
  • Hotfix/2388-sensitive
  • Hotfix/3115-userReportingEmpty
  • Hotfix/3115-userReportingEmpty2
  • Hotfix/xxxx-rors
  • Issue/2181-kpiGeneratorBase
  • Issue/2182-kpiGeneratorUser
  • Issue/2183-kpiGeneratorResource
  • Issue/2184-kpiGeneratorProject
  • Issue/2185-kpiGeneratorAP
  • Issue/2186-systemStatusReporting
  • Issue/2283-activityFix
  • Issue/2304-virtuosoRoars
  • Issue/2330-fixNaNQuotainAdmin
  • Issue/2432-publicationKpi
  • Issue/2492-respOrg
  • Issue/2518-docs
  • Issue/2568-betterLogging
  • Issue/2666-adminCronjobs
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2847-reporting
  • Issue/2850-removeGrantId
  • Issue/2982-kpiDataPub
  • Issue/3005-kpiReportingBroken
  • Issue/3073-kpi
  • Issue/3142-kpiGenerator
  • dev
  • gitkeep
  • main
  • v0.1.0
  • v0.1.1
  • v0.1.10
  • v0.1.11
  • v0.1.12
  • v0.1.13
  • v0.1.14
  • v0.1.15
  • v0.1.16
  • v0.1.17
  • v0.1.18
  • v0.1.19
  • v0.1.2
  • v0.1.20
  • v0.1.21
  • v0.1.22
  • v0.1.23
  • v0.1.3
  • v0.1.4
  • v0.1.5
  • v0.1.6
  • v0.1.7
  • v0.1.8
  • v0.1.9
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.0.5
  • v1.0.6
  • v1.0.7
  • v1.0.8
  • v1.0.9
  • v1.1.0
  • v1.1.1
  • v1.2.0
  • v1.2.1
  • v1.2.10
  • v1.2.2
  • v1.2.3
  • v1.2.4
  • v1.2.5
  • v1.2.6
  • v1.2.7
  • v1.2.8
  • v1.2.9
79 results

Target

Select target project
  • coscine/backend/scripts/kpi-generator
1 result
Select Git revision
  • Fix/xxxx-indexOutOfRange
  • Fix/xxxx-minorFixes
  • Fix/xxxx-organization
  • Fix/xxxx-wrap
  • Hotfix/2332-userInstitutesInReporting
  • Hotfix/2388-sensitive
  • Hotfix/3115-userReportingEmpty
  • Hotfix/3115-userReportingEmpty2
  • Hotfix/xxxx-rors
  • Issue/2181-kpiGeneratorBase
  • Issue/2182-kpiGeneratorUser
  • Issue/2183-kpiGeneratorResource
  • Issue/2184-kpiGeneratorProject
  • Issue/2185-kpiGeneratorAP
  • Issue/2186-systemStatusReporting
  • Issue/2283-activityFix
  • Issue/2304-virtuosoRoars
  • Issue/2330-fixNaNQuotainAdmin
  • Issue/2432-publicationKpi
  • Issue/2492-respOrg
  • Issue/2518-docs
  • Issue/2568-betterLogging
  • Issue/2666-adminCronjobs
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2847-reporting
  • Issue/2850-removeGrantId
  • Issue/2982-kpiDataPub
  • Issue/3005-kpiReportingBroken
  • Issue/3073-kpi
  • Issue/3142-kpiGenerator
  • dev
  • gitkeep
  • main
  • v0.1.0
  • v0.1.1
  • v0.1.10
  • v0.1.11
  • v0.1.12
  • v0.1.13
  • v0.1.14
  • v0.1.15
  • v0.1.16
  • v0.1.17
  • v0.1.18
  • v0.1.19
  • v0.1.2
  • v0.1.20
  • v0.1.21
  • v0.1.22
  • v0.1.23
  • v0.1.3
  • v0.1.4
  • v0.1.5
  • v0.1.6
  • v0.1.7
  • v0.1.8
  • v0.1.9
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.0.5
  • v1.0.6
  • v1.0.7
  • v1.0.8
  • v1.0.9
  • v1.1.0
  • v1.1.1
  • v1.2.0
  • v1.2.1
  • v1.2.10
  • v1.2.2
  • v1.2.3
  • v1.2.4
  • v1.2.5
  • v1.2.6
  • v1.2.7
  • v1.2.8
  • v1.2.9
79 results
Show changes
Commits on Source (3)
Showing
with 246 additions and 88 deletions
......@@ -7,7 +7,7 @@
<AssemblyName>Coscine.KpiGenerator</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.1.8</Version>
<Version>0.1.9</Version>
</PropertyGroup>
<PropertyGroup>
......@@ -19,10 +19,18 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Coscine.ApiCommons" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="1.*-*" />
<PackageReference Include="Coscine.ApiCommons" Version="*-*" />
<PackageReference Include="Coscine.Database" Version="*-*" />
<PackageReference Include="Coscine.Metadata" Version="*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="*-*" />
<PackageReference Include="GitLabApiClient" Version="1.8.1-beta.5" />
<PackageReference Include="NLog" Version="5.1.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
</ItemGroup>
<ItemGroup>
<None Update="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
using NLog;
using NLog.LayoutRenderers;
using System.Text;
namespace Coscine.KpiGenerator.Logging
{
[LayoutRenderer("assembly-name")]
public class AssemblyNameLayoutRenderer : LayoutRenderer
{
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
var assembly = typeof(Program).Assembly.GetName();
if (assembly is not null)
{
builder.Append(assembly.Name);
}
else
{
builder.Append(new Guid().ToString().Take(8));
}
}
}
}
using NLog;
using NLog.LayoutRenderers;
using System.Text;
namespace Coscine.KpiGenerator.Logging
{
[LayoutRenderer("assembly-version")]
public class AssemblyVersionLayoutRenderer : LayoutRenderer
{
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
var assembly = typeof(Program).Assembly.GetName();
if (assembly is not null && assembly.Version is not null)
{
builder.Append(assembly.Version.ToString(3));
}
else
{
builder.Append(new Version().ToString(3));
}
}
}
}
using CommandLine;
using KPIGenerator.Reportings.ApplicationProfile;
using KPIGenerator.Reportings.Complete;
using KPIGenerator.Reportings.Project;
using KPIGenerator.Reportings.Resource;
using KPIGenerator.Reportings.System;
using KPIGenerator.Reportings.User;
using Coscine.KpiGenerator.Logging;
using Coscine.KpiGenerator.Reportings.ApplicationProfile;
using Coscine.KpiGenerator.Reportings.Complete;
using Coscine.KpiGenerator.Reportings.Project;
using Coscine.KpiGenerator.Reportings.Resource;
using Coscine.KpiGenerator.Reportings.System;
using Coscine.KpiGenerator.Reportings.User;
using Microsoft.Extensions.Logging;
using NLog.Config;
using NLog.Extensions.Logging;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator;
namespace Coscine.KpiGenerator;
public static class Program
public class Program
{
static int Main(string[] args)
private static ILogger _logger = null!;
public static int Main(string[] args)
{
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("assembly-name", typeof(AssemblyNameLayoutRenderer));
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("assembly-version", typeof(AssemblyVersionLayoutRenderer));
_logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger<Program>();
try
{
bool result = Parser.Default.ParseArguments<
......@@ -24,27 +34,30 @@ public static class Program
SystemReportingOptions
>(args)
.MapResult(
(CompleteReportingOptions options) => new CompleteReporting(SanitizeOptions(options)).Run(),
(ProjectReportingOptions options) => new ProjectReporting(SanitizeOptions(options)).Run(),
(ResourceReportingOptions options) => new ResourceReporting(SanitizeOptions(options)).Run(),
(UserReportingOptions options) => new UserReporting(SanitizeOptions(options)).Run(),
(ApplicationProfileReportingOptions options) => new ApplicationProfileReporting(SanitizeOptions(options)).Run(),
(SystemReportingOptions options) => new SystemReporting(SanitizeOptions(options)).Run(),
(CompleteReportingOptions options) => new CompleteReporting(SanitizeOptions(options), _logger).Run(),
(ProjectReportingOptions options) => new ProjectReporting(SanitizeOptions(options), _logger).Run(),
(ResourceReportingOptions options) => new ResourceReporting(SanitizeOptions(options), _logger).Run(),
(UserReportingOptions options) => new UserReporting(SanitizeOptions(options), _logger).Run(),
(ApplicationProfileReportingOptions options) => new ApplicationProfileReporting(SanitizeOptions(options), _logger).Run(),
(SystemReportingOptions options) => new SystemReporting(SanitizeOptions(options), _logger).Run(),
_ => false);
if (result)
{
Console.WriteLine("\nFinished.\n");
_logger.LogInformation("Finished.");
return 0; // Exit Code 0 for Success
}
else
{
Console.WriteLine("Program execution was interrupted.\n");
_logger.LogInformation("Program execution was interrupted.");
return -1; // Exit Code -1 for Failure
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
_logger.LogError(e, e.Message);
return -1; // Exit Code -1 for Failure
}
}
......@@ -112,4 +125,12 @@ public static class Program
}
return unsanitizedOptions;
}
private static void LogInnerException(Exception ex)
{
if (ex.InnerException is not null)
{
_logger.LogError(ex.InnerException, "InnerException: {innerException}", ex.InnerException.Message);
LogInnerException(ex.InnerException);
}
}
}
\ No newline at end of file
using Coscine.Configuration;
using Coscine.KpiGenerator.Utils;
using Coscine.Metadata;
using GitLabApiClient;
using GitLabApiClient.Models.Branches.Requests;
using GitLabApiClient.Models.Commits.Requests.CreateCommitRequest;
using KPIGenerator.Utils;
using Microsoft.Extensions.Logging;
using System.Text;
using System.Web;
using VDS.RDF.Query;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator;
namespace Coscine.KpiGenerator;
public abstract class Reporting<O> where O : class
{
......@@ -29,6 +30,7 @@ public abstract class Reporting<O> where O : class
private string ReportingBranch { get; init; }
public string RwthRor { get; init; }
public readonly ILogger _logger = null!;
public readonly Organization _otherOrganization = new()
{
......@@ -36,9 +38,9 @@ public abstract class Reporting<O> where O : class
RorUrl = "https://ror.org/_other",
};
public Reporting(O options)
public Reporting(O options, ILogger logger)
{
InstanceName = this.GetType().Name;
InstanceName = GetType().Name;
Options = options;
Configuration = new ConsulConfiguration();
RdfStoreConnector = new RdfStoreConnector(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
......@@ -52,6 +54,7 @@ public abstract class Reporting<O> where O : class
ReportingBranch = Configuration.GetStringAndWait("coscine/local/reporting/branch");
RwthRor = Configuration.GetStringAndWait("coscine/global/organizations/rwth/ror_url");
_logger = logger;
}
public abstract IEnumerable<ReportingFileObject> GenerateReporting();
......@@ -64,6 +67,11 @@ public abstract class Reporting<O> where O : class
if (baseOptions is not null && baseOptions.DummyMode)
{
Console.Write(" : DUMMY MODE");
_logger.LogInformation("Initialized on {Domain} | {InstanceName} | DUMMY MODE {DummyMode}", Domain, InstanceName, baseOptions.DummyMode);
}
else
{
_logger.LogInformation("Initialized on {Domain} | {InstanceName}", Domain, InstanceName);
}
Console.WriteLine($"\n{new string('-', 80)}");
EnsureGitLabInformationIsSetAndCorrect();
......@@ -71,9 +79,11 @@ public abstract class Reporting<O> where O : class
var reportingFiles = GenerateReporting();
Console.WriteLine($"\n{new string('=', 80)}");
Console.WriteLine(" - Reporting generated successfully. Publishing...");
_logger.LogInformation("Reporting generated successfully. Publishing {reportingFiles}", reportingFiles);
// Publish Report
var success = PublishAsync(reportingFiles).Result;
Console.WriteLine(success ? " - Published successfully." : " - Publishing FAILED!");
_logger.LogInformation("Publishing successful: {success}", success);
return success;
}
......@@ -87,6 +97,7 @@ public abstract class Reporting<O> where O : class
var commitMessage = $"{InstanceName} Generated - {DateTime.Now:dd.MM.yyyy HH:mm}"; // CompleteReporting Generated - 31.08.2022 10:25
Console.WriteLine($" - Commit: \"{commitMessage}\"");
_logger.LogInformation("Commit: {commitMessage}", commitMessage);
var projectTree = await GitLabClient.Trees.GetAsync(reportingDatabaseProject, o =>
{
......@@ -143,6 +154,7 @@ public abstract class Reporting<O> where O : class
catch (Exception e)
{
Console.WriteLine(e.Message);
_logger.LogError(e, e.Message);
return false;
}
}
......@@ -178,6 +190,7 @@ public abstract class Reporting<O> where O : class
result.RorUrl = rorUrl; // Don't overwrite the RoR of the entry found, just use "Other" as name.
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($" WARNING!: Organization with ROR \"{rorUrl}\" could not be correctly identified. Will use \"{result.RorUrl}\" as RoR and \"{result.Name}\" as name.");
_logger.LogWarning("Organization with ROR {rorUrl} could not be correctly identified.", rorUrl);
Console.ResetColor();
}
}
......@@ -232,6 +245,7 @@ public abstract class Reporting<O> where O : class
}
var project = GitLabClient.Projects.GetAsync(ReportingDatabaseProjectId).Result;
Console.WriteLine($" - Report Generation to be uploaded to GitLab Project \"{project.Name}\" on branch \"{ReportingBranch}\"");
_logger.LogInformation("Report Generation to be uploaded to GitLab Project {projectName} on branch {ReportingBranch}", project.Name, ReportingBranch);
var branch = GitLabClient.Branches.GetAsync(project.Id, o => o.Search = ReportingBranch).Result;
if (!branch.Any(b => b.Name.Equals(ReportingBranch)) && Domain.Equals("DEVLEF") && !project.DefaultBranch.Equals(ReportingBranch))
......@@ -239,6 +253,7 @@ public abstract class Reporting<O> where O : class
Console.WriteLine($" - Branch \"{ReportingBranch}\" does not exist. Working on Domain {Domain}. Creating branch...");
GitLabClient.Branches.CreateAsync(ReportingDatabaseProjectId, new CreateBranchRequest(ReportingBranch, project.DefaultBranch)).Wait();
Console.WriteLine($" - Branch \"{ReportingBranch}\" successfully created");
_logger.LogInformation("Branch {ReportingBranch} successfully created", ReportingBranch);
}
else if (!branch.Any(b => b.Name.Equals(ReportingBranch)))
{
......
using KPIGenerator.Utils;
using Coscine.KpiGenerator.Utils;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using VDS.RDF.Query;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.ApplicationProfile;
namespace Coscine.KpiGenerator.Reportings.ApplicationProfile;
public class ApplicationProfileReporting : Reporting<ApplicationProfileReportingOptions>
{
public ApplicationProfileReporting(ApplicationProfileReportingOptions options) : base(options)
public ApplicationProfileReporting(ApplicationProfileReportingOptions options, ILogger _logger) : base(options, _logger)
{
ReportingFileName = "application_profiles.json";
}
......@@ -15,6 +16,7 @@ public class ApplicationProfileReporting : Reporting<ApplicationProfileReporting
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
Console.WriteLine($" - {GetType().Name}: Begin reporting generation");
_logger.LogInformation("{Name}: Begin reporting generation", GetType().Name);
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = GetApplicationProfiles();
......@@ -25,6 +27,7 @@ public class ApplicationProfileReporting : Reporting<ApplicationProfileReporting
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjects, Formatting.Indented))
});
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathGeneral(ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully. {reportingFiles}", GetType().Name, reportingFiles);
Console.WriteLine();
return reportingFiles;
......
namespace KPIGenerator.Reportings.ApplicationProfile;
namespace Coscine.KpiGenerator.Reportings.ApplicationProfile;
/// <summary>
/// Object containing the JSON structure for the reporting
......
using KPIGenerator.Reportings.ApplicationProfile;
using KPIGenerator.Reportings.Project;
using KPIGenerator.Reportings.Resource;
using KPIGenerator.Reportings.System;
using KPIGenerator.Reportings.User;
using KPIGenerator.Utils;
using Coscine.KpiGenerator.Reportings.ApplicationProfile;
using Coscine.KpiGenerator.Reportings.Project;
using Coscine.KpiGenerator.Reportings.Resource;
using Coscine.KpiGenerator.Reportings.System;
using Coscine.KpiGenerator.Reportings.User;
using Coscine.KpiGenerator.Utils;
using Microsoft.Extensions.Logging;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.Complete;
namespace Coscine.KpiGenerator.Reportings.Complete;
public class CompleteReporting : Reporting<CompleteReportingOptions>
{
public CompleteReporting(CompleteReportingOptions options) : base(options)
public CompleteReporting(CompleteReportingOptions options, ILogger _logger) : base(options, _logger)
{ }
public override IEnumerable<ReportingFileObject> GenerateReporting()
......@@ -23,11 +24,12 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
result.AddRange(new ProjectReporting(new ProjectReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
}, _logger).GenerateReporting());
}
catch (Exception e)
{
Console.WriteLine($"!! Skipping ProjectReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping ProjectReporting: {message}", e.Message);
}
// Resource Reporting
......@@ -36,11 +38,12 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
result.AddRange(new ResourceReporting(new ResourceReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
}, _logger).GenerateReporting());
}
catch (Exception e)
{
Console.WriteLine($"!! Skipping ResourceReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping ResourceReporting: {message}", e.Message);
}
// User Reporting
......@@ -49,11 +52,12 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
result.AddRange(new UserReporting(new UserReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
}, _logger).GenerateReporting());
}
catch (Exception e)
{
Console.WriteLine($"!! Skipping UserReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping UserReporting: {message}", e.Message);
}
// Application Profile Reporting
......@@ -62,11 +66,12 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
result.AddRange(new ApplicationProfileReporting(new ApplicationProfileReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
}, _logger).GenerateReporting());
}
catch (Exception e)
{
Console.WriteLine($"!! Skipping ApplicationProfileReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping ApplicationProfileReporting: {message}", e.Message);
}
// System Status Reporting
......@@ -75,11 +80,12 @@ public class CompleteReporting : Reporting<CompleteReportingOptions>
result.AddRange(new SystemReporting(new SystemReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
}, _logger).GenerateReporting());
}
catch (Exception e)
{
Console.WriteLine($"!! Skipping SystemReporting: {e.Message} \n");
_logger.LogWarning(e, "Skipping SystemReporting: {message}", e.Message);
}
return result;
......
namespace KPIGenerator.Reportings.Complete;
namespace Coscine.KpiGenerator.Reportings.Complete;
/// <summary>
/// Object containing the JSON structure for the reporting
......
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Database.ReturnObjects;
using Coscine.KpiGenerator.Utils;
using Coscine.ResourceTypes;
using KPIGenerator.Utils;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.Project;
namespace Coscine.KpiGenerator.Reportings.Project;
public class ProjectReporting : Reporting<ProjectReportingOptions>
{
......@@ -16,7 +17,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
private readonly ProjectQuotaModel _projectQuotaModel;
private readonly ResourceTypeModel _resourceTypeModel;
public ProjectReporting(ProjectReportingOptions options) : base(options)
public ProjectReporting(ProjectReportingOptions options, ILogger _logger) : base(options, _logger)
{
ReportingFileName = "projects.json";
_projectModel = new ProjectModel();
......@@ -29,6 +30,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
Console.WriteLine($" - {GetType().Name}: Begin reporting generation");
_logger.LogInformation("{Name}: Begin reporting generation", GetType().Name);
var projects = _projectModel.GetAllWhere(r => r.Deleted.Equals(true) || r.Deleted.Equals(false));
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = Generate(projects);
......@@ -40,6 +42,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjects, Formatting.Indented)),
});
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathGeneral(ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully. {reportingFiles}", GetType().Name, reportingFiles);
// Per Organization
reportingFiles.AddRange(GeneratePerOrganization(returnObjects));
......@@ -48,7 +51,7 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
return reportingFiles;
}
private List<ReturnObject> Generate(IEnumerable<Coscine.Database.DataModel.Project> projects)
private List<ReturnObject> Generate(IEnumerable<Database.DataModel.Project> projects)
{
var returnObjects = new List<ReturnObject>();
foreach (var project in projects)
......@@ -83,16 +86,19 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
{
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();
reportingFilesPerOrganization.Add(new ReportingFileObject
var reportingFile = new ReportingFileObject
{
Path = GetReportingPathOrganization(organization.RorUrl, ReportingFileName),
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented))
});
};
reportingFilesPerOrganization.Add(reportingFile);
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(organization.RorUrl, ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully {ReportingFile}.", GetType().Name, reportingFile);
}
return reportingFilesPerOrganization;
......@@ -131,13 +137,13 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
},
TotalUsed = new QuotaDimObject()
{
Value = CalculateUsedForAll(_resourceTypeModel.GetById(projectQuota.ResourceTypeId), projectId),
Unit = QuotaUnit.BYTE,
Value = CalculateUsedForAll(_resourceTypeModel.GetById(projectQuota.ResourceTypeId), projectId, QuotaUnit.GibiBYTE),
Unit = QuotaUnit.GibiBYTE,
},
};
}
private int CalculateUsedForAll(ResourceType resourceType, Guid projectId)
private float CalculateUsedForAll(ResourceType resourceType, Guid projectId, QuotaUnit outputInThisUnit)
{
var resources = _resourceModel.GetAllWhere((resource) =>
(from projectResource in resource.ProjectResources
......@@ -151,19 +157,28 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
var rt = ResourceTypeFactory.Instance.GetResourceType(resource);
if (rt.GetResourceTypeInformation().Result.IsQuotaAvailable)
{
return rt.GetResourceQuotaUsed(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id)).Result;
try
{
var usedBytes = rt.GetResourceQuotaUsed(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id)).Result;
return Helpers.ConvertCapacityUnits(new QuotaDimObject() { Value = usedBytes, Unit = QuotaUnit.BYTE }, outputInThisUnit);
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
return 0f;
}
}
else
{
return 0;
return 0f;
}
}
);
return (int)used;
return used;
}
private int CalculateAllocatedForAll(ResourceType resourceType, Guid projectId)
private float CalculateAllocatedForAll(ResourceType resourceType, Guid projectId)
{
var resources = _resourceModel.GetAllWhere((resource) =>
(from projectResource in resource.ProjectResources
......@@ -176,16 +191,24 @@ public class ProjectReporting : Reporting<ProjectReportingOptions>
// Linked has no quota.
var rt = ResourceTypeFactory.Instance.GetResourceType(resource);
if (rt.GetResourceTypeInformation().Result.IsQuotaAvailable)
{
try
{
return rt.GetResourceQuotaAvailable(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id)).Result;
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
return 0f;
}
}
else
{
return 0;
return 0f;
}
});
return (int)allocated;
return allocated;
}
private List<Organization> GetOrganizations(ProjectObject project)
......
using Coscine.Database.ReturnObjects;
namespace KPIGenerator.Reportings.Project;
namespace Coscine.KpiGenerator.Reportings.Project;
public class ResourceTypeQuotaReturnObject
{
......
using Coscine.Database.ReturnObjects;
using KPIGenerator.Utils;
using Coscine.KpiGenerator.Utils;
namespace KPIGenerator.Reportings.Project;
namespace Coscine.KpiGenerator.Reportings.Project;
/// <summary>
/// Object containing the JSON structure for the reporting
......
using Coscine.Database.Models;
using Coscine.Database.ReturnObjects;
using Coscine.KpiGenerator.Utils;
using Coscine.ResourceTypes;
using Coscine.ResourceTypes.Base;
using KPIGenerator.Utils;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.Resource;
namespace Coscine.KpiGenerator.Reportings.Resource;
public class ResourceReporting : Reporting<ResourceReportingOptions>
{
......@@ -14,7 +15,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
private readonly ProjectModel _projectModel;
private readonly ProjectResourceModel _projectResourceModel;
public ResourceReporting(ResourceReportingOptions options) : base(options)
public ResourceReporting(ResourceReportingOptions options, ILogger _logger) : base(options, _logger)
{
ReportingFileName = "resources.json";
_resourceModel = new ResourceModel();
......@@ -25,6 +26,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
Console.WriteLine($" - {GetType().Name}: Begin reporting generation");
_logger.LogInformation("{Name}: Begin reporting generation", GetType().Name);
var resources = _resourceModel.GetAllWhere(r => r.Deleted.Equals(true) || r.Deleted.Equals(false));
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = Generate(resources);
......@@ -36,6 +38,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjects, Formatting.Indented))
});
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathGeneral(ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully. {reportingFiles}", GetType().Name, reportingFiles);
// Per Organization
reportingFiles.AddRange(GeneratePerOrganization(returnObjects));
......@@ -44,7 +47,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
return reportingFiles;
}
private List<ReturnObject> Generate(IEnumerable<Coscine.Database.DataModel.Resource> resources)
private List<ReturnObject> Generate(IEnumerable<Database.DataModel.Resource> resources)
{
var returnObjects = new List<ReturnObject>();
foreach (var resource in resources)
......@@ -82,15 +85,18 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
{
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();
reportingFilesPerOrganization.Add(new ReportingFileObject
var reportingFile = new ReportingFileObject
{
Path = GetReportingPathOrganization(organization.RorUrl, ReportingFileName),
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented))
});
};
reportingFilesPerOrganization.Add(reportingFile);
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(organization.RorUrl, ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully {ReportingFile}.", GetType().Name, reportingFile);
}
return reportingFilesPerOrganization;
}
......@@ -108,7 +114,7 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
}
}
private static ResourceQuotaReturnObject? GetResourceQuota(Coscine.Database.DataModel.Resource resource)
private ResourceQuotaReturnObject? GetResourceQuota(Database.DataModel.Resource resource)
{
BaseResourceType? resourceTypeDefinition;
try
......@@ -122,9 +128,17 @@ public class ResourceReporting : Reporting<ResourceReportingOptions>
}
if (resourceTypeDefinition is not null && resourceTypeDefinition.GetResourceTypeInformation().Result.IsQuotaAdjustable)
{
try
{
return Helpers.CreateResourceQuotaReturnObject(resource, resourceTypeDefinition);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error: {message} for {@resource}", ex.Message, resource);
return null;
}
}
else
{
return null;
......
using Coscine.Database.ReturnObjects;
using KPIGenerator.Utils;
using Coscine.KpiGenerator.Utils;
namespace KPIGenerator.Reportings.Resource;
namespace Coscine.KpiGenerator.Reportings.Resource;
/// <summary>
/// Object containing the JSON structure for the reporting
......
using Newtonsoft.Json;
namespace KPIGenerator.Reportings.System;
namespace Coscine.KpiGenerator.Reportings.System;
public class MaintenanceBannerObject
{
......
namespace KPIGenerator.Reportings.System;
namespace Coscine.KpiGenerator.Reportings.System;
/// <summary>
/// Object containing the JSON structure for the reporting
......
using Coscine.Configuration;
using KPIGenerator.Utils;
using Coscine.KpiGenerator.Utils;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Text;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.System;
namespace Coscine.KpiGenerator.Reportings.System;
public class SystemReporting : Reporting<SystemReportingOptions>
{
private readonly ConsulConfiguration _configuration;
public SystemReporting(SystemReportingOptions options) : base(options)
public SystemReporting(SystemReportingOptions options, ILogger _logger) : base(options, _logger)
{
ReportingFileName = "system_status.json";
_configuration = new ConsulConfiguration();
......@@ -20,6 +21,7 @@ public class SystemReporting : Reporting<SystemReportingOptions>
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
Console.WriteLine($" - {GetType().Name}: Begin reporting generation");
_logger.LogInformation("{Name}: Begin reporting generation", GetType().Name);
var reportingFiles = new List<ReportingFileObject>();
var returnObject = GetSystemStatus();
......@@ -30,6 +32,7 @@ public class SystemReporting : Reporting<SystemReportingOptions>
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObject, Formatting.Indented))
});
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathGeneral(ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully. {reportingFiles}", GetType().Name, reportingFiles);
Console.WriteLine();
return reportingFiles;
......
using Coscine.Database.ReturnObjects;
using KPIGenerator.Utils;
using Coscine.KpiGenerator.Utils;
namespace KPIGenerator.Reportings.User;
namespace Coscine.KpiGenerator.Reportings.User;
/// <summary>
/// Object containing the JSON structure for the reporting
......
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.KpiGenerator.Utils;
using Coscine.Metadata;
using KPIGenerator.Utils;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using VDS.RDF.Query;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.User;
namespace Coscine.KpiGenerator.Reportings.User;
public class UserReporting : Reporting<UserReportingOptions>
{
......@@ -19,7 +20,7 @@ public class UserReporting : Reporting<UserReportingOptions>
private readonly LogModel _logModel;
private readonly IEnumerable<ExternalAuthenticator> _loginProviders;
public UserReporting(UserReportingOptions options) : base(options)
public UserReporting(UserReportingOptions options, ILogger _logger) : base(options, _logger)
{
ReportingFileName = "users.json";
_externalAuthenticatorModel = new ExternalAuthenticatorModel();
......@@ -36,6 +37,7 @@ public class UserReporting : Reporting<UserReportingOptions>
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
Console.WriteLine($" - {GetType().Name}: Begin reporting generation");
_logger.LogInformation("{Name}: Begin reporting generation", GetType().Name);
var users = _userModel.GetAllWhere((user) => user.Tosaccepteds.Any());
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = Generate(users);
......@@ -47,6 +49,7 @@ public class UserReporting : Reporting<UserReportingOptions>
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjects, Formatting.Indented))
});
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathGeneral(ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully. {reportingFiles}", GetType().Name, reportingFiles);
// Per Organization
reportingFiles.AddRange(GeneratePerOrganization(returnObjects));
......@@ -55,7 +58,7 @@ public class UserReporting : Reporting<UserReportingOptions>
return reportingFiles;
}
private List<ReturnObject> Generate(IEnumerable<Coscine.Database.DataModel.User> users)
private List<ReturnObject> Generate(IEnumerable<Database.DataModel.User> users)
{
var returnObjects = new List<ReturnObject>();
foreach (var user in users)
......@@ -86,16 +89,19 @@ public class UserReporting : Reporting<UserReportingOptions>
{
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();
reportingFilesPerOrganization.Add(new ReportingFileObject
var reportingFile = new ReportingFileObject
{
Path = GetReportingPathOrganization(organization.RorUrl, ReportingFileName),
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjectsForOrganization, Formatting.Indented))
});
};
reportingFilesPerOrganization.Add(reportingFile);
Console.WriteLine($" - {GetType().Name}: \"{GetReportingPathOrganization(organization.RorUrl, ReportingFileName)}\" generated successfully");
_logger.LogInformation("{Name}: Generated successfully {ReportingFile}.", GetType().Name, reportingFile);
}
return reportingFilesPerOrganization;
}
......@@ -158,8 +164,8 @@ public class UserReporting : Reporting<UserReportingOptions>
result.Add(orgOrcid);
break;
case "shibboleth":
// Find the RoR first based on the Organization Entity Id, then try based on the user's External Id.
var orgShibboleth = GetOrganizationByExternalOrEntityId(externalId.Organization) ?? GetOrganizationByExternalOrEntityId(externalId.ExternalId1);
// Find the RoR first based on the user's External Id, then try based on the Organization Entity Id.
var orgShibboleth = GetOrganizationByExternalOrEntityId(externalId.ExternalId1) ?? GetOrganizationByExternalOrEntityId(externalId.Organization);
if (orgShibboleth is null)
{
Console.WriteLine($" No {searchedEntityType} found for user with ID \"{id}\" and login provider {loginProvider.DisplayName}");
......@@ -195,6 +201,19 @@ public class UserReporting : Reporting<UserReportingOptions>
}
}
// Special case until `https://ror.org/%20https://ror.org/` is moved to `https://ror.org/_other`
if (result.Any(o => o.RorUrl.Equals("https://ror.org/%20https://ror.org/")))
{
foreach (var entry in result)
{
if (entry.RorUrl.Equals("https://ror.org/%20https://ror.org/"))
{
entry.Name = _otherOrganization.Name;
entry.RorUrl = _otherOrganization.RorUrl;
}
}
}
return result.DistinctBy(e => e.RorUrl).ToList();
}
......
namespace KPIGenerator.Utils;
namespace Coscine.KpiGenerator.Utils;
public class Organization
{
......