Skip to content
Snippets Groups Projects
Select Git revision
  • 2c7f9d1285aea308d4b832bffe41181f0562708c
  • main default protected
  • dev protected
  • Issue/3160-deactivateDownloadForFolders
  • Issue/3111-fixLoadingGitLabResource
  • Issue/3133-subProjectsChanges
  • Issue/3139-dsnrw
  • Issue/3167-changeTextAndAddLink
  • Issue/3070-newIconsForResourceTypes
  • Issue/3145-redesignLoginPage
  • Issue/3093-moreInformationInTheDeletionEmails
  • Issue/3040-closeTokenWindowWithXButton
  • Issue/3152-fixResourceStore
  • Issue/xxxx-DuckDBTest
  • Issue/3152-fixUpdateRequestPayload
  • Issue/2489-addNotificationManagement
  • Issue/3138-tooltipForDisabledCreateActions
  • Issue/3136-orderResourcesInAlphabeticalOrder
  • Issue/3119-respOrg-vol2
  • Issue/3119-respOrg
  • Issue/3129-improvmentsResourceCreation
  • v3.18.0
  • v3.17.2
  • v3.17.1
  • v3.17.0
  • v3.16.1
  • v3.16.0
  • v3.15.6
  • v3.15.5
  • v3.15.4
  • v3.15.3
  • v3.15.2
  • v3.15.1
  • v3.15.0
  • v3.14.0
  • v3.13.1
  • v3.13.0
  • v3.12.0
  • v3.11.0
  • v3.10.1
  • v3.9.3-hotfix3017
41 results

App.vue

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StructuralData.cs 3.49 KiB
    using Coscine.Configuration;
    using Coscine.Database.Models;
    using Coscine.Metadata;
    using VDS.RDF;
    using VDS.RDF.Query;
    
    namespace SQL2Linked
    {
        public abstract class StructuralData<S, T> where S : class where T : DatabaseModel<S>, new()
        {
            public T Model { get; init; }
            public ConsulConfiguration Configuration { get; init; }
            public RdfStoreConnector RdfStoreConnector { get; init; }
            public static string Prefix { get; set; }
            public readonly SparqlRemoteEndpoint QueryEndpoint;
    
            public StructuralData()
            {
                Configuration = new ConsulConfiguration();
                RdfStoreConnector = new RdfStoreConnector(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
                Model = new T();
                Prefix = Configuration.GetStringAndWait("coscine/global/epic/prefix");
                QueryEndpoint = new SparqlRemoteEndpoint(new Uri(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url")));
            }
    
            public abstract IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<S> entries);
    
            public void Migrate(bool dummyMode)
            {
                var spacer = new string('-', 35);
                Console.WriteLine($"\n{spacer}\n{typeof(T).Name}\n{spacer}");
                var graphs = ConvertToLinkedData(Model.GetAll());
                if (!dummyMode)
                {
                    StoreGraphs(graphs);
                }
            }
    
            private void StoreGraphs(IEnumerable<IGraph> graphs)
            {
                foreach (var graph in graphs)
                {
                    Console.WriteLine($" ({graph.BaseUri})");
                    var exists = RdfStoreConnector.HasGraph(graph.BaseUri);
                    if (exists)
                    {
                        Console.WriteLine($" - Graph {graph.BaseUri} exists");
    
                        // Clear the existing graph from the store
                        RdfStoreConnector.ClearGraph(graph.BaseUri);
                        Console.WriteLine($" - Cleared Graph {graph.BaseUri}");
                    }
                    // Add the new graph to the store
                    RdfStoreConnector.AddGraph(graph);
                    Console.WriteLine($" - Graph {graph.BaseUri} added successfully");
                    Console.WriteLine();
                }
            }
            public void AssertToGraphUriNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject)
            {
                graph.Assert(
                    new Triple(
                        graph.CreateUriNode(new Uri(graphSubject)),
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateUriNode(new Uri(graphObject))
                    )
                );
            }
            public void AssertToGraphLiteralNode(IGraph graph, string graphSubject, string graphPredicate, string graphObject, Uri? objectType = null)
            {
                graph.Assert(
                    new Triple(
                        graph.CreateUriNode(new Uri(graphSubject)),
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateLiteralNode(graphObject, objectType)
                    )
                );
            }
    
            public void AssertToGraphBlankAndUriNode(IGraph graph, IBlankNode graphSubject, string graphPredicate, string graphObject)
            {
                graph.Assert(
                    new Triple(
                        graphSubject,
                        graph.CreateUriNode(new Uri(graphPredicate)),
                        graph.CreateUriNode(new Uri(graphObject))
                    )
                );
            }
        }
    }