Skip to content

Commit

Permalink
Merge pull request #81 from bcgov/feature/api-definition
Browse files Browse the repository at this point in the history
Feature/api definition
  • Loading branch information
mjunkin authored Nov 19, 2024
2 parents 6e12fc6 + 3c77c77 commit e712782
Show file tree
Hide file tree
Showing 18 changed files with 768 additions and 130 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/openshift-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
- uses: bcgov-nr/action-builder-ghcr@v2.2.0
with:
keep_versions: 50
build_context: .
build_file: ${{matrix.package}}/Dockerfile
package: ${{ matrix.package }}
tag: ${{ github.event.number }}
tag_fallback: latest
Expand Down
12 changes: 9 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

# "Provides the native-image executable. Used by the Maven and Gradle plugin from Quarkus to build linux64 executables"
FROM quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:jdk-21 AS build
ARG CONTEXT="backend"

# Image defaults to /project; copy controlled by .dockerignore
COPY --chown=quarkus:quarkus . ./
RUN chmod +x ./mvnw && ./mvnw package -Pnative -DskipTests
COPY --chown=quarkus:quarkus ./${CONTEXT} ./${CONTEXT}
COPY --chown=quarkus:quarkus ./buildtools ./buildtools
COPY ./pom.xml ./pom.xml
RUN chmod +x buildtools/mvnw && chmod +x ${CONTEXT}/mvnw && ./buildtools/mvnw clean install -N --batch-mode
RUN cd buildtools && ./mvnw clean install --batch-mode -DskipTests && cd ..
RUN cd ${CONTEXT} && ./mvnw clean package --batch-mode -DskipTests

# "A base image to run Quarkus native application using UBI Micro"
FROM quay.io/quarkus/quarkus-micro-image:2.0
Expand All @@ -16,6 +21,7 @@ EXPOSE 3000
HEALTHCHECK --interval=300s --timeout=3s CMD curl -f http://localhost:3000/ || exit 1

# Startup
COPY --chown=1001:root --from=build /project/target/*-runner /app
ARG CONTEXT="./backend"
COPY --chown=1001:root --from=build /project/${CONTEXT}/target/*-runner /app
USER 1001
CMD ["/app", "-Dquarkus.http.host=0.0.0.0"]
120 changes: 62 additions & 58 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,46 +256,49 @@
</dependencies>
<build>
<plugins>
<!--plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.9.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi/vdyp-file.swagger.yaml</inputSpec>
<generatorName>jaxrs-spec</generatorName>
<templateDirectory>${project.basedir}/src/main/resources/openapi/templates</templateDirectory>
<verbose>true</verbose>
<configOptions>
<library>quarkus</library>
<supportAsync>true</supportAsync>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<useTags>false</useTags>
<useSwaggerAnnotations>false</useSwaggerAnnotations>
<addCompileSourceRoot>true</addCompileSourceRoot>
<apiPackage>ca.bc.gov.nrs.vdyp.backend.v1.api</apiPackage>
<modelPackage>ca.bc.gov.nrs.vdyp.backend.v1.model</modelPackage>
<artifactId>vdyp-resource-layer</artifactId>
<artifactVersion>${project.version}</artifactVersion>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
<groupId>${project.groupId}</groupId>
<parentGroupId>ca.bc.gov.nrs.vdyp.api.v1</parentGroupId>
<parentArtifactId>vdyp-backend</parentArtifactId>
<parentVersion>0.0.1-SNAPSHOT</parentVersion>
<title>VDYP Resource Layer</title>
<useJakartaEe>true</useJakartaEe>
<useMicroProfileOpenAPIAnnotations>true</useMicroProfileOpenAPIAnnotations>
<useMutiny>true</useMutiny>
</configOptions>
</configuration>
</execution>
</executions>
</plugin-->
<!-- plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.9.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/openapi/vdyp-file.swagger.yaml</inputSpec>
<generatorName>jaxrs-spec</generatorName>
<templateDirectory>
${project.basedir}/src/main/resources/openapi/templates</templateDirectory>
<verbose>true</verbose>
<configOptions>
<library>quarkus</library>
<supportAsync>true</supportAsync>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<useTags>false</useTags>
<useSwaggerAnnotations>false</useSwaggerAnnotations>
<addCompileSourceRoot>true</addCompileSourceRoot>
<apiPackage>ca.bc.gov.nrs.vdyp.backend.v1.api</apiPackage>
<modelPackage>
ca.bc.gov.nrs.vdyp.backend.v1.model</modelPackage>
<artifactId>vdyp-resource-layer</artifactId>
<artifactVersion>${project.version}</artifactVersion>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
<groupId>${project.groupId}</groupId>
<parentGroupId>ca.bc.gov.nrs.vdyp.api.v1</parentGroupId>
<parentArtifactId>vdyp-backend</parentArtifactId>
<parentVersion>0.0.1-SNAPSHOT</parentVersion>
<title>VDYP Resource Layer</title>
<useJakartaEe>true</useJakartaEe>
<useMicroProfileOpenAPIAnnotations>true</useMicroProfileOpenAPIAnnotations>
<useMutiny>true</useMutiny>
</configOptions>
</configuration>
</execution>
</executions>
</plugin-->
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down Expand Up @@ -342,24 +345,25 @@
</executions>
</plugin>
<!--plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi/src/gen/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin-->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>
${project.build.directory}/generated-sources/openapi/src/gen/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin-->
</plugins>
<pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.ParameterDetailsMessage;
import ca.bc.gov.nrs.vdyp.backend.v1.model.ParameterDetailsMessageBuilder;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;

public class HelpApiService {

public Response helpGet(SecurityContext securityContext) throws NotFoundException {
private static final Logger logger = LoggerFactory.getLogger(HelpApiService.class);

public List<ParameterDetailsMessage> helpGet(SecurityContext securityContext) throws NotFoundException {

logger.info("<helpGet");

List<ParameterDetailsMessage> messageList = new ArrayList<>();

Expand Down Expand Up @@ -477,6 +483,6 @@ public Response helpGet(SecurityContext securityContext) throws NotFoundExceptio
)
);

return Response.ok().entity(messageList).build();
return messageList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand All @@ -18,6 +16,7 @@
import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.ProjectionScsvPostRequest;
import jakarta.validation.Valid;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.SecurityContext;

public class ProjectionApiService {
Expand All @@ -26,14 +25,13 @@ public class ProjectionApiService {

public Response projectionDcsvPost(
@Valid ProjectionDcsvPostRequest projectionDcsvPostRequest, SecurityContext securityContext
) throws NotFoundException {
// TODO Auto-generated method stub
return null;
) {
return Response.serverError().entity("Not supported").build();
}

public Response projectionHcsvPost(
@Valid ProjectionHcsvPostRequest projectionHcsvPostRequest, SecurityContext securityContext
) throws NotFoundException {
) {
try {
logger.info("<projectionHcsvPost");

Expand All @@ -42,18 +40,18 @@ public Response projectionHcsvPost(

ZipEntry yieldTableZipEntry = new ZipEntry("Output_YldTbl.csv");
zipOut.putNextEntry(yieldTableZipEntry);
var yieldTablePath = getResourceFile("Output_YldTbl.csv");
zipOut.write(Files.readAllBytes(yieldTablePath));
var yieldTable = getResourceFile("Output_YldTbl.csv");
zipOut.write(yieldTable.readAllBytes());

ZipEntry logOutputEntry = new ZipEntry("Output_Log.txt");
zipOut.putNextEntry(logOutputEntry);
var logFilePath = getResourceFile("Output_Log.txt");
zipOut.write(Files.readAllBytes(logFilePath));
var logFile = getResourceFile("Output_Log.txt");
zipOut.write(logFile.readAllBytes());

ZipEntry errorOutputZipEntry = new ZipEntry("Output_Error.txt");
zipOut.putNextEntry(errorOutputZipEntry);
var errorFilePath = getResourceFile("Output_Error.txt");
zipOut.write(Files.readAllBytes(errorFilePath));
var errorFile = getResourceFile("Output_Error.txt");
zipOut.write(errorFile.readAllBytes());

zipOut.close();

Expand All @@ -63,7 +61,7 @@ public Response projectionHcsvPost(

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH.mm.ss");
var outputFileName = "vdyp-output-" + java.time.LocalDateTime.now().format(formatter);
return Response.ok(resultingByteArray)
return Response.ok(resultingByteArray).status(Status.CREATED)
.header("content-disposition", "attachment;filename=\"" + outputFileName + "\"").build();

} catch (IOException | URISyntaxException e) {
Expand All @@ -75,14 +73,12 @@ public Response projectionHcsvPost(

public Response projectionScsvPost(
@Valid ProjectionScsvPostRequest projectionScsvPostRequest, SecurityContext securityContext
) throws NotFoundException {
// TODO Auto-generated method stub
return null;
) {
return Response.serverError().entity("Not supported").build();
}

private Path getResourceFile(String fileName) throws URISyntaxException {
private InputStream getResourceFile(String fileName) throws URISyntaxException {
String resourceFilePath = "VDYP7Console-sample-files/hcsv/vdyp-240/" + fileName;
URL resourceUrl = getClass().getClassLoader().getResource(resourceFilePath);
return Path.of(resourceUrl.toURI());
return getClass().getClassLoader().getResourceAsStream(resourceFilePath);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package ca.bc.gov.nrs.vdyp.backend.v1.gen.api;

import java.util.List;

import ca.bc.gov.nrs.vdyp.backend.v1.api.HelpApiService;
import ca.bc.gov.nrs.vdyp.backend.v1.api.NotFoundException;
import ca.bc.gov.nrs.vdyp.backend.v1.api.factories.HelpApiServiceFactory;
import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.ParameterDetailsMessage;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;

@Path("/v1/help")

Expand All @@ -21,17 +22,11 @@ public HelpApi(/* @Context ServletConfig servletContext */) {
HelpApiService delegate = null;

/*
if (servletContext != null) {
String implClass = servletContext.getInitParameter("HelpApi.implementation");
if (implClass != null && !"".equals(implClass.trim())) {
try {
delegate = (HelpApiService) Class.forName(implClass).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
*/
* if (servletContext != null) { String implClass = servletContext.getInitParameter("HelpApi.implementation");
* if (implClass != null && !"".equals(implClass.trim())) { try { delegate = (HelpApiService)
* Class.forName(implClass).getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new
* RuntimeException(e); } } }
*/

if (delegate == null) {
delegate = HelpApiServiceFactory.getHelpApi();
Expand Down Expand Up @@ -60,7 +55,8 @@ public HelpApi(/* @Context ServletConfig servletContext */) {
code = 200, message = "OK", response = ParameterDetailsMessage.class, responseContainer = "List"
) }
)
public Response helpGet(/* @Context SecurityContext securityContext */) throws NotFoundException {
public List<ParameterDetailsMessage> helpGet(/* @Context SecurityContext securityContext */)
throws NotFoundException {
return delegate.helpGet(null /* securityContext */);
}
}
Loading

0 comments on commit e712782

Please sign in to comment.