diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..1ff0c423042b46cb1d617b81efb715defbe8054d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7cdf465cdfbcae98eaca0ef127878a9b08936ec9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,274 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Database connection for t4 class generation from database +**/*.generated.cs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Pp]roperties/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user +Resharper + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +#cake +tools/* +!tools/packages.config +dist/ + +# Dotnet Tool Manifest +.config/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..49108b73e020ada3fea02d30c4c24bb0444fe050 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +include: + - project: coscine/tools/gitlab-ci-templates + file: + - /dotnet.yml + +stages: + - build + - publish + - commands + + +variables: + DOTNET_MAIN_PROJECT_FOLDER: "SQL2Linked" + +build-branch: + extends: .build-branch + +build-nuget-release: + extends: .build-nuget-release + +publish-gitlab-release: + extends: .publish-gitlab-release + +publish: + extends: .publish-artifact-release + +migration: + rules: + - if: $CI_PIPELINE_SOURCE != "schedule" + when: manual + stage: commands + script: + - dotnet run --project .\src\$DOTNET_MAIN_PROJECT_FOLDER -- --noDryRun + when: manual \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..b8cd48a4db77aeee8a31fbec89cd7c8c4fb0b5ff --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 RWTH Aachen University + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/SQL2Linked.sln b/src/SQL2Linked.sln new file mode 100644 index 0000000000000000000000000000000000000000..43616d1f576ed51660654fad476e07c80846833c --- /dev/null +++ b/src/SQL2Linked.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32414.318 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQL2Linked", "SQL2Linked\SQL2Linked.csproj", "{B76A7422-1D0F-491F-B71C-D00E7C885C4A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B76A7422-1D0F-491F-B71C-D00E7C885C4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B76A7422-1D0F-491F-B71C-D00E7C885C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B76A7422-1D0F-491F-B71C-D00E7C885C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B76A7422-1D0F-491F-B71C-D00E7C885C4A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {177E1F01-F4FD-4BDC-B927-C530335E068E} + EndGlobalSection +EndGlobal diff --git a/src/SQL2Linked/Implementations/ProjectStructuralData.cs b/src/SQL2Linked/Implementations/ProjectStructuralData.cs new file mode 100644 index 0000000000000000000000000000000000000000..97f2dfba0106661faa31dd80df644b288b7528c0 --- /dev/null +++ b/src/SQL2Linked/Implementations/ProjectStructuralData.cs @@ -0,0 +1,15 @@ +using Coscine.Database.DataModel; +using Coscine.Database.Models; +using VDS.RDF; + +namespace SQL2Linked.Implementations +{ + public class ProjectStructuralData : StructuralData<Project, ProjectModel> + { + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Project> entries) + { + // ToDo: Implement + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/SQL2Linked/Implementations/ResourceStructuralData.cs b/src/SQL2Linked/Implementations/ResourceStructuralData.cs new file mode 100644 index 0000000000000000000000000000000000000000..7e1b030b7e5a9f4db5c23cc2599a1cae1de6aa0d --- /dev/null +++ b/src/SQL2Linked/Implementations/ResourceStructuralData.cs @@ -0,0 +1,15 @@ +using Coscine.Database.DataModel; +using Coscine.Database.Models; +using VDS.RDF; + +namespace SQL2Linked.Implementations +{ + public class ResourceStructuralData : StructuralData<Resource, ResourceModel> + { + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Resource> entries) + { + // ToDo: Implement + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs b/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs new file mode 100644 index 0000000000000000000000000000000000000000..766787fc5726996935a20b523bf1e2e094e70fa6 --- /dev/null +++ b/src/SQL2Linked/Implementations/ResourceTypeStructuralData.cs @@ -0,0 +1,15 @@ +using Coscine.Database.DataModel; +using Coscine.Database.Models; +using VDS.RDF; + +namespace SQL2Linked.Implementations +{ + public class ResourceTypeStructuralData : StructuralData<ResourceType, ResourceTypeModel> + { + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<ResourceType> entries) + { + // ToDo: Implement + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/SQL2Linked/Implementations/RoleStructuralData.cs b/src/SQL2Linked/Implementations/RoleStructuralData.cs new file mode 100644 index 0000000000000000000000000000000000000000..b393353ae800afb27ffbc64055d1db720f062ff3 --- /dev/null +++ b/src/SQL2Linked/Implementations/RoleStructuralData.cs @@ -0,0 +1,15 @@ +using Coscine.Database.DataModel; +using Coscine.Database.Models; +using VDS.RDF; + +namespace SQL2Linked.Implementations +{ + public class RoleStructuralData : StructuralData<Role, RoleModel> + { + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<Role> entries) + { + // ToDo: Implement + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/SQL2Linked/Implementations/UserStructuralData.cs b/src/SQL2Linked/Implementations/UserStructuralData.cs new file mode 100644 index 0000000000000000000000000000000000000000..b0b43c3e03e21483515e5b0cb61619308bc776c4 --- /dev/null +++ b/src/SQL2Linked/Implementations/UserStructuralData.cs @@ -0,0 +1,15 @@ +using Coscine.Database.DataModel; +using Coscine.Database.Models; +using VDS.RDF; + +namespace SQL2Linked.Implementations +{ + public class UserStructuralData : StructuralData<User, UserModel> + { + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<User> entries) + { + // ToDo: Implement + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/SQL2Linked/Program.cs b/src/SQL2Linked/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..b9d0aa6a150c349541fa09512110b842c5e6e833 --- /dev/null +++ b/src/SQL2Linked/Program.cs @@ -0,0 +1,27 @@ +using SQL2Linked.Implementations; + +var dummyMode = !(args.Length > 0 && args[0] == "--noDryRun"); +if (dummyMode) +{ + Console.WriteLine("\n DUMMY MODE \n"); + Console.WriteLine(" To exit dummy mode, execute with the \"--noDryRun\" argument"); +} + +Console.WriteLine("\nBegin SQL 2 Linked Data migration"); + +var roleStructuralData = new RoleStructuralData(); +roleStructuralData.Migrate(dummyMode); + +var userStructuralData = new UserStructuralData(); +userStructuralData.Migrate(dummyMode); + +var resourceTypeStructuralData = new ResourceTypeStructuralData(); +resourceTypeStructuralData.Migrate(dummyMode); + +var projectStructuralData = new ProjectStructuralData(); +projectStructuralData.Migrate(dummyMode); + +var resourceStructuralData = new ResourceStructuralData(); +resourceStructuralData.Migrate(dummyMode); + +Console.WriteLine("\n Finished."); diff --git a/src/SQL2Linked/SQL2Linked.csproj b/src/SQL2Linked/SQL2Linked.csproj new file mode 100644 index 0000000000000000000000000000000000000000..bc66d81c5b7987f6d5a6560997b2a57374df7fab --- /dev/null +++ b/src/SQL2Linked/SQL2Linked.csproj @@ -0,0 +1,15 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Coscine.Database" Version="2.*-*" /> + <PackageReference Include="Coscine.Metadata" Version="2.*-*" /> + </ItemGroup> + +</Project> diff --git a/src/SQL2Linked/StructuralData.cs b/src/SQL2Linked/StructuralData.cs new file mode 100644 index 0000000000000000000000000000000000000000..883fe3fb3d8c6309632431a518d7cee605754ae8 --- /dev/null +++ b/src/SQL2Linked/StructuralData.cs @@ -0,0 +1,55 @@ +using Coscine.Configuration; +using Coscine.Database.Models; +using Coscine.Metadata; +using VDS.RDF; + +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 StructuralData() + { + Configuration = new ConsulConfiguration(); + RdfStoreConnector = new RdfStoreConnector(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url")); + Model = new T(); + } + + 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(); + } + } + } +} \ No newline at end of file