Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • gitkeep
  • dev protected
  • Issue/2449-GuidPidSlugToProjectSettings
  • Issue/2309-docs
  • Issue/2355-topLevelOrg
  • Issue/2328-noFailOnLog
  • Hotfix/2371-fixGitLabinRCV
  • Issue/2287-guestRole
  • Fix/xxxx-activateGitlab
  • Test/xxxx-enablingGitLab
  • Issue/2349-gitlabHttps
  • Issue/2259-updatePids
  • Issue/2101-gitLabResTypeUi
  • Hotfix/2202-fixNaNQuota
  • Issue/2246-quotaResoval
  • Issue/2221-projectDateCreated
  • Hotfix/2224-quotaSizeAnalytics
  • Fix/xxxx-resourceVisibility
  • Issue/2000-gitlabResourcesAPI
  • v4.4.3
  • v4.4.2
  • v4.4.1
  • v4.4.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
  • v4.3.0
  • v4.2.8
  • v4.2.7
  • v4.2.6
  • v4.2.5
  • v4.2.4
  • v4.2.3
  • v4.2.2
  • v4.2.1
  • v4.2.0
  • v4.1.1
  • v4.1.0
40 results

ProjectQuotaController.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;
                }
            }
        }
    }