diff --git a/src/SQL2Linked/Implementations/ProjectStructuralData.cs b/src/SQL2Linked/Implementations/ProjectStructuralData.cs index b50b0b1884c7e18c83b9dc8b807c78cd1ffe3764..6242f4b266a9b95e70def8931120c5b4419d956a 100644 --- a/src/SQL2Linked/Implementations/ProjectStructuralData.cs +++ b/src/SQL2Linked/Implementations/ProjectStructuralData.cs @@ -33,7 +33,7 @@ public class ProjectStructuralData : StructuralData<ProjectAdminDto> public override async Task<IEnumerable<IGraph>> ConvertToLinkedDataAsync(IEnumerable<ProjectAdminDto> entries) { var graphs = new List<IGraph>(); - var coscineHandlePrefix = UriHelper.TryCombineUri(RdfUris.HandlePrefix, _pidConfiguration.Prefix) + var coscineHandlePrefix = UriHelper.TryCombinePath(RdfUris.HandlePrefix, _pidConfiguration.Prefix) ?? throw new Exception("Could not combine handle prefix with PID prefix"); var coscineGraph = new Graph diff --git a/src/SQL2Linked/Implementations/ResourceStructuralData.cs b/src/SQL2Linked/Implementations/ResourceStructuralData.cs index 67eb96c17c8de89a259cc314ee9a28a332a2dbd4..cb1683459cd21c6d6c92c9823dcbb0ccde297e74 100644 --- a/src/SQL2Linked/Implementations/ResourceStructuralData.cs +++ b/src/SQL2Linked/Implementations/ResourceStructuralData.cs @@ -3,6 +3,7 @@ using Coscine.ApiClient.Core.Model; using Newtonsoft.Json; using SQL2Linked.Utils; using VDS.RDF; +using VDS.RDF.Parsing; namespace SQL2Linked.Implementations; @@ -34,7 +35,7 @@ public class ResourceStructuralData : StructuralData<ResourceAdminDto> public override async Task<IEnumerable<IGraph>> ConvertToLinkedDataAsync(IEnumerable<ResourceAdminDto> entries) { var graphs = new List<IGraph>(); - var coscineHandlePrefix = UriHelper.TryCombineUri(RdfUris.HandlePrefix, _pidConfiguration.Prefix) + var coscineHandlePrefix = UriHelper.TryCombinePath(RdfUris.HandlePrefix, _pidConfiguration.Prefix) ?? throw new Exception("Could not combine handle prefix with PID prefix"); foreach (var entry in entries) @@ -120,7 +121,32 @@ public class ResourceStructuralData : StructuralData<ResourceAdminDto> Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {RdfUris.FoafHomepage} {resourceGraphName}'. "); AssertToGraphLiteralNode(graph, resourceGraphName, RdfUris.CoscineTermsResourceDeleted, entry.Deleted.ToString().ToLower(), new Uri("http://www.w3.org/2001/XMLSchema#boolean")); - Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{resourceGraphName} {RdfUris.CoscineTermsResourceDeleted} {entry.Deleted}'. "); + Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {RdfUris.CoscineTermsResourceDeleted} {entry.Deleted}'. "); + + // Reinstate the catalog assignments + var oldResourceGraphResponse = await _adminApi.GetMetadataGraphAsync( + resourceGraphName.AbsoluteUri, + RdfFormat.TextTurtle + ); + if (oldResourceGraphResponse is not null) + { + var oldResourceGraph = new Graph(); + var ttlparser = new TurtleParser(); + ttlparser.Load(oldResourceGraph, new StringReader(oldResourceGraphResponse.Data.Content)); + + foreach (var result in oldResourceGraph.GetTriplesWithPredicate(RdfUris.DcatCatalog)) + { + if (result.Object.NodeType == NodeType.Uri) + { + var catalogedUri = result.Object as IUriNode; + if (catalogedUri is not null) + { + AssertToGraphUriNode(graph, resourceGraphName, RdfUris.DcatCatalog, catalogedUri.Uri); + Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {RdfUris.DcatCatalog} {catalogedUri.Uri}'. "); + } + } + } + } foreach (var projectResource in entry.ProjectResources) { @@ -151,7 +177,7 @@ public class ResourceStructuralData : StructuralData<ResourceAdminDto> if (entry.DateCreated is not null && entry.DateCreated.HasValue) { AssertToGraphLiteralNode(graph, resourceGraphName, RdfUris.DcTermsCreated, entry.DateCreated.Value.ToString(), new Uri("http://www.w3.org/2001/XMLSchema#dateTime")); - Console.WriteLine($"For project '{entry.DisplayName}' will migrate triple '{resourceGraphName} {RdfUris.DcTermsCreated} {entry.DateCreated}'. "); + Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {RdfUris.DcTermsCreated} {entry.DateCreated}'. "); } graphs.Add(graph); diff --git a/src/SQL2Linked/SQL2Linked.csproj b/src/SQL2Linked/SQL2Linked.csproj index a473097445d1bba6e2123093ccf43637b7d0b607..b9b1ce633d9756ae44ad6a245710f2c3b10cad30 100644 --- a/src/SQL2Linked/SQL2Linked.csproj +++ b/src/SQL2Linked/SQL2Linked.csproj @@ -1,4 +1,4 @@ -<Project Sdk="Microsoft.NET.Sdk"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> @@ -16,7 +16,7 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="Coscine.ApiClient" Version="1.3.0" /> + <PackageReference Include="Coscine.ApiClient" Version="1.3.1" /> <PackageReference Include="dotNetRdf" Version="3.1.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" /> diff --git a/src/SQL2Linked/Utils/UriHelper.cs b/src/SQL2Linked/Utils/UriHelper.cs index e0e8f068a924d00ca3eeaca62d7c26c1ce53ad51..af5e5048536b11d2e5b78fc4a6c89dc5abd898e5 100644 --- a/src/SQL2Linked/Utils/UriHelper.cs +++ b/src/SQL2Linked/Utils/UriHelper.cs @@ -5,6 +5,30 @@ /// </summary> public static class UriHelper { + /// <summary> + /// + /// </summary> + /// <param name="baseUri"></param> + /// <param name="relativePath"></param> + /// <returns></returns> + public static Uri? TryCombinePath(Uri baseUri, string relativePath) + { + Uri.TryCreate(baseUri, relativePath + "/", out Uri? result); + return result; + } + + /// <summary> + /// + /// </summary> + /// <param name="baseUri"></param> + /// <param name="relativePath"></param> + /// <returns></returns> + public static Uri? TryCombinePath(Uri baseUri, Guid relativePath) + { + Uri.TryCreate(baseUri, relativePath.ToString() + "/", out Uri? result); + return result; + } + /// <summary> /// /// </summary>