Skip to content
Snippets Groups Projects
Select Git revision
  • b8be1a0367aad83017d81db83b77a3c7a0f9ff02
  • master default protected
  • develop
  • v2021.a
  • v2020.a
  • v2019.a
  • v2018.b
7 results

RedstartWindow.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ResourceStructuralData.cs 9.29 KiB
    using Coscine.Database.DataModel;
    using Coscine.Database.Models;
    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();
            private LicenseModel LicenseModel = new LicenseModel();
    
            public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Resource> entries)
            {
                IEnumerable<Visibility> visibilities = VisibilityModel.GetAll();
                IEnumerable<ProjectResource> projectResources = ProjectResourceModel.GetAll();
                IEnumerable<License> licenses = LicenseModel.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;
                        }
                    }
    
                    foreach (var license in licenses)
                    {
                        if (entry.LicenseId == license.Id)
                        {
                            AssertToGraphLiteralNode(graph, resourceGraphName, dcterms + "license", license.DisplayName);
                            Console.WriteLine($"For resource '{entry.DisplayName}' will migrate triple '{resourceGraphName} {dcterms}license {license.DisplayName}'. ");
                        }
                    }
    
                    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()}'. ");
                    }
    
                    foreach (var projectResource in projectResources)
                    {
                        if (entry.Id == projectResource.ResourceId)
                        {
                            var blankNode = graph.CreateBlankNode();
    
                            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 + "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;
            }
        }
    }