Skip to content

Commit

Permalink
feat: validation improvements (#428)
Browse files Browse the repository at this point in the history
* no message

* fix(fe/be):
- Fixed validation messages on the BE
- Fixed missing return in validation messages component
- Added missing validation in contacts section
- Refactored code in both FE and BE
- Beautified code

* fix(be):
- Fixed as per recommended (WhitespaceAround: '+' is not followed by whitespace.)

* feat(be):
- Cleaned and organized imports

* feat(fe/be):
- Improved code after code reviews

* feat/fix(be):
- Fixed unit testting bug
- Cleaned imports
- Beautified code for better readibility

* Revert "feat(be):"

This reverts commit 12b8122.

* fix(be):
- Made code reviews

* fix(be):
- Fixed code smell issues #1

* fix(be):
- Removed extra separation in import group to satisfy SonarCloud

* fix(be):
- Fixed code smell issues #2

* fix(be):
- Fixed code smell issues #3

* fix(be):
- Code reviews: Defined a constant instead of duplicating literal

* fix(be):
- Reverted change as I had it before

* fix(be):
- Fixed typo

* fix(be):
- Changed field to businessName as the incorporation number is hidden in the UI

* fix(be):
- Fixed based on code reviews standard
- Fixed code smells. Need to discuss this with the team as this doesn't make sense.

* feat(fe):
- Removed error msgs when value changes

* feat(BE): updating bc registry to use document requisition

* feat(fe):
- FSADT1-736

* fix(be):
- Changed wording as per suggested by Paulo

---------

Co-authored-by: Maria Martinez <[email protected]>
Co-authored-by: Maria Martinez <[email protected]>
  • Loading branch information
3 people authored Apr 12, 2023
1 parent 3a6e0b2 commit 645c19a
Show file tree
Hide file tree
Showing 27 changed files with 553 additions and 161 deletions.
13 changes: 13 additions & 0 deletions backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package ca.bc.gov.app;

import ca.bc.gov.app.dto.bcregistry.BcRegistryDocumentAccessRequestDto;
import ca.bc.gov.app.dto.bcregistry.BcRegistryDocumentAccessTypeDto;
import ca.bc.gov.app.dto.bcregistry.BcRegistryDocumentRequestBodyDto;
import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand All @@ -9,5 +13,14 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ApplicationConstant {
public static final String POSTGRES_ATTRIBUTE_SCHEMA = "nrfc";
public static final BcRegistryDocumentRequestBodyDto
BUSINESS_SUMMARY_FILING_HISTORY =
new BcRegistryDocumentRequestBodyDto(
new BcRegistryDocumentAccessRequestDto(
List.of(
new BcRegistryDocumentAccessTypeDto("BUSINESS_SUMMARY_FILING_HISTORY")
)
)
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryAddressDto(
Integer id,
String addressCity,
String addressCountry,
String addressRegion,
String addressType,
String deliveryInstructions,
String postalCode,
String streetAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package ca.bc.gov.app.dto.bcregistry;

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

@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryBusinessAdressesDto(
BcRegistryAddressDto mailingAddress,
BcRegistryAddressDto deliveryAddress
) {
public boolean isValid(){
return mailingAddress != null || deliveryAddress != null;
}

public Set<BcRegistryAddressDto> addresses(){
Set<BcRegistryAddressDto> addressDtoSet = new HashSet<>();
if(mailingAddress != null)
addressDtoSet.add(mailingAddress);
if(deliveryAddress != null)
addressDtoSet.add(deliveryAddress);
return addressDtoSet;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ca.bc.gov.app.dto.bcregistry;

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

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryBusinessDto(
Boolean goodStanding,
Expand Down
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,56 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.With;

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

/**
* Returns a mapping of addresses to sets of parties associated with those addresses. If the
* offices object is valid, adds all of its addresses to the mapping with an empty set of parties.
* For each valid party, adds it to the set of parties associated with its mailing or delivery
* address in the mapping.
*
* @return a mapping of addresses to sets of parties associated with those addresses
*/
public Map<BcRegistryAddressDto, Set<BcRegistryPartyDto>> matchOfficesParties() {

Map<BcRegistryAddressDto, Set<BcRegistryPartyDto>> results = new HashMap<>();

// If offices exist and are valid, add all their addresses to the results map
if (offices != null && offices.isValid()) {
offices.addresses().forEach(address -> results.put(address, new HashSet<>()));
}

// For each party, if it's valid and has a mailing or delivery address,
// add it to the set of parties associated with that address in the results map
for (BcRegistryPartyDto party : parties) {
if (!party.isValid()) {
continue;
}

BcRegistryAddressDto mailingAddress = party.mailingAddress();
if (mailingAddress != null) {
results.computeIfAbsent(mailingAddress, key -> new HashSet<>()).add(party);
}

BcRegistryAddressDto deliveryAddress = party.deliveryAddress();
if (deliveryAddress != null) {
results.computeIfAbsent(deliveryAddress, key -> new HashSet<>()).add(party);
}
}

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

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

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryDocumentRequestBodyDto(
BcRegistryDocumentAccessRequestDto documentAccessRequest
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ca.bc.gov.app.dto.bcregistry;

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

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryDocumentRequestDocumentDto(
String documentKey,
String documentType,
String fileName,
Long id
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 BcRegistryDocumentRequestResponseDto(
String businessIdentifier,
String businessName,
List<BcRegistryDocumentRequestDocumentDto> documents,
String paymentStatus,
String status
) {
}
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 lombok.With;

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryExceptionMessageDto(
String errorMessage,
String rootCause
) {
}
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;

@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryOfficerDto(
String email,
String firstName,
String lastName,
String middleInitial,
String partyType
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ca.bc.gov.app.dto.bcregistry;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.With;

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryOfficesDto(
BcRegistryBusinessAdressesDto businessOffice
) {
public Set<BcRegistryAddressDto> addresses() {
return Optional
.ofNullable(businessOffice)
.filter(BcRegistryBusinessAdressesDto::isValid)
.map(BcRegistryBusinessAdressesDto::addresses)
.orElse(Set.of());
}
public boolean isValid(){
return businessOffice != null && businessOffice.isValid();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 BcRegistryPartyDto(
BcRegistryAddressDto deliveryAddress,
BcRegistryAddressDto mailingAddress,
BcRegistryOfficerDto officer,
List<BcRegistryRoleDto> roles
) {
public boolean isValid() {
return officer != null && (mailingAddress != null || deliveryAddress != null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ca.bc.gov.app.dto.bcregistry;

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

@With
@JsonIgnoreProperties(ignoreUnknown = true)
public record BcRegistryRoleDto(
LocalDate appointmentDate,
LocalDate cessationDate,
String roleType
) {
public boolean active() {
return cessationDate == null || LocalDate.now().isBefore(cessationDate);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.bc.gov.app.dto.client;

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

@Schema(
description = "Client information contact",
Expand All @@ -17,6 +18,7 @@
"email": "[email protected]",
}"""
)
@With
public record ClientContactDto(
@Schema(description = "The type of contact",
example = "person")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface CountryCodeRepository extends ReactiveCrudRepository<CountryCod
Flux<CountryCodeEntity> findBy(Pageable pageable);

Mono<CountryCodeEntity> findByCountryCode(String code);
Mono<CountryCodeEntity> findByDescription(String description);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Mono<ProvinceCodeEntity> findByCountryCodeAndProvinceCode(String countryCode,
String provinceCode);

Mono<ProvinceCodeEntity> findByProvinceCode(String provinceCode);
Mono<ProvinceCodeEntity> findByDescription(String description);
}
Loading

0 comments on commit 645c19a

Please sign in to comment.