diff --git a/src/SQL2Linked/Implementations/UserStructuralData.cs b/src/SQL2Linked/Implementations/UserStructuralData.cs index 3771d33e7edb4e7be7a79173be8996a85943907a..0f457fb589c42d2779295614375c07167f4857c9 100644 --- a/src/SQL2Linked/Implementations/UserStructuralData.cs +++ b/src/SQL2Linked/Implementations/UserStructuralData.cs @@ -2,58 +2,54 @@ using Coscine.Database.Models; using Coscine.Metadata; using VDS.RDF; -using VDS.RDF.Query; namespace SQL2Linked.Implementations { public class UserStructuralData : StructuralData<User, UserModel> { public readonly string UserUrlPrefix = "https://purl.org/coscine/users"; - public readonly Uri FoafPerson = new Uri("http://xmlns.com/foaf/0.1/Person"); + 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) { var graphs = new List<IGraph>(); - foreach (User entry in entries) + foreach (var entry in entries) { - string userGraphName = $"{UserUrlPrefix}/{entry.Id}"; - IGraph graph = RdfStoreConnector.GetGraph(userGraphName); + 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.Count() == 0) + if (!getTriples.Any()) { // check if a user graph already exists - bool exists = RdfStoreConnector.HasGraph(userGraphName); + var exists = RdfStoreConnector.HasGraph(userGraphName); if (!exists) { RdfStoreConnector.CreateNamedGraph(userGraphName); } - // extend graph by triple https://purl.org/coscine/users/{userId} a foaf:Person - var commandString = new SparqlParameterizedString - { - CommandText = @"INSERT - { - GRAPH @userGraphName - { - [ - a foaf:Person ; - ] - } - }" - }; - - commandString.Namespaces.AddNamespace("foaf", FoafPrefixUrl); - commandString.SetUri("userGraphName", new Uri(userGraphName)); - QueryEndpoint.QueryRaw(commandString.ToString()); + graph.Assert( + new Triple( + graph.CreateBlankNode(), + graph.CreateUriNode(RdfType), + graph.CreateUriNode(FoafPerson) + ) + ); + + Console.WriteLine($"Will migrate user '{entry.DisplayName}' with id '{entry.Id}'."); + } + else + { + Console.WriteLine($"Will NOT migrate user '{entry.DisplayName}' with id '{entry.Id}'."); } graphs.Add(graph); } return graphs; } } -} \ No newline at end of file +} diff --git a/src/SQL2Linked/StructuralData.cs b/src/SQL2Linked/StructuralData.cs index b33123ca4499130a9a481b857416625d5da966b3..78d70e490e2d9156cc7d5989e86bca52103a5ea7 100644 --- a/src/SQL2Linked/StructuralData.cs +++ b/src/SQL2Linked/StructuralData.cs @@ -2,7 +2,6 @@ using Coscine.Database.Models; using Coscine.Metadata; using VDS.RDF; -using VDS.RDF.Query; namespace SQL2Linked { @@ -11,17 +10,14 @@ namespace SQL2Linked public T Model { get; init; } public ConsulConfiguration Configuration { get; init; } public RdfStoreConnector RdfStoreConnector { get; init; } - public readonly SparqlRemoteEndpoint QueryEndpoint; - public readonly Uri FoafPrefixUrl = new Uri("http://xmlns.com/foaf/0.1/"); - + public StructuralData() { Configuration = new ConsulConfiguration(); RdfStoreConnector = new RdfStoreConnector(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url")); Model = new T(); - QueryEndpoint = new SparqlRemoteEndpoint(new Uri(string.Format("http://localhost:8890/sparql"))); } - + public abstract IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<S> entries); public void Migrate(bool dummyMode) @@ -56,4 +52,4 @@ namespace SQL2Linked } } } -} \ No newline at end of file +}