-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODLD-385: Create beans for Default and StructureB LCCN normalization
- Loading branch information
Showing
24 changed files
with
183 additions
and
142 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
17 changes: 0 additions & 17 deletions
17
src/main/java/org/folio/search/cql/BibframeIsbnSearchTermProcessor.java
This file was deleted.
Oops, something went wrong.
7 changes: 5 additions & 2 deletions
7
src/main/java/org/folio/search/cql/LccnSearchTermProcessor.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,15 +1,18 @@ | ||
package org.folio.search.cql; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.folio.search.utils.SearchUtils; | ||
import org.folio.search.service.lccn.LccnNormalizer; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class LccnSearchTermProcessor implements SearchTermProcessor { | ||
|
||
private final LccnNormalizer lccnNormalizer; | ||
|
||
@Override | ||
public String getSearchTerm(String inputTerm) { | ||
return SearchUtils.normalizeLccn(inputTerm); | ||
return lccnNormalizer.apply(inputTerm) | ||
.orElse(null); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/org/folio/search/service/lccn/DefaultLccnNormalizer.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 org.folio.search.service.lccn; | ||
|
||
import java.util.Optional; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Primary | ||
public class DefaultLccnNormalizer implements LccnNormalizer { | ||
|
||
@Override | ||
public Optional<String> apply(String lccn) { | ||
if (StringUtils.isBlank(lccn)) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(StringUtils.deleteWhitespace(lccn)) | ||
.map(String::toLowerCase); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/folio/search/service/lccn/LccnNormalizer.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,7 @@ | ||
package org.folio.search.service.lccn; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
public interface LccnNormalizer extends Function<String, Optional<String>> { | ||
} |
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
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
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
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
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
19 changes: 16 additions & 3 deletions
19
src/test/java/org/folio/search/cql/LccnSearchTermProcessorTest.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,23 +1,36 @@ | ||
package org.folio.search.cql; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Optional; | ||
import org.folio.search.service.lccn.LccnNormalizer; | ||
import org.folio.spring.testing.type.UnitTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
|
||
@UnitTest | ||
@ExtendWith(MockitoExtension.class) | ||
class LccnSearchTermProcessorTest { | ||
@Mock | ||
private LccnNormalizer normalizer; | ||
@InjectMocks | ||
private LccnSearchTermProcessor lccnSearchTermProcessor; | ||
|
||
@Test | ||
void getSearchTerm_positive() { | ||
// given | ||
var searchTerm = " N 123456 "; | ||
var lccnSearchTermProcessor = new LccnSearchTermProcessor(); | ||
var normalizedTerm = "n123456"; | ||
when(normalizer.apply(searchTerm)).thenReturn(Optional.of(normalizedTerm)); | ||
|
||
// when | ||
var actual = lccnSearchTermProcessor.getSearchTerm(searchTerm); | ||
assertThat(actual).isEqualTo("n123456"); | ||
|
||
// then | ||
assertThat(actual).isEqualTo(normalizedTerm); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/org/folio/search/service/lccn/DefaultLccnNormalizerTest.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 org.folio.search.service.lccn; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.folio.spring.testing.type.UnitTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
@UnitTest | ||
class DefaultLccnNormalizerTest { | ||
private final DefaultLccnNormalizer lccnNormalizer = new DefaultLccnNormalizer(); | ||
|
||
@DisplayName("LCCN value normalization") | ||
@CsvSource({"n 1234,n1234", " N 1234 ,n1234", "*1234,*1234", "1234*,1234*"}) | ||
@ParameterizedTest(name = "[{index}] value={0}, expected={1}") | ||
void getLccnNormalized_parameterized(String value, String expected) { | ||
var normalized = lccnNormalizer.apply(value); | ||
assertThat(normalized).contains(expected); | ||
} | ||
} |
Oops, something went wrong.