Skip to content

Commit

Permalink
feat(be:FSADT1-1575): First draft
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia committed Nov 19, 2024
1 parent 70e5b64 commit f13340b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ca.bc.gov.app.dto.bcregistry.ClientDetailsDto;
import ca.bc.gov.app.dto.client.ClientListDto;
import ca.bc.gov.app.dto.client.ClientLookUpDto;
import ca.bc.gov.app.dto.legacy.ForestClientDto;
import ca.bc.gov.app.exception.NoClientDataFound;
import ca.bc.gov.app.service.client.ClientLegacyService;
import ca.bc.gov.app.service.client.ClientService;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ClientController {
private final ClientLegacyService clientLegacyService;

@GetMapping("/{clientNumber}")
public Mono<ClientDetailsDto> getClientDetails(
public Mono<ClientDetailsDto> getClientDetailsByIncorporationNumber(
@PathVariable String clientNumber,
JwtAuthenticationToken principal
) {
Expand All @@ -45,14 +46,30 @@ public Mono<ClientDetailsDto> getClientDetails(
JwtPrincipalUtil.getUserId(principal)
);
return clientService
.getClientDetails(
.getClientDetailsByIncorporationNumber(
clientNumber,
JwtPrincipalUtil.getUserId(principal),
JwtPrincipalUtil.getBusinessId(principal),
JwtPrincipalUtil.getProvider(principal)
);
}

@GetMapping("/details/{clientNumber}")
public Mono<ForestClientDto> getClientDetailsByClientNumber(
@PathVariable String clientNumber,
JwtAuthenticationToken principal
) {
log.info("Requesting client details for client number {} from the client service. {}",
clientNumber,
JwtPrincipalUtil.getUserId(principal)
);
return clientService.getClientDetailsByClientNumber(
clientNumber,
JwtPrincipalUtil.getUserId(principal),
JwtPrincipalUtil.getBusinessId(principal),
JwtPrincipalUtil.getProvider(principal));
}

@GetMapping("/search")
public Flux<ClientListDto> fullSearch(
@RequestParam(required = false, defaultValue = "0") int page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* This class is responsible for interacting with the legacy API to fetch client data. It uses the
Expand Down Expand Up @@ -87,6 +88,28 @@ public Flux<ForestClientDto> searchLegacy(
registrationNumber, companyName, dto.clientNumber()));
}

public Mono<ForestClientDto> searchByClientNumber(
String clientNumber
) {
log.info("Searching for client number {} in legacy", clientNumber);

return
legacyApi
.get()
.uri(builder ->
builder
.path("/api/search/clientNumber")
.queryParam("clientNumber", clientNumber)
.build(Map.of())
)
.exchangeToMono(response -> response.bodyToMono(ForestClientDto.class))
.doOnNext(
dto -> log.info(
"Found Legacy data for in legacy with client number {}",
dto.clientNumber())
);
}

/**
* This method is used to search for a client in the legacy system using the client's ID and last
* name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ClientService {
* @param clientNumber the client number for which to retrieve details
* @return a Mono that emits a ClientDetailsDto object representing the details of the client
*/
public Mono<ClientDetailsDto> getClientDetails(
public Mono<ClientDetailsDto> getClientDetailsByIncorporationNumber(
String clientNumber,
String userId,
String businessId,
Expand Down Expand Up @@ -141,6 +141,16 @@ public Mono<ClientDetailsDto> getClientDetails(
"Unable to process request. This sole proprietor is not owned by a person"
)));
}

public Mono<ForestClientDto> getClientDetailsByClientNumber(
String clientNumber,
String userId,
String businessId,
String provider
) {
log.info("Loading details for {} {} {} {}", clientNumber, userId, businessId, provider);
return legacyService.searchByClientNumber(clientNumber);
}

/**
* Searches the BC Registry API for {@link BcRegistryFacetSearchResultEntryDto} instances matching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@Slf4j
Expand Down Expand Up @@ -73,6 +74,14 @@ public Flux<ForestClientDto> findByIdAndLastName(
log.info("Receiving request to search by ID {} and Last Name {}", clientId, lastName);
return service.findByIdAndLastName(clientId, lastName);
}

@GetMapping("/clientNumber")
public Mono<ForestClientDto> findByClientNumber(
@RequestParam String clientNumber
) {
log.info("Receiving request to search by ID {} and Last Name", clientNumber);
return service.findByClientNumber(clientNumber);
}

@GetMapping("/id/{idType}/{identification}")
public Flux<ForestClientDto> findByIdentification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,22 @@ public Flux<ForestClientDto> findByClientName(String clientName) {
dto.clientNumber(), dto.clientName())
);
}

public Mono<ForestClientDto> findByClientNumber(String clientNumber) {
log.info("Searching for client with number {}", clientNumber);

if (StringUtils.isBlank(clientNumber)) {
return Mono.error(new MissingRequiredParameterException("clientNumber"));
}

return forestClientRepository.findByClientNumber(clientNumber)
.map(forestClientMapper::toDto)
.doOnNext(
dto -> log.info("Found client with client number {}",
clientNumber,
dto.clientNumber())
);
}

public Flux<Pair<PredictiveSearchResultDto, Long>> complexSearch(String value, Pageable page) {
// This condition is for predictive search, and we will stop here if no query param is provided
Expand Down

0 comments on commit f13340b

Please sign in to comment.