Skip to content
Snippets Groups Projects
Commit 310edc24 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Merge branch 'Sprint/2021-15' into 'master'

Sprint/2021 15

See merge request !44
parents b741abb4 50081280
No related branches found
No related tags found
1 merge request!44Sprint/2021 15
## C# Template
## Tree
This template includes:
* Automatic building using cake
* Automatic testing with NUnit
* Automatic linting with Resharper
* Automatic documentation publishing using Gitlab CI / CD and a self written script which puts the docs in the docs folder to the wiki
* Automatic releases using semantic-release ([ESLint Code Convention](docs/ESLintConvention)), cake and Gitlab CI / CD
## What you need to do
Place you C# project solution file in .src/.
Make sure Create directory for solution is unticked.
![alt text](docs/images/create_project.png "Create a new Project")
Delete unused docs and update this README.
Add [NUnit](docs/nunit.md) tests to your solution.
## Building
Build this project by running either the build.ps1 or the build<span></span>.sh script.
The project will be build and tested.
### Links
* [Commit convention](docs/ESLintConvention.md)
* [Everything possible with markup](docs/testdoc.md)
* [Adding NUnit tests](docs/nunit.md)
The TreeApi handles the retrieving or storing metadata to a certain path.
......@@ -118,10 +118,18 @@ namespace Coscine.Api.Tree.Controllers
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
var infos = await resourceTypeDefinition.ListEntries(resourceId, path, resourceTypeOptions);
var fileInfos = await resourceTypeDefinition.ListEntries(resourceId, path, resourceTypeOptions);
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;
foreach (var info in infos)
foreach (var info in metadataInfos)
{
var id = GenerateId(resourceId, info.Key);
if (_rdfStoreConnector.HasGraph(id.AbsoluteUri))
......@@ -135,11 +143,11 @@ namespace Coscine.Api.Tree.Controllers
var jObject = new JObject(
new JProperty("data", new JObject(
new JProperty("metadataStorage", JToken.FromObject(graphs)),
new JProperty("fileStorage", JToken.FromObject(infos.Select(x =>
new JProperty("fileStorage", JToken.FromObject(fileInfos.Select(x =>
{
var objectMetaInfo = new ObjectMetaInfo
{
Name = x.Key[(x.Key.LastIndexOf("/") + 1)..],
Name = GetFolderOrFileName(x),
Path = x.Key,
Size = (int)x.BodyBytes,
Kind = x.Key[(x.Key.LastIndexOf(".") + 1)..],
......@@ -155,10 +163,12 @@ namespace Coscine.Api.Tree.Controllers
["Modified"] = objectMetaInfoReturnObject.Modified,
["Created"] = objectMetaInfoReturnObject.Created,
["Provider"] = objectMetaInfoReturnObject.Provider,
["IsFolder"] = objectMetaInfoReturnObject.IsFolder,
["IsFile"] = objectMetaInfoReturnObject.IsFile,
["Action"] = new JObject {
["Delete"] = new JObject {
["IsFolder"] = !x.HasBody,
["IsFile"] = x.HasBody,
["Action"] = new JObject
{
["Delete"] = new JObject
{
["Method"] = "DELETE",
["Url"] = objectMetaInfoReturnObject.DeleteLink
},
......@@ -186,12 +196,34 @@ namespace Coscine.Api.Tree.Controllers
return Json(jObject);
}
catch
catch (Exception e)
{
return BadRequest($"Error in communication with the resource");
}
}
/// <summary>
/// This method retrieves the folder or file name.
/// </summary>
/// <param name="x">Resource Entry</param>
/// <returns>Name</returns>
private static string GetFolderOrFileName(ResourceEntry x)
{
var lastSlash = x.Key.LastIndexOf("/") + 1;
var name = x.Key[lastSlash..];
if (name == "")
{
var tempPath = x.Key[..(lastSlash - 1)];
if (tempPath.Contains("/"))
{
tempPath = tempPath[(tempPath.IndexOf("/") + 1)..];
}
name = tempPath;
}
return name;
}
/// <summary>
/// This method stores the metadata of the file
/// </summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment