Read the 3 input files reports.json, reports.csv, reports.xml and output a combined CSV file with the following characteristics:
- The same column order and formatting as reports.csv
- All report records with packets-serviced equal to zero should be excluded
- records should be sorted by request-time in ascending order
Additionally, the application should print a summary showing the number of records in the output file associated with each service-guid.
Please provide source, documentation on how to run the program and an explanation on why you chose the tools/libraries used.
My submission was build with Apache Maven.
The project contains 4 Java classes:
DataMerge
- The main executable class that handles data merging, filtering, and sorting.Report
- Contains builder and other methods associated with individual report entries.FileReader
- Methods for reading CSV, JSON, and XML reports files.FileWriter
- Methods for writing reports to a CSV file.
Two external libraries were used to streamline file I/O:
- Apache Commons IO - 2.11.0
The commons-io library is used in the project for writing data to a CSV file. I chose this library becuase it had great documentation, comes from a trusted publisher, and is one of the most popular IO Java libraries.
- Org.Json - 20220320
This project uses the org.json library for converting strings read from CSV, JSON, and XML files into JSON objects and JSON arrays.
The JSON data created using the library simplifies data merging and parsing into Report
instances.
I chose this library due to its simple implementation, lack of external dependencies and because it is consistently maintained/updated.
Clone this repository to your target directory with:
git clone [email protected]:gregolive/datamerge.git
- From IDE (IntelliJ IDEA shown)
Launch the project in an IDE from the /solution directory and open the DataMerge.java
class from within /src/main/java.
Click run and the program will print the packets-serviced data to the deployment console.
Locate the mergedReports.csv
output file at /src/main/resources.
- From Command Line/Terminal
Navigate to the solution directory within the datamerge project folder.
Run the program with:
java -jar out/artifacts/solution_jar/solution.jar
The program will print the packets-serviced data to the open CLI and save the mergedReports.csv
output file to /src/main/resources.