Skip to content

Commit

Permalink
issue #137: allowableRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Jun 21, 2022
1 parent d294a29 commit 0bcf11b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public CommonParameters(String[] arguments) throws ParseException {
trimId = cmd.hasOption("trimId");
readIgnorableFields();
readIgnorableRecords();
readAllowableRecords();
readDefaultEncoding();
readAlephseqLineType();
readPicaIdField();
Expand Down Expand Up @@ -165,6 +166,7 @@ private void readIgnorableRecords() {
}

private void readAllowableRecords() {

String allowableRecords = cmd.hasOption("allowableRecords") ? cmd.getOptionValue("allowableRecords") : "";
setRecordFilter(allowableRecords);
}
Expand Down Expand Up @@ -448,6 +450,9 @@ public void setRecordIgnorator(String ignorableRecords) {
this.recordIgnorator = RecordIgnoratorFactory.create(schemaType, ignorableRecords.trim());
}

public RecordFilter getRecordFilter() {
return recordFilter;
}

public void setRecordFilter(String allowableRecords) {
this.recordFilter = RecordFilterFactory.create(schemaType, allowableRecords.trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ private boolean subfieldEndsWith(List<MarcSubfield> instances) {
return false;
}

@Override
public String toString() {
return "CriteriumPica{" +
"path=" + path.getPath() +
", operator=" + operator +
", value='" + value + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ protected DataField parseField(String field) {
}

protected boolean met(MarcRecord marcRecord) {
if (isEmpty())
return false;

for (DataField condition : conditions) {
List<DataField> recordFields = marcRecord.getDatafield(condition.getTag());
if (recordFields == null || recordFields.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public boolean isEmpty() {

@Override
public boolean isAllowable(MarcRecord marcRecord) {
if (isEmpty())
return true;

return met(marcRecord);
}

@Override
public String toString() {
return isEmpty() ? "" : conditions.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public boolean isEmpty() {

@Override
public boolean isAllowable(MarcRecord marcRecord) {
if (isEmpty())
return true;

for (CriteriumPica criterium : criteria) {
boolean passed = criterium.met(marcRecord);
if (passed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public boolean isEmpty() {

@Override
public boolean isIgnorable(MarcRecord marcRecord) {
if (isEmpty())
return false;

return met(marcRecord);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package de.gwdg.metadataqa.marc.cli.parameters;

import de.gwdg.metadataqa.marc.cli.utils.ignorablerecords.RecordFilterMarc21;
import de.gwdg.metadataqa.marc.cli.utils.ignorablerecords.RecordFilterPica;
import de.gwdg.metadataqa.marc.cli.utils.ignorablerecords.RecordIgnoratorMarc21;
import de.gwdg.metadataqa.marc.cli.utils.ignorablerecords.RecordIgnoratorPica;
import de.gwdg.metadataqa.marc.definition.DataSource;
import de.gwdg.metadataqa.marc.definition.MarcFormat;
import de.gwdg.metadataqa.marc.definition.bibliographic.SchemaType;
Expand Down Expand Up @@ -317,4 +321,64 @@ public void getPicaRecordType_set() {
assertEquals("003$d", parameters.getPicaRecordTypeField());
}

@Test
public void getRecordIgnorator_pica() {
String[] arguments = new String[]{"--schemaType", "PICA", "--ignorableRecords", "[email protected] !~ '^L'"};
CommonParameters parameters = null;
try {
parameters = new CommonParameters(arguments);
} catch (ParseException e) {
logger.log(Level.WARNING, "error in schemaType()", e);
}
assertEquals("RecordIgnoratorPica", parameters.getRecordIgnorator().getClass().getSimpleName());
assertEquals(1, ((RecordIgnoratorPica)parameters.getRecordIgnorator()).getCriteria().size());
assertEquals("CriteriumPica{[email protected], operator=NOT_MATCH, value='^L'}",
((RecordIgnoratorPica)parameters.getRecordIgnorator()).getCriteria().get(0).toString());
}

@Test
public void getRecordIgnorator_marc21() {
String[] arguments = new String[]{"--schemaType", "MARC21", "--ignorableRecords", "STA$a=SUPPRESSED"};
CommonParameters parameters = null;
try {
parameters = new CommonParameters(arguments);
} catch (ParseException e) {
logger.log(Level.WARNING, "error in schemaType()", e);
}
assertEquals("RecordIgnoratorMarc21", parameters.getRecordIgnorator().getClass().getSimpleName());
assertEquals(
"[DataField{STA, ind1=' ', ind2=' ', subfields=[MarcSubfield{code='a', value='SUPPRESSED'}]}]",
((RecordIgnoratorMarc21)parameters.getRecordIgnorator()).toString());
}

@Test
public void getRecordFilter_pica() {
String[] arguments = new String[]{"--schemaType", "PICA", "--allowableRecords", "[email protected] !~ '^L'"};
CommonParameters parameters = null;
try {
parameters = new CommonParameters(arguments);
} catch (ParseException e) {
logger.log(Level.WARNING, "error in schemaType()", e);
}
assertEquals("RecordFilterPica", parameters.getRecordFilter().getClass().getSimpleName());
assertEquals(1, ((RecordFilterPica)parameters.getRecordFilter()).getCriteria().size());
assertEquals("CriteriumPica{[email protected], operator=NOT_MATCH, value='^L'}",
((RecordFilterPica)parameters.getRecordFilter()).getCriteria().get(0).toString());
}

@Test
public void getRecordFilter_marc21() {
String[] arguments = new String[]{"--schemaType", "MARC21", "--allowableRecords", "STA$a=SUPPRESSED"};
CommonParameters parameters = null;
try {
parameters = new CommonParameters(arguments);
} catch (ParseException e) {
logger.log(Level.WARNING, "error in schemaType()", e);
}
assertEquals("RecordFilterMarc21", parameters.getRecordFilter().getClass().getSimpleName());
assertEquals(
"[DataField{STA, ind1=' ', ind2=' ', subfields=[MarcSubfield{code='a', value='SUPPRESSED'}]}]",
((RecordFilterMarc21)parameters.getRecordFilter()).toString());
}

}

0 comments on commit 0bcf11b

Please sign in to comment.