Skip to content
Snippets Groups Projects
Select Git revision
  • 08af9ed06d05b87ee3b29592702cdeeb94096278
  • 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

UserStructuralData.cs

Blame
  • Hanna Führ's avatar
    Hanna Führ authored and Benedikt Heinrichs committed
    42ec34db
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    UserStructuralData.cs 1.89 KiB
    using Coscine.Database.DataModel;
    using Coscine.Database.Models;
    using Coscine.Metadata;
    using VDS.RDF;
    
    namespace SQL2Linked.Implementations
    {
        public class UserStructuralData : StructuralData<User, UserModel>
        {
            public readonly string UserUrlPrefix = "https://purl.org/coscine/users";
            public readonly Uri rdf = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            public readonly Uri foaf = new("http://xmlns.com/foaf/0.1/");
    
            public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<User> entries)
            {
                var graphs = new List<IGraph>();
    
                foreach (var entry in entries)
                {
                    var userGraphName = $"{UserUrlPrefix}/{entry.Id}";
                    var graph = RdfStoreConnector.GetGraph(userGraphName);
    
                    // check if a triple with a foaf:Person already exists in the user graph
                    var getTriples = graph.GetTriplesWithObject(new Uri(foaf + "Person"));
                    // check if the current display name is already applied in the user graph
                    var getTriplesName = graph.GetTriplesWithPredicate(new Uri(foaf + "name"));
    
                    if (!getTriples.Any() || !getTriplesName.Any((triple) => triple.Object.ToString() == entry.DisplayName))
                    {
                        AssertToGraphUriNode(graph, userGraphName, rdf + "type", foaf + "Person");
    
                        graph.Retract(getTriplesName);
                        AssertToGraphLiteralNode(graph, userGraphName, foaf + "name", entry.DisplayName);
    
                        graphs.Add(graph);
    
                        Console.WriteLine($"Will migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
                    }
                    else
                    {
                        Console.WriteLine($"Will NOT migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
                    }
                }
                return graphs;
            }
        }
    }