[Feature] Implementato sistema di valori default per campi mapping
- Creato modello FieldMappingEntry per gestione unificata di field mapping e default values - Aggiunta colonna DefaultValuesJson alla tabella DataCouplerProfile (max 4000 caratteri) - Implementata UI con toggle per selezionare modalità Mapping o Default - Supporto per 9 tipi di dati: string, int, long, decimal, double, float, boolean, datetime, datetimeoffset - Aggiornata logica TransformRecordToRestEntity per applicare valori default dopo field mapping - Implementata serializzazione/deserializzazione DefaultValues in DataCouplerProfileService - Sistema completo di salvataggio/caricamento valori default nei profili - Migrazione database AddDefaultValuesJsonToProfile creata e applicata
This commit is contained in:
@@ -216,6 +216,7 @@ public class DataCouplerProfileService : IDataCouplerProfileService
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Deserializza il JSON delle External ID Relationships
|
||||
/// </summary>
|
||||
@@ -236,6 +237,64 @@ public class DataCouplerProfileService : IDataCouplerProfileService
|
||||
return new List<ExternalIdRelationshipDto>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializza i default values in JSON
|
||||
/// </summary>
|
||||
public string SerializeDefaultValues(Dictionary<string, (object? Value, string? Type)>? defaultValues)
|
||||
{
|
||||
if (defaultValues == null || !defaultValues.Any())
|
||||
return string.Empty;
|
||||
|
||||
// Converti in un formato serializzabile (Dictionary<string, DefaultValueDto>)
|
||||
var serializable = new Dictionary<string, DefaultValueDto>();
|
||||
foreach (var entry in defaultValues)
|
||||
{
|
||||
serializable[entry.Key] = new DefaultValueDto
|
||||
{
|
||||
Value = entry.Value.Value,
|
||||
Type = entry.Value.Type
|
||||
};
|
||||
}
|
||||
|
||||
return JsonSerializer.Serialize(serializable, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializza il JSON dei default values
|
||||
/// </summary>
|
||||
public Dictionary<string, (object? Value, string? Type)> DeserializeDefaultValues(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
return new Dictionary<string, (object?, string?)>();
|
||||
|
||||
try
|
||||
{
|
||||
var deserialized = JsonSerializer.Deserialize<Dictionary<string, DefaultValueDto>>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
|
||||
if (deserialized == null)
|
||||
return new Dictionary<string, (object?, string?)>();
|
||||
|
||||
// Converti nel formato tuple
|
||||
var result = new Dictionary<string, (object?, string?)>();
|
||||
foreach (var entry in deserialized)
|
||||
{
|
||||
result[entry.Key] = (entry.Value.Value, entry.Value.Type);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Dictionary<string, (object?, string?)>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converte un DataCouplerProfile in DTO
|
||||
@@ -262,6 +321,7 @@ public class DataCouplerProfileService : IDataCouplerProfileService
|
||||
DestinationTable = profile.DestinationTable,
|
||||
DestinationEndpoint = profile.DestinationEndpoint,
|
||||
FieldMappings = DeserializeFieldMappings(profile.FieldMappingJson),
|
||||
DefaultValues = DeserializeDefaultValues(profile.DefaultValuesJson),
|
||||
ExternalIdRelationships = DeserializeExternalIdRelationships(profile.ExternalIdRelationshipsJson),
|
||||
SourceKeyField = profile.SourceKeyField,
|
||||
UseRecordAssociations = profile.UseRecordAssociations
|
||||
@@ -291,6 +351,7 @@ public class DataCouplerProfileService : IDataCouplerProfileService
|
||||
DestinationTable = dto.DestinationTable,
|
||||
DestinationEndpoint = dto.DestinationEndpoint,
|
||||
FieldMappingJson = SerializeFieldMappings(dto.FieldMappings),
|
||||
DefaultValuesJson = SerializeDefaultValues(dto.DefaultValues),
|
||||
ExternalIdRelationshipsJson = SerializeExternalIdRelationships(dto.ExternalIdRelationships),
|
||||
SourceKeyField = dto.SourceKeyField,
|
||||
UseRecordAssociations = dto.UseRecordAssociations,
|
||||
|
||||
Reference in New Issue
Block a user