Skip to content

Commit

Permalink
MODINV-1044 Additional Requirements - Update Data Import logic to nor…
Browse files Browse the repository at this point in the history
…malize OCLC 035 values (#630)

* MODINV-1044 Additional Requirements - Update Data Import logic to normalize OCLC 035 values

* Update AdditionalFieldsUtilTest.java
  • Loading branch information
JavokhirAbdullayev authored Jul 10, 2024
1 parent 8f6b160 commit 2d06578
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [MODSOURCE-756](https://issues.folio.org/browse/MODSOURCE-756) After setting an instance as marked for deletion it is no longer editable in quickmarc
* [MODSOURCE-753](https://folio-org.atlassian.net/browse/MODSOURCE-753) Change SQL query parameters for MARC Search
* [MODSOURCE-773](https://folio-org.atlassian.net/browse/MODSOURCE-773) MARC Search omits suppressed from discovery records in default search
* [MODINV-1044](https://folio-org.atlassian.net/browse/MODINV-1044) Additional Requirements - Update Data Import logic to normalize OCLC 035 values

## 2024-03-20 5.8.0
* [MODSOURCE-733](https://issues.folio.org/browse/MODSOURCE-733) Reduce Memory Allocation of Strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public final class AdditionalFieldsUtil {
private static final char HR_ID_FIELD_IND = ' ';
private static final String ANY_STRING = "*";
private static final String OCLC = "OCoLC";
private static final String OCLC_PATTERN = "\\((" + OCLC + ")\\)((ocm|ocn)?0*|([a-zA-Z]+)0*)(\\d+\\w*)";
private static final String OCLC_PATTERN = "\\((" + OCLC + ")\\)((ocm|ocn|on)?0*|([a-zA-Z]+)0*)(\\d+\\w*)";


public static final DateTimeFormatter dateTime005Formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss.S");
Expand Down Expand Up @@ -460,7 +460,7 @@ private static Set<String> formatOclc(List<Subfield> subFields) {
Pattern pattern = Pattern.compile(OCLC_PATTERN);

for (Subfield subfield : subFields) {
String data = subfield.getData();
String data = subfield.getData().replaceAll("[.\\s]", "");
var code = subfield.getCode();
Matcher matcher = pattern.matcher(data);

Expand All @@ -469,7 +469,7 @@ private static Set<String> formatOclc(List<Subfield> subFields) {
String numericAndTrailing = matcher.group(5); // Numeric part and any characters that follow
String prefix = matcher.group(2); // Entire prefix including letters and potentially leading zeros

if (prefix != null && (prefix.startsWith("ocm") || prefix.startsWith("ocn"))) {
if (prefix != null && (prefix.startsWith("ocm") || prefix.startsWith("ocn") || prefix.startsWith("on"))) {
// If "ocm" or "ocn", strip entirely from the prefix
processedSet.add(code + "&(" + oclcTag + ")" + numericAndTrailing);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@ public void shouldReturnSubfieldIfOclcExist() {
Assert.assertEquals(expectedSubfields.get(0), subfields.get(0));
}

@Test
public void shouldRemovePeriodsAndSpacesAfterNormalization() {
// given
var parsedContent = "{\"leader\":\"00120nam 22000731a 4500\",\"fields\":[{\"001\":\"in001\"}," +
"{\"035\":{\"subfields\":[{\"a\":\"(OCoLC)on. 607TST .001\"}],\"ind1\":\" \",\"ind2\":\" \"}}," +
"{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";

var expectedParsedContent = "{\"leader\":\"00098nam 22000611a 4500\",\"fields\":[{\"001\":\"in001\"}," +
"{\"035\":{\"subfields\":[{\"a\":\"(OCoLC)607TST001\"}],\"ind1\":\" \",\"ind2\":\" \"}}," +
"{\"500\":{\"subfields\":[{\"a\":\"data\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
ParsedRecord parsedRecord = new ParsedRecord().withContent(parsedContent);

Record record = new Record().withId(UUID.randomUUID().toString())
.withParsedRecord(parsedRecord)
.withGeneration(0)
.withState(Record.State.ACTUAL)
.withExternalIdsHolder(new ExternalIdsHolder().withInstanceId("001").withInstanceHrid("in001"));
// when
AdditionalFieldsUtil.normalize035(record);
Assert.assertEquals(expectedParsedContent, parsedRecord.getContent());
}

@Test
public void shouldNotReturnSubfieldIfOclcNotExist() {
// given
Expand Down

0 comments on commit 2d06578

Please sign in to comment.