Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FSADT1-751): updating dtos #83

Merged
merged 19 commits into from
Oct 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/reusable-tests-be.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
-Dsonar.projectKey=bcgov_nr-forest-client-commons
-Dsonar.coverage.jacoco.xmlReportPaths=target/coverage-reports/merged-test-report/jacoco.xml
-Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml
-Dsonar.coverage.exclusions= **/dto/**,**/*$*Builder*,**/LogUtil*
-Dsonar.coverage.exclusions= **/dto/**,**/*$*Builder*
sonar_token: ${{ secrets.SONAR_TOKEN_COMMONS }}
triggers: ('core/')

Expand Down
6 changes: 3 additions & 3 deletions certextractor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ LABEL org.opencontainers.image.vendor="Government of British Columbia"
LABEL org.opencontainers.image.description="Extracts the Oracle Database Client certificates from the Oracle connection and adds them to the Java Truststore."
LABEL org.opencontainers.image.base.name="eclipse-temurin:17.0.11_9-jdk-alpine"

ENV LANG en_CA.UTF-8
ENV LANGUAGE en_CA.UTF-8
ENV LC_ALL en_CA.UTF-8
ENV LANG=en_CA.UTF-8
ENV LANGUAGE=en_CA.UTF-8
ENV LC_ALL=en_CA.UTF-8

WORKDIR /app

Expand Down
37 changes: 32 additions & 5 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@
<sonar.coverage.exclusions>
**/dto/**,
**/*$*Builder*,
**/LogUtil*
</sonar.coverage.exclusions>
<sonar.java.checkstyle.reportPaths>target/checkstyle-result.xml</sonar.java.checkstyle.reportPaths>

<junit-jupiter-api.version>5.9.1</junit-jupiter-api.version>
<junit-platform.version>1.9.1</junit-platform.version>
<assertj.version>3.24.2</assertj.version>
<junit-jupiter-api.version>5.10.5</junit-jupiter-api.version>
<oci.revision>${project.version}</oci.revision>
<assertj-core.version>3.25.3</assertj-core.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -80,6 +78,36 @@
<artifactId>swagger-annotations</artifactId>
<version>2.2.25</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter-api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -117,7 +145,6 @@
<excludes>
<exclude>**/dto/**</exclude>
<exclude>**/*$*Builder*</exclude>
<exclude>**/LogUtil*</exclude>
</excludes>
</configuration>
<executions>
Expand Down
52 changes: 29 additions & 23 deletions core/src/main/java/ca/bc/gov/app/dto/ValidationError.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package ca.bc.gov.app.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.With;

@Schema(
description = "Represents a validation error during submission",
title = "ValidationError",
example = """
{
"fieldId": "person.name",
"errorMsg": "Name is required"
}"""
)
@With
public record ValidationError(
@Schema(description = "The field id that failed validation", example = "person.name")
String fieldId,
@Schema(description = "The error message for that specific field", example = "Name is required")
String errorMsg
) {

}
package ca.bc.gov.app.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.With;
import org.apache.commons.lang3.StringUtils;

@Schema(
description = "Represents a validation error during submission",
title = "ValidationError",
example = """
{
"fieldId": "person.name",
"errorMsg": "Name is required"
}"""
)
@With
public record ValidationError(
@Schema(description = "The field id that failed validation", example = "person.name")
String fieldId,
@Schema(description = "The error message for that specific field", example = "Name is required")
String errorMsg
) {

@JsonIgnore
public boolean isValid() {
return !StringUtils.isAllBlank(fieldId, errorMsg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Objects;
import lombok.With;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* Data Transfer Object (DTO) representing an address in the BC Registry.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@With
public record BcRegistryAddressDto(
String addressCity,
String addressCountry,
String addressRegion,
String deliveryInstructions,
String postalCode,
String streetAddress,
String streetAddressAdditional,
String addressType
) {

/**
* Checks if this object is equal to another object.
*
* @param o the object to compare with
* @return true if the objects are equal, false otherwise
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

BcRegistryAddressDto that = (BcRegistryAddressDto) o;

return new EqualsBuilder()
.append(addressCity, that.addressCity)
.append(addressCountry, that.addressCountry)
.append(addressRegion, that.addressRegion)
.append(postalCode, that.postalCode)
.append(streetAddress, that.streetAddress)
.isEquals();
}

/**
* Generates a hash code for this object.
*
* @return the hash code
*/
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(addressCity)
.append(addressCountry)
.append(addressRegion)
.append(postalCode)
.append(streetAddress)
.toHashCode();
}

/**
* Validates the address.
*
* @return true if the street address and postal code are not null, false otherwise
*/
public boolean isValid() {
return !Objects.isNull(streetAddress) && !Objects.isNull(postalCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import lombok.With;

/**
* Data Transfer Object (DTO) representing an alternate name in the BC Registry.
*/
@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryAlternateNameDto(
String entityType, // The type of entity
String identifier, // The identifier of the entity
String name, // The alternate name of the entity
ZonedDateTime registeredDate, // The date when the name was registered
LocalDate startDate // The start date of the alternate name
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.HashSet;
import java.util.Set;

/**
* Data Transfer Object (DTO) representing business addresses in the BC Registry.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryBusinessAdressesDto(
BcRegistryAddressDto mailingAddress, // The mailing address of the business
BcRegistryAddressDto deliveryAddress // The delivery address of the business
) {

/**
* Validates the business addresses.
*
* @return true if either the mailing address or the delivery address is not null, false otherwise
*/
public boolean isValid() {
return mailingAddress != null || deliveryAddress != null;
}

/**
* Retrieves a set of business addresses with their types.
*
* @return a set of business addresses with their types
*/
public Set<BcRegistryAddressDto> addresses() {
Set<BcRegistryAddressDto> addressDtoSet = new HashSet<>();
if (mailingAddress != null) {
addressDtoSet.add(mailingAddress.withAddressType("mailing"));
}
if (deliveryAddress != null) {
addressDtoSet.add(deliveryAddress.withAddressType("delivery"));
}
return addressDtoSet;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Comparator;
import java.util.List;
import lombok.With;

/**
* Data Transfer Object (DTO) representing a business in the BC Registry.
*/
@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryBusinessDto(
List<BcRegistryAlternateNameDto> alternateNames, // List of alternate names for the business
Boolean goodStanding,
// Indicates if the business is in good standing
Boolean hasCorrections, // Indicates if the business has corrections
Boolean hasCourtOrders, // Indicates if the business has court orders
Boolean hasRestrictions, // Indicates if the business has restrictions
String identifier, // The identifier of the business
String legalName, // The legal name of the business
String legalType, // The legal type of the business
String state // The state of the business
) {

/**
* Resolves and returns the legal name of the business. If alternate names are available, it
* returns the first registered alternate name. Otherwise, it returns the legal name.
*
* @return the resolved legal name of the business
*/
public String getResolvedLegalName() {

List<BcRegistryAlternateNameDto> names =
(alternateNames == null || alternateNames.isEmpty())
? List.of()
: alternateNames;

return
names
.stream()
.sorted(Comparator.comparing(BcRegistryAlternateNameDto::registeredDate))
.map(BcRegistryAlternateNameDto::name)
.findFirst()
.orElse(legalName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import lombok.With;

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryDocumentAccessRequestDto(
List<BcRegistryDocumentAccessTypeDto> documents
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.With;

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryDocumentAccessTypeDto(
@JsonProperty("type")
String documentType
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import lombok.With;

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryDocumentDto(
BcRegistryBusinessDto business,
BcRegistryOfficesDto offices,
List<BcRegistryPartyDto> parties
) {

public boolean isOwnedByPerson() {
List<BcRegistryPartyDto> localParties = parties == null ? List.of() : parties;
return localParties.stream().anyMatch(BcRegistryPartyDto::isPerson);
}

public BcRegistryPartyDto getProprietor() {
if (parties == null) {
return null;
}
return parties
.stream()
.filter(BcRegistryPartyDto::isProprietor)
.findFirst()
.orElse(null);
}

}
Loading
Loading