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
a288bc50
Commit
a288bc50
authored
2 years ago
by
Benedikt Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup Controller
parent
17fa3e3f
Branches
Sprint/2020-10
No related tags found
1 merge request
!90
New: Use the new metadata structure (coscine/issues#1792)
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Tree/Controllers/TreeController.cs
+5
-51
5 additions, 51 deletions
src/Tree/Controllers/TreeController.cs
src/Tree/Util/CustomUri.cs
+0
-28
0 additions, 28 deletions
src/Tree/Util/CustomUri.cs
with
5 additions
and
79 deletions
src/Tree/Controllers/TreeController.cs
+
5
−
51
View file @
a288bc50
using
Coscine.Api.Tree.Util
;
using
Coscine.ApiCommons
;
using
Coscine.ApiCommons
;
using
Coscine.ApiCommons.Factories
;
using
Coscine.ApiCommons.Factories
;
using
Coscine.Configuration
;
using
Coscine.Configuration
;
...
@@ -7,7 +6,6 @@ using Coscine.Database.Models;
...
@@ -7,7 +6,6 @@ using Coscine.Database.Models;
using
Coscine.Database.Util
;
using
Coscine.Database.Util
;
using
Coscine.Logging
;
using
Coscine.Logging
;
using
Coscine.Metadata
;
using
Coscine.Metadata
;
using
Coscine.Metadata.Util
;
using
Coscine.ResourceTypes
;
using
Coscine.ResourceTypes
;
using
Coscine.ResourceTypes.Base
;
using
Coscine.ResourceTypes.Base
;
using
Coscine.ResourceTypes.Base.Models
;
using
Coscine.ResourceTypes.Base.Models
;
...
@@ -37,6 +35,7 @@ namespace Coscine.Api.Tree.Controllers
...
@@ -37,6 +35,7 @@ namespace Coscine.Api.Tree.Controllers
private
readonly
Authenticator
_authenticator
;
private
readonly
Authenticator
_authenticator
;
private
readonly
ResourceModel
_resourceModel
;
private
readonly
ResourceModel
_resourceModel
;
private
readonly
RdfStoreConnector
_rdfStoreConnector
;
private
readonly
RdfStoreConnector
_rdfStoreConnector
;
private
readonly
CoscineLDPHelper
_coscineLDPHelper
;
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
ProjectResourceModel
_projectResourceModel
;
private
readonly
ProjectResourceModel
_projectResourceModel
;
private
readonly
CoscineLogger
_coscineLogger
;
private
readonly
CoscineLogger
_coscineLogger
;
...
@@ -65,52 +64,7 @@ namespace Coscine.Api.Tree.Controllers
...
@@ -65,52 +64,7 @@ namespace Coscine.Api.Tree.Controllers
var
path
=
rule
[
rule
.
IndexOf
(
"/"
)..];
var
path
=
rule
[
rule
.
IndexOf
(
"/"
)..];
_blobApiLink
=
$"https://
{
host
}{
path
}
/blob/"
;
_blobApiLink
=
$"https://
{
host
}{
path
}
/blob/"
;
_prefix
=
_configuration
.
GetStringAndWait
(
"coscine/global/epic/prefix"
);
_prefix
=
_configuration
.
GetStringAndWait
(
"coscine/global/epic/prefix"
);
}
_coscineLDPHelper
=
new
CoscineLDPHelper
(
_rdfStoreConnector
,
_prefix
);
/// <summary>
/// Generates Id
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to file</param>
/// <param name="retrieve">Is retrieve action?</param>
/// <returns> Uri </returns>
public
Uri
GenerateId
(
string
resourceId
,
string
path
,
bool
retrieve
=
false
,
bool
storing
=
false
)
{
if
(!
path
.
StartsWith
(
"/"
))
{
path
=
"/"
+
path
;
}
var
currentId
=
_rdfStoreConnector
.
GetMetadataId
(
resourceId
,
path
);
if
(
currentId
==
null
&&
retrieve
)
{
return
GenerateOldId
(
resourceId
,
path
);
}
else
if
(
currentId
==
null
||
storing
)
{
var
newVersionGraph
=
new
CustomUri
(
$"https://purl.org/coscine/resources/
{
resourceId
}{
path
}
/@type=metadata&version=
{
VersionUtil
.
GetNewVersion
()}
"
);
return
newVersionGraph
;
}
else
{
return
new
CustomUri
(
currentId
);
}
}
/// <summary>
/// Generates Id
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to file</param>
/// <returns> Uri </returns>
public
Uri
GenerateOldId
(
string
resourceId
,
string
path
)
{
if
(!
path
.
StartsWith
(
"/"
))
{
path
=
"/"
+
path
;
}
return
new
CustomUri
(
$"https://hdl.handle.net/
{
_prefix
}
/
{
resourceId
}
@path=
{
Uri
.
EscapeDataString
(
path
)}
"
);
}
}
/// <summary>
/// <summary>
...
@@ -191,7 +145,7 @@ namespace Coscine.Api.Tree.Controllers
...
@@ -191,7 +145,7 @@ namespace Coscine.Api.Tree.Controllers
// Add to metadata infos, if no "physical" file for it exists
// Add to metadata infos, if no "physical" file for it exists
if
(!
metadataInfos
.
Any
((
metadataInfo
)
=>
metadataInfo
.
Key
==
path
))
if
(!
metadataInfos
.
Any
((
metadataInfo
)
=>
metadataInfo
.
Key
==
path
))
{
{
metadataInfos
.
Add
(
new
ResourceEntry
(
path
,
true
,
0
,
GenerateId
(
resourceId
,
path
,
true
).
AbsoluteUri
,
null
,
DateTime
.
Now
,
DateTime
.
Now
));
metadataInfos
.
Add
(
new
ResourceEntry
(
path
,
true
,
0
,
_coscineLDPHelper
.
GenerateId
(
resourceId
,
path
,
true
).
AbsoluteUri
,
null
,
DateTime
.
Now
,
DateTime
.
Now
));
}
}
var
applicationProfileGraph
=
_rdfStoreConnector
.
GetGraph
(
resource
.
ApplicationProfile
);
var
applicationProfileGraph
=
_rdfStoreConnector
.
GetGraph
(
resource
.
ApplicationProfile
);
...
@@ -202,7 +156,7 @@ namespace Coscine.Api.Tree.Controllers
...
@@ -202,7 +156,7 @@ namespace Coscine.Api.Tree.Controllers
int
metadataCount
=
0
;
int
metadataCount
=
0
;
foreach
(
var
info
in
metadataInfos
)
foreach
(
var
info
in
metadataInfos
)
{
{
var
id
=
GenerateId
(
resourceId
,
info
.
Key
,
true
);
var
id
=
_coscineLDPHelper
.
GenerateId
(
resourceId
,
info
.
Key
,
true
);
if
(
_rdfStoreConnector
.
HasGraph
(
id
.
AbsoluteUri
))
if
(
_rdfStoreConnector
.
HasGraph
(
id
.
AbsoluteUri
))
{
{
var
graph
=
_rdfStoreConnector
.
GetGraph
(
id
);
var
graph
=
_rdfStoreConnector
.
GetGraph
(
id
);
...
@@ -367,7 +321,7 @@ namespace Coscine.Api.Tree.Controllers
...
@@ -367,7 +321,7 @@ namespace Coscine.Api.Tree.Controllers
// Ducktape solution for supporting multiple mimetypes
// Ducktape solution for supporting multiple mimetypes
var
metadataObject
=
ObjectFactory
<
JToken
>.
DeserializeFromStream
(
Request
.
Body
);
var
metadataObject
=
ObjectFactory
<
JToken
>.
DeserializeFromStream
(
Request
.
Body
);
var
graphNameUri
=
GenerateId
(
resourceId
,
path
,
false
,
true
);
var
graphNameUri
=
_coscineLDPHelper
.
GenerateId
(
resourceId
,
path
,
false
,
true
);
JObject
json
;
JObject
json
;
...
...
This diff is collapsed.
Click to expand it.
src/Tree/Util/CustomUri.cs
deleted
100644 → 0
+
0
−
28
View file @
17fa3e3f
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