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
6173d9c5
Commit
6173d9c5
authored
3 years ago
by
L. Ellenbeck
Committed by
Petar Hristov
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
New: Updated to new resource types
parent
f811a07c
No related branches found
No related tags found
1 merge request
!70
Issue/2072 worm resource type
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Tree.sln
+2
-2
2 additions, 2 deletions
src/Tree.sln
src/Tree/Controllers/TreeController.cs
+39
-33
39 additions, 33 deletions
src/Tree/Controllers/TreeController.cs
src/Tree/Tree.csproj
+1
-3
1 addition, 3 deletions
src/Tree/Tree.csproj
with
42 additions
and
38 deletions
src/Tree.sln
+
2
−
2
View file @
6173d9c5
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 1
6
VisualStudioVersion = 1
6
.0.
28803.156
# Visual Studio Version 1
7
VisualStudioVersion = 1
7
.0.
32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tree", "Tree\Tree.csproj", "{AC8882D4-3F0C-4BBF-83CE-22A5B05ED3FB}"
EndProject
...
...
This diff is collapsed.
Click to expand it.
src/Tree/Controllers/TreeController.cs
+
39
−
33
View file @
6173d9c5
...
...
@@ -7,12 +7,12 @@ using Coscine.Database.Models;
using
Coscine.Database.Util
;
using
Coscine.Logging
;
using
Coscine.Metadata
;
using
Coscine.ResourceLoader
;
using
Coscine.ResourceTypeBase
;
using
Coscine.ResourceTypes
;
using
Coscine.ResourceTypes.Base
;
using
Coscine.ResourceTypes.Base.Models
;
using
Coscine.WaterbutlerHelper
;
using
Coscine.WaterbutlerHelper.ReturnObjects
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json.Linq
;
...
...
@@ -75,6 +75,11 @@ namespace Coscine.Api.Tree.Controllers
/// <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
)}
"
);
}
...
...
@@ -98,7 +103,7 @@ namespace Coscine.Api.Tree.Controllers
/// <param name="path">Path to the file</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
,
[
System
.
Web
.
Http
.
FromUri
]
string
path
=
""
)
public
async
Task
<
IActionResult
>
GetMetadataWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
=
""
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -117,15 +122,13 @@ namespace Coscine.Api.Tree.Controllers
/// <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
=
""
)
{
var
rawPath
=
path
;
path
=
$"/
{
path
}
"
;
if
(
path
.
Contains
(
"%2F"
)
||
path
.
Contains
(
"%2f"
))
{
return
BadRequest
(
"Path can not contain the sequence %2F."
);
}
var
user
=
_authenticator
.
GetUser
();
var
check
=
CheckResourceIdAndPath
(
resourceId
,
path
,
out
Resource
resource
);
var
check
=
CheckResourceIdAndPath
(
resourceId
,
$"/
{
path
}
"
,
out
Resource
resource
);
if
(
check
!=
null
)
{
return
check
;
...
...
@@ -143,20 +146,15 @@ namespace Coscine.Api.Tree.Controllers
try
{
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
Instance
.
GetResourceType
(
resource
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
}
var
fileInfos
=
await
resourceTypeDefinition
.
ListEntries
(
resourceId
,
path
,
resourceTypeOptions
);
var
fileInfos
=
await
resourceTypeDefinition
.
ListEntries
(
resourceId
,
path
);
var
resourceTypeInformation
=
resourceTypeDefinition
.
GetResourceTypeInformation
().
Result
;
var
metadataInfos
=
new
List
<
ResourceEntry
>(
fileInfos
);
if
(
path
.
EndsWith
(
"/"
))
{
metadataInfos
.
Insert
(
0
,
new
ResourceEntry
(
path
,
false
,
0
,
null
,
null
,
new
DateTime
(),
new
DateTime
()));
}
var
graphs
=
new
List
<
JToken
>();
int
metadataCount
=
0
;
...
...
@@ -167,14 +165,15 @@ namespace Coscine.Api.Tree.Controllers
{
var
graph
=
_rdfStoreConnector
.
GetGraph
(
id
);
metadataCount
=
graph
.
Triples
.
Count
;
graphs
.
Add
(
JToken
.
Parse
(
VDS
.
RDF
.
Writing
.
StringWriter
.
Write
(
graph
,
new
RdfJsonWriter
())));
graphs
.
Add
(
JToken
.
Parse
(
StringWriter
.
Write
(
graph
,
new
RdfJsonWriter
())));
}
}
var
jObject
=
new
JObject
(
new
JProperty
(
"data"
,
new
JObject
(
new
JProperty
(
"metadataStorage"
,
JToken
.
FromObject
(
graphs
)),
new
JProperty
(
"fileStorage"
,
JToken
.
FromObject
(
fileInfos
.
Select
(
x
=>
new
JProperty
(
"fileStorage"
,
JToken
.
FromObject
(
fileInfos
.
Select
(
x
=>
{
var
objectMetaInfo
=
new
ObjectMetaInfo
{
...
...
@@ -185,7 +184,7 @@ namespace Coscine.Api.Tree.Controllers
Provider
=
resource
.
Type
.
DisplayName
};
var
objectMetaInfoReturnObject
=
new
ObjectMetaInfoReturnObject
(
objectMetaInfo
,
_blobApiLink
,
resource
.
Id
.
ToString
());
var
result
=
new
JObject
var
obj
=
new
JObject
{
[
"Name"
]
=
objectMetaInfoReturnObject
.
Name
,
[
"Path"
]
=
objectMetaInfoReturnObject
.
Path
,
...
...
@@ -196,33 +195,39 @@ namespace Coscine.Api.Tree.Controllers
[
"Provider"
]
=
objectMetaInfoReturnObject
.
Provider
,
[
"IsFolder"
]
=
!
x
.
HasBody
,
[
"IsFile"
]
=
x
.
HasBody
,
[
"Action"
]
=
new
JObject
[
"Action"
]
=
new
JObject
()
};
if
(
resourceTypeInformation
.
CanCreateLinks
)
{
obj
[
"Action"
]
=
new
JObject
{
[
"Delete"
]
=
new
JObject
{
[
"Method"
]
=
"DELETE"
,
[
"Url"
]
=
objectMetaInfoReturnObject
.
DeleteLink
[
"Url"
]
=
resourceTypeDefinition
?.
GetPresignedUrl
(
resource
.
Id
.
ToString
(),
objectMetaInfoReturnObject
.
Path
,
CoscineHttpVerb
.
DELETE
).
Result
?.
ToString
()
},
[
"Download"
]
=
new
JObject
{
[
"Method"
]
=
"GET"
,
[
"Url"
]
=
resourceTypeDefinition
?.
Get
EntryDownloadUrl
(
rawPath
,
null
,
resourceTypeOptions
).
Result
?.
ToString
()
[
"Url"
]
=
resourceTypeDefinition
?.
Get
PresignedUrl
(
resource
.
Id
.
ToString
(),
objectMetaInfoReturnObject
.
Path
,
CoscineHttpVerb
.
GET
).
Result
?.
ToString
()
},
[
"Upload"
]
=
new
JObject
{
[
"Method"
]
=
"PUT"
,
[
"Url"
]
=
resourceTypeDefinition
?.
GetEntryStoreUrl
(
rawPath
,
null
,
resourceTypeOptions
).
Result
?.
ToString
()
}
[
"Url"
]
=
resourceTypeDefinition
?.
GetPresignedUrl
(
resource
.
Id
.
ToString
(),
objectMetaInfoReturnObject
.
Path
,
CoscineHttpVerb
.
DELETE
).
Result
?.
ToString
()
}
};
return
result
;
}
return
obj
;
})))
))
);
if
(
CoscineLoggerConfiguration
.
IsLogLevelActivated
(
LogType
.
Analytics
)
&&
path
!=
"/"
)
{
LogAnalyticsViewMd
(
_projectResourceModel
.
GetProjectForResource
(
resource
.
Id
).
Value
,
resource
.
Id
,
path
,
user
,
GetMetadataCompleteness
(
metadataCount
,
resource
));
LogAnalyticsViewMd
(
_projectResourceModel
.
GetProjectForResource
(
resource
.
Id
).
Value
,
resource
.
Id
,
$"/
{
path
}
"
,
user
,
GetMetadataCompleteness
(
metadataCount
,
resource
));
}
return
Json
(
jObject
);
...
...
@@ -245,7 +250,7 @@ namespace Coscine.Api.Tree.Controllers
if
(
name
?.
Length
==
0
)
{
var
tempPath
=
x
.
Key
[..(
lastSlash
-
1
)];
if
(
tempPath
.
Contains
(
"/"
))
if
(
tempPath
.
Contains
(
'/'
))
{
tempPath
=
tempPath
[(
tempPath
.
IndexOf
(
"/"
)
+
1
)..];
}
...
...
@@ -275,7 +280,7 @@ namespace Coscine.Api.Tree.Controllers
/// <param name="path">Path to the file</param>
/// <returns>If OK status code 204, otherwise status code 400 or 401</returns>
[
HttpPut
(
"[controller]/{resourceId}/"
)]
public
IActionResult
StoreMetadataForFileWithParameter
(
string
resourceId
,
[
System
.
Web
.
Http
.
FromUri
]
string
path
=
""
)
public
IActionResult
StoreMetadataForFileWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
=
""
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -336,8 +341,7 @@ namespace Coscine.Api.Tree.Controllers
};
// throw bad request if empty node value is detected
JToken
root
=
json
.
First
.
First
;
foreach
(
var
node
in
root
)
foreach
(
var
node
in
json
.
First
.
First
)
{
string
nodeValue
=
node
.
First
.
First
[
"value"
].
ToString
().
ToLower
();
if
(
string
.
IsNullOrEmpty
(
nodeValue
))
...
...
@@ -408,7 +412,9 @@ namespace Coscine.Api.Tree.Controllers
{
_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
}
...
...
@@ -442,7 +448,7 @@ namespace Coscine.Api.Tree.Controllers
return
BadRequest
(
$"Your path \"
{
path
}
\" is empty."
);
}
Regex
rgx
=
new
Regex
(
@"[\:?*<>|]+"
);
var
rgx
=
new
Regex
(
@"[\:?*<>|]+"
);
if
(
rgx
.
IsMatch
(
path
))
{
return
BadRequest
(
$"Your path \"
{
path
}
\" contains bad characters. The following characters are not permissible:
{
@"\/:?*<>|"
}
."
);
...
...
@@ -468,7 +474,7 @@ namespace Coscine.Api.Tree.Controllers
if
(
resource
.
Type
==
null
)
{
ResourceTypeModel
resourceTypeModel
=
new
ResourceTypeModel
();
var
resourceTypeModel
=
new
ResourceTypeModel
();
resource
.
Type
=
resourceTypeModel
.
GetById
(
resource
.
TypeId
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Tree/Tree.csproj
+
1
−
3
View file @
6173d9c5
...
...
@@ -21,9 +21,7 @@
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="*-*" />
<PackageReference Include="Coscine.WaterbutlerHelper" Version="2.*-*" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />
</ItemGroup>
</Project>
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