4
4
import akka .actor .typed .Behavior ;
5
5
import akka .actor .typed .javadsl .*;
6
6
import akka .http .javadsl .server .directives .FileInfo ;
7
-
8
- import com .fasterxml .jackson .core .JsonProcessingException ;
9
7
import com .fasterxml .jackson .databind .ObjectMapper ;
10
8
import io .vavr .control .Either ;
11
9
import org .apache .commons .io .FileUtils ;
32
30
import java .sql .Timestamp ;
33
31
import java .time .LocalDateTime ;
34
32
import java .util .*;
35
- import java .sql .PreparedStatement ;
36
- import java .sql .ResultSet ;
37
33
38
34
public final class BackEnd extends AbstractBehavior <BackEnd .Event > {
39
35
40
36
private static final Logger LOGGER = LogManager .getLogger (BackEnd .class );
41
- private final PsqlClient psqlClient ;
42
37
private final String pgIP ;
43
- private final int pgPort ;
44
38
private final String pgUser ;
45
39
private final String pgPassword ;
46
40
private final String pgNotificationsDb ;
@@ -80,7 +74,7 @@ private BackEnd(
80
74
this .dgraphHosts = dgraphHosts ;
81
75
this .dgraphPorts = dgraphPorts ;
82
76
this .pgIP = sqlIP ;
83
- this . pgPort = sqlPort ;
77
+ Integer pgPort = sqlPort ;
84
78
this .pgUser = sqlUser ;
85
79
this .pgPassword = sqlPassword ;
86
80
this .pgNotificationsDb = sqlNotificationsDb ;
@@ -93,7 +87,6 @@ private BackEnd(
93
87
psqlNotifications = new PsqlNotifications (sqlIP , sqlPort , sqlNotificationsDb , sqlUser , sqlPassword );
94
88
psqlAuditTrail = new PsqlAuditTrail (sqlIP , sqlPort , sqlAuditDb , sqlUser , sqlPassword );
95
89
openMPI (kafkaBootstrapServers , kafkaClientId , debugLevel );
96
- psqlClient = new PsqlClient (sqlIP , sqlPort , sqlConfigurationDb , sqlUser , sqlPassword );
97
90
} catch (Exception e ) {
98
91
LOGGER .error (e .getMessage (), e );
99
92
throw e ;
@@ -505,7 +498,7 @@ private Behavior<Event> getSqlDashboardDataHandler(final SQLDashboardDataRequest
505
498
return Behaviors .same ();
506
499
}
507
500
508
- private Behavior <Event > getConfigurationHandlers (final GetConfigurationRequest request ) {
501
+ private Behavior <Event > getConfigurationHandler (final GetConfigurationRequest request ) {
509
502
Path configMasterJsonFilePath = Paths .get (systemConfigDirectory , configMasterFileName );
510
503
Path configReferenceJsonFilePath = Paths .get (systemConfigDirectory , configReferenceFileName );
511
504
@@ -526,61 +519,7 @@ private Behavior<Event> getConfigurationHandlers(final GetConfigurationRequest r
526
519
return Behaviors .same ();
527
520
}
528
521
529
- private Behavior <Event > getConfigurationHandler (final GetConfigurationRequest request ) {
530
- try {
531
- psqlClient .connect ();
532
- String sql = "SELECT json FROM CONFIGURATION WHERE key = 'config' ORDER BY id DESC LIMIT 1" ;
533
- try (PreparedStatement preparedStatement = psqlClient .prepareStatement (sql );
534
- ResultSet rs = preparedStatement .executeQuery ()) {
535
-
536
- if (rs .next ()) {
537
- LOGGER .info ("rs.....getConfigurationHandler.........................................: {}" , rs );
538
- String configFileContent = rs .getString ("json" );
539
- LOGGER .info ("configFileContent..........getConfigurationHandler....................................: {}" , configFileContent );
540
- ObjectMapper mapper = new ObjectMapper ();
541
- Configuration configuration = mapper .readValue (configFileContent , Configuration .class );
542
- request .replyTo .tell (new GetConfigurationResponse (configuration ));
543
- } else {
544
- LOGGER .warn ("No configuration found in the database." );
545
- request .replyTo .tell (new GetConfigurationResponse (null ));
546
- }
547
- }
548
- } catch (SQLException | JsonProcessingException e ) {
549
- LOGGER .error ("getConfigurationHandler failed with error: {}" , e .getMessage ());
550
- }
551
-
552
- return Behaviors .same ();
553
- }
554
-
555
522
private Behavior <Event > getFieldsConfigurationHandler (final GetFieldsConfigurationRequest request ) {
556
- try {
557
- psqlClient .connect ();
558
- String sql = "SELECT json FROM CONFIGURATION WHERE key = 'config-api' ORDER BY id DESC LIMIT 1" ;
559
- try (PreparedStatement preparedStatement = psqlClient .prepareStatement (sql );
560
- ResultSet rs = preparedStatement .executeQuery ()) {
561
-
562
- if (rs .next ()) {
563
- LOGGER .info ("rs...............getFieldsConfigurationHandler...............................: {}" , rs );
564
- String configFileContent = rs .getString ("json" );
565
- LOGGER .info ("configFileContent...........getFieldsConfigurationHandler...................................: {}" , configFileContent );
566
- FieldsConfiguration fieldsConfiguration = AppUtils .OBJECT_MAPPER .readValue (configFileContent , FieldsConfiguration .class );
567
- ArrayList <FieldsConfiguration .Field > fields = new ArrayList <>();
568
- fields .addAll (fieldsConfiguration .systemFields ());
569
- fields .addAll (fieldsConfiguration .fields ());
570
- request .replyTo .tell (new GetFieldsConfigurationResponse (fields ));
571
- } else {
572
- LOGGER .warn ("No configuration found in the database." );
573
- request .replyTo .tell (new GetFieldsConfigurationResponse (null ));
574
- }
575
- }
576
- } catch (SQLException | JsonProcessingException e ) {
577
- LOGGER .error ("getConfigurationHandler failed with error: {}" , e .getMessage ());
578
- }
579
-
580
- return Behaviors .same ();
581
- }
582
-
583
- private Behavior <Event > getFieldsConfigurationHandlers (final GetFieldsConfigurationRequest request ) {
584
523
final var separator = FileSystems .getDefault ().getSeparator ();
585
524
final String configDir = System .getenv ("SYSTEM_CONFIG_DIRS" );
586
525
Path filePath = Paths .get ("" ); // Start with an empty path
0 commit comments