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
721 changes: 721 additions & 0 deletions ORACLE_LINUX_DEPLOYMENT.md

Large diffs are not rendered by default.

417 changes: 356 additions & 61 deletions README.md

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.oraclequantapi</groupId>
<artifactId>oraclequantapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<name/>
<description/>
<url/>
Expand All @@ -35,6 +35,23 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

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

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<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
@@ -0,0 +1,12 @@
package com.example.pkc_api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class PackageMeasurementApiApplication {

public static void main(String[] args) {
SpringApplication.run(PackageMeasurementApiApplication.class, args);
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/example/pkc_api/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.pkc_api.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*") // TODO: Restrict this for production.
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.pkc_api.controller;


import com.example.pkc_api.dto.UpdateHistoryRequest;
import com.example.pkc_api.entity.SequenceHistory;
import com.example.pkc_api.service.HistoryService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/history")
public class HistoryController {

private final HistoryService historyService;

public HistoryController(HistoryService historyService) {
this.historyService = historyService;
}

@GetMapping
public List<SequenceHistory> getAllHistory() {
return historyService.getAllHistory();
}

@GetMapping("/{id}")
public SequenceHistory getHistoryById(@PathVariable UUID id) {
return historyService.getHistoryById(id);
}

@PatchMapping("/{id}")
public SequenceHistory updateHistory(
@PathVariable UUID id,
@RequestBody UpdateHistoryRequest request
) {
return historyService.updateHistory(id, request);
}

@PutMapping("/{id}")
public SequenceHistory replaceHistory(
@PathVariable UUID id,
@RequestBody UpdateHistoryRequest request
) {
return historyService.updateHistory(id, request);
}

@DeleteMapping
public String clearHistory() {
historyService.clearHistory();
return "History cleared successfully.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.pkc_api.controller;


import com.example.pkc_api.service.HistoryService;
import com.example.pkc_api.service.MeasurementConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MeasurementController {

private static final Logger log = LoggerFactory.getLogger(MeasurementController.class);

private final MeasurementConverter measurementConverter;
private final HistoryService historyService;

public MeasurementController(MeasurementConverter measurementConverter, HistoryService historyService) {
this.measurementConverter = measurementConverter;
this.historyService = historyService;
}

@GetMapping("/convert-measurements")
public List<Integer> convertMeasurements(
@RequestParam String input
) {
List<Integer> output = measurementConverter.convertMeasurements(input);

historyService.saveHistory(input, output.toString());
log.info("Converted measurement inputLength={} output={}", input.length(), output);

return output;
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/example/pkc_api/dto/UpdateHistoryRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.pkc_api.dto;

public class UpdateHistoryRequest {

private String input;
private String output;

public String getInput() {
return input;
}

public String getOutput() {
return output;
}

public void setInput(String input) {
this.input = input;
}

public void setOutput(String output) {
this.output = output;
}
}
65 changes: 65 additions & 0 deletions src/main/java/com/example/pkc_api/entity/SequenceHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.pkc_api.entity;


import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import java.time.LocalDateTime;
import java.util.UUID;

@Entity
@Table(name = "sequence_history")
@SuppressWarnings("unused")
public class SequenceHistory {

@Id
@Column(nullable = false, updatable = false)
private UUID id = UUID.randomUUID();

private LocalDateTime timestamp;

@Column(length = 2000)
private String input;

@Column(length = 2000)
private String output;

public SequenceHistory() {
}

public SequenceHistory(LocalDateTime timestamp, String input, String output) {
this.timestamp = timestamp;
this.input = input;
this.output = output;
}

public UUID getId() {
return id;
}

public LocalDateTime getTimestamp() {
return timestamp;
}

public String getInput() {
return input;
}

public String getOutput() {
return output;
}

public void setTimestamp(LocalDateTime timestamp) {
this.timestamp = timestamp;
}

public void setInput(String input) {
this.input = input;
}

public void setOutput(String output) {
this.output = output;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.pkc_api.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.UUID;

@ResponseStatus(HttpStatus.NOT_FOUND)
public class HistoryRecordNotFoundException extends RuntimeException {

public HistoryRecordNotFoundException(UUID id) {
super("History record not found with id: " + id);
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/example/pkc_api/parser/EncodedNumberParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.pkc_api.parser;

import org.springframework.stereotype.Component;

@Component
public class EncodedNumberParser implements NumberParser {

@Override
public ParsedNumber parse(String input, int startIndex) {
if (input == null || startIndex >= input.length()) {
return new ParsedNumber(0, startIndex);
}

char current = input.charAt(startIndex);

if (isContinuationCharacter(current)) {
return parseMultiCharacterNumber(input, startIndex);
}

int value = getCharacterValue(current);
return new ParsedNumber(value, startIndex + 1);
}

private ParsedNumber parseMultiCharacterNumber(String input, int index) {
int total = 0;

while (index < input.length() && isContinuationCharacter(input.charAt(index))) {
total += 26;
index++;
}

if (index < input.length()) {
total += getCharacterValue(input.charAt(index));
index++;
}

return new ParsedNumber(total, index);
}

private int getCharacterValue(char character) {
character = Character.toLowerCase(character);

if (character >= 'a' && character <= 'z') {
return character - 'a' + 1;
}

return 0;
}

private boolean isContinuationCharacter(char character) {
return Character.toLowerCase(character) == 'z';
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/example/pkc_api/parser/NumberParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.pkc_api.parser;

public interface NumberParser {

ParsedNumber parse(String input, int startIndex);
}
20 changes: 20 additions & 0 deletions src/main/java/com/example/pkc_api/parser/ParsedNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.pkc_api.parser;

public class ParsedNumber {

private final int value;
private final int nextIndex;

public ParsedNumber(int value, int nextIndex) {
this.value = value;
this.nextIndex = nextIndex;
}

public int getValue() {
return value;
}

public int getNextIndex() {
return nextIndex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.pkc_api.repository;


import com.example.pkc_api.entity.SequenceHistory;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.UUID;

public interface SequenceHistoryRepository extends JpaRepository<SequenceHistory, UUID> {
}
Loading