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

fix(FSADT1-1595): fixing missing contact code desc #1383

Merged
merged 10 commits into from
Jan 14, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public record ForestClientContactDto(
String clientLocnCode,
List<String> locationCode,
String contactCode,
String contactCodeDescription,
String contactName,
String businessPhone,
String secondaryPhone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.app.entity.client.ContactTypeCodeEntity;
import java.time.LocalDate;
import java.util.Set;
import org.springframework.data.domain.Pageable;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
Expand All @@ -25,4 +26,6 @@ public interface ContactTypeCodeRepository
Flux<ContactTypeCodeEntity> findActiveAt(LocalDate activeDate, Pageable pageable);

Mono<ContactTypeCodeEntity> findByOrDescription(String id, String description);

Flux<ContactTypeCodeEntity> findByContactTypeCodeIn(Set<String> contactTypeCodes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.bc.gov.app.dto.client.CodeNameDto;
import ca.bc.gov.app.dto.client.IdentificationTypeDto;
import ca.bc.gov.app.entity.client.ClientTypeCodeEntity;
import ca.bc.gov.app.entity.client.ContactTypeCodeEntity;
import ca.bc.gov.app.predicates.QueryPredicates;
import ca.bc.gov.app.repository.client.ClientTypeCodeRepository;
import ca.bc.gov.app.repository.client.ContactTypeCodeRepository;
Expand All @@ -13,6 +14,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -155,5 +157,14 @@ public Mono<CodeNameDto> getIdentificationTypeByCode(String idCode) {
entity.getDescription()));
}

public Mono<Map<String,String>> fetchContactTypesFromList(Set<String> contactTypes){

return contactTypeCodeRepository
.findByContactTypeCodeIn(contactTypes)
.collectMap(
ContactTypeCodeEntity::getContactTypeCode,
ContactTypeCodeEntity::getDescription
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ca.bc.gov.app.dto.client.ClientValueTextDto;
import ca.bc.gov.app.dto.client.EmailRequestDto;
import ca.bc.gov.app.dto.client.LegalTypeEnum;
import ca.bc.gov.app.dto.legacy.ForestClientContactDto;
import ca.bc.gov.app.dto.legacy.ForestClientDetailsDto;
import ca.bc.gov.app.dto.legacy.ForestClientDto;
import ca.bc.gov.app.exception.ClientAlreadyExistException;
Expand All @@ -28,15 +29,19 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand All @@ -48,6 +53,7 @@ public class ClientService {

private final ClientCountryProvinceService countryProvinceService;
private final BcRegistryService bcRegistryService;
private final ClientCodeService codeService;
private final ChesService chesService;
private final ClientLegacyService legacyService;
private final Predicate<BcRegistryAddressDto> isMultiAddressEnabled;
Expand Down Expand Up @@ -147,6 +153,7 @@ public Mono<ClientDetailsDto> getClientDetailsByIncorporationNumber(
public Mono<ForestClientDetailsDto> getClientDetailsByClientNumber(String clientNumber) {
return legacyService
.searchByClientNumber(clientNumber)
.flatMap(this::populateContactTypes)
.flatMap(forestClientDetailsDto -> Mono
.just(forestClientDetailsDto)
.filter(dto -> (StringUtils.isNotBlank(dto.corpRegnNmbr())))
Expand All @@ -158,6 +165,7 @@ public Mono<ForestClientDetailsDto> getClientDetailsByClientNumber(String client
.next()
)
.flatMap(documentMono -> populateGoodStandingInd(forestClientDetailsDto, documentMono))

.onErrorContinue(NoClientDataFound.class, (ex, obj) ->
log.error("No data found on BC Registry for client number: {}", clientNumber)
)
Expand All @@ -169,27 +177,6 @@ public Mono<ForestClientDetailsDto> getClientDetailsByClientNumber(String client
);
}

private Mono<ForestClientDetailsDto> populateGoodStandingInd(
ForestClientDetailsDto forestClientDetailsDto,
BcRegistryDocumentDto document
) {
Boolean goodStandingInd = document.business().goodStanding();
String goodStanding = BooleanUtils.toString(
goodStandingInd,
"Y",
"N",
StringUtils.EMPTY
);

log.info("Setting goodStandingInd for client: {} to {}",
forestClientDetailsDto.clientNumber(), goodStanding);

ForestClientDetailsDto updatedDetails =
forestClientDetailsDto.withGoodStandingInd(goodStanding);

return Mono.just(updatedDetails);
}

/**
* Searches the BC Registry API for {@link BcRegistryFacetSearchResultEntryDto} instances matching
* the given value and maps them to {@link ClientLookUpDto} instances.
Expand Down Expand Up @@ -268,6 +255,61 @@ public Mono<Void> triggerEmailDuplicatedClient(
.then();
}

private Mono<ForestClientDetailsDto> populateContactTypes(
ForestClientDetailsDto forestClientDetailsDto
) {

if(CollectionUtils.isEmpty(forestClientDetailsDto.contacts()))
return Mono.just(forestClientDetailsDto);

Set<String> contactCodes =
forestClientDetailsDto
.contacts()
.stream()
.filter(Objects::nonNull)
.map(ForestClientContactDto::contactCode)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());


return codeService
.fetchContactTypesFromList(contactCodes)
.map(map ->
forestClientDetailsDto
.withContacts(
forestClientDetailsDto
.contacts()
.stream()
.map(contact ->
contact.withContactCodeDescription(map.getOrDefault(contact.contactCode(), StringUtils.EMPTY))
)
.toList()
)
);
}


private Mono<ForestClientDetailsDto> populateGoodStandingInd(
ForestClientDetailsDto forestClientDetailsDto,
BcRegistryDocumentDto document
) {
Boolean goodStandingInd = document.business().goodStanding();
String goodStanding = BooleanUtils.toString(
goodStandingInd,
"Y",
"N",
StringUtils.EMPTY
);

log.info("Setting goodStandingInd for client: {} to {}",
forestClientDetailsDto.clientNumber(), goodStanding);

ForestClientDetailsDto updatedDetails =
forestClientDetailsDto.withGoodStandingInd(goodStanding);

return Mono.just(updatedDetails);
}

private Function<BcRegistryDocumentDto, Mono<ClientDetailsDto>> buildDetails() {
return document ->
buildAddress(
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/ClientDetailsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const formatCount = (count = 0) => {
};

const formatAddress = (location: ClientLocation) => {
const { addressOne, city, provinceCode, countryDesc, postalCode } = location;
const list = [addressOne, city, provinceCode, countryDesc, postalCode];
const { addressOne, city, province, country, postalCode } = location;
const list = [addressOne, city, province, country, postalCode];
return list.join(", ");
};

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ const openClientDetails = (clientCode: string) => {
const url = featureFlags.STAFF_CLIENT_DETAIL
? `/clients/details/${clientCode}`
: `https://${greenDomain}/int/client/client02MaintenanceAction.do?bean.clientNumber=${clientCode}`;
window.open(url, "_blank", "noopener");

if(featureFlags.STAFF_CLIENT_DETAIL)
window.open(url, "_self");
else
window.open(url, "_blank", "noopener");
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/client-details/ContactView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const faxNumber = computed(() => formatPhoneNumber(props.data.faxNumber));
<template>
<div :id="`contact-${index}-general-section`" class="flex-column-1_5rem margin-left-1_75rem">
<read-only-component label="Contact type" :id="`contact-${index}-contactType`">
<span class="body-compact-01">{{ data.contactTypeDesc }}</span>
<span class="body-compact-01">{{ data.contactCodeDescription }}</span>
</read-only-component>
<read-only-component label="Associated locations" :id="`contact-${index}-associatedLocations`">
<span class="body-compact-01">{{ associatedLocationsString }}</span>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/client-details/LocationView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const faxNumber = computed(() => formatPhoneNumber(props.data.faxNumber));
{{ data.addressOne }}
</span>
<span :id="`location-${indexString}-city-province`" class="body-compact-01">
{{ data.city }}, {{ data.provinceDesc }}
{{ data.city }}, {{ data.province }}
</span>
<span :id="`location-${indexString}-country`" class="body-compact-01">
{{ data.countryDesc }}
{{ data.country }}
</span>
<span :id="`location-${indexString}-postalCode`" class="body-compact-01">
{{ data.postalCode }}
Expand Down
Loading