Skip to content

Commit

Permalink
feat(FSADT1-973): adding doing business as matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Nov 17, 2023
1 parent 7221eec commit 08b7861
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ca.bc.gov.app.repository.legacy;

import ca.bc.gov.app.entity.legacy.ClientDoingBusinessAsEntity;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Repository
Expand All @@ -12,4 +14,12 @@ public interface ClientDoingBusinessAsRepository extends
ReactiveSortingRepository<ClientDoingBusinessAsEntity, Integer> {

Mono<Boolean> existsByClientNumber(String clientNumber);

@Query("""
SELECT *
FROM THE.CLIENT_DOING_BUSINESS_AS
WHERE
UTL_MATCH.JARO_WINKLER_SIMILARITY(UPPER(DOING_BUSINESS_AS_NAME),UPPER(:companyName)) >= 95
ORDER BY CLIENT_NUMBER""")
Flux<ClientDoingBusinessAsEntity> matchBy(String companyName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ca.bc.gov.app.service.processor;

import static java.util.function.Predicate.not;

import ca.bc.gov.app.dto.MatcherResult;
import ca.bc.gov.app.dto.SubmissionInformationDto;
import ca.bc.gov.app.entity.legacy.ClientDoingBusinessAsEntity;
import ca.bc.gov.app.entity.legacy.ForestClientEntity;
import ca.bc.gov.app.repository.legacy.ClientDoingBusinessAsRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Component
@RequiredArgsConstructor
@Slf4j
public class DoingBusinessAsProcessorMatcher implements ProcessorMatcher {

private final ClientDoingBusinessAsRepository doingBusinessAsRepository;

@Override
public boolean enabled(SubmissionInformationDto submission) {
return "RSP".equalsIgnoreCase(submission.clientType());
}

@Override
public String name() {
return "Doing Business As Fuzzy Matcher";
}

@Override
public Mono<MatcherResult> matches(SubmissionInformationDto submission) {

log.info("{} :: Validating {}", name(), submission.corporationName());

return
matchBy(submission.corporationName())
.map(ClientDoingBusinessAsEntity::getClientNumber)
.collectList()
.filter(not(List::isEmpty))
.map(values ->
new MatcherResult("corporationName", String.join(",", values))
);
}

private Flux<ClientDoingBusinessAsEntity> matchBy(String companyName) {
return
doingBusinessAsRepository
.matchBy(companyName)
.doOnNext(entity -> log.info("Found a match {}", entity));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package ca.bc.gov.app.service.processor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import ca.bc.gov.app.dto.MatcherResult;
import ca.bc.gov.app.dto.SubmissionInformationDto;
import ca.bc.gov.app.entity.legacy.ClientDoingBusinessAsEntity;
import ca.bc.gov.app.entity.legacy.ForestClientEntity;
import ca.bc.gov.app.repository.legacy.ClientDoingBusinessAsRepository;
import ca.bc.gov.app.repository.legacy.ForestClientRepository;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

@DisplayName("Unit Test | Doing Business As Matcher")
class DoingBusinessAsProcessorMatcherTest {

private final ClientDoingBusinessAsRepository repository = mock(ClientDoingBusinessAsRepository.class);
ProcessorMatcher matcher = new DoingBusinessAsProcessorMatcher(repository);

@Test
@DisplayName("Name matching")
void shouldMatchName() {
assertEquals("Doing Business As Fuzzy Matcher", matcher.name());
}

@ParameterizedTest
@MethodSource("legalName")
@DisplayName("Match or not")
void shouldMatchOrNot(
SubmissionInformationDto dto,
boolean success,
MatcherResult result,
Flux<ClientDoingBusinessAsEntity> mockData
) {

when(repository.matchBy(dto.corporationName()))
.thenReturn(mockData);

StepVerifier.FirstStep<MatcherResult> verifier =
matcher
.matches(dto)
.as(StepVerifier::create);

if (success) {
verifier.verifyComplete();
} else {
verifier
.expectNext(result)
.verifyComplete();
}
}

private static Stream<Arguments> legalName() {
return
Stream.of(
Arguments.of(
new SubmissionInformationDto("James", null,null, null,"C"),
true,
null,
Flux.empty()
),
Arguments.of(
new SubmissionInformationDto("Marco", null, null, null,"C"),
false,
new MatcherResult("corporationName", String.join(",", "00000000")),
Flux.just(new ForestClientEntity().withClientNumber("00000000"))
),
Arguments.of(
new SubmissionInformationDto("Lucca", null, null, null,"C"),
false,
new MatcherResult("corporationName", String.join(",", "00000000", "00000001")),
Flux.just(new ClientDoingBusinessAsEntity().withClientNumber("00000000"),
new ClientDoingBusinessAsEntity().withClientNumber("00000001"))
)
);
}

}

0 comments on commit 08b7861

Please sign in to comment.