-
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.
- Loading branch information
Showing
14 changed files
with
366 additions
and
89 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
50 changes: 50 additions & 0 deletions
50
LeedsExperiment/Dashboard/Views/ImportExport/ExportResult.cshtml
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,50 @@ | ||
@using Dashboard.Borrowed | ||
@using Dashboard.Helpers | ||
@using Utils | ||
@model Preservation.ExportResult | ||
|
||
<div> | ||
<h1 class="display-4">Export Result 📦</h1> | ||
|
||
@if (!string.IsNullOrEmpty(Model.Problem)) | ||
{ | ||
<div class="alert alert-danger" role="alert"> | ||
@Model.Problem | ||
</div> | ||
} else | ||
{ | ||
<table class="table"> | ||
<tbody> | ||
<tr> | ||
<th scope="row">Archival Group</th> | ||
<td><a href="/ocfl/@Model.ArchivalGroupPath">@Model.ArchivalGroupPath</a></td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Destination (@Model.StorageType)</th> | ||
<td><a href="@S3Util.GetAwsConsoleUri(Model.Destination)">@Model.Destination</a></td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Version</th> | ||
<td>@Model.Version</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Time taken</th> | ||
<td>@((Model.End - Model.Start).TotalMilliseconds) ms</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Files</th> | ||
<td> | ||
<ul class="list-unstyled"> | ||
@foreach(var file in Model.Files) | ||
{ | ||
<li><a href="@S3Util.GetAwsConsoleUri(file)">@file.RemoveStart($"{Model.Destination}/")</a></li> | ||
} | ||
</ul> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
} | ||
|
||
</div> | ||
|
61 changes: 61 additions & 0 deletions
61
LeedsExperiment/Dashboard/Views/ImportExport/ExportStart.cshtml
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,61 @@ | ||
@using Dashboard.Helpers | ||
@using Utils | ||
@model Fedora.Abstractions.ArchivalGroup | ||
|
||
<div> | ||
<h1 class="display-4">Export 📦 - @Model.GetDisplayName()</h1> | ||
<p> | ||
Version: <strong>@Model.Version!.OcflVersion</strong> - | ||
@if (Model.Version.Equals(Model.StorageMap!.HeadVersion)) | ||
{ | ||
<em>This is the current (head) version.</em> | ||
} | ||
else | ||
{ | ||
<em>This is a <strong>previous</strong> version.</em> | ||
} | ||
</p> | ||
<p><a href="/ocfl/@ViewBag.Path">View storage (OCFL)</a></p> | ||
|
||
<hr/> | ||
|
||
<p>The following files will be exported to a location in a staging bucket for you to pick up.</p> | ||
|
||
|
||
<div class="alert alert-secondary" role="alert"> | ||
<small class="text-muted">(Later you will have more control about where you can have the Preservation API export content to)</small> | ||
</div> | ||
|
||
<form method="post" action="/export/@(ViewBag.Path)?version=@Model.Version.OcflVersion"> | ||
<div class="row g-3 align-items-center"> | ||
<div class="col-auto"> | ||
<input class="btn btn-primary form-control" type="submit" value="Export"> | ||
</div> | ||
<div class="col-auto"> | ||
<span class="form-text"> | ||
Click here to export the following files: | ||
</span> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>File path</th> | ||
<th>Hash</th> | ||
<th>Versioned path</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var fileEntry in Model.StorageMap.Files.OrderBy(kvp => kvp.Key)) | ||
{ | ||
<tr> | ||
<td>@fileEntry.Key</td> | ||
<td><span title="@fileEntry.Value.Hash">@fileEntry.Value.Hash.Substring(0, 8)</span></td> | ||
<td>@fileEntry.Value.FullPath</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> |
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
31 changes: 1 addition & 30 deletions
31
LeedsExperiment/Fedora/Abstractions/Transfer/ContainerDirectory.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 |
---|---|---|
@@ -1,34 +1,5 @@ | ||
namespace Fedora.Abstractions.Transfer; | ||
|
||
public class ContainerDirectory | ||
public class ContainerDirectory : ResourceWithParentUri | ||
{ | ||
/// <summary> | ||
/// The repository path (not a full Uri), will end with Slug | ||
/// Only contains permitted characters (e.g., no spaces) | ||
/// | ||
/// This is not required if you supply Slug and a parent | ||
/// </summary> | ||
public string? Path { get; set; } | ||
|
||
private string? slug; | ||
public string? Slug | ||
{ | ||
get | ||
{ | ||
if (string.IsNullOrEmpty(Path)) | ||
{ | ||
return slug; | ||
} | ||
return Path.Split('/')[^1]; | ||
} | ||
set | ||
{ | ||
slug = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The name of the resource in Fedora (dc:title) | ||
/// </summary> | ||
public required string Name { get; set; } | ||
} |
29 changes: 29 additions & 0 deletions
29
LeedsExperiment/Fedora/Abstractions/Transfer/ResourceWithParentUri.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,29 @@ | ||
namespace Fedora.Abstractions.Transfer; | ||
|
||
public abstract class ResourceWithParentUri | ||
{ | ||
/// <summary> | ||
/// The repository path (not a full Uri), will end with Slug | ||
/// Only contains permitted characters (e.g., no spaces) | ||
/// | ||
/// The Path is relative to some container or parent, which may not be the immediate parent. | ||
/// It will often be relative to the ArchivalGroup parent. | ||
/// </summary> | ||
public required string Path { get; set; } | ||
|
||
/// <summary> | ||
/// The Fedora repository Uri that is the parent of Path - i.e., where this file is to be put (or where it came from) | ||
/// </summary> | ||
public required Uri Parent { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the resource in Fedora (dc:title) | ||
/// Usually the original name of the directory or file, which will usually be the same as Slug if all characters are path safe | ||
/// </summary> | ||
public required string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Only contains permitted characters (e.g., no spaces) | ||
/// </summary> | ||
public string Slug => Path.Split('/')[^1]; | ||
} |
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
63 changes: 63 additions & 0 deletions
63
LeedsExperiment/Preservation.API/Controllers/ExportController.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,63 @@ | ||
using Amazon.S3; | ||
using Fedora; | ||
using Fedora.Storage; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Preservation.API.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ExportController : Controller | ||
{ | ||
private readonly IStorageMapper storageMapper; | ||
private readonly IFedora fedora; | ||
private readonly PreservationApiOptions options; | ||
private IAmazonS3 s3Client; | ||
|
||
public ExportController( | ||
IStorageMapper storageMapper, | ||
IFedora fedora, | ||
IOptions<PreservationApiOptions> options, | ||
IAmazonS3 awsS3Client | ||
) | ||
{ | ||
this.storageMapper = storageMapper; | ||
this.fedora = fedora; | ||
this.options = options.Value; | ||
this.s3Client = awsS3Client; | ||
} | ||
|
||
[HttpGet(Name = "Export")] | ||
[Route("{*path}")] | ||
public async Task<ExportResult?> Index([FromRoute] string path, [FromQuery] string? version) | ||
{ | ||
var agUri = fedora.GetUri(path); | ||
var exportKey = $"exports/{path}/{DateTime.Now:yyyy-MM-dd-HH-mm-ss}"; | ||
var storageMap = await storageMapper.GetStorageMap(agUri, version); | ||
var result = new ExportResult | ||
{ | ||
ArchivalGroupPath = path, | ||
Destination = $"s3://{options.StagingBucket}/{exportKey}", | ||
StorageType = StorageTypes.S3, | ||
Version = storageMap.Version, | ||
Start = DateTime.Now | ||
}; | ||
try | ||
{ | ||
foreach (var file in storageMap.Files) | ||
{ | ||
var sourceKey = $"{storageMap.ObjectPath}/{file.Value.FullPath}"; | ||
var destKey = $"{exportKey}/{file.Key}"; | ||
var resp = await s3Client.CopyObjectAsync(storageMap.Root, sourceKey, options.StagingBucket, destKey); | ||
result.Files.Add($"s3://{options.StagingBucket}/{destKey}"); | ||
} | ||
result.End = DateTime.Now; | ||
} | ||
catch(Exception ex) | ||
{ | ||
result.Problem = ex.Message; | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.