Skip to content

Commit

Permalink
Merge branch 'main' into fix/fe/FSADT1-1086
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia authored Jan 4, 2024
2 parents cc903ed + 5a56a8c commit fa8e4f9
Show file tree
Hide file tree
Showing 173 changed files with 4,038 additions and 9,524 deletions.
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<jacoco.output.data>${project.build.directory}/coverage-reports</jacoco.output.data>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<testcontainers.version>1.19.3</testcontainers.version>
<testcontainers.version>1.19.1</testcontainers.version>
<junit-jupiter-api.version>5.9.1</junit-jupiter-api.version>
<junit-platform.version>1.9.1</junit-platform.version>
<oci.revision>${project.version}</oci.revision>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private ResponseCookie buildCookie(
return ResponseCookie
.from(cookieName, cookieValue)
.httpOnly(false)
.sameSite("None")
.sameSite(isLocal() ? "Lax" : "None")
.path("/")
.maxAge(Duration.ofSeconds(expiresInSeconds != null ? expiresInSeconds : 3600))
.secure(!isLocal())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.StringUtils;

@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryOfficerDto(
Expand All @@ -10,4 +11,8 @@ public record BcRegistryOfficerDto(
String middleInitial,
String partyType
) {

public boolean isPerson() {
return StringUtils.isNotBlank(partyType) && partyType.equalsIgnoreCase("Person");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ public boolean isMatch(
.stream()
.anyMatch(provided::equals);
}

public boolean isPerson(){
return officer != null && officer().isPerson();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ public enum ClientTypeCodeEnum {
ClientTypeCodeEnum(String description) {
this.description = description;
}

public static String as(String code) {
for (ClientTypeCodeEnum clientTypeCodeEnum : ClientTypeCodeEnum.values()) {
if (clientTypeCodeEnum.name().equals(code)) {
return clientTypeCodeEnum.description;
}
}
return code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ca.bc.gov.app.exception;

import ca.bc.gov.app.dto.legacy.ClientTypeCodeEnum;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.ResponseStatusException;

@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
public class UnsuportedClientTypeException extends ResponseStatusException {

public UnsuportedClientTypeException(String clientType) {
super(HttpStatus.NOT_ACCEPTABLE,
String.format("Client type %s is not supported at the moment",
ClientTypeCodeEnum.as(clientType)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import ca.bc.gov.app.exception.ClientAlreadyExistException;
import ca.bc.gov.app.exception.InvalidAccessTokenException;
import ca.bc.gov.app.exception.NoClientDataFound;
import ca.bc.gov.app.exception.UnableToProcessRequestException;
import ca.bc.gov.app.exception.UnsuportedClientTypeException;
import ca.bc.gov.app.repository.client.ClientTypeCodeRepository;
import ca.bc.gov.app.repository.client.ContactTypeCodeRepository;
import ca.bc.gov.app.repository.client.CountryCodeRepository;
Expand Down Expand Up @@ -102,29 +104,27 @@ public Mono<CodeNameDto> getCountryByCode(String countryCode) {
return countryCodeRepository
.findByCountryCode(countryCode)
.map(entity -> new CodeNameDto(entity.getCountryCode(),
entity.getDescription()));
entity.getDescription()));
}

/**
* Retrieves a client type by its unique code.
* This method queries the clientTypeCodeRepository to find a client type entity
* with the specified code. If a matching entity is found, it is converted to a
* {@code CodeNameDto} object containing the code and description, and wrapped
* in a Mono. If no matching entity is found, the Mono will complete without emitting
* any items.
* Retrieves a client type by its unique code. This method queries the clientTypeCodeRepository to
* find a client type entity with the specified code. If a matching entity is found, it is
* converted to a {@code CodeNameDto} object containing the code and description, and wrapped in a
* Mono. If no matching entity is found, the Mono will complete without emitting any items.
*
* @param code The unique code of the client type to retrieve.
* @return A Mono emitting a {@code CodeNameDto} if a matching client type is found, or an
* empty result if no match is found.
* @return A Mono emitting a {@code CodeNameDto} if a matching client type is found, or an empty
* result if no match is found.
* @see CodeNameDto
*/
public Mono<CodeNameDto> getClientTypeByCode(String code) {
return clientTypeCodeRepository
.findByCode(code)
.map(entity -> new CodeNameDto(entity.getCode(),
entity.getDescription()));
entity.getDescription()));
}

/**
* <p><b>List Provinces</b></p>
* <p>List provinces by country (which include states) by page with a defined size.
Expand Down Expand Up @@ -205,7 +205,17 @@ public Mono<ClientDetailsDto> getClientDetails(
)
)
.map(BcRegistryDocumentDto.class::cast)
.flatMap(buildDetails());

//if document type is SP and party contains only one entry that is not a person, fail
.filter(document ->
!("SP".equalsIgnoreCase(document.business().legalType())
&& document.parties().size() == 1
&& !document.parties().get(0).isPerson())
)
.flatMap(buildDetails())
.switchIfEmpty(Mono.error(new UnableToProcessRequestException(
"Unable to process request. This sole proprietor is not owner by a person"
)));
}

/**
Expand All @@ -227,7 +237,14 @@ public Flux<ClientLookUpDto> findByClientNameOrIncorporation(String value) {
entry.status(),
entry.legalType()
)
);
)
.flatMap(client ->{
if(List.of("A", "I", "S", "SP","RSP","USP").contains(client.legalType())){
return Mono.just(client);
}
return Mono.error(new UnsuportedClientTypeException(client.legalType()));
})
.doOnError(System.out::println);
}

/**
Expand Down Expand Up @@ -291,7 +308,8 @@ private Mono<ClientDetailsDto> buildAddress(
addressDto.addressCity(),
addressDto.postalCode().trim().replaceAll("\\s+", ""),
index.getAndIncrement(),
(addressDto.addressType() != null ? addressDto.addressType() : "").concat(" address").toUpperCase()
(addressDto.addressType() != null ? addressDto.addressType() : "").concat(
" address").toUpperCase()
)
)
.flatMap(address -> loadCountry(address.country().text()).map(address::withCountry))
Expand All @@ -303,6 +321,8 @@ private Mono<ClientDetailsDto> buildAddress(
.defaultIfEmpty(new ArrayList<>())
.flatMap(addresses ->
Flux.fromIterable(document.parties())
.filter(party ->
!"SP".equalsIgnoreCase(document.business().legalType()) || party.isPerson())
.map(party ->
new ClientContactDto(
null,
Expand Down Expand Up @@ -381,21 +401,21 @@ private Function<ForestClientDto, Mono<ForestClientDto>> triggerEmailDuplicatedC
String email, String userName) {

return legacy -> chesService.sendEmail(
"matched",
email,
"Client number application can’t go ahead",
legacy.description(userName),
null)
"matched",
email,
"Client number application can’t go ahead",
legacy.description(userName),
null)
.thenReturn(legacy);
}

private Mono<String> triggerEmail(EmailRequestDto emailRequestDto) {
return chesService.sendEmail(
emailRequestDto.templateName(),
emailRequestDto.email(),
emailRequestDto.subject(),
emailRequestDto.variables(),
null);
emailRequestDto.templateName(),
emailRequestDto.email(),
emailRequestDto.subject(),
emailRequestDto.variables(),
null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static <T extends Enum<T>> boolean isValidEnum(
}

if (!EnumUtils.isValidEnum(enumClass, value)) {
errors.rejectValue(field, String.format("%s has an invalid value", field));
errors.rejectValue(field, String.format("%s has an invalid value [%s]", field,value));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ca.bc.gov.app.dto.client.ClientLocationDto;
import ca.bc.gov.app.dto.client.ClientSubmissionDto;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -19,10 +20,11 @@
@Component
@RequiredArgsConstructor
public class ClientSubmitRequestValidator implements Validator {

private final RegisteredBusinessInformationValidator registeredBusinessInformationValidator;
private final UnregisteredBusinessInformationValidator unregisteredBusinessInformationValidator;
private final ClientLocationDtoValidator locationDtoValidator;

@Override
public boolean supports(Class<?> clazz) {
return ClientSubmissionDto.class.equals(clazz);
Expand All @@ -49,34 +51,38 @@ private void validateBusinessInformation(
return;
}
errors.pushNestedPath(businessInformationField);

String businessType = businessInformation.businessType();
if (StringUtils.isAllBlank(businessType)) {
errors.rejectValue("businessType", "You must choose an option");
errors.popNestedPath();
return;
}
else if (!EnumUtils.isValidEnum(BusinessTypeEnum.class, businessType)) {
} else if (!EnumUtils.isValidEnum(BusinessTypeEnum.class, businessType)) {
errors.rejectValue("businessType", String.format("%s has an invalid value", "Business type"));
errors.popNestedPath();
return;
}

String clientType = businessInformation.clientType();

if(StringUtils.isBlank(clientType)) {
if (StringUtils.isBlank(clientType)) {
errors.rejectValue("clientType", "Client does not have a type");
errors.popNestedPath();
return;
}

if (ApplicationConstant.REG_SOLE_PROPRIETORSHIP_CLIENT_TYPE_CODE.equals(clientType)
|| ApplicationConstant.UNREG_SOLE_PROPRIETORSHIP_CLIENT_TYPE_CODE.equals(clientType)
|| ApplicationConstant.INDIVIDUAL_CLIENT_TYPE_CODE.equals(clientType)
|| ApplicationConstant.UNREG_SOLE_PROPRIETORSHIP_CLIENT_TYPE_CODE.equals(clientType)
|| ApplicationConstant.INDIVIDUAL_CLIENT_TYPE_CODE.equals(clientType)
) {
validateBirthdate(businessInformation.birthdate(), errors);
}


if (!List.of("A", "I", "S", "USP", "RSP","SP").contains(clientType)) {
errors.rejectValue("businessType",
String.format("%s %s is not supported at the moment", "Business type",clientType));
}

errors.popNestedPath();

if (BusinessTypeEnum.U.toString().equals(businessType)) {
Expand All @@ -93,8 +99,7 @@ private void validateBirthdate(LocalDate birthdate, Errors errors) {
String dobFieldName = "birthdate";
if (birthdate == null) {
errors.rejectValue(dobFieldName, fieldIsMissingErrorMessage("Birthdate"));
}
else {
} else {
LocalDate minAgeDate = LocalDate.now().minusYears(19);
if (birthdate.isAfter(minAgeDate)) {
errors.rejectValue(dobFieldName, "Sole proprietorship must be at least 19 years old");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void validate(Object target, Errors errors) {
String businessNameField = "businessName";
ValidationUtils.rejectIfEmpty(errors, businessNameField,
fieldIsMissingErrorMessage(businessNameField));

// fails if businessName does not contain whitespace, Ex: forest1 should fail, but forest 1 should pass
String businessName = (String) errors.getFieldValue(businessNameField);
if (businessName != null && !businessName.matches(".*\\s+.*")) {
errors.rejectValue(businessNameField, "Business name must be composed of first and last name");
}
errors.popNestedPath();
}
}
Loading

0 comments on commit fa8e4f9

Please sign in to comment.