-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Re-factor. GetFile query was excessively complex so split up part into separate query. Also updated FileEntity to use Actor entity consistenly. * Added application code for deleting file * Added Hangfire support * Added deletion after everyone has confirmed download * Added code to add service owner to database * Added corresponding field to File * Add logic to trigger Hangfire jobs for deleting file on all confirmed downloaded and file initialized * Removed unused return value * Formatting * Consolidated naming * Formatting * Fix test data * Known issue in Serilog: serilog/serilog-aspnetcore#289 and we get around it by not using BootstrapLogger. We do not need it anyway * Try with joining the repeatable migration sripts together. Seems one fails to run if it is dependent on the other one when in a brand new environment. Should find better way to split up in more test scripts if we get big script. * Hangfire in memory during tests to avoid issues with concurrent initialization
- Loading branch information
Showing
35 changed files
with
260 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
INSERT INTO broker.service_owner (service_owner_id_pk, service_owner_name, file_time_to_live) | ||
VALUES ('0192:991825827', 'Digitaliseringsdirektoratet Avd Oslo', '1 Days'); | ||
|
||
INSERT INTO broker.storage_provider (storage_provider_id_pk, service_owner_id_fk, created, storage_provider_type, resource_name) | ||
VALUES (DEFAULT, '0192:991825827', NOW(), 'Altinn3Azure', 'dummy-value'); | ||
|
||
INSERT INTO broker.file (file_id_pk, service_owner_id_fk, filename, checksum, sender_actor_id_fk, external_file_reference, created, storage_provider_id_fk, file_location, expiration_time) | ||
VALUES ('ed76ce89-3768-481a-bca1-4e4262d9098b', '0192:991825827', 'filename.txt', NULL, 1, 'external_reference', NOW(), 1, 'https://blob-storage-example', NOW() + INTERVAL '1 DAY') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Altinn.Broker.Application/DeleteFileCommand/DeleteFileCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Altinn.Broker.Core.Application; | ||
using Altinn.Broker.Core.Repositories; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using OneOf; | ||
|
||
namespace Altinn.Broker.Application.DeleteFileCommand; | ||
public class DeleteFileCommandHandler : IHandler<Guid, Task> | ||
{ | ||
private readonly IFileRepository _fileRepository; | ||
private readonly IFileStatusRepository _fileStatusRepository; | ||
private readonly IServiceOwnerRepository _serviceOwnerRepository; | ||
private readonly IBrokerStorageService _brokerStorageService; | ||
private readonly ILogger<DeleteFileCommandHandler> _logger; | ||
|
||
public DeleteFileCommandHandler(IFileRepository fileRepository, IFileStatusRepository fileStatusRepository, IServiceOwnerRepository serviceOwnerRepository, IBrokerStorageService brokerStorageService, ILogger<DeleteFileCommandHandler> logger) | ||
{ | ||
_fileRepository = fileRepository; | ||
_fileStatusRepository = fileStatusRepository; | ||
_serviceOwnerRepository = serviceOwnerRepository; | ||
_brokerStorageService = brokerStorageService; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<OneOf<Task, Error>> Process(Guid fileId) | ||
{ | ||
_logger.LogInformation("Deleting file with id {fileId}", fileId.ToString()); | ||
var file = await _fileRepository.GetFile(fileId); | ||
if (file is null) | ||
{ | ||
return Errors.FileNotFound; | ||
} | ||
var serviceOwner = await _serviceOwnerRepository.GetServiceOwner(file.ServiceOwnerId); | ||
if (serviceOwner is null) | ||
{ | ||
return Errors.ServiceOwnerNotConfigured; | ||
} | ||
if (file.FileStatus >= Core.Domain.Enums.FileStatus.Deleted) | ||
{ | ||
_logger.LogInformation("File has already been set to deleted"); | ||
} | ||
|
||
await _fileStatusRepository.InsertFileStatus(fileId, Core.Domain.Enums.FileStatus.Deleted); | ||
await _brokerStorageService.DeleteFile(serviceOwner, file); | ||
var recipientsWhoHaveNotDownloaded = file.RecipientCurrentStatuses.Where(latestStatus => latestStatus.Status <= Core.Domain.Enums.ActorFileStatus.DownloadConfirmed).ToList(); | ||
foreach (var recipient in recipientsWhoHaveNotDownloaded) | ||
{ | ||
_logger.LogError("Recipient {recipientExternalReference} did not download the file with id {fileId}", recipient.Actor.ActorExternalId, recipient.FileId.ToString()); | ||
// TODO, send events | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.