diff --git a/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs b/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs index 766787fc5726996935a20b523bf1e2e094e70fa6..fe455a9233c456e34294f7350c1765e1f7166234 100644 --- a/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs +++ b/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs @@ -6,10 +6,44 @@ namespace SQL2Linked.Implementations { public class ResourceTypeStructuralData : StructuralData<ResourceType, ResourceTypeModel> { + public readonly string ResourceTypeUrlPrefix = "https://purl.org/coscine/resourcetype"; + public readonly Uri RdfType = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + public readonly Uri DcatDataService = new ("http://www.w3.org/ns/dcat#DataService"); + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<ResourceType> entries) { - // ToDo: Implement - throw new NotImplementedException(); + + var graphs = new List<IGraph>(); + + foreach (var entry in entries) + { + var resourceTypeGraphName = $"{ResourceTypeUrlPrefix}/{entry.Id}"; + var graph = RdfStoreConnector.GetGraph(resourceTypeGraphName); + + // check if a triple with a dcat:DataService already exists in the resourcetype graph + var getTriples = graph.GetTriplesWithObject(DcatDataService); + + if (!getTriples.Any()) + { + graph.Assert( + new Triple( + graph.CreateBlankNode(), + graph.CreateUriNode(RdfType), + graph.CreateUriNode(DcatDataService) + ) + ); + + graphs.Add(graph); + + Console.WriteLine($"Will migrate resource type '{entry.DisplayName}' with id '{entry.Id}'."); + } + else + { + Console.WriteLine($"Will NOT migrate resource type '{entry.DisplayName}' with id '{entry.Id}'."); + } + } + return graphs; } } + } \ No newline at end of file diff --git a/src/SQL2Linked/Implementations/UserStructuralData.cs b/src/SQL2Linked/Implementations/UserStructuralData.cs index 5faa65586694c06f0f16cc0efea396d96e6bba4f..14abb64ea8a4d97f7af0d1b2883682974238be3b 100644 --- a/src/SQL2Linked/Implementations/UserStructuralData.cs +++ b/src/SQL2Linked/Implementations/UserStructuralData.cs @@ -25,14 +25,6 @@ namespace SQL2Linked.Implementations 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(),