Select Git revision
Program.cs
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Program.cs 7.44 KiB
using Coscine.Configuration;
using Coscine.Database.Models;
using Coscine.Metadata;
using System;
using System.Linq;
using System.Collections.Generic;
using VDS.RDF;
using VDS.RDF.Query;
using VDS.RDF.Query.Builder;
using VDS.RDF.Storage;
using VDS.RDF.Update;
using Coscine.Database.DataModel;
using Coscine.ActiveDirectory;
using LinqToDB.Data;
using Coscine.Database.Settings;
namespace Coscine.UserImporter
{
public class Program
{
private static Dictionary<string, string> RORMap = new Dictionary<string, string>()
{
{ "https://ror.org/04xfq0f34", "https://login.rz.rwth-aachen.de/shibboleth" },
};
public static void Main(string[] args)
{
var configuration = new ConsulConfiguration();
DataConnection.DefaultSettings = new CoscineSettings(configuration);
var virtuosoServer = configuration.GetString("coscine/local/virtuoso/additional/url");
using (var rdfStoreConnector = new RdfStoreConnector(virtuosoServer))
{
var externalIdModel = new ExternalIdModel();
var userModel = new UserModel();
var externalAuthenticatorModel = new ExternalAuthenticatorModel();
var shib = externalAuthenticatorModel.GetWhere((entry) => entry.DisplayName == "Shibboleth");
var updateEndpoint = new SparqlRemoteUpdateEndpoint(new Uri(string.Format(virtuosoServer)));
var queryEndpoint = new SparqlRemoteEndpoint(new Uri(string.Format(virtuosoServer)));
var readWriteSparqlConnector = new ReadWriteSparqlConnector(queryEndpoint, updateEndpoint);
var graphs = readWriteSparqlConnector.ListGraphs();
foreach (var graph in graphs)
{
var absoluteUri = graph.AbsoluteUri;
if (absoluteUri.StartsWith("https://ror.org/"))
{
SparqlResultSet pers = null;
var offset = 0;
var graphImpl = new Graph
{
BaseUri = graph
};
// Get all users from the current graph which are a person
// The graph is queried in a batch of 5000 entries since there seems to be a hard limit on 10000 entries per request
do
{
var query = QueryBuilder.Select(new SparqlVariable("s"), new SparqlVariable("p"), new SparqlVariable("o"))
.Graph(graph, graphEntry => graphEntry
.Where((where) => where.Subject("s").Predicate("p").Object("o"))
.Where((where) => where.Subject("s")
.PredicateUri(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"))
.Object(new Uri("http://xmlns.com/foaf/0.1/Person"))))
.Limit(5000)
.Offset(offset)