Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Coscine
backend
apis
TreeApi
Commits
06e5fc9e
Commit
06e5fc9e
authored
Jun 07, 2022
by
Petar Hristov
💬
Browse files
Merge branch 'dev' into 'master'
Release: Sprint/2022 10
🤖
See merge request
!73
parents
d61ee1d6
c5dd9264
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/Tree/Controllers/TreeController.cs
View file @
06e5fc9e
...
...
@@ -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,13 @@ namespace Coscine.Api.Tree.Controllers
var
resourceTypeInformation
=
resourceTypeDefinition
.
GetResourceTypeInformation
().
Result
;
var
metadataInfos
=
new
List
<
ResourceEntry
>(
fileInfos
);
var
graphs
=
new
List
<
JToken
>();
// Add to metadata infos, if no "physical" file for it exists
if
(!
metadataInfos
.
Any
((
metadataInfo
)
=>
metadataInfo
.
Key
==
path
))
{
metadataInfos
.
Add
(
new
ResourceEntry
(
path
,
true
,
0
,
GenerateId
(
resourceId
,
path
).
AbsoluteUri
,
null
,
DateTime
.
Now
,
DateTime
.
Now
));
}
var
graphs
=
new
List
<
object
>();
int
metadataCount
=
0
;
foreach
(
var
info
in
metadataInfos
)
{
...
...
@@ -165,7 +172,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 +298,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 +309,7 @@ namespace Coscine.Api.Tree.Controllers
path
=
path
[
1.
.];
}
return
StoreMetadataForFile
(
resourceId
,
path
);
return
StoreMetadataForFile
(
resourceId
,
path
,
mimeType
);
}
/// <summary>
...
...
@@ -296,8 +317,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 +327,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"
)
{
[
graphNameUri
.
AbsoluteUri
]
=
innerBlock
};
json
=
new
JObject
{
[
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
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment