1515 */
1616package com .hubsante .hub .config ;
1717
18+ import com .hubsante .hub .service .ClientPropertiesRegistry ;
1819import com .hubsante .model .EdxlHandler ;
1920import com .hubsante .model .Validator ;
2021import com .univocity .parsers .common .ParsingContext ;
2627import jakarta .annotation .PostConstruct ;
2728import java .io .*;
2829import java .nio .charset .StandardCharsets ;
29- import java .nio .file .Files ;
3030import java .util .*;
3131import java .util .stream .Collectors ;
3232import lombok .extern .slf4j .Slf4j ;
33- import org .apache .commons .csv .CSVFormat ;
34- import org .apache .commons .csv .CSVParser ;
35- import org .apache .commons .csv .CSVRecord ;
33+ import org .springframework .beans .factory .annotation .Autowired ;
3634import org .springframework .beans .factory .annotation .Value ;
3735import org .springframework .context .annotation .Bean ;
3836import org .springframework .context .annotation .Configuration ;
@@ -45,8 +43,6 @@ public class HubConfiguration {
4543 private static final int ROW_LENGTH = 11 ;
4644 private static final String DATA_DIVIDER = "," ;
4745 private static final String COLUMN_DIVIDER = ";" ;
48- private static final String CLIENT_ID_HEADER = "client_id" ;
49- private static final String INHIBITED_USE_CASES_HEADER = "inhibited_use_cases" ;
5046
5147 private static final StructuredLogger structuredLog = new StructuredLogger (log );
5248
@@ -64,11 +60,9 @@ public class HubConfiguration {
6460 @ Value ("${spring.rabbitmq.virtual-host}" )
6561 private String vhost ;
6662
67- private HashMap <String , Boolean > useXmlPreferences = new HashMap <>();
68- private HashMap <String , Boolean > directCisuPreferences = new HashMap <>();
69- private HashMap <String , String > clientsEditorMap = new HashMap <>();
63+ @ Autowired private ClientPropertiesRegistry clientPropertiesRegistry ;
64+
7065 private Map <String , Map <String , String >> clientsPerimeterAndVersions = new HashMap <>();
71- private Map <String , List <String >> clientsInhibitedMessages = new HashMap <>();
7266 private List <String > supportedMessages ;
7367
7468 @ PostConstruct
@@ -94,9 +88,6 @@ public void rowProcessed(Object[] objects, ParsingContext parsingContext) {
9488 ROW_LENGTH );
9589 }
9690 String [] items = Arrays .asList (objects ).toArray (new String [ROW_LENGTH ]);
97- useXmlPreferences .put (items [0 ], Boolean .parseBoolean (items [1 ]));
98- directCisuPreferences .put (items [0 ], Boolean .parseBoolean (items [2 ]));
99- clientsEditorMap .put (items [0 ], items [3 ]);
10091 }
10192 };
10293 CsvParserSettings parserSettings = new CsvParserSettings ();
@@ -109,7 +100,6 @@ public void rowProcessed(Object[] objects, ParsingContext parsingContext) {
109100 CsvParser parser = new CsvParser (parserSettings );
110101 parser .parse (new BufferedReader (new FileReader (configFile , StandardCharsets .UTF_8 )));
111102 clientsPerimeterAndVersions = loadClientsPerimetersAndVersions ();
112- clientsInhibitedMessages = loadClientsInhibitedMessages ();
113103 supportedMessages = loadSupportedMessages (vhost );
114104 } catch (Exception e ) {
115105 throw new Exception ("Could not read config file " + configFile .getAbsolutePath (), e );
@@ -157,18 +147,19 @@ public Map<String, Map<String, String>> loadClientsPerimetersAndVersions() throw
157147 return clientsPerimeterAndVersions ;
158148 }
159149
160- public String [] getClientVersionsForPerimeter (String clientId , String perimeterName ) {
161- Map <String , String > clientPerimeterDefinition =
162- clientsPerimeterAndVersions .getOrDefault (clientId , null );
163- if (clientPerimeterDefinition == null ) {
164- structuredLog .warn (
165- "ClientId was not found in clientsPerimeterAndVersions, or the variable is not initialized." ,
166- Map .of (LogConstants .RECIPIENT_ID , clientId ));
167- return null ;
168- }
169- String versions = clientPerimeterDefinition .getOrDefault (perimeterName , null );
170- return splitString (versions );
171- }
150+ // public String[] getClientVersionsForPerimeter(String clientId, String perimeterName) {
151+ // Map<String, String> clientPerimeterDefinition =
152+ // clientsPerimeterAndVersions.getOrDefault(clientId, null);
153+ // if (clientPerimeterDefinition == null) {
154+ // structuredLog.warn(
155+ // "ClientId was not found in clientsPerimeterAndVersions, or the variable is
156+ // not initialized.",
157+ // Map.of(LogConstants.RECIPIENT_ID, clientId));
158+ // return null;
159+ // }
160+ // String versions = clientPerimeterDefinition.getOrDefault(perimeterName, null);
161+ // return splitString(versions);
162+ // }
172163
173164 public List <String > loadSupportedMessages (String vhost ) throws Exception {
174165 List <String > supportedMessages = new ArrayList <>();
@@ -198,64 +189,10 @@ public List<String> loadSupportedMessages(String vhost) throws Exception {
198189 return supportedMessages ;
199190 }
200191
201- private Map <String , List <String >> loadClientsInhibitedMessages () throws IOException {
202- Map <String , List <String >> result = new HashMap <>();
203-
204- try (Reader reader = Files .newBufferedReader (configFile .toPath ());
205- CSVParser parser =
206- CSVFormat .DEFAULT
207- .builder ()
208- .setDelimiter (';' )
209- .setHeader ()
210- .setSkipHeaderRecord (true )
211- .setTrim (true )
212- .build ()
213- .parse (reader )) {
214- boolean hasUseCasesColumn =
215- parser .getHeaderMap ().containsKey (INHIBITED_USE_CASES_HEADER );
216-
217- for (CSVRecord record : parser ) {
218-
219- String clientId = record .get (CLIENT_ID_HEADER );
220- List <String > useCases ;
221-
222- if (hasUseCasesColumn ) {
223- useCases =
224- Arrays .stream (record .get (INHIBITED_USE_CASES_HEADER ).split ("," ))
225- .map (String ::trim )
226- .filter (s -> !s .isEmpty ())
227- .toList ();
228- } else {
229- useCases = List .of ();
230- }
231-
232- result .put (clientId , useCases );
233- }
234- }
235-
236- return Collections .unmodifiableMap (result );
237- }
238-
239192 public List <String > getSupportedMessages () {
240193 return supportedMessages ;
241194 }
242195
243- public HashMap <String , Boolean > getUseXmlPreferences () {
244- return useXmlPreferences ;
245- }
246-
247- public HashMap <String , Boolean > getDirectCisuPreferences () {
248- return directCisuPreferences ;
249- }
250-
251- public HashMap <String , String > getClientsEditorMap () {
252- return clientsEditorMap ;
253- }
254-
255- public Map <String , List <String >> getClientsInhibitedMessages () {
256- return clientsInhibitedMessages ;
257- }
258-
259196 public long getDefaultTTL () {
260197 return defaultTTL ;
261198 }
@@ -264,6 +201,10 @@ public String getVhost() {
264201 return vhost ;
265202 }
266203
204+ public ClientPropertiesRegistry getClientPropertiesRegistry () {
205+ return clientPropertiesRegistry ;
206+ }
207+
267208 @ Bean
268209 public EdxlHandler edxlHandler () {
269210 return new EdxlHandler ();
0 commit comments