Skip to content
Snippets Groups Projects

Hotfix/0071 fix resource create

Merged L. Ellenbeck requested to merge Hotfix/0071-fixResourceCreate into master
4 files
+ 21
22
Compare changes
  • Side-by-side
  • Inline
Files
4
using Coscine.WaterbutlerHelper;
using Coscine.WaterbutlerHelper.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Factories;
using Coscine.Configuration;
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Database.Util;
using Coscine.Logging;
using Coscine.Metadata;
using Coscine.ResourceLoader;
using Coscine.ResourceTypeBase;
using Coscine.WaterbutlerHelper;
using Coscine.WaterbutlerHelper.ReturnObjects;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
@@ -20,9 +23,6 @@ using System.Web;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Writing;
using Coscine.ResourceLoader;
using Coscine.Configuration;
using Coscine.ResourceTypeBase;
namespace Coscine.Api.Tree.Controllers
{
@@ -81,7 +81,7 @@ namespace Coscine.Api.Tree.Controllers
/// </summary>
/// <param name="resourceId"> Id of a resource</param>
/// <param name="path">Path to the file</param>
/// <returns> JSON Object with the metadata if ok, otherwise Statuscode 400 or 401 or 404</returns>
/// <returns> JSON Object with the metadata if OK, otherwise status code 400 or 401 or 404</returns>
[HttpGet("[controller]/{resourceId}/{*path}")]
public async Task<IActionResult> GetMetadata(string resourceId, string path = "")
{
@@ -117,8 +117,8 @@ namespace Coscine.Api.Tree.Controllers
{
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
var fileInfos = await resourceTypeDefinition.ListEntries(resourceId, path, resourceTypeOptions);
var fileInfos = await resourceTypeDefinition.ListEntries(null, path, resourceTypeOptions);
var metadataInfos = new List<ResourceEntry>(fileInfos);
if (path.EndsWith("/"))
@@ -126,7 +126,6 @@ namespace Coscine.Api.Tree.Controllers
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 metadataInfos)
@@ -211,7 +210,7 @@ namespace Coscine.Api.Tree.Controllers
{
var lastSlash = x.Key.LastIndexOf("/") + 1;
var name = x.Key[lastSlash..];
if (name == "")
if (name?.Length == 0)
{
var tempPath = x.Key[..(lastSlash - 1)];
if (tempPath.Contains("/"))
@@ -229,7 +228,7 @@ namespace Coscine.Api.Tree.Controllers
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the file</param>
/// <returns>If ok Statuscode 204, otherwise Statuscode 400 or 401</returns>
/// <returns>If OK status code 204, otherwise status code 400 or 401</returns>
[HttpPut("[controller]/{resourceId}/{*path}")]
public IActionResult StoreMetadataForFile(string resourceId, string path)
{
@@ -257,7 +256,7 @@ namespace Coscine.Api.Tree.Controllers
if (resource.Archived == "1")
{
return BadRequest("The resource is readonly!");
return BadRequest("The resource is read only!");
}
if (resource.ApplicationProfile[^1] != '/')
@@ -356,7 +355,6 @@ namespace Coscine.Api.Tree.Controllers
_rdfStoreConnector.AddGraph(graph);
return NoContent();
}
/// <summary>
@@ -365,7 +363,7 @@ namespace Coscine.Api.Tree.Controllers
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the file</param>
/// <param name="resource">Resource</param>
/// <returns>null, otherwise Statuscode 400 or 404 </returns>
/// <returns>null, otherwise status code 400 or 404 </returns>
private IActionResult CheckResourceIdAndPath(string resourceId, string path, out Resource resource)
{
resource = null;
@@ -383,7 +381,7 @@ namespace Coscine.Api.Tree.Controllers
if (!Guid.TryParse(resourceId, out Guid resourceGuid))
{
return BadRequest($"{resourceId} is not a guid.");
return BadRequest($"{resourceId} is not a GUID.");
}
try
@@ -472,4 +470,4 @@ namespace Coscine.Api.Tree.Controllers
return $"{present}/{total}";
}
}
}
}
\ No newline at end of file
Loading