Skip to content
Snippets Groups Projects

New: Updated to new resource types

Merged L. Ellenbeck requested to merge Issue/2072-wormResourceType into master
Files
2
@@ -8,7 +8,7 @@ using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Logging;
using Coscine.Metadata;
using Coscine.ResourceLoader;
using Coscine.ResourceTypes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
@@ -25,7 +25,6 @@ namespace Coscine.Api.Admin.Controllers
{
private readonly RdfStoreConnector _rdfStoreConnector = new(Program.Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
private readonly Authenticator _authenticator;
private readonly IConfiguration _configuration;
private readonly string _graphUrl;
private readonly string _memberUrl;
private readonly string _userUrlPrefix;
@@ -46,7 +45,6 @@ namespace Coscine.Api.Admin.Controllers
public AdminController(ILogger<AdminController> logger)
{
_authenticator = new Authenticator(this, Program.Configuration);
_configuration = Program.Configuration;
_graphUrl = "https://ror.org/04xfq0f34/roles";
_memberUrl = "http://www.w3.org/ns/org#member";
_userUrlPrefix = "https://coscine.rwth-aachen.de/u/";
@@ -94,14 +92,18 @@ namespace Coscine.Api.Admin.Controllers
/// <returns>Allocated quota of the given resource type in the project.</returns>
private int CalculateAllocatedForAll(ResourceType resourceType, Guid projectId)
{
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration);
var resources = _resourceModel.GetAllWhere((resource) =>
(from projectResource in resource.ProjectResources
where projectResource.ProjectId == projectId
select projectResource).Any() &&
resource.TypeId == resourceType.Id);
var allocated = resources.Sum(y => resourceTypeDefinition.GetResourceQuotaAvailable(y.Id.ToString(), _resourceModel.GetResourceTypeOptions(y.Id)).Result);
var allocated = resources.Sum(resource => ResourceTypeFactory
.Instance
.GetResourceType(resource)
.GetResourceQuotaAvailable(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id))
.Result);
return (int)allocated;
}
@@ -113,14 +115,18 @@ namespace Coscine.Api.Admin.Controllers
/// <returns>Used quota of the given resource type in the project.</returns>
private int CalculateUsedForAll(ResourceType resourceType, Guid projectId)
{
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration);
var resources = _resourceModel.GetAllWhere((resource) =>
(from projectResource in resource.ProjectResources
where projectResource.ProjectId == projectId
select projectResource).Any() &&
resource.TypeId == resourceType.Id);
var used = Math.Ceiling(resources.Sum(y => resourceTypeDefinition.GetResourceQuotaUsed(y.Id.ToString(), _resourceModel.GetResourceTypeOptions(y.Id)).Result / _oneGb));
var used = Math.Ceiling(resources.Sum(resource => ResourceTypeFactory
.Instance
.GetResourceType(resource)
.GetResourceQuotaUsed(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id))
.Result / _oneGb));
return (int)used;
}
Loading