Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • gitkeep
  • dev protected
  • Issue/2309-docs
  • Hotfix/2097-fixTimeFormat
  • Issue/1910-MigrationtoNET6.0
  • Sprint/2022-01
  • Sprint/2021-05
  • Product/1188-LoggingExtended
  • Topic/1221-LogginExtendedNew
  • Sprint/2021-03
  • Product/1287-dotnet5Sharepoint
  • Topic/1334-dotnet5migration
  • Topic/1221-LoggingExtended
  • Sprint/2021-01
  • Product/407-net5migration
  • Topic/1226-loggingLibraryMigration
  • v2.2.2
  • v2.2.1
  • v2.2.0
  • v2.1.0
  • v2.0.0
  • v1.3.0
  • v1.2.0
  • v1.1.0
  • v1.0.1
  • v1.0.0
27 results

AnalyticsLogObject.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    RoleStructuralData.cs 2.86 KiB
    using Coscine.ApiClient.Core.Api;
    using Coscine.ApiClient.Core.Model;
    using Microsoft.Extensions.Logging;
    using VDS.RDF;
    using VDS.RDF.Parsing;
    
    namespace Coscine.GraphDeployer;
    
    /// <summary>
    /// Class responsible for converting role data into linked data graphs.
    /// It retrieves role information from the API and then transforms this data into a series of RDF graphs,
    /// making use of predefined URIs and RDF constructs.
    /// </summary>
    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)
        {
            await foreach (var entry in entries)
            {
                var roleGraphName = UriHelper.TryCombineUri(RdfUris.CoscineRoles, entry.Id)
                    ?? throw new Exception("Could not combine role prefix with role ID");
                var response = await _adminApi.GetMetadataGraphAsync(roleGraphName.AbsoluteUri, RdfFormat.TextTurtle);
    
                var graph = new Graph()
                {
                    BaseUri = roleGraphName
                };
    
                graph.LoadFromString(response.Data.Content, new TurtleParser());
    
                // check if a triple with a org:role already exists in the role graph
                var getTriplesOrgRole = graph.GetTriplesWithObject(RdfUris.OrgRoleClass);
    
                if (!getTriplesOrgRole.Any())
                {
                    GraphExtensions.AssertToGraph(graph, roleGraphName, RdfUris.A, RdfUris.OrgRoleClass);
                    _logger.LogInformation($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {RdfUris.A} {RdfUris.OrgRoleClass}'. ");
                }
                else
                {
                    _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
                var getTriplesDctermsTitle = graph.GetTriplesWithPredicate(RdfUris.DcTermsTitle);
    
                if (!getTriplesDctermsTitle.Any())
                {
                    GraphExtensions.AssertToGraph(graph, roleGraphName, RdfUris.DcTermsTitle, entry.DisplayName);
                   _logger.LogInformation($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.DisplayName}'. ");
                }
                else
                {
                    _logger.LogInformation($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri} {RdfUris.DcTermsTitle} {entry.DisplayName}'. ");
                }
                if (!getTriplesOrgRole.Any() || !getTriplesDctermsTitle.Any())
                {
                    yield return graph;
                }
            }
        }
    }