99import java .security .cert .Certificate ;
1010import java .security .cert .CertificateException ;
1111import java .security .cert .X509Certificate ;
12+ import java .util .Map ;
1213import java .util .UUID ;
1314
1415import org .bouncycastle .pkcs .PKCSException ;
2021import de .netzwerk_universitaetsmedizin .codex .processes .data_transfer .client .fhir .DataStoreFhirClient ;
2122import de .netzwerk_universitaetsmedizin .codex .processes .data_transfer .client .fhir .DataStoreFhirClientStub ;
2223import de .netzwerk_universitaetsmedizin .codex .processes .data_transfer .logging .DataLogger ;
24+ import de .netzwerk_universitaetsmedizin .codex .processes .data_transfer .spring .config .ReceiveDataStoreConfig ;
2325import de .rwh .utils .crypto .CertificateHelper ;
2426import de .rwh .utils .crypto .io .CertificateReader ;
2527import de .rwh .utils .crypto .io .PemIo ;
2628
2729public class DataStoreClientFactory
2830{
2931 private static final Logger logger = LoggerFactory .getLogger (DataStoreClientFactory .class );
32+ private static final String DEFAULT_DATA_STORE = "default" ;
3033
3134 private static final class DataStoreClientStub implements DataStoreClient
3235 {
@@ -91,10 +94,7 @@ public boolean shouldUseChainedParameterNotLogicalReference()
9194 private final int socketTimeout ;
9295 private final int connectionRequestTimeout ;
9396
94- private final String dataStoreServerBase ;
95- private final String dataStoreServerBasicAuthUsername ;
96- private final String dataStoreServerBasicAuthPassword ;
97- private final String dataStoreServerBearerToken ;
97+ private final Map <String , ReceiveDataStoreConfig .DataStoreConnectionValues > dataStoreConnectionMap ;
9898
9999 private final String proxyUrl ;
100100 private final String proxyUsername ;
@@ -112,7 +112,8 @@ public boolean shouldUseChainedParameterNotLogicalReference()
112112 public DataStoreClientFactory (Path trustStorePath , Path certificatePath , Path privateKeyPath ,
113113 char [] privateKeyPassword , int connectTimeout , int socketTimeout , int connectionRequestTimeout ,
114114 String dataStoreServerBase , String dataStoreServerBasicAuthUsername ,
115- String dataStoreServerBasicAuthPassword , String dataStoreServerBearerToken , String proxyUrl ,
115+ String dataStoreServerBasicAuthPassword , String dataStoreServerBearerToken ,
116+ Map <String , ReceiveDataStoreConfig .DataStoreConnectionValues > dataStoreConnectionMap , String proxyUrl ,
116117 String proxyUsername , String proxyPassword , boolean hapiClientVerbose , FhirContext fhirContext ,
117118 Path searchBundleOverride , Class <DataStoreFhirClient > dataStoreFhirClientClass ,
118119 boolean useChainedParameterNotLogicalReference , DataLogger dataLogger )
@@ -126,10 +127,11 @@ public DataStoreClientFactory(Path trustStorePath, Path certificatePath, Path pr
126127 this .socketTimeout = socketTimeout ;
127128 this .connectionRequestTimeout = connectionRequestTimeout ;
128129
129- this .dataStoreServerBase = dataStoreServerBase ;
130- this .dataStoreServerBasicAuthUsername = dataStoreServerBasicAuthUsername ;
131- this .dataStoreServerBasicAuthPassword = dataStoreServerBasicAuthPassword ;
132- this .dataStoreServerBearerToken = dataStoreServerBearerToken ;
130+ this .dataStoreConnectionMap = dataStoreConnectionMap ;
131+ this .dataStoreConnectionMap .put (DEFAULT_DATA_STORE ,
132+ new ReceiveDataStoreConfig .DataStoreConnectionValues (dataStoreServerBase ,
133+ dataStoreServerBasicAuthUsername , dataStoreServerBasicAuthPassword ,
134+ dataStoreServerBearerToken ));
133135
134136 this .proxyUrl = proxyUrl ;
135137 this .proxyUsername = proxyUsername ;
@@ -146,21 +148,25 @@ public DataStoreClientFactory(Path trustStorePath, Path certificatePath, Path pr
146148
147149 public String getServerBase ()
148150 {
149- return dataStoreServerBase ;
151+ return dataStoreConnectionMap . get ( DEFAULT_DATA_STORE ). getBaseUrl () ;
150152 }
151153
152154 public void testConnection ()
153155 {
154156 try
155157 {
156- logger .info (
157- "Testing connection to Data Store FHIR server with {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
158- + " basicAuthUsername: {}, basicAuthPassword: {}, bearerToken: {}, serverBase: {}, proxy: values from 'DEV_DSF_PROXY'... config}" ,
159- trustStorePath , certificatePath , privateKeyPath , privateKeyPassword != null ? "***" : "null" ,
160- dataStoreServerBasicAuthUsername , dataStoreServerBasicAuthPassword != null ? "***" : "null" ,
161- dataStoreServerBearerToken != null ? "***" : "null" , dataStoreServerBase );
162-
163- getDataStoreClient ().testConnection ();
158+ for (String client : dataStoreConnectionMap .keySet ())
159+ {
160+ final ReceiveDataStoreConfig .DataStoreConnectionValues value = dataStoreConnectionMap .get (client );
161+ logger .info (
162+ "Testing connection to Data Store FHIR server with {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
163+ + " basicAuthUsername: {}, basicAuthPassword: {}, bearerToken: {}, serverBase: {}, proxy: values from 'DEV_DSF_PROXY'... config}" ,
164+ trustStorePath , certificatePath , privateKeyPath , privateKeyPassword != null ? "***" : "null" ,
165+ value .getBaseUrl (), value .getPassword () != null ? "***" : "null" ,
166+ value .getBearerToken () != null ? "***" : "null" , value .getUsername ());
167+
168+ getDataStoreClient (client ).testConnection ();
169+ }
164170 }
165171 catch (Exception e )
166172 {
@@ -170,18 +176,29 @@ public void testConnection()
170176
171177 public DataStoreClient getDataStoreClient ()
172178 {
173- if (configured ())
174- return createDataStoreClient ();
179+ return getDataStoreClient (DEFAULT_DATA_STORE );
180+ }
181+
182+ public DataStoreClient getDataStoreClient (String client )
183+ {
184+ if (configured (client ))
185+ return createDataStoreClient (client );
175186 else
176187 return new DataStoreClientStub (fhirContext , dataLogger );
177188 }
178189
179- private boolean configured ()
190+ private boolean configured (String client )
180191 {
181- return dataStoreServerBase != null && !dataStoreServerBase .isBlank ();
192+ return dataStoreConnectionMap .get (client ).getBaseUrl () != null
193+ && !dataStoreConnectionMap .get (client ).getBaseUrl ().isBlank ();
182194 }
183195
184196 protected DataStoreClient createDataStoreClient ()
197+ {
198+ return createDataStoreClient (DEFAULT_DATA_STORE );
199+ }
200+
201+ protected DataStoreClient createDataStoreClient (String dataStore )
185202 {
186203 KeyStore trustStore = null ;
187204 char [] keyStorePassword = null ;
@@ -200,9 +217,11 @@ protected DataStoreClient createDataStoreClient()
200217 keyStore = readKeyStore (certificatePath , privateKeyPath , privateKeyPassword , keyStorePassword );
201218 }
202219
220+ final ReceiveDataStoreConfig .DataStoreConnectionValues dataStoreConfig = dataStoreConnectionMap .get (dataStore );
221+
203222 return new DataStoreClientImpl (trustStore , keyStore , keyStorePassword , connectTimeout , socketTimeout ,
204- connectionRequestTimeout , dataStoreServerBasicAuthUsername , dataStoreServerBasicAuthPassword ,
205- dataStoreServerBearerToken , dataStoreServerBase , proxyUrl , proxyUsername , proxyPassword ,
223+ connectionRequestTimeout , dataStoreConfig . getUsername (), dataStoreConfig . getPassword () ,
224+ dataStoreConfig . getBearerToken (), dataStoreConfig . getBaseUrl () , proxyUrl , proxyUsername , proxyPassword ,
206225 hapiClientVerbose , fhirContext , searchBundleOverride , dataStoreFhirClientClass ,
207226 useChainedParameterNotLogicalReference , dataLogger );
208227 }
0 commit comments