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
a2772e5f
Commit
a2772e5f
authored
2 years ago
by
Petar Hristov
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev' into 'master'
Release: Sprint/2023 04
See merge request
!108
parents
6dc9ffc1
67b74f0a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!108
Release: Sprint/2023 04 :robot:
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-2
1 addition, 2 deletions
README.md
src/Tree/Controllers/TreeController.cs
+16
-52
16 additions, 52 deletions
src/Tree/Controllers/TreeController.cs
src/Tree/Util/CustomUri.cs
+0
-28
0 additions, 28 deletions
src/Tree/Util/CustomUri.cs
with
17 additions
and
82 deletions
README.md
+
1
−
2
View file @
a2772e5f
#
# Tree
# Tree
API
The TreeApi handles the retrieving or storing metadata to a certain path.
Check out the
[
docs
](
https://coscine.rwth-aachen.de/coscine/api/Coscine.Api.Tree/swagger
)
.
This diff is collapsed.
Click to expand it.
src/Tree/Controllers/TreeController.cs
+
16
−
52
View file @
a2772e5f
using
Coscine.Api.Tree.Util
;
using
Coscine.ApiCommons
;
using
Coscine.ApiCommons.Factories
;
using
Coscine.Configuration
;
...
...
@@ -36,6 +35,7 @@ namespace Coscine.Api.Tree.Controllers
private
readonly
Authenticator
_authenticator
;
private
readonly
ResourceModel
_resourceModel
;
private
readonly
RdfStoreConnector
_rdfStoreConnector
;
private
readonly
CoscineLDPHelper
_coscineLDPHelper
;
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
ProjectResourceModel
_projectResourceModel
;
private
readonly
CoscineLogger
_coscineLogger
;
...
...
@@ -64,22 +64,7 @@ namespace Coscine.Api.Tree.Controllers
var
path
=
rule
[
rule
.
IndexOf
(
"/"
)..];
_blobApiLink
=
$"https://
{
host
}{
path
}
/blob/"
;
_prefix
=
_configuration
.
GetStringAndWait
(
"coscine/global/epic/prefix"
);
}
/// <summary>
/// Generates Id
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path"> Path to file</param>
/// <returns> Uri </returns>
public
Uri
GenerateId
(
string
resourceId
,
string
path
)
{
if
(!
path
.
StartsWith
(
"/"
))
{
path
=
"/"
+
path
;
}
return
new
CustomUri
(
$"https://hdl.handle.net/
{
_prefix
}
/
{
resourceId
}
@path=
{
Uri
.
EscapeDataString
(
path
)}
"
);
_coscineLDPHelper
=
new
CoscineLDPHelper
(
_rdfStoreConnector
,
_prefix
);
}
/// <summary>
...
...
@@ -159,10 +144,12 @@ namespace Coscine.Api.Tree.Controllers
var
resourceTypeInformation
=
resourceTypeDefinition
.
GetResourceTypeInformation
().
Result
;
var
metadataInfos
=
new
List
<
ResourceEntry
>(
fileInfos
);
var
metadataIds
=
_rdfStoreConnector
.
ListMetadata
(
resourceId
);
// 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
));
metadataInfos
.
Add
(
new
ResourceEntry
(
path
,
true
,
0
,
_coscineLDPHelper
.
GetId
(
resourceId
,
path
,
true
,
false
,
"metadata"
,
metadataIds
).
AbsoluteUri
,
null
,
DateTime
.
Now
,
DateTime
.
Now
));
}
var
applicationProfileGraph
=
_rdfStoreConnector
.
GetGraph
(
resource
.
ApplicationProfile
);
...
...
@@ -173,7 +160,7 @@ namespace Coscine.Api.Tree.Controllers
int
metadataCount
=
0
;
foreach
(
var
info
in
metadataInfos
)
{
var
id
=
Generate
Id
(
resourceId
,
info
.
Key
);
var
id
=
_coscineLDPHelper
.
Get
Id
(
resourceId
,
info
.
Key
,
true
,
false
,
"metadata"
,
metadataIds
);
if
(
_rdfStoreConnector
.
HasGraph
(
id
.
AbsoluteUri
))
{
var
graph
=
_rdfStoreConnector
.
GetGraph
(
id
);
...
...
@@ -297,9 +284,9 @@ namespace Coscine.Api.Tree.Controllers
/// <returns>If OK status code 204, otherwise status code 400 or 401</returns>
[
HttpPut
(
"[controller]/{resourceId}/{*path}"
)]
[
ApiExplorerSettings
(
IgnoreApi
=
true
)]
public
IActionResult
StoreMetadataForFileWithPath
(
string
resourceId
,
string
path
)
public
async
Task
<
IActionResult
>
StoreMetadataForFileWithPath
(
string
resourceId
,
string
path
)
{
return
StoreMetadataForFile
(
resourceId
,
path
);
return
await
StoreMetadataForFile
(
resourceId
,
path
);
}
/// <summary>
...
...
@@ -310,7 +297,7 @@ namespace Coscine.Api.Tree.Controllers
/// <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
=
""
,
[
FromQuery
]
string
mimeType
=
"application/rdf+json"
)
public
async
Task
<
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
(
"/"
))
...
...
@@ -318,7 +305,7 @@ namespace Coscine.Api.Tree.Controllers
path
=
path
[
1
..];
}
return
StoreMetadataForFile
(
resourceId
,
path
,
mimeType
);
return
await
StoreMetadataForFile
(
resourceId
,
path
,
mimeType
);
}
/// <summary>
...
...
@@ -328,7 +315,7 @@ namespace Coscine.Api.Tree.Controllers
/// <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
,
string
mimeType
=
"application/rdf+json"
)
public
async
Task
<
IActionResult
>
StoreMetadataForFile
(
string
resourceId
,
string
path
,
string
mimeType
=
"application/rdf+json"
)
{
path
=
$"/
{
path
}
"
;
if
(
path
.
Contains
(
"%2F"
)
||
path
.
Contains
(
"%2f"
))
...
...
@@ -339,7 +326,7 @@ namespace Coscine.Api.Tree.Controllers
// Ducktape solution for supporting multiple mimetypes
var
metadataObject
=
ObjectFactory
<
JToken
>.
DeserializeFromStream
(
Request
.
Body
);
var
graphNameUri
=
Generate
Id
(
resourceId
,
path
);
var
graphNameUri
=
_coscineLDPHelper
.
Get
Id
(
resourceId
,
path
,
false
,
true
);
JObject
json
;
...
...
@@ -443,38 +430,15 @@ namespace Coscine.Api.Tree.Controllers
return
BadRequest
(
"Data has the wrong format!"
);
}
// store the data
if
(
_rdfStoreConnector
.
HasGraph
(
graphNameUri
))
{
_rdfStoreConnector
.
ClearGraph
(
graphNameUri
);
if
(
CoscineLoggerConfiguration
.
IsLogLevelActivated
(
LogType
.
Analytics
))
{
LogAnalyticsUpdateMd
(
_projectResourceModel
.
GetProjectForResource
(
resource
.
Id
).
Value
,
resource
.
Id
,
path
,
user
,
GetMetadataCompleteness
(
graph
.
Triples
.
Count
,
resource
));
}
}
else
{
try
{
_rdfStoreConnector
.
CreateNamedGraph
(
graphNameUri
);
}
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
catch
(
Exception
)
#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.
{
// Graph creation failed because it has been created before, skip this for now
}
if
(
CoscineLoggerConfiguration
.
IsLogLevelActivated
(
LogType
.
Analytics
))
{
LogAnalyticsUploadMd
(
_projectResourceModel
.
GetProjectForResource
(
resource
.
Id
).
Value
,
resource
.
Id
,
path
,
user
,
GetMetadataCompleteness
(
graph
.
Triples
.
Count
,
resource
));
}
}
// BaseUri must be set for the sparql query
graph
.
BaseUri
=
graphNameUri
;
_rdfStoreConnector
.
AddGraph
(
graph
);
await
_rdfStoreConnector
.
AddMetadataAsync
(
graph
);
return
NoContent
();
}
...
...
This diff is collapsed.
Click to expand it.
src/Tree/Util/CustomUri.cs
deleted
100644 → 0
+
0
−
28
View file @
6dc9ffc1
using
System
;
namespace
Coscine.Api.Tree.Util
{
/// <summary>
/// Adapts the returned ToString of a Uri
/// </summary>
public
class
CustomUri
:
Uri
{
/// <summary>
/// Constructs a Custom Uri
/// </summary>
/// <param name="uri"></param>
public
CustomUri
(
string
uri
)
:
base
(
uri
)
{
}
/// <summary>
/// Overwrites the ToString for returning the AbsoluteUri (for dotNetRDF)
/// </summary>
/// <returns></returns>
public
override
string
ToString
()
{
return
AbsoluteUri
;
}
}
}
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