-
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.
- Loading branch information
1 parent
b3fbc15
commit f790b95
Showing
31 changed files
with
1,389 additions
and
0 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
17 changes: 17 additions & 0 deletions
17
src/main/java/org/folio/search/cql/BibframeIsbnSearchTermProcessor.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,17 @@ | ||
package org.folio.search.cql; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.folio.search.service.setter.bibframe.BibframeIsbnProcessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class BibframeIsbnSearchTermProcessor implements SearchTermProcessor { | ||
|
||
private final BibframeIsbnProcessor isbnProcessor; | ||
|
||
@Override | ||
public String getSearchTerm(String inputTerm) { | ||
return String.join(" ", isbnProcessor.normalizeIsbn(inputTerm)); | ||
} | ||
} |
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)); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
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.List; | ||
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(this::normalizeIsbn) | ||
.flatMap(Collection::stream) | ||
.collect(toCollection(LinkedHashSet::new)); | ||
} | ||
|
||
public List<String> normalizeIsbn(String value) { | ||
return isbnProcessor.normalizeIsbn(value); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/folio/search/service/setter/bibframe/BibframeLccnProcessor.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,39 @@ | ||
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.LCCN; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
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.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class BibframeLccnProcessor implements FieldProcessor<Bibframe, Set<String>> { | ||
|
||
private final LccnNormalizer lccnNormalizer; | ||
|
||
@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 -> LCCN.equals(i.getType())) | ||
.map(BibframeInstancesInnerIdentifiersInner::getValue) | ||
.filter(Objects::nonNull) | ||
.map(lccnNormalizer::normalizeLccn) | ||
.flatMap(Optional::stream) | ||
.collect(toCollection(LinkedHashSet::new)); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/folio/search/service/setter/bibframe/BibframeSortTitleProcessor.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,31 @@ | ||
package org.folio.search.service.setter.bibframe; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.folio.search.domain.dto.Bibframe; | ||
import org.folio.search.domain.dto.BibframeInstancesInner; | ||
import org.folio.search.domain.dto.BibframeTitlesInner; | ||
import org.folio.search.service.setter.FieldProcessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class BibframeSortTitleProcessor implements FieldProcessor<Bibframe, String> { | ||
|
||
@Override | ||
public String getFieldValue(Bibframe bibframe) { | ||
var workTitles = ofNullable(bibframe.getTitles()).stream().flatMap(Collection::stream); | ||
var instanceTitles = ofNullable(bibframe.getInstances()).stream().flatMap(Collection::stream) | ||
.map(BibframeInstancesInner::getTitles).filter(Objects::nonNull).flatMap(Collection::stream); | ||
return Stream.concat(workTitles, instanceTitles) | ||
.filter(Objects::nonNull) | ||
.map(BibframeTitlesInner::getValue) | ||
.filter(StringUtils::isNotBlank) | ||
.collect(Collectors.joining()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/folio/search/service/setter/bibframe/BibframeTitleProcessor.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.BibframeInstancesInner; | ||
import org.folio.search.domain.dto.BibframeTitlesInner; | ||
import org.folio.search.service.setter.FieldProcessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class BibframeTitleProcessor implements FieldProcessor<Bibframe, Set<String>> { | ||
|
||
@Override | ||
public Set<String> getFieldValue(Bibframe bibframe) { | ||
var workTitles = ofNullable(bibframe.getTitles()).stream().flatMap(Collection::stream); | ||
var instTitles = ofNullable(bibframe.getInstances()).stream().flatMap(Collection::stream).filter(Objects::nonNull) | ||
.map(BibframeInstancesInner::getTitles).filter(Objects::nonNull).flatMap(Collection::stream); | ||
return Stream.concat(workTitles, instTitles) | ||
.filter(Objects::nonNull) | ||
.map(BibframeTitlesInner::getValue) | ||
.filter(StringUtils::isNotBlank) | ||
.map(String::trim) | ||
.collect(toCollection(LinkedHashSet::new)); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/folio/search/service/setter/bibframe/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,64 @@ | ||
package org.folio.search.service.setter.bibframe; | ||
|
||
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; | ||
|
||
@Log4j2 | ||
@Service | ||
public class 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> normalizeLccn(@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
Oops, something went wrong.