Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Changelog

All notable changes to the Measurement Conversion API will be documented in this file.

---
## [1.0.0] - 2026-05-21
## [2.0.0] - 2026-05-25

### Added

* REST API for measurement sequence conversion (`/convert-measurements`)
* Oracle XE integration using Spring Data JPA
* Persistent history tracking in `CONVERSION_HISTORY` table
* Full History CRUD endpoints under `/input`
* Sequence parsing engine with counter-based tokenization
* Support for `'z'` chaining logic in decoding algorithm

### Changed

* Improved `SequenceService` logic for package decoding
* Refactored history update endpoints to correctly use `SequenceHistory`
* Enhanced logging for request tracing and debugging

### Fixed

* Fixed incorrect request body type in HistoryController (`SequenceHistory` instead of `Sequence`)
* Fixed update/patch logic consistency in `HistoryService`

### Security Notes

* Database credentials currently stored in `application.properties` (should be externalized in production)

---

## [1.0.0] - Initial Prototype

### Added

* Basic sequence parsing model
* In-memory sequence repository
* Initial REST controller structure

---

## Planned

* Input validation improvements
* Global exception handling (`@ControllerAdvice`)
* OpenAPI/Swagger documentation
* Docker support
* Authentication layer (JWT or Basic Auth)

---
224 changes: 163 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,163 @@
## Submission Instructions

To submit your Oracle JAVA Spring Boot Maven project as a solution, please follow these steps:

### Step 1: Install git on your PC
- Install "git" as shown in this tutorial: [How to install git](https://youtu.be/iYkLrXobBbA?si=_l0haibv_X9NpIjJ)
- Open command prompt and run
```bash
git version
```
- If you see the version, then git is successfully installed.

### Step 2: Fork the Repository
- Navigate to [this repository](https://github.com/CodelineAtyab/oraclequantapi) provided by Codeline.
- Click on the "Fork" button at the top-right corner of the page to create a copy of the repository under your own GitHub account.

### Step 3: Clone the Forked Repository
- Open your terminal or command prompt.
- Clone the forked repository to your local machine using the following command:
```bash
git clone https://github.com/your-username/repo-name.git
```

### Step 4: Create a new branch
- Navigate to the cloned repository directory
```bash
cd repo-name
```
- Create a new branch for your code submissions (Replace your-name with your name in your-name-submission-branch):
```bash
git checkout -b your-name-submission-branch
```


### Step 5: Add Your Code
- Implement the API

### Step 6: Commit your changes
- Run the following commands in order to commit your changes:
```bash
git add *
git commit -m "Meaningful commit message here"
```

### Step 7: Push Your Branch to GitHub
- Run the following commands to upload the changes to the forked github repository (Replace your-name with your name in your-name-submission-branch):
```bash
git push origin your-name-submission-branch
```

### Step 8: Create a Pull Request
- Go to your forked repository on GitHub.
- You should see a prompt to create a pull request. Click on "Compare & pull request".
- Provide a title and description for your pull request, then click "Create pull request".

### Step 9: Notify Codeline
- Notify on slack that you have created a PR for your solution.

## Note: If you face any issues in the process above, Please do the following:
- Watch [this youtube tutorial](https://www.youtube.com/watch?v=a_FLqX3vGR4)
- Contact Ikhlas or Atyab.
# Measurement Conversion API

A Spring Boot REST API that parses and converts encoded measurement sequences into numeric results and stores request history in an Oracle XE database.

---

## Overview

This service exposes endpoints to:

* Parse encoded measurement input strings
* Convert them into numeric package totals
* Store every request in an Oracle database
* Retrieve, update, and delete conversion history

---

## Setup

* Java 17
* Spring Boot 3.5.x
* Spring Web
* Spring Data JPA
* Oracle XE (JDBC)
* Maven

---

## API Endpoints

### Convert Measurements

**GET** `/convert-measurements?input={string}`

Converts encoded measurement input into numeric results.

**Example:**

```
GET /convert-measurements?input=abczz_a
```

**Response:**

```json
[3, 28]
```

---

### History API

Base path: `/input`

#### Get all history

```
GET /input
```

#### Get history by ID

```
GET /input/{id}
```

#### Full update (PUT)

```
PUT /input/{id}
```

#### Partial update (PATCH)

```
PATCH /input/{id}
```

#### Delete all history

```
DELETE /input
```

---

## Encoding Rules

* `a = 1, b = 2, ..., z = 26`
* `_ = 0`
* First character of each package = counter (number of value slots)
* `'z'` introduces chaining: adds 26 + next character value recursively

Example:

```
dz_a_a → 28
```

---

## Database Setup

Uses Oracle XE with JPA.

Table: `MEASUREMENT_HISTORY`

Fields:

* ID (UUID)
* TIMESTAMP
* SOURCE_IP_ADDRESS
* INPUT
* OUTPUT

---

## Configuration

Update `application.properties`:

```properties
spring.datasource.url=jdbc:oracle:thin:@<host>:1521/XEPDB1
spring.datasource.username=system
spring.datasource.password=your_password
```

---

## Run Application

```bash
mvn spring-boot:run
```

Or:

```bash
mvn clean package
java -jar target/measurement-conversion-2.0.0.jar
```

---

## Project Structure

* `controllers` → REST endpoints
* `services` → business logic
* `models` → domain + entity classes
* `repositories` → JPA + in-memory store

---

## Logging

* Request logging via SLF4J
* Debug logs for parsing and conversion steps

---

## License

Internal / educational use (update as needed).
24 changes: 19 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.14</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.oraclequantapi</groupId>
<artifactId>oraclequantapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>om.measurement</groupId>
<artifactId>measurement-conversion</artifactId>
<version>2.0.0</version>
<name/>
<description/>
<url/>
Expand All @@ -35,6 +36,19 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- JPA / Hibernate -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- Oracle JDBC driver -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = "com.oraclequantapi.oraclequantapi")
public class OraclequantapiApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.oraclequantapi.oraclequantapi.controllers;

import com.oraclequantapi.oraclequantapi.models.Sequence;
import com.oraclequantapi.oraclequantapi.models.SequenceHistory;
import com.oraclequantapi.oraclequantapi.services.HistoryService;
import com.oraclequantapi.oraclequantapi.services.SequenceService;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;


@RestController
@RequestMapping("/convert-measurements")
public class ConversionController {

private static final Logger logger = LoggerFactory.getLogger(ConversionController.class);

@Autowired
private SequenceService sequenceService;

@Autowired
private HistoryService historyService;

//endpoint "input"
@GetMapping
public ResponseEntity<List<Integer>> convertMeasurements(
@RequestParam("input") String input,
HttpServletRequest request) {

logger.info("GET /measurements?input='{}' | ip='{}'",
input, request.getRemoteAddr());

Sequence sequence = sequenceService.getSequence(input);
List<Integer> result = sequenceService.processSequence(sequence);

historyService.save(new SequenceHistory(
null,
LocalDateTime.now(),
request.getRemoteAddr(),
input,
result.toString()
));

return ResponseEntity.ok(result);
}
}
Loading