Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metadata
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
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
libraries
Metadata
Merge requests
!58
New: First integration of a LDP Client (coscine/issues#1792)
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
New: First integration of a LDP Client (coscine/issues#1792)
Issue/1792-newMetadataStructure
into
dev
Overview
0
Commits
57
Pipelines
57
Changes
21
Merged
Benedikt Heinrichs
requested to merge
Issue/1792-newMetadataStructure
into
dev
2 years ago
Overview
0
Commits
57
Pipelines
57
Changes
21
Expand
0
0
Merge request reports
Compare
dev
version 56
164f7404
2 years ago
version 55
dbd83505
2 years ago
version 54
cd45684f
2 years ago
version 53
2c9c70f8
2 years ago
version 52
d63bce24
2 years ago
version 51
cb5d1fff
2 years ago
version 50
38065ffd
2 years ago
version 49
0410bcad
2 years ago
version 48
7e6b8a04
2 years ago
version 47
1717899a
2 years ago
version 46
11966aa4
2 years ago
version 45
a494c138
2 years ago
version 44
36804171
2 years ago
version 43
026366c9
2 years ago
version 42
46660f37
2 years ago
version 41
e85260be
2 years ago
version 40
554aede7
2 years ago
version 39
8f575493
2 years ago
version 38
d43e43f8
2 years ago
version 37
000a0deb
2 years ago
version 36
469f1503
2 years ago
version 35
ab39c40e
2 years ago
version 34
e403a85d
2 years ago
version 33
082fb28e
2 years ago
version 32
23b58284
2 years ago
version 31
2a9c295d
2 years ago
version 30
0c5d9490
2 years ago
version 29
957f2bfc
2 years ago
version 28
427fa54b
2 years ago
version 27
a66d51b0
2 years ago
version 26
1464401b
2 years ago
version 25
ac5a494a
2 years ago
version 24
e9b8c5e4
2 years ago
version 23
13c465f2
2 years ago
version 22
a325569d
2 years ago
version 21
5db45a26
2 years ago
version 20
ae980699
2 years ago
version 19
0c1a5440
2 years ago
version 18
7294082e
2 years ago
version 17
cf64fa11
2 years ago
version 16
9dcb886c
2 years ago
version 15
77639387
2 years ago
version 14
1fc6f18a
2 years ago
version 13
d0bb26b4
2 years ago
version 12
afbbe77b
2 years ago
version 11
d4a458f6
2 years ago
version 10
299e86be
2 years ago
version 9
be270d75
2 years ago
version 8
0b0b9588
2 years ago
version 7
4aec2e79
2 years ago
version 6
69ac5160
2 years ago
version 5
454b78d1
2 years ago
version 4
1370bc99
2 years ago
version 3
b0fd9f7e
2 years ago
version 2
df4057a1
2 years ago
version 1
3e180be6
2 years ago
dev (base)
and
latest version
latest version
1bfb725d
57 commits,
2 years ago
version 56
164f7404
56 commits,
2 years ago
version 55
dbd83505
55 commits,
2 years ago
version 54
cd45684f
54 commits,
2 years ago
version 53
2c9c70f8
53 commits,
2 years ago
version 52
d63bce24
52 commits,
2 years ago
version 51
cb5d1fff
51 commits,
2 years ago
version 50
38065ffd
50 commits,
2 years ago
version 49
0410bcad
49 commits,
2 years ago
version 48
7e6b8a04
48 commits,
2 years ago
version 47
1717899a
47 commits,
2 years ago
version 46
11966aa4
46 commits,
2 years ago
version 45
a494c138
45 commits,
2 years ago
version 44
36804171
44 commits,
2 years ago
version 43
026366c9
43 commits,
2 years ago
version 42
46660f37
42 commits,
2 years ago
version 41
e85260be
41 commits,
2 years ago
version 40
554aede7
40 commits,
2 years ago
version 39
8f575493
39 commits,
2 years ago
version 38
d43e43f8
38 commits,
2 years ago
version 37
000a0deb
37 commits,
2 years ago
version 36
469f1503
36 commits,
2 years ago
version 35
ab39c40e
35 commits,
2 years ago
version 34
e403a85d
34 commits,
2 years ago
version 33
082fb28e
33 commits,
2 years ago
version 32
23b58284
32 commits,
2 years ago
version 31
2a9c295d
31 commits,
2 years ago
version 30
0c5d9490
30 commits,
2 years ago
version 29
957f2bfc
29 commits,
2 years ago
version 28
427fa54b
28 commits,
2 years ago
version 27
a66d51b0
27 commits,
2 years ago
version 26
1464401b
26 commits,
2 years ago
version 25
ac5a494a
25 commits,
2 years ago
version 24
e9b8c5e4
24 commits,
2 years ago
version 23
13c465f2
23 commits,
2 years ago
version 22
a325569d
22 commits,
2 years ago
version 21
5db45a26
21 commits,
2 years ago
version 20
ae980699
20 commits,
2 years ago
version 19
0c1a5440
19 commits,
2 years ago
version 18
7294082e
18 commits,
2 years ago
version 17
cf64fa11
17 commits,
2 years ago
version 16
9dcb886c
16 commits,
2 years ago
version 15
77639387
15 commits,
2 years ago
version 14
1fc6f18a
14 commits,
2 years ago
version 13
d0bb26b4
13 commits,
2 years ago
version 12
afbbe77b
12 commits,
2 years ago
version 11
d4a458f6
11 commits,
2 years ago
version 10
299e86be
10 commits,
2 years ago
version 9
be270d75
9 commits,
2 years ago
version 8
0b0b9588
8 commits,
2 years ago
version 7
4aec2e79
7 commits,
2 years ago
version 6
69ac5160
6 commits,
2 years ago
version 5
454b78d1
5 commits,
2 years ago
version 4
1370bc99
4 commits,
2 years ago
version 3
b0fd9f7e
3 commits,
2 years ago
version 2
df4057a1
2 commits,
2 years ago
version 1
3e180be6
1 commit,
2 years ago
21 files
+
2375
−
302
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
21
Search (e.g. *.vue) (Ctrl+P)
src/Metadata/LDPWrapper/CoscineLDPWrapper.cs
0 → 100644
+
193
−
0
Options
using
Coscine.Configuration
;
using
Coscine.Metadata.Util
;
using
System
;
using
System.IO
;
using
System.Linq
;
using
System.Net.Http
;
using
System.Net.Http.Headers
;
using
System.Threading.Tasks
;
using
VDS.RDF
;
using
VDS.RDF.Parsing
;
using
VDS.RDF.Writing
;
namespace
Coscine.Metadata.LDPWrapper
{
/// <summary>
/// WIP Implementation of an implementation which interacts with Linked Data Platforms
/// </summary>
public
class
CoscineLDPWrapper
:
ILDPWrapper
{
// Will be documented when fully implemented
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
private
readonly
IConfiguration
_configuration
;
private
readonly
HttpClient
_httpClient
;
private
readonly
string
_endpoint
;
public
string
?
JWT
{
get
;
set
;
}
public
CoscineLDPWrapper
(
IConfiguration
configuration
,
HttpClient
httpClient
,
bool
wrapperUse
=
true
,
string
?
jwt
=
null
)
{
_configuration
=
configuration
;
_httpClient
=
httpClient
;
_endpoint
=
wrapperUse
?
_configuration
.
GetString
(
"coscine/local/ldpwrapper/url"
,
"http://localhost:5000/"
)
:
_configuration
.
GetString
(
"coscine/local/trellis/url"
,
"http://localhost:8253/"
);
JWT
=
jwt
;
}
public
async
Task
<
string
?>
Add
(
string
container
,
string
identifier
,
IGraph
?
body
=
null
)
{
var
message
=
new
HttpRequestMessage
()
{
Method
=
HttpMethod
.
Post
,
RequestUri
=
new
Uri
(
$"
{
_endpoint
}{
container
}
"
)
};
if
(
body
!=
null
)
{
message
.
Content
=
new
StringContent
(
VDS
.
RDF
.
Writing
.
StringWriter
.
Write
(
body
,
new
CompressingTurtleWriter
()));
message
.
Content
.
Headers
.
ContentType
=
new
MediaTypeHeaderValue
(
"text/turtle"
);
}
message
.
Headers
.
Add
(
"Accept"
,
"text/turtle"
);
message
.
Headers
.
Add
(
"Link"
,
"<http://www.w3.org/ns/ldp#Resource>; rel=\"type\""
);
message
.
Headers
.
Add
(
"Slug"
,
identifier
);
return
ParseIdentifier
(
await
FireRequest
(
message
)
);
}
public
async
Task
<
string
?>
Create
(
string
identifier
,
IGraph
?
body
=
null
)
{
var
message
=
new
HttpRequestMessage
()
{
Method
=
HttpMethod
.
Post
,
RequestUri
=
new
Uri
(
$"
{
_endpoint
}
"
)
};
if
(
body
!=
null
)
{
message
.
Content
=
new
StringContent
(
VDS
.
RDF
.
Writing
.
StringWriter
.
Write
(
body
,
new
CompressingTurtleWriter
()));
message
.
Content
.
Headers
.
ContentType
=
new
MediaTypeHeaderValue
(
"text/turtle"
);
}
message
.
Headers
.
Add
(
"Accept"
,
"text/turtle"
);
message
.
Headers
.
Add
(
"Link"
,
"<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\""
);
message
.
Headers
.
Add
(
"Slug"
,
identifier
);
return
ParseIdentifier
(
await
FireRequest
(
message
)
);
}
public
Task
<
bool
>
Delete
(
string
identifier
)
{
throw
new
NotImplementedException
();
}
public
async
Task
<
IGraph
?>
Get
(
string
identifier
)
{
var
message
=
new
HttpRequestMessage
()
{
Method
=
HttpMethod
.
Get
,
RequestUri
=
new
Uri
(
$"
{
_endpoint
}{
identifier
}
"
)
};
message
.
Headers
.
Add
(
"Accept"
,
"text/turtle"
);
return
await
ParseGraph
(
await
FireRequest
(
message
)
);
}
public
async
Task
<
bool
>
Exists
(
string
identifier
)
{
var
message
=
new
HttpRequestMessage
()
{
Method
=
HttpMethod
.
Get
,
RequestUri
=
new
Uri
(
$"
{
_endpoint
}{
identifier
}
"
)
};
message
.
Headers
.
Add
(
"Accept"
,
"text/turtle"
);
return
(
await
FireRequest
(
message
)).
IsSuccessStatusCode
;
}
public
async
Task
<
bool
>
SetAuthorization
(
string
identifier
,
IGraph
?
body
=
null
)
{
return
await
Update
(
identifier
+
"/?ext=acl"
,
body
,
LinkType
.
Authorization
);
}
public
async
Task
<
bool
>
Update
(
string
identifier
,
IGraph
?
body
=
null
,
LinkType
?
linkType
=
null
)
{
var
message
=
new
HttpRequestMessage
()
{
Method
=
HttpMethod
.
Put
,
RequestUri
=
new
Uri
(
$"
{
_endpoint
}{
identifier
}
"
)
};
if
(
body
!=
null
)
{
message
.
Content
=
new
StringContent
(
VDS
.
RDF
.
Writing
.
StringWriter
.
Write
(
body
,
new
CompressingTurtleWriter
()));
message
.
Content
.
Headers
.
ContentType
=
new
MediaTypeHeaderValue
(
"text/turtle"
);
}
message
.
Headers
.
Add
(
"Accept"
,
"text/turtle"
);
if
(
linkType
!=
null
)
{
switch
(
linkType
)
{
case
LinkType
.
Container
:
message
.
Headers
.
Add
(
"Link"
,
"<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\""
);
break
;
case
LinkType
.
Resource
:
message
.
Headers
.
Add
(
"Link"
,
"<http://www.w3.org/ns/ldp#Resource>; rel=\"type\""
);
break
;
case
LinkType
.
Authorization
:
message
.
Headers
.
Add
(
"Link"
,
"<http://www.w3.org/ns/auth/acl#Authorization>; rel=\"type\""
);
break
;
}
}
return
(
await
FireRequest
(
message
)).
IsSuccessStatusCode
;
}
private
async
Task
<
HttpResponseMessage
>
FireRequest
(
HttpRequestMessage
message
)
{
if
(
JWT
!=
null
)
{
message
.
Headers
.
Add
(
"Authorization"
,
$"Bearer
{
JWT
}
"
);
}
return
await
_httpClient
.
SendAsync
(
message
);
}
private
async
Task
<
IGraph
?>
ParseGraph
(
HttpResponseMessage
response
)
{
var
graphString
=
await
response
.
Content
.
ReadAsStringAsync
();
try
{
var
graph
=
new
Graph
();
var
ttlparser
=
new
TurtleParser
();
ttlparser
.
Load
(
graph
,
new
StringReader
(
graphString
));
return
graph
;
}
catch
{
return
null
;
}
}
private
string
?
ParseIdentifier
(
HttpResponseMessage
response
)
{
return
response
.
Headers
.
GetValues
(
"location"
).
FirstOrDefault
();
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
}
\ No newline at end of file
Loading