diff --git a/README.md b/README.md
index 16732fdf20a186bde6afc185762c779be3f146ed..0722a0d5f86a91535903cda01674465e6d438fbf 100644
--- a/README.md
+++ b/README.md
@@ -1,31 +1,3 @@
-## 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.
-
-
-
-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.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.
diff --git a/src/Tree/Controllers/TreeController.cs b/src/Tree/Controllers/TreeController.cs
index aa9f8639f8a1e57e0671d2b7f4176b95cc0d9664..4c58bd5e3b67a2aeea1bb6ace8d188163136f102 100644
--- a/src/Tree/Controllers/TreeController.cs
+++ b/src/Tree/Controllers/TreeController.cs
@@ -108,7 +108,7 @@ namespace Coscine.Api.Tree.Controllers
{
return BadRequest("User has no Access to this resource.");
}
-
+
try
{
var resourceTypeOptions = _resourceModel.GetResourceTypeOptions(resource.Id);
@@ -117,11 +117,19 @@ namespace Coscine.Api.Tree.Controllers
{
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
+
+ var fileInfos = await resourceTypeDefinition.ListEntries(resourceId, path, resourceTypeOptions);
+
+ var metadataInfos = new List(fileInfos);
+ if (path.EndsWith("/"))
+ {
+ metadataInfos.Insert(0, new ResourceEntry(path, false, 0, null, null, new DateTime(), new DateTime()));
+ }
+
- var infos = await resourceTypeDefinition.ListEntries(resourceId, path, resourceTypeOptions);
var graphs = new List();
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");
}
}
+ ///
+ /// This method retrieves the folder or file name.
+ ///
+ /// Resource Entry
+ /// Name
+ 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;
+ }
+
///
/// This method stores the metadata of the file
///
@@ -390,7 +422,7 @@ namespace Coscine.Api.Tree.Controllers
ApplicationsProfile = _resourceModel.CreateReturnObjectFromDatabaseObject(_resourceModel.GetById(resourceId)).ApplicationProfile,
MetadataCompleteness = metadataCompletness,
};
-
+
_coscineLogger.AnalyticsLog(analyticsLogObject);
}