Files
Data-Coupler/DataConnection/CredentialManagement/Interfaces/IDataConnectionCredentialService.cs
T
Alessio 04f0403f12 feat: Implementato sistema di associazioni chiave per prevenire duplicati nel data coupling
BREAKING CHANGE: Rimosso completamente il vecchio sistema RecordAssociation

Modifiche principali:
- Sostituito RecordAssociation con KeyAssociation basato sui valori delle chiavi
- Implementata logica robusta di UPDATE vs INSERT basata su associazioni esistenti
- Aggiunta normalizzazione delle chiavi (.Trim()) per consistenza
- Implementato fallback nella ricerca associazioni per maggiore affidabilità
- Sostituita verifica pre-UPDATE con tentativo diretto più efficiente

Componenti modificati:
- Nuovo modello: KeyAssociation.cs con campi ottimizzati
- Nuovo servizio: KeyAssociationService.cs con metodi completi
- Aggiornato: DataCoupler.razor con logica migliorata di gestione associazioni
- Aggiornato: CredentialDbContext per gestire solo KeyAssociations
- Aggiornati: tutti i servizi di interfaccia per supportare il nuovo sistema
- Creata: pagina KeyAssociations.razor per gestione associazioni
- Aggiornato: NavMenu.razor con link alla gestione associazioni

Miglioramenti tecnici:
- Logica di UPDATE più robusta: tenta direttamente l'aggiornamento invece di verificare prima l'esistenza
- Gestione errori migliorata con cleanup automatico delle associazioni non valide
- Debug logging estensivo per troubleshooting
- Fallback nella ricerca associazioni se parametri specifici falliscono
- Normalizzazione valori chiave per prevenire problemi di whitespace

Risultato:
Il sistema ora previene correttamente i duplicati utilizzando le associazioni per decidere
se fare INSERT (nuovo record) o UPDATE (record esistente) basandosi sui valori delle chiavi.

Database:
- Creata migrazione EF per rimuovere RecordAssociations e aggiungere KeyAssociations
- Eliminati file e codice legacy non più necessari
2025-06-29 20:44:20 +02:00

78 lines
4.5 KiB
C#

using CredentialManager.Models;
using CredentialManager.Services;
namespace DataConnection.CredentialManagement.Interfaces;
/// <summary>
/// Interfaccia per la gestione delle credenziali integrate con DataConnection
/// </summary>
public interface IDataConnectionCredentialService
{
// Database credentials
Task<DatabaseCredential?> GetDatabaseCredentialAsync(string name);
Task<DatabaseCredential?> GetDatabaseCredentialAsync(int id);
Task<List<DatabaseCredential>> GetAllDatabaseCredentialsAsync();
Task<int> SaveDatabaseCredentialAsync(DatabaseCredential credential);
Task<bool> DeleteDatabaseCredentialAsync(int id);
Task<bool> DeleteDatabaseCredentialAsync(string name);
// REST API credentials
Task<RestApiCredential?> GetRestApiCredentialAsync(string name);
Task<RestApiCredential?> GetRestApiCredentialAsync(int id);
Task<List<RestApiCredential>> GetAllRestApiCredentialsAsync();
Task<int> SaveRestApiCredentialAsync(RestApiCredential credential);
Task<bool> DeleteRestApiCredentialAsync(int id);
Task<bool> DeleteRestApiCredentialAsync(string name);
// SAP B1 Service Layer credentials
Task<SapB1ServiceLayerCredential?> GetSapB1CredentialAsync(string name);
Task<SapB1ServiceLayerCredential?> GetSapB1CredentialAsync(int id);
Task<List<SapB1ServiceLayerCredential>> GetAllSapB1CredentialsAsync();
Task<int> SaveSapB1CredentialAsync(SapB1ServiceLayerCredential credential);
Task<bool> DeleteSapB1CredentialAsync(int id);
Task<bool> DeleteSapB1CredentialAsync(string name);
// Salesforce credentials
Task<SalesforceCredential?> GetSalesforceCredentialAsync(string name);
Task<SalesforceCredential?> GetSalesforceCredentialAsync(int id);
Task<List<SalesforceCredential>> GetAllSalesforceCredentialsAsync();
Task<int> SaveSalesforceCredentialAsync(SalesforceCredential credential);
Task<bool> DeleteSalesforceCredentialAsync(int id);
Task<bool> DeleteSalesforceCredentialAsync(string name);
// DataConnection specific operations
Task<string> GetConnectionStringAsync(string credentialName);
Task<string> GetConnectionStringAsync(int credentialId);
Task<DataConnection.EF.DbManagerOptions> GetDbManagerOptionsAsync(string credentialName);
Task<DataConnection.EF.DbManagerOptions> GetDbManagerOptionsAsync(int credentialId);
Task<DataConnection.REST.Configuration.RestServiceOptions> GetRestServiceOptionsAsync(string credentialName);
Task<DataConnection.REST.Configuration.RestServiceOptions> GetRestServiceOptionsAsync(int credentialId);
// Connection testing
Task<(bool Success, string Message)> TestDatabaseConnectionAsync(string credentialName);
Task<(bool Success, string Message)> TestDatabaseConnectionAsync(DatabaseCredential credential);
Task<(bool Success, string Message)> TestRestApiConnectionAsync(string credentialName);
Task<(bool Success, string Message)> TestRestApiConnectionAsync(RestApiCredential credential);
Task<(bool Success, string Message)> TestSapB1ConnectionAsync(string credentialName);
Task<(bool Success, string Message)> TestSapB1ConnectionAsync(SapB1ServiceLayerCredential credential);
Task<(bool Success, string Message)> TestSalesforceConnectionAsync(string credentialName);
Task<(bool Success, string Message)> TestSalesforceConnectionAsync(SalesforceCredential credential);
// Key associations
Task<int> SaveKeyAssociationAsync(KeyAssociation association);
Task<KeyAssociation?> FindKeyAssociationByValueAsync(string keyValue, string destinationEntity, string restCredentialName);
Task<KeyAssociation?> FindKeyAssociationByValueAsync(string keyValue);
Task<List<KeyAssociation>> GetKeyAssociationsByDestinationAsync(string destinationEntity, string restCredentialName);
Task<List<KeyAssociation>> GetAllActiveKeyAssociationsAsync();
Task<List<KeyAssociation>> GetAllKeyAssociationsAsync();
Task<bool> UpdateKeyAssociationAsync(KeyAssociation association);
Task<bool> DeactivateKeyAssociationAsync(int id);
Task<bool> DeleteKeyAssociationAsync(int id);
Task<int> ClearKeyAssociationsAsync(string destinationEntity, string restCredentialName);
Task<int> ClearAllKeyAssociationsAsync();
Task<List<KeyAssociation>> GetInvalidKeyAssociationsAsync(string destinationEntity, string restCredentialName);
Task<int> CleanupInvalidKeyAssociationsAsync(string destinationEntity, string restCredentialName);
Task<bool> UpdateKeyAssociationLastVerifiedAsync(int id);
Task<AssociationStatistics> GetKeyAssociationStatisticsAsync();
}