Skip to content
Snippets Groups Projects
Select Git revision
  • be5306a9066bbb34e7d825c06c6477b0365ac843
  • main default protected
  • gitkeep
  • dev protected
  • Issue/2914-trellisMigrator
  • Issue/2847-reporting
  • Hotfix/2776-workingNewVersion
  • Hotfix/xxxx-correctAssignments
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2666-adminCronjobs
  • Issue/2518-docs
  • Hotfix/xxxx-coscineGraph
  • Issue/2304-virtuosoRoars
  • Fix/v0.1.7-dependencies
  • Hotfix/2212-fixFiles
  • Issue/2222-resourceDateCreated
  • Issue/2221-projectDateCreated
  • Hotfix/xxxx-changeUrls
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1782-structualDataIntegration
  • Issue/2084-migrateResourceStructuralData
  • v0.1.24
  • v0.1.23
  • v0.1.22
  • v0.1.21
  • v0.1.20
  • v0.1.19
  • v0.1.18
  • v0.1.17
  • v0.1.16
  • v0.1.15
  • v0.1.14
  • v0.1.13
  • v0.1.12
  • v0.1.11
  • v0.1.10
  • v0.1.9
  • v0.1.7
  • v0.1.8
  • v0.1.6
  • v0.1.5
41 results

ResourceStructuralData.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ResourceStructuralData.cs 8.73 KiB
    using Coscine.Database.DataModel;
    using Coscine.Database.Models;
    using Coscine.Configuration;
    using VDS.RDF;
    using VDS.RDF.Query;
    
    namespace SQL2Linked.Implementations
    {
        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)
            {
                IEnumerable<Visibility> visibilities = VisibilityModel.GetAll();
                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/visibility#public");
                            Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#visibility {cosc}terms/visibility#public'. ");
                            break;
                        }
                        else if (entry.VisibilityId == visibility.Id && visibility.DisplayName.Contains("Project Members"))
                        {
                            AssertToGraphUriNode(graph, resourceGraphName, cosc + "terms/resource#visibility", cosc + $"terms/visibility#projectMember");
                            Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {cosc}terms/resource#visibility {cosc}terms/visibility#projectMember'. ");
                            break;
                        }
                    }
    
                    if (entry.Keywords.Any())
                    {
                        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}'. ");
    
                    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()}'. ");
                    }
    
                    var blankNode= graph.CreateBlankNode(entry.Id.ToString());
    
                    AssertToGraphBlankAndUriNode(graph, blankNode, rdf + "type", acl + "Authorization");
                    Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {rdf}type {acl}Authorization'. ");
    
                    foreach (var projectResource in projectResources)
                    {
                        if (entry.Id == projectResource.ResourceId)
                        {
                            AssertToGraphBlankAndUriNode(graph, blankNode, acl + "agentGroup", $"{resourceUrlPrefix}/{projectResource.ProjectId}");
                            Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}agentGroup {resourceUrlPrefix}/{projectResource.ProjectId}'. ");
                            break;
                        }
                    }
    
                    AssertToGraphBlankAndUriNode(graph, blankNode, acl + "accessTo", resourceGraphName);
                    Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}accessTo {resourceGraphName}'. ");
    
                    AssertToGraphBlankAndUriNode(graph, blankNode, acl + "mode", acl + "Control");
                    Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{blankNode} {acl}accessTo {acl}Control'. ");
    
                    graphs.Add(graph);
                }
                return graphs;
            }
        }
    }