Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TreeApi
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Coscine
backend
apis
TreeApi
Commits
3ea1375b
Commit
3ea1375b
authored
3 years ago
by
Benedikt Heinrichs
Committed by
Petar Hristov
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update: Extend with a Mimetype attribute
parent
d61ee1d6
No related branches found
No related tags found
2 merge requests
!73
Release: Sprint/2022 10 :robot:
,
!71
Update: Extend with a Mimetype attribute
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tree/Controllers/TreeController.cs
+50
-13
50 additions, 13 deletions
src/Tree/Controllers/TreeController.cs
with
50 additions
and
13 deletions
src/Tree/Controllers/TreeController.cs
+
50
−
13
View file @
3ea1375b
...
...
@@ -24,7 +24,6 @@ using System.Threading.Tasks;
using
System.Web
;
using
VDS.RDF
;
using
VDS.RDF.Parsing
;
using
VDS.RDF.Writing
;
namespace
Coscine.Api.Tree.Controllers
{
...
...
@@ -101,9 +100,10 @@ namespace Coscine.Api.Tree.Controllers
/// </summary>
/// <param name="resourceId"> Id of a resource</param>
/// <param name="path">Path to the file</param>
/// <param name="mimeType">Requested MimeType of the metadata</param>
/// <returns> JSON Object with the metadata if OK, otherwise status code 400 or 401 or 404</returns>
[
HttpGet
(
"[controller]/{resourceId}/"
)]
public
async
Task
<
IActionResult
>
GetMetadataWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
=
""
)
public
async
Task
<
IActionResult
>
GetMetadataWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
=
""
,
[
FromQuery
]
string
mimeType
=
"application/rdf+json"
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -111,7 +111,7 @@ namespace Coscine.Api.Tree.Controllers
path
=
path
[
1
..];
}
return
await
GetMetadata
(
resourceId
,
path
);
return
await
GetMetadata
(
resourceId
,
path
,
mimeType
);
}
/// <summary>
...
...
@@ -119,8 +119,9 @@ namespace Coscine.Api.Tree.Controllers
/// </summary>
/// <param name="resourceId"> Id of a resource</param>
/// <param name="path">Path to the file</param>
/// <param name="mimeType">Requested MimeType of the metadata</param>
/// <returns> JSON Object with the metadata if OK, otherwise status code 400 or 401 or 404</returns>
public
async
Task
<
IActionResult
>
GetMetadata
(
string
resourceId
,
string
path
=
""
)
public
async
Task
<
IActionResult
>
GetMetadata
(
string
resourceId
,
string
path
=
""
,
string
mimeType
=
"application/rdf+json"
)
{
if
(
path
.
Contains
(
"%2F"
)
||
path
.
Contains
(
"%2f"
))
{
...
...
@@ -156,7 +157,7 @@ namespace Coscine.Api.Tree.Controllers
var
resourceTypeInformation
=
resourceTypeDefinition
.
GetResourceTypeInformation
().
Result
;
var
metadataInfos
=
new
List
<
ResourceEntry
>(
fileInfos
);
var
graphs
=
new
List
<
JToken
>();
var
graphs
=
new
List
<
object
>();
int
metadataCount
=
0
;
foreach
(
var
info
in
metadataInfos
)
{
...
...
@@ -165,7 +166,20 @@ namespace Coscine.Api.Tree.Controllers
{
var
graph
=
_rdfStoreConnector
.
GetGraph
(
id
);
metadataCount
=
graph
.
Triples
.
Count
;
graphs
.
Add
(
JToken
.
Parse
(
StringWriter
.
Write
(
graph
,
new
RdfJsonWriter
())));
var
writer
=
MimeTypesHelper
.
GetWriter
(
new
List
<
string
>()
{
mimeType
});
var
parsedRdf
=
VDS
.
RDF
.
Writing
.
StringWriter
.
Write
(
graph
,
writer
);
// Legacy Support
if
(
mimeType
==
"application/rdf+json"
)
{
graphs
.
Add
(
JToken
.
Parse
(
parsedRdf
));
}
else
{
graphs
.
Add
(
new
JObject
{
[
id
.
AbsoluteUri
]
=
parsedRdf
});
}
}
}
...
...
@@ -278,9 +292,10 @@ namespace Coscine.Api.Tree.Controllers
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the file</param>
/// <param name="mimeType">Requested MimeType of the metadata</param>
/// <returns>If OK status code 204, otherwise status code 400 or 401</returns>
[
HttpPut
(
"[controller]/{resourceId}/"
)]
public
IActionResult
StoreMetadataForFileWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
=
""
)
public
IActionResult
StoreMetadataForFileWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
=
""
,
[
FromQuery
]
string
mimeType
=
"application/rdf+json"
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -288,7 +303,7 @@ namespace Coscine.Api.Tree.Controllers
path
=
path
[
1
..];
}
return
StoreMetadataForFile
(
resourceId
,
path
);
return
StoreMetadataForFile
(
resourceId
,
path
,
mimeType
);
}
/// <summary>
...
...
@@ -296,8 +311,9 @@ namespace Coscine.Api.Tree.Controllers
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the file</param>
/// <param name="mimeType">Requested MimeType of the metadata</param>
/// <returns>If OK status code 204, otherwise status code 400 or 401</returns>
public
IActionResult
StoreMetadataForFile
(
string
resourceId
,
string
path
)
public
IActionResult
StoreMetadataForFile
(
string
resourceId
,
string
path
,
string
mimeType
=
"application/rdf+json"
)
{
path
=
$"/
{
path
}
"
;
if
(
path
.
Contains
(
"%2F"
)
||
path
.
Contains
(
"%2f"
))
...
...
@@ -305,13 +321,34 @@ namespace Coscine.Api.Tree.Controllers
return
BadRequest
(
"Path can not contain the sequence %2F."
);
}
var
innerBlock
=
ObjectFactory
<
JToken
>.
DeserializeFromStream
(
Request
.
Body
);
// Ducktape solution for supporting multiple mimetypes
var
metadataObject
=
ObjectFactory
<
JToken
>.
DeserializeFromStream
(
Request
.
Body
);
var
graphNameUri
=
GenerateId
(
resourceId
,
path
);
var
json
=
new
JObject
JObject
json
;
// Legacy Support
if
(
mimeType
==
"application/rdf+json"
)
{
json
=
new
JObject
{
[
graphNameUri
.
AbsoluteUri
]
=
innerBlock
[
graphNameUri
.
AbsoluteUri
]
=
metadataObject
};
}
else
{
var
tempGraph
=
new
Graph
();
StringParser
.
Parse
(
tempGraph
,
metadataObject
.
Value
<
string
>(
"metadata"
).
ToString
(),
MimeTypesHelper
.
GetParser
(
mimeType
));
var
triplesList
=
tempGraph
.
Triples
.
ToArray
();
var
subjectNode
=
tempGraph
.
CreateUriNode
(
graphNameUri
);
foreach
(
var
triple
in
triplesList
)
{
tempGraph
.
Retract
(
triple
);
tempGraph
.
Assert
(
new
Triple
(
subjectNode
,
triple
.
Predicate
,
triple
.
Object
));
}
json
=
JObject
.
Parse
(
VDS
.
RDF
.
Writing
.
StringWriter
.
Write
(
tempGraph
,
MimeTypesHelper
.
GetWriter
(
"application/rdf+json"
)));
}
var
user
=
_authenticator
.
GetUser
();
var
resource
=
_resourceModel
.
GetById
(
Guid
.
Parse
(
resourceId
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment