This project is a result of a project for my school. The goal was to create a batch processor that monitors a directory for new CSV files, parses the files to extract user data, and inserts the data into a database. Requirements can be found here
The application is composed of the following components:
- Main Class (
Program): Entry point of the application. - FileWatcher: Monitors a directory for new files.
- CSVParser: Parses CSV files to extract user data.
- DatabaseManager: Handles database operations (like create connection).
- Repository (
UserRepository): Handles database operations (like insert in batch). - FileMover: Moves processed files to another directory.
- Models (
Reimbursement): Represents the data structure for the user.
- Java Development Kit (JDK) 21 or higher
- Maven (for dependency management)
- MariaDB
A configuration file (application.properties) is present in resources directory with the following content:
# Database connection properties
db.uri=jdbc:mariadb://localhost:3306/project_telecom_java
db.username=root
db.password=exampleClone the repository and build the project using Maven:
git clone https://github.com/Swansky/ProjetTelecomJava.git
cd ProjetTelecomJava
mvn clean install- Maven: Used for dependency management and build automation.
- WatchService API: Utilized to monitor the file system for new files.
- MariaDB: Used because it's open-source and easy to set up and because H2 database for test have a mariadb mode.
- OpenCSV: Used for parsing CSV files.
Orchestrates the overall workflow by initializing components and handling the sequence of operations.
Monitors the specified directory for new CSV files using Java's WatchService.
Reads and parses CSV files to extract user data into Reimbursement objects.
Handles database operations such as create connection.
Moves processed files to a specified directory.
Represents a user record with fields corresponding to the CSV data and database schema.
The application includes basic error handling mechanisms such as try-catch blocks to catch and handle exceptions. It's essential to handle errors gracefully to avoid crashing the application and to log errors for debugging and maintenance purposes.
I use build-in logging system of Java (java.util.logging) to log errors and information messages.
To ensure the robustness and reliability of the application, it's crucial to write unit tests and integration tests. Using testing frameworks like JUnit can help automate and streamline the testing process.
Some unit tests are written to test individual components of the application in isolation. For the database, I use H2 database in memory to test the repository.
This project is licensed under the MIT License. See the LICENSE file for details.