#498 import public data
This commit is contained in:
parent
0fb3110dd9
commit
a19c8a3128
@ -2462,7 +2462,7 @@ namespace RMuseum.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = _ganjoorService.StartImportFromPublicDataRepo(request.UseHttp, request.Location);
|
var res = _ganjoorService.StartImportFromPublicDataRepo(request.UseHttp, request.Location, request.PoetId);
|
||||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||||
return BadRequest(res.ExceptionString);
|
return BadRequest(res.ExceptionString);
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|||||||
@ -15,5 +15,11 @@ namespace RMuseum.Models.Ganjoor.PublicExport
|
|||||||
/// base URL (UseHttp=true) or local folder path (UseHttp=false) of the exported data tree
|
/// base URL (UseHttp=true) or local folder path (UseHttp=false) of the exported data tree
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Location { get; set; }
|
public string Location { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 0 imports every poet in the export; a specific poet id imports only that poet — handy
|
||||||
|
/// on a slow connection, or when only one poet's data is needed for local testing
|
||||||
|
/// </summary>
|
||||||
|
public int PoetId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -647,8 +647,9 @@ namespace RMuseum.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="useHttp">true: fetch over HTTP (location is a base URL). false: read from a local folder (location is a path).</param>
|
/// <param name="useHttp">true: fetch over HTTP (location is a base URL). false: read from a local folder (location is a path).</param>
|
||||||
/// <param name="location">base URL or local folder path of the exported data tree</param>
|
/// <param name="location">base URL or local folder path of the exported data tree</param>
|
||||||
|
/// <param name="poetId">0 imports every poet; a specific id imports only that poet (useful on a slow connection)</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
RServiceResult<bool> StartImportFromPublicDataRepo(bool useHttp, string location);
|
RServiceResult<bool> StartImportFromPublicDataRepo(bool useHttp, string location, int poetId = 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// examine site pages for broken links
|
/// examine site pages for broken links
|
||||||
|
|||||||
@ -40,9 +40,11 @@ namespace RMuseum.Services.Implementation
|
|||||||
/// one that already has some content (merge): every entity is looked up by its id first
|
/// one that already has some content (merge): every entity is looked up by its id first
|
||||||
/// and only inserted if missing, so re-running never duplicates or overwrites anything —
|
/// and only inserted if missing, so re-running never duplicates or overwrites anything —
|
||||||
/// including content a developer may have hand-edited locally after a previous import.
|
/// including content a developer may have hand-edited locally after a previous import.
|
||||||
/// Always imports every poet in the export's manifest; there's no partial/single-poet mode.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RServiceResult<bool> StartImportFromPublicDataRepo(bool useHttp, string location)
|
/// <param name="useHttp">true: fetch over HTTP (location is a base URL). false: read from a local folder (location is a path).</param>
|
||||||
|
/// <param name="location">base URL or local folder path of the exported data tree</param>
|
||||||
|
/// <param name="poetId">0 imports every poet in the export's manifest; a specific id imports only that poet — useful on a slow connection, or when a developer only needs one poet's data for local testing</param>
|
||||||
|
public RServiceResult<bool> StartImportFromPublicDataRepo(bool useHttp, string location, int poetId = 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -70,11 +72,19 @@ namespace RMuseum.Services.Implementation
|
|||||||
|
|
||||||
var manifest = JsonSerializer.Deserialize<PublicExportManifestDto>(manifestJson, _importJsonOptions);
|
var manifest = JsonSerializer.Deserialize<PublicExportManifestDto>(manifestJson, _importJsonOptions);
|
||||||
|
|
||||||
|
var poetsToImport = manifest.Poets;
|
||||||
|
if (poetId != 0)
|
||||||
|
{
|
||||||
|
poetsToImport = manifest.Poets.Where(p => p.Id == poetId).ToList();
|
||||||
|
if (poetsToImport.Count == 0)
|
||||||
|
throw new Exception($"poet id {poetId} was not found in manifest.json");
|
||||||
|
}
|
||||||
|
|
||||||
int poetIndex = 0;
|
int poetIndex = 0;
|
||||||
foreach (var poetEntry in manifest.Poets)
|
foreach (var poetEntry in poetsToImport)
|
||||||
{
|
{
|
||||||
poetIndex++;
|
poetIndex++;
|
||||||
await jobProgressServiceEF.UpdateJob(job.Id, (int)(100.0 * poetIndex / Math.Max(1, manifest.Poets.Count)), $"Importing {poetEntry.Nickname}");
|
await jobProgressServiceEF.UpdateJob(job.Id, (int)(100.0 * poetIndex / Math.Max(1, poetsToImport.Count)), $"Importing {poetEntry.Nickname}");
|
||||||
await ImportPoetFromPublicData(context, source, poetEntry.Id, poetEntry.FullUrl);
|
await ImportPoetFromPublicData(context, source, poetEntry.Id, poetEntry.FullUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user