covid_10012023_covid-reports/src/Main.java

74 lines
2.6 KiB
Java

import data.dtos.QueryDTO;
import data.enums.CustomPreparedStatementsRead;
import data.repos.QueryResultsRepository;
import services.AppConfigService;
import services.DatabaseService;
import services.ReportGenerationService;
import java.sql.SQLException;
/**
* Entry point of the application
*/
public class Main {
public static void main(String[] args) {
final App app = new App();
app.run();
}
}
/**
* Responsible for the overall flow of the application. It creates and manages instances Services.
*/
class App {
public App() {
databaseService = new DatabaseService();
appConfigService = new AppConfigService();
reportGenerationService = new ReportGenerationService();
}
final private DatabaseService databaseService;
final private AppConfigService appConfigService;
final private ReportGenerationService reportGenerationService;
/**
* Endpoints mentioned under the `Report` section
*/
private static final CustomPreparedStatementsRead[] reportEndpoints = {
CustomPreparedStatementsRead.HighestAndLowest10Vaccination,
CustomPreparedStatementsRead.HighestInfectionsPer100K,
CustomPreparedStatementsRead.CountriesLaggingBehind,
};
/**
* Endpoints mentioned under the `Query` section
*/
private static final CustomPreparedStatementsRead[] queryEndpoints = {
CustomPreparedStatementsRead.DailyInfectionsAndDeathAggregate,
};
/**
* Responsible for the overall flow of the application.
* It retrieves data from the database using the `DatabaseService` class,
* generates reports using the `ReportGenerationService` class, and prompts the user for input using the `AppConfigService` class.
*/
public void run() {
try {
QueryResultsRepository resultsRepository;
for (final CustomPreparedStatementsRead query : reportEndpoints) {
resultsRepository = databaseService.executeReadReportsEndpoint(new QueryDTO(query));
reportGenerationService.reportBaseResults(resultsRepository);
}
for(final CustomPreparedStatementsRead query: queryEndpoints) {
appConfigService.promptAndSetUserArguments();
resultsRepository = databaseService.executeReadReportsEndpoint(new QueryDTO(query, new Object[]{appConfigService.countryName, appConfigService.date,}));
reportGenerationService.reportBaseResults(resultsRepository);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}