Skip to content
Snippets Groups Projects

New: Migrate resource structured data to linked data

Merged Hanna Führ requested to merge Issue/2084-migrateResourceStructuralData into dev
Files
6
using Coscine.Database.DataModel;
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Database.Models;
 
using Coscine.Configuration;
using VDS.RDF;
using VDS.RDF;
 
using VDS.RDF.Query;
namespace SQL2Linked.Implementations
namespace SQL2Linked.Implementations
{
{
public class ResourceStructuralData : StructuralData<Resource, ResourceModel>
public class ResourceStructuralData : StructuralData<Resource, ResourceModel>
{
{
 
public readonly Uri org = new("http://www.w3.org/ns/org#");
 
public readonly Uri dcat = new("http://www.w3.org/ns/dcat#");
 
public readonly Uri dcterms = new("http://purl.org/dc/terms/");
 
public readonly Uri acl = new("http://www.w3.org/ns/auth/acl#");
 
public readonly Uri foaf = new("http://xmlns.com/foaf/0.1/");
 
public readonly Uri pim = new("http://www.w3.org/ns/pim/space#");
 
public readonly Uri rdf = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
 
public readonly Uri cosc = new("https://purl.org/coscine/");
 
private VisibilityModel VisibilityModel = new VisibilityModel();
 
private ProjectResourceModel ProjectResourceModel =new ProjectResourceModel();
 
public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Resource> entries)
public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Resource> entries)
{
{
// ToDo: Implement
IEnumerable<Visibility> visibilities = VisibilityModel.GetAll();
throw new NotImplementedException();
IEnumerable<ProjectResource> projectResources = ProjectResourceModel.GetAll();
 
 
var graphs = new List<IGraph>();
 
string resourceUrlPrefix = "https://hdl.handle.net/" + Prefix;
 
 
foreach (var entry in entries)
 
{
 
var resourceGraphName = $"{resourceUrlPrefix}/{entry.Id}";
 
 
var graph = new Graph();
 
graph.BaseUri = new Uri(resourceGraphName);
 
 
AssertToGraphUriNode(graph, resourceGraphName, rdf + "type", dcat + "Catalog");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {rdf}type {dcat}Catalog'. ");
 
 
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}'. ");
 
 
AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "title", entry.ResourceName);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}title {entry.ResourceName}'. ");
 
 
AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "alternative", entry.DisplayName);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}alternative {entry.DisplayName}'. ");
 
 
foreach (var visibility in visibilities)
 
{
 
if (entry.VisibilityId == visibility.Id && visibility.DisplayName.Contains("Public"))
 
{
 
AssertToGraphUriNode(graph, resourceGraphName, cosc + "terms/resource#visibility", cosc + $"terms/vivibility#public");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#visibility {cosc}terms/vivibility#public'. ");
 
break;
 
}
 
else if (entry.VisibilityId == visibility.Id && visibility.DisplayName.Contains("Project Members"))
 
{
 
AssertToGraphUriNode(graph, resourceGraphName, cosc + "terms/resource#visibility", cosc + $"terms/vivibility#projectMember");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#visibility {cosc}terms/vivibility#projectMember'. ");
 
break;
 
}
 
}
 
 
var listKeywords = entry.Keywords.Split(';').ToList();
 
foreach (var keyword in listKeywords)
 
{
 
AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "subject", keyword);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}subject {keyword}'. ");
 
}
 
 
AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "rights", entry.UsageRights);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}rights {entry.UsageRights}'. ");
 
 
AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "description", entry.Description);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}description {entry.Description}'. ");
 
 
AssertToGraphUriNode(graph, resourceGraphName, dcterms + "conformsTo", entry.ApplicationProfile);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}conformsTo {entry.ApplicationProfile}'. ");
 
 
AssertToGraphLiteralNode(graph, resourceGraphName,cosc + "terms/resource#fixedValues", entry.FixedValues);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#fixedValues {entry.FixedValues}'. ");
 
 
AssertToGraphUriNode(graph, resourceGraphName, dcterms + "creator", cosc + $"users/{entry.Creator}");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}creator {cosc}users/{entry.Creator}'. ");
 
 
AssertToGraphLiteralNode(graph, resourceGraphName, cosc + "terms/resource#archived", entry.Archived.ToString(), 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.ToString()}'. ");
 
 
AssertToGraphUriNode(graph, resourceGraphName, foaf + "homepage", resourceGraphName);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {foaf}homepage {resourceGraphName}'. ");
 
 
SparqlParameterizedString cmdString = new SparqlParameterizedString
 
{
 
CommandText = "SELECT DISTINCT ?g " +
 
"WHERE {" +
 
"GRAPH ?g { ?s ?p ?o } . " +
 
"FILTER(STRSTARTS(STR(?s), \"" + resourceGraphName + "@\"))" +
 
"}"
 
};
 
 
var resultSet = QueryEndpoint.QueryWithResultSet(cmdString.ToString());
 
 
foreach(var result in resultSet)
 
{
 
AssertToGraphUriNode(graph, resourceGraphName, dcat + "catalog", result[0].ToString());
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcat}catalog {result[0].ToString()}'. ");
 
}
 
 
AssertToGraphUriNode(graph, resourceGraphName, rdf + "type", acl + "Authorization");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {rdf}type {acl}Authorization'. ");
 
 
foreach (var projectResource in projectResources)
 
{
 
if (entry.Id == projectResource.ResourceId)
 
{
 
AssertToGraphUriNode(graph, resourceGraphName, acl + "agentGroup", $"{resourceUrlPrefix}/{projectResource.ProjectId}");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {acl}agentGroup {resourceUrlPrefix}/{projectResource.ProjectId}'. ");
 
break;
 
}
 
}
 
 
AssertToGraphUriNode(graph, resourceGraphName, acl + "accessTo", resourceGraphName);
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {acl}accessTo {resourceGraphName}'. ");
 
 
AssertToGraphUriNode(graph, resourceGraphName, acl + "mode", acl + "Control");
 
Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {acl}accessTo {acl}Control'. ");
 
 
graphs.Add(graph);
 
 
}
 
return graphs;
}
}
}
}
}
}
 
\ No newline at end of file
Loading