fix: Correzione salvataggio campo MappedDestinationField in KeyAssociations

- Aggiunto campo MappedDestinationField al modello KeyAssociation per tracciare il campo destinazione mappato alla chiave sorgente
- Creata migration AddMappedDestinationFieldToKeyAssociation per aggiungere la colonna al database
- Implementata logica di popolamento in CreateAssociationAsync e StartDataTransferOriginal per salvare il campo destinazione mappato
- Aggiornato SaveAssociationParallelAsync per includere MappedDestinationField nelle query SQL UPDATE e INSERT
- Corretti indici parametri nella query UPDATE (da {7-9} a {8-10}) per includere il nuovo campo
- Aggiunta visualizzazione campo nell'interfaccia KeyAssociations (tabella, dettagli, export CSV)
- Implementato controllo validazione per impedire trasferimenti se il campo chiave non è mappato
- Aggiunto logging diagnostico dettagliato per debug del mapping dei campi
- Aggiornato ScheduledProfileExecutionService per popolare MappedDestinationField nelle esecuzioni schedulate
- Rimosso file BackgroundServices.cs obsoleto
- Documentazione completa creata (4 markdown files)

Fixes: Campo MappedDestinationField rimaneva NULL perché le query SQL raw non includevano il nuovo campo
This commit is contained in:
2025-10-20 00:42:07 +02:00
parent 22c0a15b8e
commit 5d9b9756cf
19 changed files with 2433 additions and 48 deletions
@@ -0,0 +1,8 @@
using System;
namespace Data_Coupler.Services;
public class AssociationService
{
}
@@ -970,14 +970,31 @@ public class ScheduledProfileExecutionService : IScheduledProfileExecutionServic
if (string.IsNullOrEmpty(sourceKey))
return;
// Calcola il MappingCount in modo sicuro
// Calcola il MappingCount in modo sicuro e trova il campo destinazione mappato al campo chiave sorgente
int mappingCount = 0;
string? mappedDestinationField = null;
try
{
if (!string.IsNullOrEmpty(profile.FieldMappingJson))
{
var mappings = ParseFieldMappings(profile.FieldMappingJson);
mappingCount = mappings?.Count ?? 0;
// Cerca il campo destinazione mappato al campo chiave sorgente
if (mappings != null && !string.IsNullOrEmpty(profile.SourceKeyField))
{
if (mappings.TryGetValue(profile.SourceKeyField, out var destinationFieldName))
{
mappedDestinationField = destinationFieldName;
_logger.LogDebug("SCHEDULED MAPPING: Campo sorgente '{SourceField}' è mappato al campo destinazione '{DestField}'",
profile.SourceKeyField, mappedDestinationField);
}
else
{
_logger.LogWarning("SCHEDULED MAPPING: Campo chiave sorgente '{SourceKeyField}' NON trovato nei mappings del profilo {ProfileName}",
profile.SourceKeyField, profile.Name);
}
}
}
}
catch (Exception ex)
@@ -990,6 +1007,7 @@ public class ScheduledProfileExecutionService : IScheduledProfileExecutionServic
KeyValue = sourceKey,
SourceKeyField = profile.SourceKeyField ?? "",
DestinationKeyField = "Id", // Campo ID standard per REST
MappedDestinationField = mappedDestinationField, // Campo destinazione mappato al campo chiave sorgente
DestinationEntity = profile.DestinationEndpoint ?? "",
DestinationId = entityId,
RestCredentialName = restCredential.Name, // Usa il nome della credenziale
@@ -1014,8 +1032,8 @@ public class ScheduledProfileExecutionService : IScheduledProfileExecutionServic
var associationId = await _dataConnectionCredentialService.SaveKeyAssociationParallelAsync(association);
_logger.LogDebug("COMPOSITE SCHEDULED: Associazione creata con ID: {AssociationId} per record {RecordNumber} - Key: {SourceKey}, EntityId: {EntityId}, Hash: {Hash}",
associationId, recordNumber, sourceKey, entityId, dataHash);
_logger.LogDebug("COMPOSITE SCHEDULED: Associazione creata con ID: {AssociationId} per record {RecordNumber} - Key: {SourceKey}, EntityId: {EntityId}, Hash: {Hash}, MappedField: {MappedField}",
associationId, recordNumber, sourceKey, entityId, dataHash, mappedDestinationField ?? "N/A");
}
catch (Exception ex)
{