From ff44aefc1a3df6b47eacaddf78ebee54633d4cbe Mon Sep 17 00:00:00 2001
From: Heinrichs <Heinrichs@itc.rwth-aachen.de>
Date: Wed, 10 Aug 2022 12:43:06 +0200
Subject: [PATCH] Add User Displayname

---
 src/SQL2Linked/Implementations/UserStructuralData.cs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/SQL2Linked/Implementations/UserStructuralData.cs b/src/SQL2Linked/Implementations/UserStructuralData.cs
index 02865a1..29f8111 100644
--- a/src/SQL2Linked/Implementations/UserStructuralData.cs
+++ b/src/SQL2Linked/Implementations/UserStructuralData.cs
@@ -10,6 +10,7 @@ namespace SQL2Linked.Implementations
         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>();
@@ -21,11 +22,16 @@ namespace SQL2Linked.Implementations
 
                 // 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())
+                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}'.");
@@ -33,7 +39,7 @@ namespace SQL2Linked.Implementations
                 else
                 {
                     Console.WriteLine($"Will NOT migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
-                } 
+                }
             }
             return graphs;
         }
-- 
GitLab