-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FSADT1-1363): backend fuzzy match for individuals (#996)
* feat(FSADT1-1363): adding new endpoint and cleaning old code * chore(FSADT1-1363): changing testcontainer for oracle changing it due to the issues with Mac M2 chip. Increased the timeout to allow the oracle instance to spin up properly * chore(FSADT1-1363): updating test data updating test data for oracle * feat(FSADT1-1363): fuzzy match for individuals initial commit with some of the heavy lifting. not final * chore(FSADT1-1363): adding temporary api auth this entry is temporary and it will be changed before final push * feat(FSADT1-1363): updated api auth to matches * chore(FSADT1-1363): refactoring matcher code Refactored the code to allow easy to use on next iterations * test(FSADT1-1363): adding tests * chore: code cleanup * feat(FSADT1-1363): setting flag to allow match endpoint to work * feat(FSADT1-1363): add fe stub * chore(FSADT1-1363): code refactor * chore(FSADT1-1363): updating oracle sql files * fix(FSADT1-1363): mergind and rebasing * fix(FSADT1-1363): fixed branch due to dto changes * test(FSADT1-1363): updating test
- Loading branch information
1 parent
4b733d4
commit bf1dcd3
Showing
33 changed files
with
2,711 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
backend/src/main/java/ca/bc/gov/app/controller/client/ClientMatchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ca.bc.gov.app.controller.client; | ||
|
||
import ca.bc.gov.app.dto.client.ClientSubmissionDto; | ||
import ca.bc.gov.app.service.client.ClientMatchService; | ||
import io.micrometer.observation.annotation.Observed; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* This class is a REST controller for client matching operations. | ||
* It uses the ClientMatchService to perform the matching operations. | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/api/clients/matches", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Observed | ||
public class ClientMatchController { | ||
|
||
/** | ||
* The ClientMatchService used to perform the matching operations. | ||
*/ | ||
private final ClientMatchService matchService; | ||
|
||
/** | ||
* This method is a POST endpoint for fuzzy matching clients. | ||
* It takes a ClientSubmissionDto object and a step number as input. | ||
* It uses the ClientMatchService to perform the matching operation. | ||
* | ||
* @param dto The ClientSubmissionDto object containing the client data to be matched. | ||
* @param step The step number for the matching operation. | ||
* @return A Mono<Void> indicating when the matching process is complete. | ||
*/ | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public Mono<Void> fuzzyMatchClients( | ||
@RequestBody ClientSubmissionDto dto, | ||
@RequestHeader(name = "X-STEP") int step | ||
) { | ||
return matchService.matchClients(dto, step); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 34 additions & 32 deletions
66
backend/src/main/java/ca/bc/gov/app/dto/client/ClientLocationDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
package ca.bc.gov.app.dto.client; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public record ClientLocationDto( | ||
List<ClientAddressDto> addresses, | ||
|
||
List<ClientContactDto> contacts | ||
) { | ||
|
||
public Map<String, Object> description() { | ||
return | ||
Stream.concat( | ||
contacts | ||
.stream() | ||
.map(ClientContactDto::description), | ||
addresses | ||
.stream() | ||
.map(ClientAddressDto::description) | ||
) | ||
.flatMap(map -> map.entrySet().stream()) | ||
.collect(Collectors.toMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue, | ||
(v1, v2) -> v2 | ||
) | ||
); | ||
} | ||
} | ||
package ca.bc.gov.app.dto.client; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import lombok.With; | ||
|
||
@With | ||
public record ClientLocationDto( | ||
List<ClientAddressDto> addresses, | ||
|
||
List<ClientContactDto> contacts | ||
) { | ||
|
||
public Map<String, Object> description() { | ||
return | ||
Stream.concat( | ||
contacts | ||
.stream() | ||
.map(ClientContactDto::description), | ||
addresses | ||
.stream() | ||
.map(ClientAddressDto::description) | ||
) | ||
.flatMap(map -> map.entrySet().stream()) | ||
.collect(Collectors.toMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue, | ||
(v1, v2) -> v2 | ||
) | ||
); | ||
} | ||
} |
46 changes: 24 additions & 22 deletions
46
backend/src/main/java/ca/bc/gov/app/dto/client/ClientSubmissionDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
package ca.bc.gov.app.dto.client; | ||
|
||
import java.util.Map; | ||
|
||
public record ClientSubmissionDto( | ||
ClientBusinessInformationDto businessInformation, | ||
ClientLocationDto location, | ||
String userId, | ||
String userLastName) { | ||
/** | ||
* Returns a map containing the description of the client's business information. | ||
* | ||
* @return a map with keys representing the description fields and corresponding values | ||
*/ | ||
public Map<String, Object> description(String userName) { | ||
Map<String, Object> descriptions = location.description(); | ||
descriptions.put("business", businessInformation.description()); | ||
descriptions.put("userName", userName); | ||
return descriptions; | ||
} | ||
|
||
} | ||
package ca.bc.gov.app.dto.client; | ||
|
||
import java.util.Map; | ||
import lombok.With; | ||
|
||
@With | ||
public record ClientSubmissionDto( | ||
ClientBusinessInformationDto businessInformation, | ||
ClientLocationDto location, | ||
String userId, | ||
String userLastName) { | ||
/** | ||
* Returns a map containing the description of the client's business information. | ||
* | ||
* @return a map with keys representing the description fields and corresponding values | ||
*/ | ||
public Map<String, Object> description(String userName) { | ||
Map<String, Object> descriptions = location.description(); | ||
descriptions.put("business", businessInformation.description()); | ||
descriptions.put("userName", userName); | ||
return descriptions; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/ca/bc/gov/app/dto/client/MatchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ca.bc.gov.app.dto.client; | ||
|
||
public record MatchResult( | ||
String field, | ||
String match, | ||
boolean fuzzy | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/ca/bc/gov/app/dto/client/StepMatchEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ca.bc.gov.app.dto.client; | ||
|
||
public enum StepMatchEnum { | ||
STEP1INDIVIDUAL, | ||
STEP1REGISTERED, | ||
STEP1UNREGISTERED, | ||
STEP1FIRSTNATION, | ||
STEP1FORESTS, | ||
STEP1GOVERNMENT, | ||
STEP2, | ||
STEP3 | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/ca/bc/gov/app/exception/DataMatchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ca.bc.gov.app.exception; | ||
|
||
import ca.bc.gov.app.dto.client.MatchResult; | ||
import java.util.List; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
@Getter | ||
@ResponseStatus(HttpStatus.CONFLICT) | ||
public class DataMatchException extends ResponseStatusException { | ||
|
||
private final transient List<MatchResult> matches; | ||
|
||
public DataMatchException(List<MatchResult> matches) { | ||
super(HttpStatus.CONFLICT, "Match found on existing data."); | ||
this.matches = matches; | ||
} | ||
|
||
} |
Oops, something went wrong.