Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Fix/xxxx-indexOutOfRange
  • Fix/xxxx-minorFixes
  • Fix/xxxx-organization
  • Fix/xxxx-wrap
  • Hotfix/2332-userInstitutesInReporting
  • Hotfix/2388-sensitive
  • Hotfix/3115-userReportingEmpty
  • Hotfix/3115-userReportingEmpty2
  • Hotfix/xxxx-rors
  • Issue/2181-kpiGeneratorBase
  • Issue/2182-kpiGeneratorUser
  • Issue/2183-kpiGeneratorResource
  • Issue/2184-kpiGeneratorProject
  • Issue/2185-kpiGeneratorAP
  • Issue/2186-systemStatusReporting
  • Issue/2283-activityFix
  • Issue/2304-virtuosoRoars
  • Issue/2330-fixNaNQuotainAdmin
  • Issue/2432-publicationKpi
  • Issue/2492-respOrg
  • Issue/2518-docs
  • Issue/2568-betterLogging
  • Issue/2666-adminCronjobs
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2847-reporting
  • Issue/2850-removeGrantId
  • Issue/2982-kpiDataPub
  • Issue/3005-kpiReportingBroken
  • Issue/3073-kpi
  • Issue/3142-kpiGenerator
  • dev
  • gitkeep
  • main
  • v0.1.0
  • v0.1.1
  • v0.1.10
  • v0.1.11
  • v0.1.12
  • v0.1.13
  • v0.1.14
  • v0.1.15
  • v0.1.16
  • v0.1.17
  • v0.1.18
  • v0.1.19
  • v0.1.2
  • v0.1.20
  • v0.1.21
  • v0.1.22
  • v0.1.23
  • v0.1.3
  • v0.1.4
  • v0.1.5
  • v0.1.6
  • v0.1.7
  • v0.1.8
  • v0.1.9
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.0.5
  • v1.0.6
  • v1.0.7
  • v1.0.8
  • v1.0.9
  • v1.1.0
  • v1.1.1
  • v1.2.0
  • v1.2.1
  • v1.2.10
  • v1.2.2
  • v1.2.3
  • v1.2.4
  • v1.2.5
  • v1.2.6
  • v1.2.7
  • v1.2.8
  • v1.2.9
79 results

Target

Select target project
  • coscine/backend/scripts/kpi-generator
1 result
Select Git revision
  • Fix/xxxx-indexOutOfRange
  • Fix/xxxx-minorFixes
  • Fix/xxxx-organization
  • Fix/xxxx-wrap
  • Hotfix/2332-userInstitutesInReporting
  • Hotfix/2388-sensitive
  • Hotfix/3115-userReportingEmpty
  • Hotfix/3115-userReportingEmpty2
  • Hotfix/xxxx-rors
  • Issue/2181-kpiGeneratorBase
  • Issue/2182-kpiGeneratorUser
  • Issue/2183-kpiGeneratorResource
  • Issue/2184-kpiGeneratorProject
  • Issue/2185-kpiGeneratorAP
  • Issue/2186-systemStatusReporting
  • Issue/2283-activityFix
  • Issue/2304-virtuosoRoars
  • Issue/2330-fixNaNQuotainAdmin
  • Issue/2432-publicationKpi
  • Issue/2492-respOrg
  • Issue/2518-docs
  • Issue/2568-betterLogging
  • Issue/2666-adminCronjobs
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2847-reporting
  • Issue/2850-removeGrantId
  • Issue/2982-kpiDataPub
  • Issue/3005-kpiReportingBroken
  • Issue/3073-kpi
  • Issue/3142-kpiGenerator
  • dev
  • gitkeep
  • main
  • v0.1.0
  • v0.1.1
  • v0.1.10
  • v0.1.11
  • v0.1.12
  • v0.1.13
  • v0.1.14
  • v0.1.15
  • v0.1.16
  • v0.1.17
  • v0.1.18
  • v0.1.19
  • v0.1.2
  • v0.1.20
  • v0.1.21
  • v0.1.22
  • v0.1.23
  • v0.1.3
  • v0.1.4
  • v0.1.5
  • v0.1.6
  • v0.1.7
  • v0.1.8
  • v0.1.9
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.0.5
  • v1.0.6
  • v1.0.7
  • v1.0.8
  • v1.0.9
  • v1.1.0
  • v1.1.1
  • v1.2.0
  • v1.2.1
  • v1.2.10
  • v1.2.2
  • v1.2.3
  • v1.2.4
  • v1.2.5
  • v1.2.6
  • v1.2.7
  • v1.2.8
  • v1.2.9
79 results
Show changes
Commits on Source (3)
......@@ -25,8 +25,8 @@ public class ProjectReportingTests
private IOptionsMonitor<KpiConfiguration> _kpiConfiguration = null!;
private IOptionsMonitor<ReportingConfiguration> _reportingConfiguration = null!;
private IAdminApi _adminApi = null!;
private IProjectQuotaApi _projectQuotaApi = null!;
private IProjectCacheService _projectCacheService = null!;
private ProjectReporting _projectReporting = null!; // System Under Test
[SetUp]
......@@ -69,7 +69,8 @@ public class ProjectReportingTests
_reportingConfiguration = Substitute.For<IOptionsMonitor<ReportingConfiguration>>();
_reportingConfiguration.CurrentValue.Returns(reportingConfig);
_adminApi = Substitute.For<IAdminApi>();
_projectCacheService = Substitute.For<IProjectCacheService>();
_projectQuotaApi = Substitute.For<IProjectQuotaApi>();
}
#region GenerateReportingAsync Tests
......@@ -80,21 +81,10 @@ public class ProjectReportingTests
// Arrange
var projects = TestData.ProjectAdminDtos;
_adminApi
.GetAllProjectsAsync(
includeDeleted: Arg.Any<bool>(),
includeQuotas: Arg.Any<bool>(),
includePublicationRequests: Arg.Any<bool>(),
pageNumber: Arg.Any<int>(),
pageSize: Arg.Any<int>()
)
.Returns(ci =>
{
// Return the test projects data, single page
var pagination = new Pagination(currentPage: 1, pageSize: 2, totalCount: 2, totalPages: 1);
return Task.FromResult(new ProjectAdminDtoPagedResponse(data: projects, pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_projectReporting = new ProjectReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_projectCacheService
.GetAllProjectsAsync()
.Returns(ci => Task.FromResult(projects));
_projectReporting = new ProjectReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _projectCacheService, _projectQuotaApi);
// Act
var result = await _projectReporting.GenerateReportingAsync();
......@@ -118,15 +108,10 @@ public class ProjectReportingTests
public async Task GenerateReportingAsync_ReturnsOnlyGeneralFile_WhenNoProjects()
{
// Arrange
_adminApi
_projectCacheService
.GetAllProjectsAsync()
.Returns(ci =>
{
// No projects, empty data
var pagination = new Pagination(currentPage: 1, pageSize: 0, totalCount: 0, totalPages: 1);
return Task.FromResult(new ProjectAdminDtoPagedResponse(data: [], pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_projectReporting = new ProjectReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
.Returns(ci => Task.FromResult(new List<ProjectAdminDto>()));
_projectReporting = new ProjectReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _projectCacheService, _projectQuotaApi);
// Act
var result = await _projectReporting.GenerateReportingAsync();
......@@ -153,7 +138,7 @@ public class ProjectReportingTests
};
// We want to ensure that GenerateReportingAsync returns some test objects
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _projectCacheService, _projectQuotaApi);
_projectReporting
.Configure()
.GenerateReportingAsync()
......@@ -193,7 +178,7 @@ public class ProjectReportingTests
};
// Partial mock to override GenerateReportingAsync
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _projectCacheService, _projectQuotaApi);
_projectReporting
.Configure()
.GenerateReportingAsync()
......@@ -233,7 +218,7 @@ public class ProjectReportingTests
};
// Partial mock to override GenerateReportingAsync
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _projectCacheService, _projectQuotaApi);
_projectReporting
.Configure()
.GenerateReportingAsync()
......@@ -270,7 +255,7 @@ public class ProjectReportingTests
};
// Partial mock
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_projectReporting = Substitute.ForPartsOf<ProjectReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _projectCacheService, _projectQuotaApi);
_projectReporting
.Configure()
.GenerateReportingAsync()
......
......@@ -26,7 +26,7 @@ public class ResourceReportingTests
private IOptionsMonitor<ReportingConfiguration> _reportingConfiguration = null!;
private IAdminApi _adminApi = null!;
private IProjectCacheService _projectCacheService = null!;
private ResourceReporting _resourceReporting = null!; // System Under Test
[SetUp]
......@@ -70,6 +70,7 @@ public class ResourceReportingTests
_reportingConfiguration.CurrentValue.Returns(reportingConfig);
_adminApi = Substitute.For<IAdminApi>();
_projectCacheService = Substitute.For<IProjectCacheService>();
}
#region GenerateReportingAsync Tests
......@@ -81,18 +82,9 @@ public class ResourceReportingTests
var projects = TestData.ProjectAdminDtos;
var resources = TestData.ResourceAdminDtos;
_adminApi
.GetAllProjectsAsync(
includeDeleted: Arg.Any<bool>(),
pageNumber: Arg.Any<int>(),
pageSize: Arg.Any<int>()
)
.Returns(ci =>
{
// Return the test projects data, single page
var pagination = new Pagination(currentPage: 1, pageSize: 2, totalCount: 2, totalPages: 1);
return Task.FromResult(new ProjectAdminDtoPagedResponse(data: projects, pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_projectCacheService
.GetAllProjectsAsync()
.Returns(ci => Task.FromResult(projects));
_adminApi
.GetAllResourcesAsync(
includeDeleted: Arg.Any<bool>(),
......@@ -106,7 +98,7 @@ public class ResourceReportingTests
var pagination = new Pagination(currentPage: 1, pageSize: 2, totalCount: 2, totalPages: 1);
return Task.FromResult(new ResourceAdminDtoPagedResponse(data: resources, pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_resourceReporting = new ResourceReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_resourceReporting = new ResourceReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _projectCacheService);
// Act
var result = await _resourceReporting.GenerateReportingAsync();
......@@ -130,14 +122,9 @@ public class ResourceReportingTests
public async Task GenerateReportingAsync_ReturnsOnlyGeneralFile_WhenNoProjects()
{
// Arrange
_adminApi
_projectCacheService
.GetAllProjectsAsync()
.Returns(ci =>
{
// No projects, empty data
var pagination = new Pagination(currentPage: 1, pageSize: 0, totalCount: 0, totalPages: 1);
return Task.FromResult(new ProjectAdminDtoPagedResponse(data: [], pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
.Returns(ci => Task.FromResult(new List<ProjectAdminDto>()));
_adminApi
.GetAllResourcesAsync()
.Returns(ci =>
......@@ -146,7 +133,7 @@ public class ResourceReportingTests
var pagination = new Pagination(currentPage: 1, pageSize: 0, totalCount: 0, totalPages: 1);
return Task.FromResult(new ResourceAdminDtoPagedResponse(data: [], pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_resourceReporting = new ResourceReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_resourceReporting = new ResourceReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _projectCacheService);
// Act
var result = await _resourceReporting.GenerateReportingAsync();
......@@ -173,7 +160,7 @@ public class ResourceReportingTests
};
// We want to ensure that GenerateReportingAsync returns some test objects
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _projectCacheService);
_resourceReporting
.Configure()
.GenerateReportingAsync()
......@@ -213,7 +200,7 @@ public class ResourceReportingTests
};
// Partial mock to override GenerateReportingAsync
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _projectCacheService);
_resourceReporting
.Configure()
.GenerateReportingAsync()
......@@ -253,7 +240,7 @@ public class ResourceReportingTests
};
// Partial mock to override GenerateReportingAsync
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _projectCacheService);
_resourceReporting
.Configure()
.GenerateReportingAsync()
......@@ -290,7 +277,7 @@ public class ResourceReportingTests
};
// Partial mock
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi);
_resourceReporting = Substitute.ForPartsOf<ResourceReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _projectCacheService);
_resourceReporting
.Configure()
.GenerateReportingAsync()
......
......@@ -27,7 +27,7 @@ public class UserReportingTests
private IAdminApi _adminApi = null!;
private IRoleApi _roleApi = null!;
private IProjectCacheService _projectCacheService = null!;
private UserReporting _userReporting = null!; // System Under Test
[SetUp]
......@@ -72,6 +72,7 @@ public class UserReportingTests
_adminApi = Substitute.For<IAdminApi>();
_roleApi = Substitute.For<IRoleApi>();
_projectCacheService = Substitute.For<IProjectCacheService>();
}
#region GenerateReportingAsync Tests
......@@ -84,18 +85,9 @@ public class UserReportingTests
var users = TestData.UserDtos;
var roles = TestData.RoleDtos;
_adminApi
.GetAllProjectsAsync(
includeDeleted: Arg.Any<bool>(),
pageNumber: Arg.Any<int>(),
pageSize: Arg.Any<int>()
)
.Returns(ci =>
{
// Return the test projects data, single page
var pagination = new Pagination(currentPage: 1, pageSize: 2, totalCount: 2, totalPages: 1);
return Task.FromResult(new ProjectAdminDtoPagedResponse(data: projects, pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_projectCacheService
.GetAllProjectsAsync()
.Returns(ci => Task.FromResult(projects));
_adminApi
.GetAllUsersAsync(
tosAccepted: Arg.Any<bool>(),
......@@ -119,7 +111,7 @@ public class UserReportingTests
var pagination = new Pagination(currentPage: 1, pageSize: 2, totalCount: 2, totalPages: 1);
return Task.FromResult(new RoleDtoPagedResponse(data: roles, pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_userReporting = new UserReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi);
_userReporting = new UserReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi, _projectCacheService);
// Act
var result = await _userReporting.GenerateReportingAsync();
......@@ -143,14 +135,9 @@ public class UserReportingTests
public async Task GenerateReportingAsync_ReturnsOnlyGeneralFile_WhenNoProjects()
{
// Arrange
_adminApi
_projectCacheService
.GetAllProjectsAsync()
.Returns(ci =>
{
// No projects, empty data
var pagination = new Pagination(currentPage: 1, pageSize: 0, totalCount: 0, totalPages: 1);
return Task.FromResult(new ProjectAdminDtoPagedResponse(data: [], pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
.Returns(ci => Task.FromResult(new List<ProjectAdminDto>()));
_adminApi
.GetAllUsersAsync()
.Returns(ci =>
......@@ -167,7 +154,7 @@ public class UserReportingTests
var pagination = new Pagination(currentPage: 1, pageSize: 0, totalCount: 0, totalPages: 1);
return Task.FromResult(new RoleDtoPagedResponse(data: [], pagination: pagination, statusCode: 200, traceId: "dummy-trace-id"));
});
_userReporting = new UserReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi);
_userReporting = new UserReporting(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi, _projectCacheService);
// Act
var result = await _userReporting.GenerateReportingAsync();
......@@ -194,7 +181,7 @@ public class UserReportingTests
};
// We want to ensure that GenerateReportingAsync returns some test objects
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi);
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi, _projectCacheService);
_userReporting
.Configure()
.GenerateReportingAsync()
......@@ -234,7 +221,7 @@ public class UserReportingTests
};
// Partial mock to override GenerateReportingAsync
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi);
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi, _projectCacheService);
_userReporting
.Configure()
.GenerateReportingAsync()
......@@ -274,7 +261,7 @@ public class UserReportingTests
};
// Partial mock to override GenerateReportingAsync
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi);
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi, _projectCacheService);
_userReporting
.Configure()
.GenerateReportingAsync()
......@@ -311,7 +298,7 @@ public class UserReportingTests
};
// Partial mock
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi);
_userReporting = Substitute.ForPartsOf<UserReporting>(_mapper, _logger, _gitlabStorageService, _localStorageService, _kpiConfiguration, _reportingConfiguration, _adminApi, _roleApi, _projectCacheService);
_userReporting
.Configure()
.GenerateReportingAsync()
......
......@@ -7,7 +7,7 @@
<AssemblyName>Coscine.KpiGenerator</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.2.9</Version>
<Version>1.2.10</Version>
</PropertyGroup>
<PropertyGroup>
......@@ -21,7 +21,7 @@
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Coscine.ApiClient" Version="1.9.9" />
<PackageReference Include="Coscine.ApiClient" Version="1.10.0" />
<PackageReference Include="dotNetRdf.Core" Version="3.1.1" />
<PackageReference Include="GitLabApiClient" Version="1.8.1-beta.5" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
......
......@@ -176,10 +176,11 @@ public class Program
BasePath = $"{reportingConfiguration.Endpoint.TrimEnd('/')}/coscine",
ApiKeyPrefix = { { "Authorization", "Bearer" } },
ApiKey = { { "Authorization", reportingConfiguration.ApiKey } },
Timeout = TimeSpan.FromSeconds(300) // 5 minutes
Timeout = TimeSpan.FromSeconds(300), // 5 minutes
};
services.AddSingleton<IAdminApi>(new AdminApi(apiConfiguration));
services.AddSingleton<IApplicationProfileApi>(new ApplicationProfileApi(apiConfiguration));
services.AddSingleton<IProjectCacheService, ProjectCacheService>();
services.AddSingleton<IProjectApi>(new ProjectApi(apiConfiguration));
services.AddSingleton<IProjectQuotaApi>(new ProjectQuotaApi(apiConfiguration));
services.AddSingleton<IProjectResourceQuotaApi>(new ProjectResourceQuotaApi(apiConfiguration));
......
......@@ -21,7 +21,8 @@ public class ProjectReporting
private readonly IStorageService _localStorageService;
private readonly KpiConfiguration _kpiConfiguration;
private readonly ReportingConfiguration _reportingConfiguration;
private readonly IAdminApi _adminApi;
private readonly IProjectCacheService _projectCacheService;
private readonly IProjectQuotaApi _projectQuotaApi;
public ProjectReportingOptions Options { get; private set; } = null!;
public string ReportingFileName { get; }
......@@ -33,7 +34,8 @@ public class ProjectReporting
[FromKeyedServices("local")] IStorageService localStorageService,
IOptionsMonitor<KpiConfiguration> kpiConfiguration,
IOptionsMonitor<ReportingConfiguration> reportingConfiguration,
IAdminApi adminApi
IProjectCacheService projectCacheService,
IProjectQuotaApi projectQuotaApi
)
{
_mapper = mapper;
......@@ -44,7 +46,8 @@ public class ProjectReporting
_reportingConfiguration = reportingConfiguration.CurrentValue;
ReportingFileName = _kpiConfiguration.ProjectKpi.FileName;
_adminApi = adminApi;
_projectCacheService = projectCacheService;
_projectQuotaApi = projectQuotaApi;
}
public async Task<bool> RunAsync(ProjectReportingOptions reportingOptions)
......@@ -81,16 +84,36 @@ public class ProjectReporting
public virtual async Task<IEnumerable<ReportingFileObject>> GenerateReportingAsync()
{
_logger.LogDebug("Working on projects asynchronously...");
var projects = PaginationHelper.GetAllAsync<ProjectAdminDtoPagedResponse, ProjectAdminDto>(
(currentPage) => _adminApi.GetAllProjectsAsync(includeDeleted: false, includeQuotas: true, includePublicationRequests: true, pageNumber: currentPage, pageSize: 50));
var projects = await _projectCacheService.GetAllProjectsAsync();
_logger.LogInformation("Found {count} projects.", projects.Count);
// Filter out projects that are deleted
projects = [.. projects.Where(p => !p.Deleted)];
_logger.LogInformation("Filtered out deleted projects. Remaining projects: {count}", projects.Count);
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = new List<ProjectReport>();
// Additional processing
await foreach (var project in projects)
foreach (var project in projects)
{
_logger.LogDebug("Processing project {projectId}...", project.Id);
var quotas = PaginationHelper.GetAllAsync<ProjectQuotaDtoPagedResponse, ProjectQuotaDto>(
(currentPage) =>
{
_logger.LogDebug("Getting page {page} of quotas for project {projectId}...", currentPage, project.Id);
return _projectQuotaApi.GetProjectQuotasAsync(project.Id.ToString(), pageNumber: currentPage, pageSize: 50);
});
await foreach (var quota in quotas)
{
if (quota == null)
{
_logger.LogWarning("Quota for project {projectId} is null, skipping...", project.Id);
continue;
}
// Map the quota to the project
project.ProjectQuota.Add(quota);
}
var returnObject = _mapper.Map<ProjectReport>(project);
returnObjects.Add(returnObject);
}
......
......@@ -23,6 +23,7 @@ public class ResourceReporting
private readonly KpiConfiguration _kpiConfiguration;
private readonly ReportingConfiguration _reportingConfiguration;
private readonly IAdminApi _adminApi;
private readonly IProjectCacheService _projectCacheService;
public ResourceReportingOptions Options { get; private set; } = null!;
public string ReportingFileName { get; }
......@@ -34,7 +35,8 @@ public class ResourceReporting
[FromKeyedServices("local")] IStorageService localStorageService,
IOptionsMonitor<KpiConfiguration> kpiConfiguration,
IOptionsMonitor<ReportingConfiguration> reportingConfiguration,
IAdminApi adminApi
IAdminApi adminApi,
IProjectCacheService projectCacheService
)
{
_mapper = mapper;
......@@ -44,16 +46,8 @@ public class ResourceReporting
_kpiConfiguration = kpiConfiguration.CurrentValue;
_reportingConfiguration = reportingConfiguration.CurrentValue;
ReportingFileName = _kpiConfiguration.ResourceKpi.FileName;
var configuration = new Configuration()
{
BasePath = $"{_reportingConfiguration.Endpoint.TrimEnd('/')}/coscine",
ApiKeyPrefix = { { "Authorization", "Bearer" } },
ApiKey = { { "Authorization", _reportingConfiguration.ApiKey } },
Timeout = TimeSpan.FromSeconds(300) // 5 minutes
};
_adminApi = adminApi;
_projectCacheService = projectCacheService;
}
public async Task<bool> RunAsync(ResourceReportingOptions reportingOptions)
......@@ -89,13 +83,16 @@ public class ResourceReporting
public virtual async Task<IEnumerable<ReportingFileObject>> GenerateReportingAsync()
{
_logger.LogDebug("Getting all projects...");
var projects = await PaginationHelper.GetAllAsync<ProjectAdminDtoPagedResponse, ProjectAdminDto>(
(currentPage) => _adminApi.GetAllProjectsAsync(includeDeleted: true, pageNumber: currentPage, pageSize: 50)).ToListAsync();
_logger.LogDebug("Got all projects.");
var projects = await _projectCacheService.GetAllProjectsAsync();
_logger.LogDebug("Got all {count} projects, including deleted ones.", projects.Count);
_logger.LogDebug("Working on resources asynchronously...");
var resources = PaginationHelper.GetAllAsync<ResourceAdminDtoPagedResponse, ResourceAdminDto>(
(currentPage) => _adminApi.GetAllResourcesAsync(includeDeleted: false, includeQuotas: true, pageNumber: currentPage, pageSize: 50));
(currentPage) =>
{
_logger.LogDebug("Getting page {page} of resources...", currentPage);
return _adminApi.GetAllResourcesAsync(includeDeleted: false, includeQuotas: true, pageNumber: currentPage, pageSize: 10);
});
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = new List<ResourceReport>();
......
......@@ -23,6 +23,7 @@ public class UserReporting
private readonly ReportingConfiguration _reportingConfiguration;
private readonly IAdminApi _adminApi;
private readonly IRoleApi _roleApi;
private readonly IProjectCacheService _projectCacheService;
public UserReportingOptions Options { get; private set; } = null!;
public string ReportingFileName { get; }
......@@ -35,7 +36,8 @@ public class UserReporting
IOptionsMonitor<KpiConfiguration> kpiConfiguration,
IOptionsMonitor<ReportingConfiguration> reportingConfiguration,
IAdminApi adminApi,
IRoleApi roleApi
IRoleApi roleApi,
IProjectCacheService projectCacheService
)
{
_mapper = mapper;
......@@ -48,6 +50,7 @@ public class UserReporting
_adminApi = adminApi;
_roleApi = roleApi;
_projectCacheService = projectCacheService;
}
public async Task<bool> RunAsync(UserReportingOptions reportingOptions)
......@@ -83,9 +86,10 @@ public class UserReporting
public virtual async Task<IEnumerable<ReportingFileObject>> GenerateReportingAsync()
{
_logger.LogDebug("Getting all projects...");
var projects = await PaginationHelper.GetAllAsync<ProjectAdminDtoPagedResponse, ProjectAdminDto>(
(currentPage) => _adminApi.GetAllProjectsAsync(includeDeleted: false, pageNumber: currentPage, pageSize: 50)).ToListAsync();
_logger.LogDebug("Got all projects.");
var projects = await _projectCacheService.GetAllProjectsAsync();
// Filter out projects that are deleted
projects = [.. projects.Where(p => !p.Deleted)];
_logger.LogInformation("Filtered out deleted projects. Remaining projects: {count}", projects.Count);
_logger.LogDebug("Getting all roles...");
var roles = await PaginationHelper.GetAllAsync<RoleDtoPagedResponse, RoleDto>(
......@@ -94,7 +98,11 @@ public class UserReporting
_logger.LogDebug("Working on users asynchronously...");
var users = PaginationHelper.GetAllAsync<UserDtoPagedResponse, UserDto>(
(currentPage) => _adminApi.GetAllUsersAsync(tosAccepted: true, pageNumber: currentPage, pageSize: 50));
(currentPage) =>
{
_logger.LogDebug("Getting page {page} of users...", currentPage);
return _adminApi.GetAllUsersAsync(tosAccepted: true, pageNumber: currentPage, pageSize: 10);
});
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = new List<UserReport>();
......
using Coscine.ApiClient;
using Coscine.ApiClient.Core.Api;
using Coscine.ApiClient.Core.Model;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
namespace Coscine.KpiGenerator.Utils;
public interface IProjectCacheService
{
Task<List<ProjectAdminDto>> GetAllProjectsAsync();
}
public class ProjectCacheService(IAdminApi adminApi, IMemoryCache cache, ILogger<ProjectCacheService> logger) : IProjectCacheService
{
private const string CacheKey = "AllProjects";
private readonly IAdminApi _adminApi = adminApi;
private readonly IMemoryCache _cache = cache;
private readonly ILogger<ProjectCacheService> _logger = logger;
public async Task<List<ProjectAdminDto>> GetAllProjectsAsync()
{
return await _cache.GetOrCreateAsync(CacheKey, async entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(120);
_logger.LogDebug("Fetching all projects from API");
var list = await PaginationHelper
.GetAllAsync<ProjectAdminDtoPagedResponse, ProjectAdminDto>(
page => _adminApi.GetAllProjectsAsync(includeDeleted: true, includePublicationRequests: true, pageNumber: page, pageSize: 50))
.ToListAsync();
_logger.LogDebug("Cached {Count} projects", list.Count);
return list;
}) ?? [];
}
}