From 883ab7b65c4d1a8ed1ebc8d064ac9a1abd2f543e Mon Sep 17 00:00:00 2001 From: Sirieam Marie Hunke <hunke@itc.rwth-aachen.de> Date: Wed, 28 Aug 2024 11:07:58 +0000 Subject: [PATCH] Optimizing the code --- src/GraphDeployer/Deployer.cs | 30 +++++++++++++++---- .../ResourcetypeStructuralData.cs | 12 +------- .../Implementations/RoleStructuralData.cs | 6 ---- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/GraphDeployer/Deployer.cs b/src/GraphDeployer/Deployer.cs index 46484df..e1c377e 100644 --- a/src/GraphDeployer/Deployer.cs +++ b/src/GraphDeployer/Deployer.cs @@ -20,6 +20,8 @@ public class Deployer private readonly ILogger<Deployer> _logger; private readonly GraphDeployerConfiguration _graphDeployerConfiguration; private readonly AdminApi _adminApi; + private readonly ResourceTypeApi _resourceTypeApi; + private readonly RoleApi _roleApi; public Deployer(ILogger<Deployer> logger, IOptionsMonitor<GraphDeployerConfiguration> graphDeployerConfiguration) { @@ -42,6 +44,8 @@ public class Deployer apiClientConfig.RemoteCertificateValidationCallback = (_, _, _, _) => true; } _adminApi = new(apiClientConfig); + _resourceTypeApi = new ResourceTypeApi(apiClientConfig); + _roleApi = new RoleApi(apiClientConfig); } public static string WorkingFolder { get; set; } = "./output/"; @@ -52,6 +56,14 @@ public class Deployer 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 @@ -77,6 +89,16 @@ public class Deployer (currentPage) => _adminApi.GetDeployedGraphsAsync(pageNumber: currentPage, pageSize: 50)); var deployedGraphsList = await graphs.ToListAsync(); + var roleResponse = PaginationHelper.GetAllAsync<RoleDtoPagedResponse, RoleDto>( + (currentPage) => _roleApi.GetRolesAsync(pageNumber: currentPage)); + + var resourceTypeInformationsResponse = await _resourceTypeApi.GetAllResourceTypesInformationAsync(); + var resourceTypeList = new List<ResourceTypeInformationDto>(); + foreach (var item in resourceTypeInformationsResponse.Data) + { + resourceTypeList.Add(item); + } + // Iterate over the repositories and deploy the graphs foreach (var graphRepo in _graphDeployerConfiguration.GitLab.Repositories) { @@ -168,14 +190,12 @@ public class Deployer continue; } } - // Convert to linked data - - // Store the graph } - // Clean up the working folder EmptyWorkingFolder(); } + // Convert to linked data + // Store the graph return true; } @@ -270,7 +290,7 @@ public class Deployer _logger.LogError(e, "Failed to delete contents of the working folder: \"{workingFolder}\"", WorkingFolder); } } - /// <summary> + /// <summary> /// Asynchronously stores a collection of RDF graphs in the underlying data store. /// </summary> /// <param name="graphs">An asynchronous enumerable of RDF graphs (<see cref="IAsyncEnumerable{IGraph}"/>) to be stored.</param> diff --git a/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs b/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs index 3b5356d..ffeba52 100644 --- a/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs +++ b/src/GraphDeployer/Implementations/ResourcetypeStructuralData.cs @@ -19,17 +19,7 @@ public class ResourceTypeStructuralData _deployer = deployer; } - public async IAsyncEnumerable<ResourceTypeInformationDto> GetAll() - { - var resourceTypeApi = new ResourceTypeApi(apiClientConfig); - var resourceTypeInformationsResponse = await resourceTypeApi.GetAllResourceTypesInformationAsync(); - foreach (var item in resourceTypeInformationsResponse.Data) - { - yield return item; // Yield each item in the list to keep the IAsyncEnumerable logic - } - } - - public override async IAsyncEnumerable<IGraph> ConvertToLinkedDataAsync(IAsyncEnumerable<ResourceTypeInformationDto> entries) + public async IAsyncEnumerable<IGraph> ConvertToLinkedDataAsync(IAsyncEnumerable<ResourceTypeInformationDto> entries) { await foreach (var entry in entries) { diff --git a/src/GraphDeployer/Implementations/RoleStructuralData.cs b/src/GraphDeployer/Implementations/RoleStructuralData.cs index a9e2734..ca8260a 100644 --- a/src/GraphDeployer/Implementations/RoleStructuralData.cs +++ b/src/GraphDeployer/Implementations/RoleStructuralData.cs @@ -21,12 +21,6 @@ public class RoleStructuralData _deployer = deployer; } - public IAsyncEnumerable<RoleDto> GetAll() - { - var roleApi = new RoleApi(apiClientConfig); - return PaginationHelper.GetAllAsync<RoleDtoPagedResponse, RoleDto>( - (currentPage) => roleApi.GetRolesAsync(pageNumber: currentPage)); - } public async IAsyncEnumerable<IGraph> ConvertToLinkedDataAsync(IAsyncEnumerable<RoleDto> entries) { await foreach (var entry in entries) -- GitLab