From 3cb0ff4af7149fc1cd5328ceb213dc0641ea8d5d Mon Sep 17 00:00:00 2001 From: Sirieam Marie Hunke <hunke@itc.rwth-aachen.de> Date: Fri, 20 Sep 2024 12:39:47 +0000 Subject: [PATCH] Small fixes --- src/GraphDeployer/Deployer.cs | 26 ++++++++++--------- .../ResourcetypeStructuralData.cs | 15 ++++++----- .../Implementations/RoleStructuralData.cs | 10 ++++--- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/GraphDeployer/Deployer.cs b/src/GraphDeployer/Deployer.cs index 3fb2977..76d1611 100644 --- a/src/GraphDeployer/Deployer.cs +++ b/src/GraphDeployer/Deployer.cs @@ -23,11 +23,21 @@ public class Deployer private readonly RoleStructuralData _roleStructuralData; private readonly ResourceTypeStructuralData _resourceTypeStructuralData; + // Define ANSI escape codes for colors + private const string _esc = "\u001b"; // ANSI escape character + private const string _r = $"{_esc}[91m"; + private const string _gb = $"{_esc}[1;92m"; + private const string _y = $"{_esc}[93m"; + private const string _bb = $"{_esc}[1;94m"; + private const string _c = $"{_esc}[96m"; + private const string _0 = $"{_esc}[0m"; + + public Deployer(ILogger<Deployer> logger, IOptionsMonitor<GraphDeployerConfiguration> graphDeployerConfiguration, RoleStructuralData roleStructuralData, ResourceTypeStructuralData resourceTypeStructuralData) { _logger = logger; _graphDeployerConfiguration = graphDeployerConfiguration.CurrentValue; - + // Build the configuration for the API client based on the configuration settings var apiClientConfig = new Configuration { @@ -58,15 +68,7 @@ public class Deployer // RDF URIs public static Uri CoscineEntitiesGraphDeployed { get; } = new("https://purl.org/coscine/entities/graph#deployed"); public static Uri CoscineTermsDeployedVersion { get; } = new("https://purl.org/coscine/terms/deployed#version"); - - public ResourceTypeApi GetResourceTypeApi() - { - return _resourceTypeApi; - } - public RoleApi GetRoleApi() - { - return _roleApi; - } + public async Task<bool> RunAsync(GraphDeployerOptions opts) { // Check if the graph deployer is enabled @@ -202,13 +204,13 @@ public class Deployer _logger.LogInformation("Converting resource types to linked data..."); var resourceTypeStructuralGraphs = _resourceTypeStructuralData.ConvertToLinkedDataAsync(resourceTypeInformations); - + _logger.LogInformation("Storing the graphs..."); await StoreGraphs(roleStructuralGraphs); await StoreGraphs(resourceTypeStructuralGraphs); _logger.LogInformation("All structural graphs stored successfully.\n"); - _logger.LogInformation("SQL to Linked Data migration completed successfully."); + _logger.LogInformation("SQL to Linked Data migration completed successfully."); return true; } diff --git a/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs b/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs index ff625a7..1812501 100644 --- a/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs +++ b/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs @@ -12,9 +12,12 @@ namespace Coscine.GraphDeployer; public class ResourceTypeStructuralData { private readonly AdminApi _adminApi; + private readonly ILogger<ResourceTypeStructuralData> _logger; public ResourceTypeStructuralData(AdminApi adminApi) { _adminApi = adminApi; + _logger = logger; + } public async IAsyncEnumerable<IGraph> ConvertToLinkedDataAsync(IAsyncEnumerable<ResourceTypeInformationDto> entries) { @@ -37,11 +40,11 @@ public class ResourceTypeStructuralData if (!getTriplesDcatDataService.Any()) { GraphExtensions.AssertToGraph(graph, resourceTypeGraphName, RdfUris.A, RdfUris.DcatDataServiceClass); - Console.WriteLine($"For resource type '{entry.SpecificType}' will migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.DcatDataServiceClass}'. "); + _logger.LogInformation($"For resource type '{entry.SpecificType}' will migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.DcatDataServiceClass}'. "); } else { - Console.WriteLine($"For resource type '{entry.SpecificType}' will NOT migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.DcatDataServiceClass}'. "); + _logger.LogInformation($"For resource type '{entry.SpecificType}' will NOT migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.DcatDataServiceClass}'. "); } // check if a triple with dcterms:title '{entry.DisplayName}' already exists in the role graph @@ -50,11 +53,11 @@ public class ResourceTypeStructuralData if (!getTriplesDctermsTitle.Any()) { GraphExtensions.AssertToGraph(graph, resourceTypeGraphName, RdfUris.DcTermsTitle, entry.SpecificType); - Console.WriteLine($"For resource type '{entry.SpecificType}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.SpecificType}'. "); + _logger.LogInformation($"For resource type '{entry.SpecificType}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.SpecificType}'. "); } else { - Console.WriteLine($"For resource type '{entry.SpecificType}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.SpecificType}'. "); + _logger.LogInformation($"For resource type '{entry.SpecificType}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.SpecificType}'. "); } @@ -64,11 +67,11 @@ public class ResourceTypeStructuralData if (!getTriplesDctermsAlternative.Any()) { GraphExtensions.AssertToGraph(graph, resourceTypeGraphName, RdfUris.DcTermsAlternative, entry.GeneralType); - Console.WriteLine($"For resource type '{entry.SpecificType}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsAlternative} {entry.GeneralType}'. "); + _logger.LogInformation($"For resource type '{entry.SpecificType}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsAlternative} {entry.GeneralType}'. "); } else { - Console.WriteLine($"For resource type '{entry.SpecificType}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsAlternative} {entry.GeneralType}'. "); + _logger.LogInformation($"For resource type '{entry.SpecificType}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsAlternative} {entry.GeneralType}'. "); } if (!getTriplesDcatDataService.Any() || !getTriplesDctermsTitle.Any()) diff --git a/src/GraphDeployer/Implementations/RoleStructuralData.cs b/src/GraphDeployer/Implementations/RoleStructuralData.cs index 7abe92f..0e601ad 100644 --- a/src/GraphDeployer/Implementations/RoleStructuralData.cs +++ b/src/GraphDeployer/Implementations/RoleStructuralData.cs @@ -13,9 +13,11 @@ namespace Coscine.GraphDeployer; public class RoleStructuralData { private readonly AdminApi _adminApi; + private readonly ILogger<ResourceTypeStructuralData> _logger; public RoleStructuralData(AdminApi adminApi) { _adminApi = adminApi; + _logger = logger; } public async IAsyncEnumerable<IGraph> CreateGraphAsync(IAsyncEnumerable<RoleDto> entries) @@ -39,11 +41,11 @@ public class RoleStructuralData if (!getTriplesOrgRole.Any()) { GraphExtensions.AssertToGraph(graph, roleGraphName, RdfUris.A, RdfUris.OrgRoleClass); - Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.OrgRoleClass}'. "); + _logger.LogInformation($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.OrgRoleClass}'. "); } else { - Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.OrgRoleClass}'. "); + _logger.LogInformation($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.OrgRoleClass}'. "); } // check if a triple with dcterms:title '{entry.DisplayName}' already exists in the role graph @@ -52,11 +54,11 @@ public class RoleStructuralData if (!getTriplesDctermsTitle.Any()) { GraphExtensions.AssertToGraph(graph, roleGraphName, RdfUris.DcTermsTitle, entry.DisplayName); - Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.DisplayName}'. "); + _logger.LogInformation($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.DisplayName}'. "); } else { - Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.DisplayName}'. "); + _logger.LogInformation($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.DisplayName}'. "); } if (!getTriplesOrgRole.Any() || !getTriplesDctermsTitle.Any()) { -- GitLab