Skip to content

Commit

Permalink
Tidy up API model
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrane committed Jan 9, 2024
1 parent 67f5e6d commit a45cd03
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 86 deletions.
4 changes: 0 additions & 4 deletions LeedsExperiment/Fedora/ArchivalGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ public ArchivalGroup(FedoraJsonLdResponse fedoraResponse) : base(fedoraResponse)
Type = "ArchivalGroup";
}

[JsonPropertyName("type")]
[JsonPropertyOrder(1)]
public string Type { get; } = "ArchivalGroup";

[JsonPropertyName("version")]
[JsonPropertyOrder(2)]
public ObjectVersion? Version { get; set; }
Expand Down
18 changes: 17 additions & 1 deletion LeedsExperiment/Fedora/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ public class Container : Resource
{
public Container(FedoraJsonLdResponse jsonLdResponse) : base(jsonLdResponse)
{
Type = "Container";
if(jsonLdResponse.Type == null || jsonLdResponse.Type.Length == 0)
{
throw new InvalidOperationException("No type present");
}
if(jsonLdResponse.Type.Contains("fedora:RepositoryRoot"))
{
Type = "RepositoryRoot";
}
else if(jsonLdResponse.Type.Contains("http://purl.org/dc/dcmitype/Collection"))
{
// TODO - introduce this dcmi namespace and also check for dcmi:Collection (or whatever prefix)
Type = "ArchivalGroup";
}
else
{
Type = "Container";
}
}

[JsonPropertyName("containers")]
Expand Down
4 changes: 3 additions & 1 deletion LeedsExperiment/Fedora/IFedora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Fedora
{
public interface IFedora
{
Uri GetUri(string path);

Task<string> Proxy(string contentType, string path, string? jsonLdMode = null, bool preferContained = false, string? acceptDate = null, bool head = false);

Task<Resource?> GetObject(Uri uri, Transaction? transaction = null);
Expand Down Expand Up @@ -41,6 +43,6 @@ public interface IFedora
Task RollbackTransaction(Transaction tx);

Task Delete(Uri uri, Transaction? transaction = null);

Task<Resource?> GetRepositoryRoot(Transaction? transaction = null);
}
}
3 changes: 3 additions & 0 deletions LeedsExperiment/Fedora/IStorageMapper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Fedora.Storage;
using Fedora.Storage.Ocfl;

namespace Fedora;

public interface IStorageMapper
{
Task<StorageMap> GetStorageMap(Uri archivalGroupUri, string? version = null);

Task<Inventory?> GetInventory(Uri archivalGroupUri);

string? GetArchivalGroupOrigin(Uri archivalGroupUri);
}
7 changes: 6 additions & 1 deletion LeedsExperiment/Fedora/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public Resource(FedoraJsonLdResponse jsonLdResponse)
LastModifiedBy = jsonLdResponse.LastModifiedBy;
}

[JsonPropertyName("@id")]
[JsonPropertyOrder(1)]
// The URI for this API
public Uri? PreservationApiUri { get; set; }

[JsonPropertyName("type")]
[JsonPropertyOrder(1)]
public string? Type { get; set; }
Expand All @@ -32,7 +37,7 @@ public Resource(FedoraJsonLdResponse jsonLdResponse)
[JsonPropertyName("id")]
[JsonPropertyOrder(12)]
// The Fedora identifier
public required Uri Location { get; set; }
public Uri Location { get; set; }

[JsonPropertyName("created")]
[JsonPropertyOrder(13)]
Expand Down
30 changes: 30 additions & 0 deletions LeedsExperiment/Preservation.API/Controllers/OcflController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Fedora;
using Fedora.Storage.Ocfl;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Preservation.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class OcflController : Controller
{
private readonly IStorageMapper storageMapper;
private readonly IFedora fedora;

public OcflController(IStorageMapper storageMapper, IFedora fedora)
{
this.storageMapper = storageMapper;
this.fedora = fedora;
}

[HttpGet(Name = "Inventory")]
[Route("{*path}")]
public async Task<Inventory?> Index(string path)
{
var uri = fedora.GetUri(path);
var inventory = await storageMapper.GetInventory(uri);
return inventory;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ public RepositoryController(IFedora fedora)

[HttpGet(Name = "Browse")]
[Route("{*path}")]
public async Task<Resource?> Index(string path)
public async Task<Resource?> Index(string? path = null)
{
var resource = await fedora.GetObject(path);
Resource? resource = null;
if(path == null)
{
resource = await fedora.GetRepositoryRoot();
}
else
{
resource = await fedora.GetObject(path);
}

return resource;
}
}
Expand Down
1 change: 1 addition & 0 deletions LeedsExperiment/Preservation.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
builder.Services.AddDefaultAWSOptions(fedoraAwsOptions);
builder.Services.AddAWSService<IAmazonS3>();

builder.Services.Configure<PreservationApiOptions>(builder.Configuration.GetSection("Preservation-API"));
builder.Services.Configure<FedoraAwsOptions>(builder.Configuration.GetSection("Fedora-AWS-S3"));
var apiConfig = builder.Configuration.GetSection("Fedora-API");
builder.Services.Configure<FedoraApiOptions>(apiConfig);
Expand Down
Loading

0 comments on commit a45cd03

Please sign in to comment.