* Working import/export media/document types * WIP * Refactoring of import doctype/media types - added analyze endpoint to extract relevant data without fully processing the file - split up import endpoints into POST & PUT - removed availableAtAction as the new endpoint allows clients to call the POST/PUT endpoints with confidence - Added a new service that is responsible for turning temp files into Import compatible XML and being able to extracty partial information from it * Wrap persistance access in scopes * Typos, formatting, clean-up * PR feedback * update openapi spec * Changed deleteFile flag to _temporaryFileService.EnlistDeleteIfScopeCompletes * Itty bitty typo * Moved magic cleanup into its own method so orchestration can decide when. --------- Co-authored-by: Sven Geusens <sge@umbraco.dk> Co-authored-by: kjac <kja@umbraco.dk>
40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Umbraco.Cms.Api.Management.ViewModels.Import;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Mapping;
|
|
using Umbraco.Cms.Core.Models.ImportExport;
|
|
using Umbraco.Cms.Core.Services.ImportExport;
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Import;
|
|
|
|
[ApiVersion("1.0")]
|
|
public class AnalyzeImportController : ImportControllerBase
|
|
{
|
|
private readonly ITemporaryFileToXmlImportService _temporaryFileToXmlImportService;
|
|
private readonly IUmbracoMapper _mapper;
|
|
|
|
public AnalyzeImportController(
|
|
ITemporaryFileToXmlImportService temporaryFileToXmlImportService,
|
|
IUmbracoMapper mapper)
|
|
{
|
|
_temporaryFileToXmlImportService = temporaryFileToXmlImportService;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
[HttpGet("analyze")]
|
|
[ProducesResponseType(typeof(EntityImportAnalysisResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> Analyze(CancellationToken cancellationToken, Guid temporaryFileId)
|
|
{
|
|
Attempt<EntityXmlAnalysis?, TemporaryFileXmlImportOperationStatus> analyzeResult = await _temporaryFileToXmlImportService.AnalyzeAsync(temporaryFileId);
|
|
|
|
return analyzeResult.Success is false
|
|
? TemporaryFileXmlImportOperationStatusResult(analyzeResult.Status)
|
|
: Ok(_mapper.Map<EntityImportAnalysisResponseModel>(analyzeResult.Result));
|
|
}
|
|
}
|