Commit 5fe6f155 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Fix: Graphs with special characters now work (coscine/issues#626)

parent 9c7c9a56
...@@ -112,7 +112,8 @@ namespace Coscine.Api.Project.Controllers ...@@ -112,7 +112,8 @@ namespace Coscine.Api.Project.Controllers
if (_resourceModel.HasAccess(user, resource, UserRoles.Owner, UserRoles.Member)) if (_resourceModel.HasAccess(user, resource, UserRoles.Owner, UserRoles.Member))
{ {
var id = _metadataModel.GenerateId(resourceId, filename, version); var id = _metadataModel.GenerateId(resourceId, filename, version);
var graph = _util.GetGraph(id); var uri = _metadataModel.CreateUri(id);
var graph = _util.GetGraph(uri);
return Json(JToken.Parse(VDS.RDF.Writing.StringWriter.Write(graph, new RdfJsonWriter())).ToString()); return Json(JToken.Parse(VDS.RDF.Writing.StringWriter.Write(graph, new RdfJsonWriter())).ToString());
} }
else else
...@@ -126,7 +127,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -126,7 +127,7 @@ namespace Coscine.Api.Project.Controllers
{ {
var innerBlock = ObjectFactory<JToken>.DeserializeFromStream(Request.Body); var innerBlock = ObjectFactory<JToken>.DeserializeFromStream(Request.Body);
var graphName = _metadataModel.GenerateId(resourceId, filename, version); var graphName = _metadataModel.GenerateId(resourceId, filename, version);
var graphNameUri = new Uri(graphName); var graphNameUri = _metadataModel.CreateUri(graphName);
var json = new JObject var json = new JObject
{ {
[graphName] = innerBlock [graphName] = innerBlock
......
...@@ -5,6 +5,7 @@ using LinqToDB; ...@@ -5,6 +5,7 @@ using LinqToDB;
using System; using System;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Web;
namespace Coscine.Api.Project.Models namespace Coscine.Api.Project.Models
{ {
...@@ -50,7 +51,15 @@ namespace Coscine.Api.Project.Models ...@@ -50,7 +51,15 @@ namespace Coscine.Api.Project.Models
public string GenerateId(string resourceId, string filename, string version) public string GenerateId(string resourceId, string filename, string version)
{ {
return $"https://purl.org/coscine/md/{resourceId}/{filename}/{version}/"; // Double UrlEncode since converting it to Uri executes one UrlDecode and Virtuoso
// graph names don't support special characters
var encodedFileName = HttpUtility.UrlEncode(HttpUtility.UrlEncode(filename));
return $"https://purl.org/coscine/md/{resourceId}/{encodedFileName}/{version}/";
}
public Uri CreateUri(string graphName)
{
return new Uri(graphName);
} }
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment