Skip to content

mallemala/elemental_technical_test

Repository files navigation

Elemental Technical Test

This is a Spring Boot application developed for the Elemental Technical Test. It processes a pipe-delimited text file, validates the request IP address, and logs request details to an H2 database.

Prerequisites

  • Java 17
  • Docker (optional, for containerization)

Getting Started

1. Build the Application

First, ensure you have the Gradle wrapper generated (if not already):

gradle wrapper

Then, build the project:

./gradlew clean build

2. Run the Application

You can run the application using Gradle:

./gradlew bootRun

Or run the built JAR file:

java -jar build/libs/elemental-technical-test-0.0.1-SNAPSHOT.jar

The application will start on port 8080.

3. API Documentation (OpenAPI/Swagger)

Once the application is running, you can access the OpenAPI documentation at:

4. H2 Database Console

The application uses an in-memory H2 database. You can access the console at:

Usage

Process File Endpoint

URL: /process-file Method: POST Content-Type: multipart/form-data

Parameters:

  • file: The text file to process.

Example using cURL:

curl -F "file=@EntryFile.txt" http://localhost:8080/process-file

Sample EntryFile.txt content:

18148426-89e1-11ee-b9d1-0242ac120002|1X1D14|John Smith|Likes Apricots|Rides A Bike|6.2|12.1
3ce2d17b-e66a-4c1e-bca3-40eb1c9222c7|2X2D24|Mike Smith|Likes Grape|Drives an SUV|35.0|95.5
1afb6f5d-a7c2-4311-a92d-974f3180ff5e|3X3D35|Jenny Walters|Likes Avocados|Rides A Scooter|8.5|15.3

Get Request Logs Endpoint

URL: /logs Method: GET Content-Type: application/json

Example using cURL:

curl http://localhost:8080/logs

Docker

Build the Docker Image

docker build -t elemental-technical-test .

Run the Docker Container

docker run -p 8080:8080 elemental-technical-test

Features

  • File Processing: Parses a custom pipe-delimited file format.
  • IP Validation: Validates the request IP against ip-api.com. Blocks requests from China, Spain, USA, and specific ISPs (AWS, GCP, Azure).
  • Request Logging: Logs request details (IP, Country, ISP, Duration, Status) to the database.
  • OpenAPI: Auto-generated API documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors