diff --git a/src/SQL2Linked/Implementations/RoleStructuralData.cs b/src/SQL2Linked/Implementations/RoleStructuralData.cs index b393353ae800afb27ffbc64055d1db720f062ff3..36fd917514d18a9efab0d5dcd1d8b7226107fd8e 100644 --- a/src/SQL2Linked/Implementations/RoleStructuralData.cs +++ b/src/SQL2Linked/Implementations/RoleStructuralData.cs @@ -6,10 +6,65 @@ 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) { - // ToDo: Implement - throw new NotImplementedException(); + 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.CreateLiteralNode(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 getTriplesDisplayname = graph.GetTriplesWithObject(graph.CreateLiteralNode(entry.DisplayName)); + + if (!getTriplesDisplayname.Any()) + { + graph.Assert( + new Triple( + graph.CreateLiteralNode(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() || !getTriplesDisplayname.Any()) + { + graphs.Add(graph); + } + } + return graphs; } } } \ No newline at end of file