Skip to content

Commit

Permalink
Some catalogue specific elements do not work properly #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Oct 12, 2024
1 parent 37868dc commit 9ef0d5d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class CommonParameters implements Serializable {
protected boolean lineSeparated = false;
protected boolean trimId = false;
private String outputDir = DEFAULT_OUTPUT_DIR;
@JsonIgnore
protected RecordIgnorator recordIgnorator;
protected String ignorableRecords;
protected RecordFilter recordFilter;
protected IgnorableFields ignorableFields = new IgnorableFields();
protected InputStream stream = null;
Expand Down Expand Up @@ -194,7 +196,7 @@ private void readDefaultEncoding() {
}

private void readIgnorableRecords() {
String ignorableRecords = cmd.hasOption("ignorableRecords") ? cmd.getOptionValue("ignorableRecords") : "";
ignorableRecords = cmd.hasOption("ignorableRecords") ? cmd.getOptionValue("ignorableRecords") : "";
setRecordIgnorator(ignorableRecords);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.gwdg.metadataqa.marc.cli.utils.RecordIterator;
import de.gwdg.metadataqa.marc.utils.ReadMarc;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.marc4j.marc.Record;
Expand Down Expand Up @@ -158,7 +159,7 @@ public void marcxml() throws IOException {
"--collectCollocations",
"--marcxml",
"--outputDir", outputDir,
inputFile = TestUtils.getPath("marcxml/marcxml.xml")
TestUtils.getPath("marcxml/marcxml.xml")
};
ClassificationAnalysis.main(args);

Expand Down
41 changes: 41 additions & 0 deletions src/test/java/de/gwdg/metadataqa/marc/cli/ValidatorCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -419,6 +421,45 @@ public void validate_whenUnimarc() throws Exception {
assertEquals("1", lines.get(1).trim());
}

@Test
public void validate_whenHbz() throws Exception {
clearOutput(outputDir, outputFiles);

ValidatorCli processor = new ValidatorCli(new String[]{
"--schemaType", "MARC21",
"--marcVersion", "HBZ",
"--marcxml",
"--outputDir", outputDir,
"--fixAlma",
"--ignorableRecords", "DEL$a=Y",
"--ignorableFields", "964,940,941,942,944,945,946,947,948,949,950,951,952,955,956,957,958,959,966,967,970,971,972,973,974,975,976,977,978,978,979",
"--details",
"--trimId",
"--summary",
// "--format", "csv",
// "--defaultRecordType", "BOOKS",
// "--detailsFileName", "issue-details.csv",
// "--summaryFileName", "issue-summary.csv",
TestUtils.getPath("marcxml/990082522550206441_missing_validation_custom_subfield_9_core_710.xml"),
TestUtils.getPath("marcxml/990171082050206441_missing_validation_custom_ind2_9_core_246.xml"),
TestUtils.getPath("marcxml/991000922029706482_missing_subfield_validation_t_in_customfield_GKT.xml"),
});

RecordIterator iterator = new RecordIterator(processor);
iterator.setProcessWithErrors(true);
iterator.start();

List<String> lines = getFileLines("issue-summary.csv");
System.err.println(StringUtils.join(lines, "\n"));
assertEquals(3, lines.size());
List<String> undefinedFields = lines.stream()
.filter(line -> line.contains("undefined field"))
.collect(Collectors.toList());
assertEquals(0, undefinedFields.size());
// Pattern pattern = Pattern.compile("^\\d+,952,\\d+,\\d+,undefined field");
// assertTrue(pattern.matcher(undefinedFields.get(0)).find());
}

private List<String> getFileLines(String outputFile) throws IOException {
File output = new File(outputDir, outputFile);
assertTrue(outputFile + " should exist", output.exists());
Expand Down

0 comments on commit 9ef0d5d

Please sign in to comment.