From c28f25f7756f07561675222e8c66c34a197858bb Mon Sep 17 00:00:00 2001
From: Heinrichs <Heinrichs@itc.rwth-aachen.de>
Date: Thu, 15 Sep 2022 15:34:28 +0200
Subject: [PATCH] Use PURLs

---
 .../Implementations/ProjectStructuralData.cs  | 13 +++--
 .../Implementations/ResourceStructuralData.cs | 22 ++++---
 .../ResourceTypeStructuralData.cs             |  2 +-
 src/SQL2Linked/StructuralData.cs              | 57 +++++++++++--------
 4 files changed, 56 insertions(+), 38 deletions(-)

diff --git a/src/SQL2Linked/Implementations/ProjectStructuralData.cs b/src/SQL2Linked/Implementations/ProjectStructuralData.cs
index b3f63d4..da1d4cd 100644
--- a/src/SQL2Linked/Implementations/ProjectStructuralData.cs
+++ b/src/SQL2Linked/Implementations/ProjectStructuralData.cs
@@ -36,11 +36,14 @@ namespace SQL2Linked.Implementations
             IEnumerable<ProjectResource> projectResources = ProjectResourceModel.GetAll();
 
             var graphs = new List<IGraph>();
-            string projectUrlPrefix = "https://hdl.handle.net/" + Prefix;
+            var projectUrlHandlePrefix = "https://hdl.handle.net/" + Prefix;
+            var projectUrlPrefix = "https://purl.org/coscine/projects";
+            var resourceUrlPrefix = "https://purl.org/coscine/resources";
 
             foreach (var entry in entries)
             {
                 var projectGraphName = $"{projectUrlPrefix}/{entry.Id}";
+                var projectHandleName = $"{projectUrlHandlePrefix}/{entry.Id}";
 
                 var graph = new Graph();
                 graph.BaseUri = new Uri(projectGraphName);
@@ -107,8 +110,8 @@ namespace SQL2Linked.Implementations
                 AssertToGraphLiteralNode(graph, projectGraphName, cosc + "terms/project#slug", entry.Slug);
                 Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{projectGraphName} {cosc}terms/project#slug {entry.Slug}'. ");
 
-                AssertToGraphUriNode(graph, projectGraphName, foaf + "homepage", projectGraphName);
-                Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{projectGraphName} {foaf}homepage {projectGraphName}'. ");
+                AssertToGraphUriNode(graph, projectGraphName, foaf + "homepage", projectHandleName);
+                Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{projectGraphName} {foaf}homepage {projectHandleName}'. ");
 
                 foreach (var projectRole in projectRoles)
                 {
@@ -137,8 +140,8 @@ namespace SQL2Linked.Implementations
                 {
                     if (entry.Id == projectResource.ProjectId)
                     {
-                        AssertToGraphUriNode(graph, projectGraphName, dcat + "catalog", $"{projectUrlPrefix}/{projectResource.ResourceId}");
-                        Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{projectGraphName} {dcat}catalog {projectUrlPrefix}/{projectResource.ResourceId}'. ");
+                        AssertToGraphUriNode(graph, projectGraphName, dcat + "catalog", $"{resourceUrlPrefix}/{projectResource.ResourceId}");
+                        Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{projectGraphName} {dcat}catalog {resourceUrlPrefix}/{projectResource.ResourceId}'. ");
                     }
                 }
 
diff --git a/src/SQL2Linked/Implementations/ResourceStructuralData.cs b/src/SQL2Linked/Implementations/ResourceStructuralData.cs
index c603d16..376f6ba 100644
--- a/src/SQL2Linked/Implementations/ResourceStructuralData.cs
+++ b/src/SQL2Linked/Implementations/ResourceStructuralData.cs
@@ -38,11 +38,14 @@ namespace SQL2Linked.Implementations
             IEnumerable<License> licenses = LicenseModel.GetAll();
 
             var graphs = new List<IGraph>();
-            string resourceUrlPrefix = "https://hdl.handle.net/" + Prefix;
+            var resourceUrlHandlePrefix = "https://hdl.handle.net/" + Prefix;
+            var projectUrlPrefix = "https://purl.org/coscine/projects";
+            var resourceUrlPrefix = "https://purl.org/coscine/resources";
 
             foreach (var entry in entries)
             {
                 var resourceGraphName = $"{resourceUrlPrefix}/{entry.Id}";
+                var resourceHandleName = $"{resourceUrlHandlePrefix}/{entry.Id}";
 
                 var graph = new Graph();
                 graph.BaseUri = new Uri(resourceGraphName);
@@ -53,8 +56,8 @@ namespace SQL2Linked.Implementations
                 AssertToGraphUriNode(graph, resourceGraphName, rdf + "type", pim + "Storage");
                 Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {rdf}type {pim}Storage'. ");
 
-                AssertToGraphUriNode(graph, resourceGraphName, dcat + "service", cosc + $"resourcetype/{entry.TypeId}");
-                Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcat}service {cosc}resourcetype/{entry.TypeId}'. ");
+                AssertToGraphUriNode(graph, resourceGraphName, dcat + "service", cosc + $"resourcetypes/{entry.TypeId}");
+                Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcat}service {cosc}resourcetypes/{entry.TypeId}'. ");
 
                 AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "title", entry.ResourceName);
                 Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}title {entry.ResourceName}'. ");
@@ -122,7 +125,7 @@ namespace SQL2Linked.Implementations
                 AssertToGraphLiteralNode(graph, resourceGraphName, cosc + "terms/resource#archived", entry.Archived.ToString().ToLower(), new Uri("http://www.w3.org/2001/XMLSchema#boolean"));
                 Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#archived {entry.Archived}'. ");
 
-                AssertToGraphUriNode(graph, resourceGraphName, foaf + "homepage", resourceGraphName);
+                AssertToGraphUriNode(graph, resourceGraphName, foaf + "homepage", resourceHandleName);
                 Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {foaf}homepage {resourceGraphName}'. ");
 
                 AssertToGraphLiteralNode(graph, resourceGraphName, cosc + "terms/resource#deleted", entry.Deleted.ToString().ToLower(), new Uri("http://www.w3.org/2001/XMLSchema#boolean"));
@@ -154,8 +157,8 @@ namespace SQL2Linked.Implementations
                         AssertToGraphBlankAndUriNode(graph, blankNode, rdf + "type", acl + "Authorization");
                         Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {rdf}type {acl}Authorization'. ");
 
-                        AssertToGraphBlankAndUriNode(graph, blankNode, acl + "agentGroup", $"{resourceUrlPrefix}/{projectResource.ProjectId}");
-                        Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}agentGroup {resourceUrlPrefix}/{projectResource.ProjectId}'. ");
+                        AssertToGraphBlankAndUriNode(graph, blankNode, acl + "agentGroup", $"{projectUrlPrefix}/{projectResource.ProjectId}");
+                        Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}agentGroup {projectUrlPrefix}/{projectResource.ProjectId}'. ");
 
                         AssertToGraphBlankAndUriNode(graph, blankNode, acl + "accessTo", resourceGraphName);
                         Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}accessTo {resourceGraphName}'. ");
@@ -163,8 +166,11 @@ namespace SQL2Linked.Implementations
                         AssertToGraphBlankAndUriNode(graph, blankNode, acl + "default", resourceGraphName);
                         Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}default {resourceGraphName}'. ");
 
-                        AssertToGraphBlankAndUriNode(graph, blankNode, acl + "mode", acl + "Control");
-                        Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}accessTo {acl}Control'. ");
+                        AssertToGraphBlankAndUriNode(graph, blankNode, acl + "mode", acl + "Read");
+                        Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}accessTo {acl}Read'. ");
+
+                        AssertToGraphBlankAndUriNode(graph, blankNode, acl + "mode", acl + "Write");
+                        Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}accessTo {acl}Write'. ");
                     }
                 }
 
diff --git a/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs b/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs
index d5fc3b2..06040e1 100644
--- a/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs
+++ b/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs
@@ -6,7 +6,7 @@ namespace SQL2Linked.Implementations
 {
     public class ResourceTypeStructuralData : StructuralData<ResourceType, ResourceTypeModel>
     {
-        public readonly string ResourceTypeUrlPrefix = "https://purl.org/coscine/resourcetype";
+        public readonly string ResourceTypeUrlPrefix = "https://purl.org/coscine/resourcetypes";
         public readonly Uri rdf = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
         public readonly Uri dcat = new("http://www.w3.org/ns/dcat#");
         public readonly Uri dcterms = new("http://purl.org/dc/terms/");
diff --git a/src/SQL2Linked/StructuralData.cs b/src/SQL2Linked/StructuralData.cs
index 9f9f113..0b86a3a 100644
--- a/src/SQL2Linked/StructuralData.cs
+++ b/src/SQL2Linked/StructuralData.cs
@@ -62,37 +62,46 @@ namespace SQL2Linked
             }
         }
 
-        public void AssertToGraphUriNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject)
+        public void AssertToGraphUriNode(IGraph graph, string graphSubject, string graphPredicate, string? graphObject)
         {
-            graph.Assert(
-                new Triple(
-                    graph.CreateUriNode(new Uri(graphSubject)),
-                    graph.CreateUriNode(new Uri(graphPredicate)),
-                    graph.CreateUriNode(new Uri(graphObject))
-                )
-            );
+            if (graphObject != null)
+            {
+                graph.Assert(
+                    new Triple(
+                        graph.CreateUriNode(new Uri(graphSubject)),
+                        graph.CreateUriNode(new Uri(graphPredicate)),
+                        graph.CreateUriNode(new Uri(graphObject))
+                    )
+                );
+            }
         }
 
-        public void AssertToGraphLiteralNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject, Uri? objectType = null)
+        public void AssertToGraphLiteralNode(IGraph graph, string graphSubject, string graphPredicate, string? graphObject, Uri? objectType = null)
         {
-            graph.Assert(
-                new Triple(
-                    graph.CreateUriNode(new Uri(graphSubject)),
-                    graph.CreateUriNode(new Uri(graphPredicate)),
-                    graph.CreateLiteralNode(graphObject, objectType)
-                )
-            );
+            if (graphObject != null)
+            {
+                graph.Assert(
+                    new Triple(
+                        graph.CreateUriNode(new Uri(graphSubject)),
+                        graph.CreateUriNode(new Uri(graphPredicate)),
+                        graph.CreateLiteralNode(graphObject, objectType)
+                    )
+                );
+            }
         }
 
-        public void AssertToGraphBlankAndUriNode(IGraph graph, IBlankNode graphSubject, string graphPredicate, string graphObject)
+        public void AssertToGraphBlankAndUriNode(IGraph graph, IBlankNode graphSubject, string graphPredicate, string? graphObject)
         {
-            graph.Assert(
-                new Triple(
-                    graphSubject,
-                    graph.CreateUriNode(new Uri(graphPredicate)),
-                    graph.CreateUriNode(new Uri(graphObject))
-                )
-            );
+            if (graphObject != null)
+            {
+                graph.Assert(
+                    new Triple(
+                        graphSubject,
+                        graph.CreateUriNode(new Uri(graphPredicate)),
+                        graph.CreateUriNode(new Uri(graphObject))
+                    )
+                );
+            }
         }
     }
 }
-- 
GitLab