-
Notifications
You must be signed in to change notification settings - Fork 17
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
Showing
7 changed files
with
236 additions
and
3 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
47 changes: 47 additions & 0 deletions
47
src/main/java/de/gwdg/metadataqa/marc/definition/general/validator/RangeValidator.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,47 @@ | ||
package de.gwdg.metadataqa.marc.definition.general.validator; | ||
|
||
import de.gwdg.metadataqa.marc.MarcSubfield; | ||
import de.gwdg.metadataqa.marc.definition.SubfieldDefinition; | ||
import de.gwdg.metadataqa.marc.definition.ValidatorResponse; | ||
import de.gwdg.metadataqa.marc.model.validation.ValidationError; | ||
import de.gwdg.metadataqa.marc.model.validation.ValidationErrorType; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.io.Serializable; | ||
|
||
public class RangeValidator implements SubfieldValidator, Serializable { | ||
|
||
private final int min; | ||
private final int max; | ||
|
||
public RangeValidator(int min, int max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
@Override | ||
public ValidatorResponse isValid(MarcSubfield subfield) { | ||
|
||
ValidatorResponse response = new ValidatorResponse(); | ||
SubfieldDefinition definition = subfield.getDefinition(); | ||
String descriptionUrl = (definition != null) | ||
? definition.getParent().getDescriptionUrl() | ||
: null; | ||
String value = subfield.getValue(); | ||
|
||
if (StringUtils.isNotBlank(value)) { | ||
int intValue = Integer.parseInt(value); | ||
if (intValue < min || intValue > max) | ||
response.addValidationError( | ||
new ValidationError( | ||
subfield.getRecord().getId(), | ||
subfield.getDefinition().getPath(), | ||
ValidationErrorType.SUBFIELD_PATTERN_MISMATCH, | ||
String.format("'%s' is out of range '%d-%d'", value, min, max), | ||
descriptionUrl | ||
) | ||
); | ||
} | ||
return response; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/de/gwdg/metadataqa/marc/definition/tags/bltags/TagVIT.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,79 @@ | ||
package de.gwdg.metadataqa.marc.definition.tags.bltags; | ||
|
||
import de.gwdg.metadataqa.marc.definition.Cardinality; | ||
import de.gwdg.metadataqa.marc.definition.DataFieldDefinition; | ||
import de.gwdg.metadataqa.marc.definition.Indicator; | ||
import de.gwdg.metadataqa.marc.definition.general.validator.RangeValidator; | ||
import de.gwdg.metadataqa.marc.definition.general.validator.RegexValidator; | ||
|
||
/** | ||
* Virtual Item | ||
*/ | ||
public class TagVIT extends DataFieldDefinition { | ||
|
||
private static TagVIT uniqueInstance; | ||
|
||
private TagVIT() { | ||
initialize(); | ||
postCreation(); | ||
} | ||
|
||
public static TagVIT getInstance() { | ||
if (uniqueInstance == null) | ||
uniqueInstance = new TagVIT(); | ||
return uniqueInstance; | ||
} | ||
|
||
private void initialize() { | ||
|
||
tag = "VIT"; | ||
label = "Virtual Item"; | ||
mqTag = "VirtualItem"; | ||
cardinality = Cardinality.Repeatable; | ||
// descriptionUrl = "https://www.loc.gov/marc/bibliographic/bd037.html"; | ||
// setCompilanceLevels("O"); | ||
|
||
ind1 = new Indicator(); | ||
|
||
ind2 = new Indicator(); | ||
|
||
setSubfieldsWithCardinality( | ||
"b", "The Barcode Identifier allocated to the Primary Item", "NR", | ||
"c", "Condition/Surrogacy Status", "NR", | ||
"d", "Item Description", "NR", | ||
"e", "From Year", "NR", | ||
"f", "From Month", "NR", | ||
"g", "From Day", "NR", | ||
"i", "From Year (and To Year if different)", "NR", | ||
"j", "From Month (and To Month if different)", "NR", | ||
"k", "From Day (and To Day if different)", "NR", | ||
"o", "OPAC Note", "NR", | ||
"s", "Contains the string ‘Supplement’ if the Newspaper Audit database Item Description field contained ‘supp’. Otherwise blank", "NR" | ||
); | ||
|
||
getSubfield("b").setMqTag("barcode"); | ||
getSubfield("c").setMqTag("status"); | ||
getSubfield("d").setMqTag("description"); | ||
getSubfield("e") | ||
.setValidator(new RegexValidator("^(1[5-9]|20)\\d\\d$")) | ||
.setMqTag("fromYear"); | ||
getSubfield("f") | ||
.setValidator(new RangeValidator(1, 12)) | ||
.setMqTag("fromMonth"); | ||
getSubfield("g") | ||
.setValidator(new RangeValidator(1, 31)) | ||
.setMqTag("fromDay"); | ||
getSubfield("i") | ||
.setValidator(new RegexValidator("^(1[5-9]|20)\\d\\d(/(1[6-9]|20)\\d\\d)?$")) | ||
.setMqTag("fromToYear"); | ||
getSubfield("j") | ||
.setValidator(new RegexValidator("^(0[1-9]|1[0-2])(/(0[1-9]|1[0-2]))?$")) | ||
.setMqTag("fromToMonth"); | ||
getSubfield("k") | ||
.setValidator( | ||
new RegexValidator("^(0[1-9]|[1-2][0-9]|3[01])(/(0[1-9]|[1-2][0-9]|3[01]))?$")) | ||
.setMqTag("fromToDay"); | ||
getSubfield("o").setMqTag("opacNote"); | ||
getSubfield("s").setMqTag("isSupplement"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/de/gwdg/metadataqa/marc/definition/general/validator/RangeValidatorTest.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,35 @@ | ||
package de.gwdg.metadataqa.marc.definition.general.validator; | ||
|
||
import de.gwdg.metadataqa.marc.DataField; | ||
import de.gwdg.metadataqa.marc.MarcRecord; | ||
import de.gwdg.metadataqa.marc.MarcSubfield; | ||
import de.gwdg.metadataqa.marc.definition.tags.tags01x.Tag020; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class RangeValidatorTest { | ||
|
||
@Test | ||
public void month() { | ||
RangeValidator validator = new RangeValidator(1, 12); | ||
assertTrue(validator.isValid(createMarcSubfield("1")).isValid()); | ||
assertFalse(validator.isValid(createMarcSubfield("13")).isValid()); | ||
} | ||
|
||
@Test | ||
public void day() { | ||
RangeValidator validator = new RangeValidator(1, 31); | ||
assertTrue(validator.isValid(createMarcSubfield("13")).isValid()); | ||
assertFalse(validator.isValid(createMarcSubfield("33")).isValid()); | ||
} | ||
|
||
private MarcSubfield createMarcSubfield(String value) { | ||
MarcRecord record = new MarcRecord("test"); | ||
DataField field = new DataField(Tag020.getInstance(), " ", " ", "a", value); | ||
field.setRecord(record); | ||
|
||
return field.getSubfield("a").get(0); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/de/gwdg/metadataqa/marc/definition/general/validator/RegexValidatorTest.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,30 @@ | ||
package de.gwdg.metadataqa.marc.definition.general.validator; | ||
|
||
import de.gwdg.metadataqa.marc.DataField; | ||
import de.gwdg.metadataqa.marc.MarcRecord; | ||
import de.gwdg.metadataqa.marc.MarcSubfield; | ||
import de.gwdg.metadataqa.marc.definition.tags.tags01x.Tag020; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class RegexValidatorTest { | ||
|
||
@Test | ||
public void yearRange() { | ||
RegexValidator validator = new RegexValidator("^(1[6-9]|20)\\d\\d(/(1[6-9]|20)\\d\\d)?$"); | ||
assertTrue(validator.isValid(createMarcSubfield("1629")).isValid()); | ||
assertTrue(validator.isValid(createMarcSubfield("1629/1703")).isValid()); | ||
assertFalse(validator.isValid(createMarcSubfield("13")).isValid()); | ||
assertFalse(validator.isValid(createMarcSubfield("1413")).isValid()); | ||
} | ||
|
||
private MarcSubfield createMarcSubfield(String value) { | ||
MarcRecord record = new MarcRecord("test"); | ||
DataField field = new DataField(Tag020.getInstance(), " ", " ", "a", value); | ||
field.setRecord(record); | ||
|
||
return field.getSubfield("a").get(0); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/de/gwdg/metadataqa/marc/definition/tags/bltags/TagVITTest.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,41 @@ | ||
package de.gwdg.metadataqa.marc.definition.tags.bltags; | ||
|
||
import org.junit.Test; | ||
|
||
public class TagVITTest extends BLTagTest { | ||
|
||
public TagVITTest() { | ||
super(TagVIT.getInstance()); | ||
} | ||
|
||
@Test | ||
public void testValidFields() { | ||
validField("b", "NP000097052", "c", "PX", "d", "(1913)", "e", "1913", "f", "1", | ||
"g", "1", "i", "1913", "j", "01/12", "k", "01/31"); | ||
validField("b", "NP000460014", "c", "01", "d", "(1799:Sep. 5 - 1814:Mar.31)", | ||
"e", "1799", "f", "9", "g", "5", "i", "1799/1814", "j", "09/03", "k", "05/31"); | ||
validField("e", "1523"); | ||
validField("f", "11"); | ||
validField("g", "31"); | ||
validField("i", "1629"); | ||
validField("i", "1629/1703"); | ||
validField("j", "11"); | ||
validField("j", "11/12"); | ||
validField("k", "11"); | ||
validField("k", "11/12"); | ||
} | ||
|
||
@Test | ||
public void testInvalidFields() { | ||
invalidField("1", "a", "Y"); | ||
invalidField("a", "X"); | ||
invalidField("e", "15"); | ||
invalidField("e", "1423"); | ||
invalidField("f", "14"); | ||
invalidField("g", "41"); | ||
invalidField("i", "13"); | ||
invalidField("j", "13"); | ||
invalidField("j", "01/13"); | ||
invalidField("k", "01/32"); | ||
} | ||
} |
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