-
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.
Merge branch 'master' into msearch-782
- Loading branch information
Showing
42 changed files
with
1,457 additions
and
40 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
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
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>> { | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/org/folio/search/service/lccn/LccnNormalizerStructureB.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,67 @@ | ||
package org.folio.search.service.lccn; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.util.Optional; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Class responsible for normalizing Structure B LCCN values. | ||
*/ | ||
@Log4j2 | ||
@Service | ||
public class LccnNormalizerStructureB implements LccnNormalizer { | ||
private static final String NORMALIZED_LCCN_REGEX = "\\d{10}"; | ||
private static final char HYPHEN = '-'; | ||
|
||
/** | ||
* Normalizes the given LCCN value and returns the normalized LCCN. | ||
* If the given LCCN is invalid, an empty Optional is returned. | ||
* | ||
* @param lccn LCCN to be normalized | ||
* @return Returns the normalized LCCN. If the given LCCN is invalid, returns an empty Optional | ||
*/ | ||
public Optional<String> apply(@NotNull final String lccn) { | ||
var normalizedLccn = lccn; | ||
|
||
// Remove white spaces | ||
normalizedLccn = normalizedLccn.replaceAll("\\s", StringUtils.EMPTY); | ||
|
||
// If lccn contains "/", remove it & all characters to the right of "/" | ||
normalizedLccn = normalizedLccn.replaceAll("/.*", StringUtils.EMPTY); | ||
|
||
// Process the serial number component of LCCN | ||
normalizedLccn = processSerialNumber(normalizedLccn); | ||
|
||
if (normalizedLccn.matches(NORMALIZED_LCCN_REGEX)) { | ||
return Optional.of(normalizedLccn); | ||
} | ||
|
||
log.warn("LCCN is not in expected format: [{}]", lccn); | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* Serial number is demarcated by a hyphen (fifth character in the value). Further, the serial number must be six | ||
* digits in length. If fewer than six digits, remove the hyphen and left fill with zeroes so that there are six | ||
* digits in the serial number. | ||
*/ | ||
private String processSerialNumber(String lccn) { | ||
if (lccn.length() >= 5 && lccn.charAt(4) == HYPHEN) { | ||
var lccnParts = lccn.split(String.valueOf(HYPHEN)); | ||
if (lccnParts.length == 2) { | ||
String prefix = lccnParts[0]; | ||
StringBuilder serialNumber = new StringBuilder(lccnParts[1]); | ||
|
||
// Left fill the serial number with zeroes to make it six digits | ||
while (serialNumber.length() < 6) { | ||
serialNumber.insert(0, "0"); | ||
} | ||
|
||
return serialNumber.insert(0, prefix).toString(); | ||
} | ||
} | ||
return lccn; | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/org/folio/search/service/setter/bibframe/BibframeContributorProcessor.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,34 @@ | ||
package org.folio.search.service.setter.bibframe; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import static java.util.stream.Collectors.toCollection; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.folio.search.domain.dto.Bibframe; | ||
import org.folio.search.domain.dto.BibframeContributorsInner; | ||
import org.folio.search.domain.dto.BibframeInstancesInner; | ||
import org.folio.search.service.setter.FieldProcessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class BibframeContributorProcessor implements FieldProcessor<Bibframe, Set<String>> { | ||
|
||
@Override | ||
public Set<String> getFieldValue(Bibframe bibframe) { | ||
var workContributors = ofNullable(bibframe.getContributors()).stream().flatMap(Collection::stream); | ||
var instanceContributors = ofNullable(bibframe.getInstances()).stream().flatMap(Collection::stream) | ||
.map(BibframeInstancesInner::getContributors).filter(Objects::nonNull).flatMap(Collection::stream); | ||
return Stream.concat(workContributors, instanceContributors) | ||
.filter(Objects::nonNull) | ||
.map(BibframeContributorsInner::getName) | ||
.filter(StringUtils::isNotBlank) | ||
.map(String::trim) | ||
.collect(toCollection(LinkedHashSet::new)); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/org/folio/search/service/setter/bibframe/BibframeIsbnProcessor.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,38 @@ | ||
package org.folio.search.service.setter.bibframe; | ||
|
||
import static java.util.Objects.nonNull; | ||
import static java.util.Optional.ofNullable; | ||
import static java.util.stream.Collectors.toCollection; | ||
import static org.folio.search.domain.dto.BibframeInstancesInnerIdentifiersInner.TypeEnum.ISBN; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.folio.search.domain.dto.Bibframe; | ||
import org.folio.search.domain.dto.BibframeInstancesInnerIdentifiersInner; | ||
import org.folio.search.service.setter.FieldProcessor; | ||
import org.folio.search.service.setter.instance.IsbnProcessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class BibframeIsbnProcessor implements FieldProcessor<Bibframe, Set<String>> { | ||
|
||
private final IsbnProcessor isbnProcessor; | ||
|
||
@Override | ||
public Set<String> getFieldValue(Bibframe bibframe) { | ||
return ofNullable(bibframe.getInstances()).stream() | ||
.flatMap(Collection::stream) | ||
.filter(i -> nonNull(i.getIdentifiers())) | ||
.flatMap(i -> i.getIdentifiers().stream()) | ||
.filter(i -> ISBN.equals(i.getType())) | ||
.map(BibframeInstancesInnerIdentifiersInner::getValue) | ||
.filter(Objects::nonNull) | ||
.map(isbnProcessor::normalizeIsbn) | ||
.flatMap(Collection::stream) | ||
.collect(toCollection(LinkedHashSet::new)); | ||
} | ||
} |
Oops, something went wrong.