denuncias
This commit is contained in:
@@ -119,10 +119,12 @@ namespace ApiDenuncias.Services
|
||||
var url = await ResolveExternalProcedureCreateFileUrlAsync(effectiveProcedureId);
|
||||
using var req = new HttpRequestMessage(HttpMethod.Post, url);
|
||||
req.Headers.Accept.Clear();
|
||||
req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
req.Headers.Accept.Add(
|
||||
MediaTypeWithQualityHeaderValue.Parse("application/vnd.gestiona.file-opening+json; version=1"));
|
||||
req.Headers.TryAddWithoutValidation("X-Gestiona-Access-Token", _opts.AccessToken);
|
||||
|
||||
using var resp = await _http.SendAsync(req);
|
||||
LogDeprecatedHeaders(resp, "POST create-file");
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
if (!resp.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"CreateFileAsync: {(int)resp.StatusCode} {resp.StatusCode}\n{body}");
|
||||
@@ -187,6 +189,7 @@ namespace ApiDenuncias.Services
|
||||
AddTokenAndAccept(req, "application/json");
|
||||
|
||||
using var resp = await _http.SendAsync(req);
|
||||
LogDeprecatedHeaders(resp, "POST file-open");
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
if (!resp.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"OpenFileAsync: {(int)resp.StatusCode} {resp.StatusCode}\n{body}");
|
||||
@@ -205,9 +208,11 @@ namespace ApiDenuncias.Services
|
||||
Content = content
|
||||
};
|
||||
req.Headers.TryAddWithoutValidation("Prefer", "return=minimal");
|
||||
AddTokenAndAccept(req, "application/vnd.gestiona.file-folder+json", "1");
|
||||
req.Headers.TryAddWithoutValidation("X-Gestiona-Access-Token", _opts.AccessToken);
|
||||
req.Headers.Accept.Clear();
|
||||
|
||||
using var resp = await _http.SendAsync(req);
|
||||
LogDeprecatedHeaders(resp, "POST file-folder");
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
if (!resp.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"CreateFolderAsync: {(int)resp.StatusCode} {resp.StatusCode}\n{body}");
|
||||
@@ -225,10 +230,12 @@ namespace ApiDenuncias.Services
|
||||
{
|
||||
using var createReq = new HttpRequestMessage(HttpMethod.Post, "/rest/uploads");
|
||||
createReq.Headers.TryAddWithoutValidation("X-Gestiona-Access-Token", _opts.AccessToken);
|
||||
createReq.Headers.TryAddWithoutValidation("Prefer", "return=minimal");
|
||||
createReq.Headers.Accept.Add(
|
||||
MediaTypeWithQualityHeaderValue.Parse("application/vnd.gestiona.upload+json"));
|
||||
|
||||
using var createResp = await _http.SendAsync(createReq);
|
||||
LogDeprecatedHeaders(createResp, "POST /rest/uploads");
|
||||
var createBody = await createResp.Content.ReadAsStringAsync();
|
||||
if (!createResp.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"CreateUpload (POST): {(int)createResp.StatusCode} {createResp.StatusCode}\n{createBody}");
|
||||
@@ -254,6 +261,7 @@ namespace ApiDenuncias.Services
|
||||
putReq.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
|
||||
|
||||
using var putResp = await _http.SendAsync(putReq);
|
||||
LogDeprecatedHeaders(putResp, "PUT upload content");
|
||||
var infoJson = await putResp.Content.ReadAsStringAsync();
|
||||
if (!putResp.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"CreateUpload (PUT): {(int)putResp.StatusCode} {putResp.StatusCode}\n{infoJson}");
|
||||
@@ -294,10 +302,9 @@ namespace ApiDenuncias.Services
|
||||
metaReq.Headers.TryAddWithoutValidation("X-Gestiona-Access-Token", _opts.AccessToken);
|
||||
metaReq.Headers.TryAddWithoutValidation("Prefer", "return=minimal");
|
||||
metaReq.Headers.Accept.Clear();
|
||||
metaReq.Headers.Accept.Add(
|
||||
MediaTypeWithQualityHeaderValue.Parse("application/vnd.gestiona.file-document+json; version=4"));
|
||||
|
||||
using var metaResp = await _http.SendAsync(metaReq);
|
||||
LogDeprecatedHeaders(metaResp, "POST file document");
|
||||
var body = await metaResp.Content.ReadAsStringAsync();
|
||||
if (!metaResp.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"UploadDocumentAsync: {(int)metaResp.StatusCode} {metaResp.StatusCode}\n{body}");
|
||||
@@ -513,6 +520,14 @@ namespace ApiDenuncias.Services
|
||||
|
||||
if (string.IsNullOrEmpty(encontrado.SelfHref))
|
||||
{
|
||||
if (!CanCreateThirdParty(thirdParty))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Se omite la creacion/enlace del tercero en Gestiona para el expediente {FileUrl}: datos identificativos incompletos.",
|
||||
fileUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
encontrado = await CrearTerceroAsync(thirdParty);
|
||||
}
|
||||
else if (thirdParty.Address?.HasAnyValue == true)
|
||||
@@ -529,7 +544,27 @@ namespace ApiDenuncias.Services
|
||||
{
|
||||
if (!thirdParty.IsAnonymous)
|
||||
{
|
||||
return thirdParty;
|
||||
var documentId = (thirdParty.DocumentId ?? string.Empty).Trim().ToUpperInvariant();
|
||||
var firstName = (thirdParty.FirstName ?? string.Empty).Trim();
|
||||
var lastName = (thirdParty.LastName ?? string.Empty).Trim();
|
||||
var businessName = (thirdParty.BusinessName ?? string.Empty).Trim();
|
||||
var isLegalEntity = thirdParty.IsLegalEntity ||
|
||||
LooksLikeLegalEntityDocument(documentId) ||
|
||||
(!string.IsNullOrWhiteSpace(businessName) &&
|
||||
string.IsNullOrWhiteSpace(firstName));
|
||||
|
||||
return new ThirdPartyIdentityData
|
||||
{
|
||||
IsAnonymous = false,
|
||||
IsLegalEntity = isLegalEntity,
|
||||
DocumentId = documentId,
|
||||
FirstName = isLegalEntity ? string.Empty : firstName,
|
||||
LastName = isLegalEntity ? string.Empty : lastName,
|
||||
BusinessName = businessName,
|
||||
Email = (thirdParty.Email ?? string.Empty).Trim(),
|
||||
CountryCode = string.IsNullOrWhiteSpace(thirdParty.CountryCode) ? "ESP" : thirdParty.CountryCode.Trim(),
|
||||
Address = thirdParty.Address
|
||||
};
|
||||
}
|
||||
|
||||
return new ThirdPartyIdentityData
|
||||
@@ -546,6 +581,25 @@ namespace ApiDenuncias.Services
|
||||
};
|
||||
}
|
||||
|
||||
private static bool CanCreateThirdParty(ThirdPartyIdentityData thirdParty)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(thirdParty.DocumentId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return thirdParty.IsLegalEntity
|
||||
? !string.IsNullOrWhiteSpace(thirdParty.BusinessName)
|
||||
: !string.IsNullOrWhiteSpace(thirdParty.FirstName) &&
|
||||
!string.IsNullOrWhiteSpace(thirdParty.LastName);
|
||||
}
|
||||
|
||||
private static bool LooksLikeLegalEntityDocument(string documentId)
|
||||
{
|
||||
var value = (documentId ?? string.Empty).Trim().ToUpperInvariant();
|
||||
return Regex.IsMatch(value, @"^[ABCDEFGHJKLMNPQRSUVW]\d{7}[A-Z0-9]$");
|
||||
}
|
||||
|
||||
// --- CONSULTAS DE EXPEDIENTES (sin recorrer histórico paginado) ---
|
||||
|
||||
private async Task<string> GetFilesAsync(object? filter = null)
|
||||
@@ -559,7 +613,7 @@ namespace ApiDenuncias.Services
|
||||
if (filter is not null)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(filter);
|
||||
req.Content = new StringContent(json, Encoding.UTF8, "application/vnd.gestiona.filter.files");
|
||||
req.Content = new StringContent(json, Encoding.UTF8, "application/vnd.gestiona.filter.files+json");
|
||||
}
|
||||
|
||||
using var resp = await _http.SendAsync(req);
|
||||
|
||||
Reference in New Issue
Block a user