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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ROUTE_SERVICE_ENDPOINT="http://0.0.0.0:8888"
DATABASE_URL="jdbc:postgresql://host:port/postgres?user=postgres&password=password"
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# InAndOut-Route-Service

## Setup

This project uses git submodules for API modelling. To ensure the project builds correctly, initialize the submodules when cloning:

```bash
git clone --recurse-submodules <repo-url>
```

Alternatively, if you've already cloned the repository, run:

```bash
git submodule update --init --recursive
```

## Build

To build the project, use the Gradle wrapper:

```bash
./gradlew build
```

It is recommended to install the [Smithy CLI](https://smithy.io/2.0/guides/smithy-cli/cli_installation.html) for diverse model checks and validation.
116 changes: 45 additions & 71 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,96 +1,70 @@
plugins {
java
application
id("org.springframework.boot") version "4.0.3"
id("io.spring.dependency-management") version "1.1.7"
id("org.graalvm.buildtools.native") version "0.11.4"
}
group = "com.shopping.inandout"
version = "0.0.1"
description = "A RESTful web service for handling customer queries and computing TSP solutions"

java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}

application {
mainClass = "com.shopping.inandout.routeservice.RouteServiceApplication"
plugins {
`java-library`
application
id("software.amazon.smithy.gradle.smithy-base")
jacoco
}

configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
application {
mainClass = "com.shopping.inandout.routeservice.RouteServiceWrapper"
}

group = "com.shopping.inandout"
version = "0.0.1-SNAPSHOT"
description = "A RESTful web service for handling customer queries and computing TSP solutions"

repositories {
mavenCentral()
mavenLocal()
}

val smithyJavaVersion: String by project

dependencies {
implementation("software.amazon.smithy.java:client-core:0.0.3")
implementation("software.amazon.smithy.java.codegen:plugins:$smithyJavaVersion")
// Core library for the Java client
// Adds the server implementation of the `RestJson1` protocol
implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion")
val smithyJavaVersion: String by project

// Smithy java model generation
smithyBuild("software.amazon.smithy.java.codegen:plugins:$smithyJavaVersion")
implementation(project(":InAndOut-API-Modelling"))

// Adds an HTTP server implementation based on netty
implementation("software.amazon.smithy.java:server-netty:$smithyJavaVersion")
// Adds the server implementation of the `RestJson1` protocol
implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion")

implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-restclient")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server")
implementation("org.springframework.boot:spring-boot-starter-security-oauth2-client")
implementation("org.springframework.boot:spring-boot-starter-session-jdbc")
implementation("org.springframework.boot:spring-boot-starter-webclient")
implementation("org.springframework.boot:spring-boot-starter-webmvc")
implementation("org.springframework.boot:spring-boot-starter-webservices")
compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-jdbc-test")
testImplementation("org.springframework.boot:spring-boot-starter-r2dbc-test")
testImplementation("org.springframework.boot:spring-boot-starter-restclient-test")
testImplementation("org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server-test")
testImplementation("org.springframework.boot:spring-boot-starter-security-oauth2-client-test")
testImplementation("org.springframework.boot:spring-boot-starter-security-test")
testImplementation("org.springframework.boot:spring-boot-starter-session-jdbc-test")
testImplementation("org.springframework.boot:spring-boot-starter-webclient-test")
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
testImplementation("org.springframework.boot:spring-boot-starter-webservices-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("com.h2database:h2")
testRuntimeOnly("io.r2dbc:r2dbc-h2")
}
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")

testCompileOnly("org.projectlombok:lombok:1.18.30")
testAnnotationProcessor("org.projectlombok:lombok:1.18.30")

afterEvaluate {
sourceSets {
main {
java.srcDir("build/java-client/java-client-codegen")
}
}
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testImplementation("org.mockito:mockito-junit-jupiter:3.11.2")
testImplementation("org.mockito:mockito-core:3.11.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.register<Exec>("smithyBuild") {
group = "build"
description = "Java models codegen from Smithy model."
commandLine("cmd", "/c", "smithy", "build",
"--config", ".\\InAndOut-API-Modelling\\smithy-build.json",
"--projection", "java-client",
"--output", "build/")
// Add generated source code to the compilation sourceSet
afterEvaluate {
val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen")
sourceSets.main.get().java.srcDir(serverPath)
}

tasks.named("compileJava") {
dependsOn("smithyBuild")
}

tasks.withType<Test> {
useJUnitPlatform()
}
tasks.named<Test>("test") {
useJUnitPlatform()

maxHeapSize = "1G"
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
9 changes: 6 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
rootProject.name = "routeservice"

pluginManagement {
val smithyGradleVersion: String by settings
plugins {
id("software.amazon.smithy.gradle.smithy-jar") version smithyGradleVersion
id("software.amazon.smithy.gradle.smithy-base") version smithyGradleVersion
id("software.amazon.smithy.gradle.smithy-jar").version(smithyGradleVersion)
id("software.amazon.smithy.gradle.smithy-base").version(smithyGradleVersion)
}

repositories {
Expand All @@ -12,4 +14,5 @@ pluginManagement {
}
}

rootProject.name = "routeservice"
// Subprojects
include("InAndOut-API-Modelling")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 changes: 9 additions & 0 deletions smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "1.0",
"plugins": {
"java-server-codegen": {
"service": "com.shopping.inandout#RouteService",
"namespace": "com.shopping.inandout"
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.shopping.inandout.routeservice;

import com.shopping.inandout.service.RouteService;

import com.shopping.inandout.routeservice.activities.CreateRouteActivity;
import com.shopping.inandout.routeservice.activities.DeleteRouteActivity;
import com.shopping.inandout.routeservice.activities.GetRouteActivity;

import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;

import software.amazon.smithy.java.server.Service;
import software.amazon.smithy.java.server.Server;

public class RouteServiceWrapper implements Runnable {
private static final Logger LOGGER = Logger.getLogger(RouteServiceWrapper.class.getName());

public static void main(String... args) throws RuntimeException {
new RouteServiceWrapper().run();
}

@Override
public void run() {
URI uri = URI.create(
System.getenv()
.getOrDefault("ROUTE_SERVICE_ENDPOINT", "http://0.0.0.0:8888"));

Service service = RouteService.builder()
.addCreateRouteOperation(new CreateRouteActivity())
.addDeleteRouteOperation(new DeleteRouteActivity())
.addGetRouteOperation(new GetRouteActivity())
.build();

Server server = Server.builder()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this can be cool https://dagger.dev/dev-guide/

.endpoints(uri)
.addService(service)
.build();

CountDownLatch latch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(
new Thread(() -> shutdownServer(server, latch)));

LOGGER.info("Starting server...");
server.start();

try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

private void shutdownServer(Server server, CountDownLatch latch) {
LOGGER.info("Stopping server...");
try {
server.shutdown().get();
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Error shutting down server", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
LOGGER.log(Level.SEVERE, "Error shutting down server", e);
} finally {
latch.countDown();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.shopping.inandout.routeservice.activities;

import com.shopping.inandout.service.CreateRouteOperation;
import com.shopping.inandout.model.CreateRouteInput;
import com.shopping.inandout.model.CreateRouteOutput;

import software.amazon.smithy.java.server.RequestContext;

public class CreateRouteActivity implements CreateRouteOperation {
public CreateRouteOutput createRoute(CreateRouteInput input, RequestContext context) {
throw new UnsupportedOperationException("Not (yet) supported operation");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.shopping.inandout.routeservice.activities;

import com.shopping.inandout.service.DeleteRouteOperation;
import com.shopping.inandout.model.DeleteRouteInput;
import com.shopping.inandout.model.DeleteRouteOutput;

import software.amazon.smithy.java.server.RequestContext;

public class DeleteRouteActivity implements DeleteRouteOperation {
public DeleteRouteOutput deleteRoute(DeleteRouteInput input, RequestContext context) {
throw new UnsupportedOperationException("Not (yet) supported operation");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.shopping.inandout.routeservice.activities;

import com.shopping.inandout.service.GetRouteOperation;
import com.shopping.inandout.model.GetRouteInput;
import com.shopping.inandout.model.GetRouteOutput;

import software.amazon.smithy.java.server.RequestContext;

public class GetRouteActivity implements GetRouteOperation {
public GetRouteOutput getRoute(GetRouteInput input, RequestContext context) {
throw new UnsupportedOperationException("Not (yet) supported operation");
}
}
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.shopping.inandout.routeservice;

import org.junit.jupiter.api.Test;

Check warning on line 3 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.junit.jupiter.api.Test'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY80w&open=AZ0mjH8nM7VHBcxZY80w&pullRequest=9
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;

Check warning on line 5 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.mockito.Mock'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY80x&open=AZ0mjH8nM7VHBcxZY80x&pullRequest=9
import org.mockito.junit.jupiter.MockitoExtension;
import software.amazon.smithy.java.server.Server;

Check warning on line 7 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'software.amazon.smithy.java.server.Server'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY80y&open=AZ0mjH8nM7VHBcxZY80y&pullRequest=9

import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;

Check warning on line 10 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.util.concurrent.CompletableFuture'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY80z&open=AZ0mjH8nM7VHBcxZY80z&pullRequest=9
import java.util.concurrent.CountDownLatch;

Check warning on line 11 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.util.concurrent.CountDownLatch'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY800&open=AZ0mjH8nM7VHBcxZY800&pullRequest=9
import java.util.concurrent.ExecutionException;

Check warning on line 12 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.util.concurrent.ExecutionException'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY801&open=AZ0mjH8nM7VHBcxZY801&pullRequest=9

import static org.junit.jupiter.api.Assertions.assertEquals;

Check warning on line 14 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.junit.jupiter.api.Assertions.assertEquals'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY802&open=AZ0mjH8nM7VHBcxZY802&pullRequest=9
import static org.junit.jupiter.api.Assertions.assertTrue;

Check warning on line 15 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.junit.jupiter.api.Assertions.assertTrue'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY803&open=AZ0mjH8nM7VHBcxZY803&pullRequest=9
import static org.mockito.Mockito.mock;

Check warning on line 16 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.mockito.Mockito.mock'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY804&open=AZ0mjH8nM7VHBcxZY804&pullRequest=9
import static org.mockito.Mockito.verify;

Check warning on line 17 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.mockito.Mockito.verify'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY805&open=AZ0mjH8nM7VHBcxZY805&pullRequest=9
import static org.mockito.Mockito.when;

Check warning on line 18 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'org.mockito.Mockito.when'.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY806&open=AZ0mjH8nM7VHBcxZY806&pullRequest=9

@ExtendWith(MockitoExtension.class)
class RouteServiceWrapperTest {

Check failure on line 21 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add some tests to this class.

See more on https://sonarcloud.io/project/issues?id=InAndOut-Stack_InAndOut-Backend&issues=AZ0mjH8nM7VHBcxZY80v&open=AZ0mjH8nM7VHBcxZY80v&pullRequest=9
}