Skip to content
Snippets Groups Projects
Select Git revision
  • 868940b19c9c08d88f3b7a6a02cd1c579885410c
  • main default protected
  • gitkeep
  • dev protected
  • Issue/2914-trellisMigrator
  • Issue/2847-reporting
  • Hotfix/2776-workingNewVersion
  • Hotfix/xxxx-correctAssignments
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2666-adminCronjobs
  • Issue/2518-docs
  • Hotfix/xxxx-coscineGraph
  • Issue/2304-virtuosoRoars
  • Fix/v0.1.7-dependencies
  • Hotfix/2212-fixFiles
  • Issue/2222-resourceDateCreated
  • Issue/2221-projectDateCreated
  • Hotfix/xxxx-changeUrls
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1782-structualDataIntegration
  • Issue/2084-migrateResourceStructuralData
  • v0.1.24
  • v0.1.23
  • v0.1.22
  • v0.1.21
  • v0.1.20
  • v0.1.19
  • v0.1.18
  • v0.1.17
  • v0.1.16
  • v0.1.15
  • v0.1.14
  • v0.1.13
  • v0.1.12
  • v0.1.11
  • v0.1.10
  • v0.1.9
  • v0.1.7
  • v0.1.8
  • v0.1.6
  • v0.1.5
41 results

RoleStructuralData.cs

Blame
  • Hanna Führ's avatar
    Hanna Führ authored and Benedikt Heinrichs committed
    95ae4127
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    RoleStructuralData.cs 2.86 KiB
    using Coscine.Database.DataModel;
    using Coscine.Database.Models;
    using VDS.RDF;
    
    namespace SQL2Linked.Implementations
    {
        public class RoleStructuralData : StructuralData<Role, RoleModel>
        {
            public readonly string RoleUrlPrefix = "https://purl.org/coscine/roles";
            public readonly Uri RdfType = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
            public readonly Uri orgRole = new("http://www.w3.org/ns/org#Role");
            public readonly Uri dctermsTitle = new("http://purl.org/dc/terms/title");
    
            public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Role> entries)
            {
                var graphs = new List<IGraph>();
    
                foreach (var entry in entries)
                {
                    var roleGraphName = $"{RoleUrlPrefix}/{entry.Id}";
                    var graph = RdfStoreConnector.GetGraph(roleGraphName);
    
                    // check if a triple with a org:role already exists in the role graph
                    var getTriplesOrgRole = graph.GetTriplesWithObject(orgRole);
    
                    if (!getTriplesOrgRole.Any())
                    {
                        graph.Assert(
                            new Triple(
                                graph.CreateUriNode(new Uri(roleGraphName)),
                                graph.CreateUriNode(RdfType),
                                graph.CreateUriNode(orgRole)
                            )
                        );
    
                        Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri}' a org:Role. ");
                    }
                    else
                    {
                        Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri}' a org:Role. ");
                    }
    
                    // check if a triple with dcterms:title '{entry.DisplayName}' already exists in the role graph
                    var getTriplesDctermsTitle = graph.GetTriplesWithPredicate(dctermsTitle);
    
                    if (!getTriplesDctermsTitle.Any())
                    {
                        graph.Assert(
                            new Triple(
                                graph.CreateUriNode(new Uri(roleGraphName)),
                                graph.CreateUriNode(dctermsTitle),
                                graph.CreateLiteralNode(entry.DisplayName)
                            )
                        );
    
                        Console.WriteLine($"For role '{entry.DisplayName}' will migrate triple '{graph.BaseUri}' dcterms:title '{entry.DisplayName}'. ");
                    }
                    else
                    {
                        Console.WriteLine($"For role '{entry.DisplayName}' will NOT migrate triple '{graph.BaseUri}' dcterms:title '{entry.DisplayName}'. ");
                    }
                    if (!getTriplesOrgRole.Any() || !getTriplesDctermsTitle.Any())
                    {
                        graphs.Add(graph);
                    }
                }
                return graphs;
            }
        }
    }