Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • coscine/backend/libraries/resource-types
1 result
Select Git revision
Loading items
Show changes
Commits on Source (7)
# Coscine Resource Types
## Resource Types Library
This library contains all resource type implementations for Coscine (RDS, RDS-S3, RDS-S3-WORM, Linked, Gitlab).
[[_TOC_]]
## 📝 Overview
The Resource Types library for .NET provides all the necessary implementations for the different resource types used in Coscine, including RDS, RDS-S3, RDS-S3-WORM, Linked, and GitLab. By encapsulating these different resource types in a single library, the Resource Types library simplifies resource management within Coscine applications and reduces the amount of boilerplate code required for accessing and manipulating different types of resources.
## ⚙️ Configuration
To install this library, you can use the NuGet package manager or you can install it using the .NET CLI.
```powershell
Install-Package Coscine.ResourceTypes
```
or using the .NET CLI
```powershell
dotnet add package Coscine.ResourceTypes
```
## 📖 Usage
For examples on how we use this library, look into the source code of the following open-source [Coscine APIs](https://git.rwth-aachen.de/coscine/backend/apis) found in our public GitLab repository:
- `Resources`
... and others.
## 👥 Contributing
As an open source plattform and project, we welcome contributions from our community in any form. You can do so by submitting bug reports or feature requests, or by directly contributing to Coscine's source code. To submit your contribution please follow our [Contributing Guideline](https://git.rwth-aachen.de/coscine/docs/public/wiki/-/blob/master/Contributing%20To%20Coscine.md).
## 📄 License
The current open source repository is licensed under the **MIT License**, which is a permissive license that allows the software to be used, modified, and distributed for both commercial and non-commercial purposes, with limited restrictions (see `LICENSE` file)
> The MIT License allows for free use, modification, and distribution of the software and its associated documentation, subject to certain conditions. The license requires that the copyright notice and permission notice be included in all copies or substantial portions of the software. The software is provided "as is" without any warranties, and the authors or copyright holders cannot be held liable for any damages or other liability arising from its use.
## 🆘 Support
1. **Check the documentation**: Before reaching out for support, check the help pages provided by the team at https://docs.coscine.de/en/. This may have the information you need to solve the issue.
2. **Contact the team**: If the documentation does not help you or if you have a specific question, you can reach out to our support team at `servicedesk@itc.rwth-aachen.de` 📧. Provide a detailed description of the issue you're facing, including any error messages or screenshots if applicable.
3. **Be patient**: Our team will do their best to provide you with the support you need, but keep in mind that they may have a lot of requests to handle. Be patient and wait for their response.
4. **Provide feedback**: If the support provided by our support team helps you solve the issue, let us know! This will help us improve our documentation and support processes for future users.
By following these simple steps, you can get the support you need to use Coscine's services as an external user.
## 📦 Release & Changelog
External users can find the _Releases and Changelog_ inside each project's repository. The repository contains a section for Releases (`Deployments > Releases`), where users can find the latest release changelog and source. Withing the Changelog you can find a list of all the changes made in that particular release and version.
By regularly checking for new releases and changes in the Changelog, you can stay up-to-date with the latest improvements and bug fixes by our team and community!
\ No newline at end of file
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -7,21 +7,16 @@ using Newtonsoft.Json;
using System.Text;
using System.Web;
using VDS.RDF;
using VDS.RDF.Query;
namespace Coscine.ResourceTypes.Linked;
public class LinkedResourceType : BaseResourceType
{
private readonly string _urlPrefix = "https://hdl.handle.net/";
private readonly string _epicPrefix;
private readonly string _predicate = "https://purl.org/coscine/terms/linked#body";
private readonly RdfStoreConnector _rdfStoreConnector;
private readonly CoscineLDPHelper _coscineLDPHelper;
public LinkedResourceType(LinkedResourceTypeConfiguration linkedResourceTypeConfiguration) : base(linkedResourceTypeConfiguration)
{
_epicPrefix = linkedResourceTypeConfiguration.EpicPrefix;
if (linkedResourceTypeConfiguration.SparqlEndpoint != null)
{
_rdfStoreConnector = new(linkedResourceTypeConfiguration.SparqlEndpoint);
......@@ -30,22 +25,11 @@ public class LinkedResourceType : BaseResourceType
{
_rdfStoreConnector = new();
}
_coscineLDPHelper = new CoscineLDPHelper(_rdfStoreConnector, _epicPrefix);
}
private string GetGraphNameForFilter(string id, string key)
{
return $"{GetSubjectName(id, key)}.*&data";
}
private string GetSubjectName(string id, string key)
{
return $"{_urlPrefix}{_epicPrefix}/{id}@path={Uri.EscapeDataString(key)}";
_coscineLDPHelper = new CoscineLDPHelper(_rdfStoreConnector);
}
public override Task CreateResource(string id, long? quota = null, Dictionary<string, string>? options = null)
{
// Nothing to do here
return Task.CompletedTask;
}
......@@ -83,7 +67,7 @@ public class LinkedResourceType : BaseResourceType
return Task.FromResult<ResourceEntry?>(null);
}
var triples = graph.GetTriplesWithPredicate(graph.CreateUriNode(new Uri(_predicate)));
var triples = graph.GetTriplesWithPredicate(graph.CreateUriNode(Uris.CoscineLinkedBody));
if (!triples.Any())
{
......@@ -100,48 +84,19 @@ public class LinkedResourceType : BaseResourceType
prefix = "/" + prefix;
}
// Should be moved to rdfStoreConnector, when it gets updated.
var cmdString = new SparqlParameterizedString
{
CommandText =
$@"SELECT DISTINCT ?g
WHERE {{
GRAPH ?g {{ ?s <{_predicate}> ?o }}
FILTER regex(?g, ""^{GetGraphNameForFilter(id, prefix)}"")
}}"
};
var resultSet = _rdfStoreConnector.QueryEndpoint.QueryWithResultSet(cmdString.ToString());
var resultList = new List<ResourceEntry>();
// Extract the actual key from the graph name and get the entry
var resultList = resultSet.Select(x =>
{
var key = x.Value("g").ToString();
key = key[$"{_urlPrefix}{_epicPrefix}/{id}@path=".Length..];
if (key.Contains("&data"))
{
key = key[..^"&data".Length];
}
key = Uri.UnescapeDataString(key);
return GetEntry(id, key).Result;
}).Where(x => x != null).Cast<ResourceEntry>().ToList();
// Add the new results as well
// Add the results
var currentDataList = _rdfStoreConnector.ListData(id);
if (currentDataList != null)
if (currentDataList is not null)
{
var resourceGraphUri = $"https://purl.org/coscine/resources/{id}";
var currentDataPaths = currentDataList.Select((entry) => entry?[..entry.LastIndexOf("/")].Replace(resourceGraphUri, ""));
var bothDataPaths = currentDataPaths.Where((currentDataPath) => resultList.Any((resultEntry) => resultEntry.Key == currentDataPath));
var newDataPaths = currentDataPaths.Where((currentDataPath) => !resultList.Any((resultEntry) => resultEntry.Key == currentDataPath));
// Remove the ones which are in both since the ones from the new structure would have the newest information
resultList.RemoveAll((entry) => bothDataPaths.Any((dataPath) => dataPath == entry.Key));
resultList.AddRange(currentDataPaths
.Where(x => x is not null)
.Select((x) => GetEntry(id, x!).Result)
.Where(x => x != null).Cast<ResourceEntry>());
.Where(x => x is not null).Cast<ResourceEntry>());
}
return Task.FromResult(resultList);
......@@ -163,7 +118,7 @@ public class LinkedResourceType : BaseResourceType
return Task.FromResult<Stream?>(null);
}
var triples = graph.GetTriplesWithPredicate(graph.CreateUriNode(new Uri(_predicate)));
var triples = graph.GetTriplesWithPredicate(graph.CreateUriNode(Uris.CoscineLinkedBody));
if (!triples.Any())
{
......@@ -200,7 +155,7 @@ public class LinkedResourceType : BaseResourceType
if (!graph.IsEmpty)
{
var triples = graph.GetTriplesWithPredicate(graph.CreateUriNode(new Uri(_predicate)));
var triples = graph.GetTriplesWithPredicate(graph.CreateUriNode(Uris.CoscineLinkedBody));
graph.Retract(triples.ToArray());
}
else
......@@ -208,7 +163,7 @@ public class LinkedResourceType : BaseResourceType
_rdfStoreConnector.CreateNamedGraph(urlId);
}
graph.Assert(new Triple(graph.CreateUriNode(urlId), graph.CreateUriNode(new Uri(_predicate)), graph.CreateLiteralNode(Encoding.UTF8.GetString(buffer))));
graph.Assert(new Triple(graph.CreateUriNode(urlId), graph.CreateUriNode(Uris.CoscineLinkedBody), graph.CreateLiteralNode(Encoding.UTF8.GetString(buffer))));
_rdfStoreConnector.AddGraph(graph);
......
......@@ -4,8 +4,11 @@ namespace Coscine.ResourceTypes.Linked;
public class LinkedResourceTypeConfiguration : ResourceTypeConfiguration
{
[Obsolete]
public string EpicPrefix { get; set; } = null!;
public string? SparqlEndpoint { get; set; }
[Obsolete]
public string UrlPrefix { get; set; } = "https://hdl.handle.net/";
[Obsolete]
public string Predicate { get; set; } = "https://purl.org/coscine/terms/linked#body";
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<RootNamespace>Coscine.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<AssemblyName>Coscine.$(MSBuildProjectName)</AssemblyName>
<Version>1.9.4</Version>
<Version>1.10.0</Version>
</PropertyGroup>
<PropertyGroup>
......