diff --git a/src/SQL2Linked/Implementations/UserStructuralData.cs b/src/SQL2Linked/Implementations/UserStructuralData.cs index b0b43c3e03e21483515e5b0cb61619308bc776c4..5faa65586694c06f0f16cc0efea396d96e6bba4f 100644 --- a/src/SQL2Linked/Implementations/UserStructuralData.cs +++ b/src/SQL2Linked/Implementations/UserStructuralData.cs @@ -1,15 +1,56 @@ 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 RdfType = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + public readonly Uri FoafPerson = new("http://xmlns.com/foaf/0.1/Person"); + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<User> entries) { - // ToDo: Implement - throw new NotImplementedException(); + 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(FoafPerson); + + if (!getTriples.Any()) + { + // check if a user graph already exists + var exists = RdfStoreConnector.HasGraph(userGraphName); + + if (!exists) + { + RdfStoreConnector.CreateNamedGraph(userGraphName); + } + + graph.Assert( + new Triple( + graph.CreateBlankNode(), + graph.CreateUriNode(RdfType), + graph.CreateUriNode(FoafPerson) + ) + ); + + 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; } } -} \ No newline at end of file +} diff --git a/src/SQL2Linked/StructuralData.cs b/src/SQL2Linked/StructuralData.cs index 883fe3fb3d8c6309632431a518d7cee605754ae8..78d70e490e2d9156cc7d5989e86bca52103a5ea7 100644 --- a/src/SQL2Linked/StructuralData.cs +++ b/src/SQL2Linked/StructuralData.cs @@ -52,4 +52,4 @@ namespace SQL2Linked } } } -} \ No newline at end of file +}