Skip to content
Snippets Groups Projects
Commit 7cc28217 authored by Hanna Führ's avatar Hanna Führ
Browse files

Update: Migrate user structural data to linked data (coscine/issues#2081)

parent 04bf9e9d
No related branches found
No related tags found
2 merge requests!4Release: Sprint/2022 12 :robot:,!3Fix: Migrate user structural data to linked data
using Coscine.Database.DataModel; using Coscine.Database.DataModel;
using Coscine.Database.Models; using Coscine.Database.Models;
using Coscine.Metadata;
using VDS.RDF; using VDS.RDF;
namespace SQL2Linked.Implementations namespace SQL2Linked.Implementations
{ {
public class UserStructuralData : StructuralData<User, UserModel> public class UserStructuralData : StructuralData<User, UserModel>
{ {
public readonly string UserUrlPrefix = "https://purl.org/coscine/users";
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) public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<User> entries)
{ {
// ToDo: Implement var graphs = new List<IGraph>();
throw new NotImplementedException();
foreach (var entry in entries)
{
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.Any())
{
// check if a user graph already exists
var exists = RdfStoreConnector.HasGraph(userGraphName);
if (!exists)
{
RdfStoreConnector.CreateNamedGraph(userGraphName);
}
graph.Assert(
new Triple(
graph.CreateBlankNode(),
graph.CreateUriNode(RdfType),
graph.CreateUriNode(FoafPerson)
)
);
graphs.Add(graph);
Console.WriteLine($"Will migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
}
else
{
Console.WriteLine($"Will NOT migrate user '{entry.DisplayName}' with id '{entry.Id}'.");
}
}
return graphs;
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment