Skip to content

Commit

Permalink
feat(FSADT1-846): adding location details (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulo Gomes da Cruz Junior authored Aug 4, 2023
1 parent 87e4fdc commit b6afd14
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 79 deletions.
30 changes: 3 additions & 27 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# Current changelog
${{ steps.changelog.outputs.clean_changelog }}
comment_includes: Current changelog
comment_tag: "# Current changelog"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pr-greeting:
Expand Down Expand Up @@ -106,39 +106,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- uses: bcgov-nr/action-builder-ghcr@v1.1.0
- uses: bcgov-nr/action-builder-ghcr@v1.2.0
with:
package: init
package: api
build_context: ./
build_file: Dockerfile
tag: ${{ github.event.number }}
tag_fallback: test
token: ${{ secrets.GITHUB_TOKEN }}

- uses: graalvm/setup-graalvm@v1
with:
version: "22.3.0"
java-version: "17"
components: "native-image"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build App
run: |
chmod +x ./mvnw
./mvnw -Pnative clean spring-boot:build-image \
-Dspring-boot.build-image.imageName="${{ env.NAME }}" \
-Doci.revision=${{ github.event.number }}
- name: Log in to the Container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pushing
run: docker push ${{ env.NAME }}

tests-backend:
name: Backend Unit Tests
runs-on: ubuntu-22.04
Expand Down
34 changes: 21 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
FROM eclipse-temurin:17.0.8_7-jdk-alpine@sha256:3ecc5edd648f5d9c92e53e8eb6361cfcfaf626220f8308332f239dfb03418c1c

ENV LANG en_CA.UTF-8
ENV LANGUAGE en_CA.UTF-8
ENV LC_ALL en_CA.UTF-8
### Builder
FROM ghcr.io/graalvm/native-image-community:20-ol7 AS build

# Copy
WORKDIR /app
COPY pom.xml mvnw ./
COPY src ./src
COPY .mvn/ ./.mvn

# Build
RUN ./mvnw -Pnative native:compile

RUN apk --no-cache add openssl

COPY startup.sh .
### Deployer
FROM gcr.io/distroless/java-base:nonroot AS deploy
ARG PORT=3001

RUN chmod g+w /app && \
chmod g+x startup.sh && \
chmod g+w ${JAVA_HOME}/lib/security/cacerts
# Copy
WORKDIR /app
COPY --from=build /app/target/nr-forest-client-api ./nr-forest-client-api

# Non-privileged user
USER app
# User, port and health check
USER 1001
EXPOSE ${PORT}
HEALTHCHECK CMD curl -f http://localhost:${PORT}/actuator/health | grep '"status":"UP"'

ENTRYPOINT ["sh", "startup.sh"]
# Startup
ENTRYPOINT ["/app/nr-forest-client-api"]
2 changes: 1 addition & 1 deletion openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ objects:
claimName: ${NAME}-${ZONE}-${COMPONENT}
initContainers:
- name: ${NAME}-init
image: ${REGISTRY}/bcgov/${NAME}/init:${ZONE}
image: ghcr.io/bcgov/nr-forest-client/common:prod
imagePullPolicy: Always
env:
- name: ORACLEDB_HOST
Expand Down
59 changes: 28 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -187,27 +187,7 @@
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<image>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
<buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
<buildpack>gcr.io/paketo-buildpacks/image-labels</buildpack>
</buildpacks>
<env>
<BP_JVM_VERSION>19.0.2</BP_JVM_VERSION>
<BP_OCI_SOURCE>https://github.com/bcgov/nr-forest-client-api</BP_OCI_SOURCE>
<BP_OCI_VERSION>${project.version}</BP_OCI_VERSION>
<BP_OCI_DESCRIPTION>${project.description}</BP_OCI_DESCRIPTION>
<BP_OCI_LICENSES>Apache License, Version 2.0</BP_OCI_LICENSES>
<BP_OCI_REVISION>${oci.revision}</BP_OCI_REVISION>
<BP_OCI_TITLE>${project.name}</BP_OCI_TITLE>
<BP_OCI_CREATED>${timestamp}</BP_OCI_CREATED>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
</env>
</image>
<layers>
<includeLayerTools>false</includeLayerTools>
</layers>

</configuration>
</plugin>

Expand Down Expand Up @@ -426,15 +406,6 @@
<id>dev</id>
</profile>

<profile>
<id>native</id>
<properties>
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
<jacoco.skip>true</jacoco.skip>
</properties>
</profile>

<profile>
<id>all-tests</id>
<properties>
Expand All @@ -453,6 +424,32 @@
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>

<profile>
<id>macos</id>
<activation>
<os>
<family>mac</family>
<arch>aarch64</arch>
</os>
</activation>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<classifier>osx-aarch_64</classifier>
</dependency>
</dependencies>
</profile>

<profile>
<id>native</id>
<properties>
<build.profile.id>native</build.profile.id>
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
import ca.bc.gov.api.oracle.legacy.service.ClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -317,7 +320,14 @@ public Flux<ClientPublicViewDto> findByAcronym(
implementation = ClientLocationDto.class
)
)
)
),
headers = {
@Header(
name = "X-DATA-TOTAL",
schema = @Schema(implementation = Long.class),
description = "The total number of records found for the search"
)
}
)
}
)
Expand All @@ -332,11 +342,56 @@ public Flux<ClientLocationDto> listClientLocations(
Integer size,

@Parameter(
description = "Name of the column to be sorted by",
description = "ID of the client to filter by",
example = "00000001")
@PathVariable(value = "clientNumber")
String clientNumber
String clientNumber,
ServerHttpResponse serverResponse
) {
return locationService.listClientLocations(clientNumber, page, size);

return
locationService
.listClientLocations(clientNumber, page, size);
}

@GetMapping("/{clientNumber}/locations/{locationNumber}")
@Operation(
summary = "Get the client location based on client number and location id",
responses = {
@ApiResponse(
responseCode = "200",
description = "Returns a client location",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(
name = "ClientLocation",
implementation = ClientLocationDto.class
)
)
),
@ApiResponse(
responseCode = "404",
description = "If no client location found for that client number and location id",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = String.class),
examples = {@ExampleObject(value = "No client location found")}
)
)
}
)
public Mono<ClientLocationDto> getClientLocationDetails(
@Parameter(
description = "ID of the client to filter by",
example = "00000001")
@PathVariable(value = "clientNumber")
String clientNumber,
@Parameter(
description = "ID of the client location to filter by",
example = "00000001")
@PathVariable(value = "locationNumber")
String locationNumber
){
return locationService.getClientLocationDetails(clientNumber, locationNumber);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ca.bc.gov.api.oracle.legacy.entity;

import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class ClientLocationEntity {
private String expired;

@Column("RETURNED_MAIL_DATE")
LocalDate returnedMailDate;
LocalDateTime returnedMailDate;

@Column("TRUST_LOCATION_IND")
private String trusted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ Mono<ClientLocationEntity> findByClientNumberAndLocationCode(
String locationCode
);

Mono<Long> countByClientNumber(String clientNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import ca.bc.gov.api.oracle.legacy.dto.ClientLocationDto;
import ca.bc.gov.api.oracle.legacy.dto.YesNoEnum;
import ca.bc.gov.api.oracle.legacy.entity.ClientLocationEntity;
import ca.bc.gov.api.oracle.legacy.exception.ClientNotFoundException;
import ca.bc.gov.api.oracle.legacy.repository.ClientLocationRepository;
import java.time.LocalDateTime;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
@Slf4j
Expand All @@ -16,6 +23,10 @@ public class ClientLocationService {

private final ClientLocationRepository repository;

public Mono<Long> countClientLocations(String clientNumber) {
return repository.countByClientNumber(clientNumber);
}

public Flux<ClientLocationDto> listClientLocations(
String clientNumber,
Integer page,
Expand Down Expand Up @@ -43,9 +54,41 @@ public Flux<ClientLocationDto> listClientLocations(
entity.getEmail(),
YesNoEnum.fromValue(entity.getExpired()),
YesNoEnum.fromValue(entity.getTrusted()),
entity.getReturnedMailDate(),
Optional.ofNullable(entity.getReturnedMailDate()).map(
LocalDateTime::toLocalDate).orElse(null),
entity.getComment()
)
);
}

public Mono<ClientLocationDto> getClientLocationDetails(String clientNumber,
String locationNumber) {
return repository
.findByClientNumberAndLocationCode(clientNumber,locationNumber)
.map(entity -> new ClientLocationDto(
entity.getClientNumber(),
entity.getLocationCode(),
entity.getLocationName(),
entity.getCompanyCode(),
entity.getAddress1(),
entity.getAddress2(),
entity.getAddress3(),
entity.getCity(),
entity.getProvince(),
entity.getPostalCode(),
entity.getCountry(),
entity.getBusinessPhone(),
entity.getHomePhone(),
entity.getCellPhone(),
entity.getFaxNumber(),
entity.getEmail(),
YesNoEnum.fromValue(entity.getExpired()),
YesNoEnum.fromValue(entity.getTrusted()),
Optional.ofNullable(entity.getReturnedMailDate()).map(
LocalDateTime::toLocalDate).orElse(null),
entity.getComment()
)
)
.switchIfEmpty(Mono.error(new ClientNotFoundException("No client location found")));
}
}
Loading

0 comments on commit b6afd14

Please sign in to comment.