Skip to content

Commit

Permalink
feat(FSADT1-1390): First nartions - Part #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia committed Aug 7, 2024
1 parent dbd2932 commit 4d782e8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import ca.bc.gov.app.dto.client.ClientValueTextDto;
import ca.bc.gov.app.dto.opendata.Feature;
import ca.bc.gov.app.dto.opendata.OpenData;
import ca.bc.gov.app.repository.client.ProvinceCodeRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RequiredArgsConstructor
@Slf4j
Expand All @@ -19,6 +21,7 @@ public class OpenDataService {

private final BcMapsService bcMapsService;
private final SacService sacService;
private final ProvinceCodeRepository provinceCodeRepository;

public Flux<ClientDetailsDto> getFirstNationData(String nationName) {
return bcMapsService
Expand All @@ -29,40 +32,53 @@ public Flux<ClientDetailsDto> getFirstNationData(String nationName) {
log.info("Returning first nation data for nationName: {} {}", nationName,
openDataFeature)
)
.map(this::convertToDto);
.flatMap(this::convertToDto);
}

private ClientDetailsDto convertToDto(Feature openDataFeature) {
private Mono<ClientDetailsDto> convertToDto(Feature openDataFeature) {
return loadProvince("CA", openDataFeature.properties().officeProvince())
.map(provinceDto -> {
ClientAddressDto addressDto = new ClientAddressDto(
StringUtils.defaultIfBlank(
openDataFeature.properties().addressLine2(),
openDataFeature.properties().addressLine1()
),
StringUtils.EMPTY,
null,
new ClientValueTextDto("CA", "Canada"),
provinceDto,
openDataFeature.properties().officeCity(),
StringUtils.defaultIfBlank(
openDataFeature.properties().officePostalCode(),
StringUtils.EMPTY)
.replace(" ", StringUtils.EMPTY),
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
0,
"Mailing Address"
);

ClientAddressDto addressDto = new ClientAddressDto(
StringUtils.defaultIfBlank(
openDataFeature.properties().addressLine2(),
openDataFeature.properties().addressLine1()
),
StringUtils.isNotBlank(openDataFeature.properties().addressLine2())
? openDataFeature.properties().addressLine1() : StringUtils.EMPTY,
StringUtils.EMPTY,
new ClientValueTextDto("CA", "Canada"),
new ClientValueTextDto(openDataFeature.properties().officeProvince(), null),
openDataFeature.properties().officeCity(),
StringUtils.defaultIfBlank(openDataFeature.properties().officePostalCode(),
StringUtils.EMPTY).replace(" ", StringUtils.EMPTY),
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
0,
"Mailing Address"
);

return new ClientDetailsDto(
openDataFeature.properties().getNationName(),
openDataFeature.properties().getNationId() + "",
true,
addressDto.isValid() ? List.of(addressDto) : List.of(),
List.of()
);
return new ClientDetailsDto(
openDataFeature.properties().getNationName(),
openDataFeature.properties().getNationId() + "",
true,
addressDto.isValid() ? List.of(addressDto) : List.of(),
List.of()
);
});
}

private Mono<ClientValueTextDto> loadProvince(String countryCode, String province) {
return
provinceCodeRepository
.findByCountryCodeAndProvinceCode(countryCode, province)
.map(
entity -> new ClientValueTextDto(entity.getProvinceCode(), entity.getDescription())
)
.defaultIfEmpty(new ClientValueTextDto(province, province));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import type {
FormDataDto,
} from "@/dto/ApplyClientNumberDto";
import type {
BusinessSearchResult,
CodeNameType,
IdentificationCodeNameType,
BusinessSearchResult
} from "@/dto/CommonTypesDto";
import { exportAddress } from "@/helpers/DataConversors";
// Importing validators
import {
getValidations,
Expand Down Expand Up @@ -56,14 +55,6 @@ const validation = reactive<Record<string, boolean>>({
businessName: !!formData.value.businessInformation.businessName,
});
watch(
() => formData.value.businessInformation.firstName,
(value) => {
// copy the firstName into the first contact
//formData.value.location.contacts[0].firstName = value;
}
);
const checkValid = () =>
Object.values(validation).reduce(
(accumulator: boolean, currentValue: boolean) =>
Expand Down Expand Up @@ -94,7 +85,6 @@ const showDetailsLoading = ref<boolean>(false);
watch([autoCompleteResult], () => {
if (autoCompleteResult.value && autoCompleteResult.value.code) {
console.log("Test " + JSON.stringify(autoCompleteResult.value));
showDetailsLoading.value = true;
}
firstNationControl.value = false;
Expand All @@ -110,19 +100,18 @@ const parseSelectedNation = (
) => {
if (selectedNation) {
validation.businessName = true;
formData.value.location.addresses = exportAddress(
selectedNation.addresses
);
}
return selectedNation;
};
const mapFirstNationInfo = (firstNations: ForestClientDetailsDto[]) => {
let maapedFirstNations: any[];
maapedFirstNations = firstNations.map((v) => ({
const mapFirstNationInfo = (firstNations: ForestClientDetailsDto[] = []) => {
return firstNations.map((v) => ({
...v,
code: v.id,
}));
return maapedFirstNations;
};
</script>
Expand Down
4 changes: 2 additions & 2 deletions frontend/stub/__files/response-opendata-autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"province": {
"value": "BC",
"text": null
"text": "British Columbia"
},
"city": "NORTH VANCOUVER",
"postalCode": "V7L4J5",
Expand All @@ -36,4 +36,4 @@
"addresses": [],
"contacts": []
}
]
]

0 comments on commit 4d782e8

Please sign in to comment.