Skip to content

Commit

Permalink
issue #75: create an error type identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Dec 21, 2020
1 parent de859ec commit 77b533e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/gwdg/metadataqa/marc/cli/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private void printSummary(char separator) {
private void printTypeCounts() {
Path path = Paths.get(parameters.getOutputDir(), "issue-by-type.csv");
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
writer.write(createRow("type", "instances", "records"));
writer.write(createRow("id", "type", "instances", "records"));
typeRecordCounter
.entrySet()
.stream()
Expand All @@ -316,7 +316,7 @@ private void printTypeCounts() {
int records = entry.getValue();
int instances = typeInstanceCounter.get(entry.getKey());
try {
writer.write(createRow(quote(type.getMessage()), instances, records));
writer.write(createRow(type.getId(), quote(type.getMessage()), instances, records));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,17 @@ private static String createCvsRow(String[] strings, char separator) {
}

private static String formatTextWithoutId(ValidationError error) {
return String.format("%s: %s '%s' (%s)",
return String.format("%s: %d - %s '%s' (%s)",
error.getMarcPath(),
error.getType().getId(),
error.getType().getMessage(),
error.getMessage(),
error.getUrl()
);
}

private static String[] headerForSummary() {
return new String[]{"id", "MarcPath", "type", "message", "url", "instances", "records"};
return new String[]{"id", "MarcPath", "typeId", "type", "message", "url", "instances", "records"};
}

private static String[] headerForCollector() {
Expand All @@ -168,6 +169,7 @@ private static String[] headerForCollector() {
private static String[] asArrayWithoutId(ValidationError error) {
return new String[]{
error.getMarcPath(),
String.valueOf(error.getType().getId()),
error.getType().getMessage(),
error.getMessage(),
error.getUrl()
Expand All @@ -177,6 +179,7 @@ private static String[] asArrayWithoutId(ValidationError error) {
private static List<String> asListWithoutId(ValidationError error) {
return Arrays.asList(
error.getMarcPath(),
String.valueOf(error.getType().getId()),
error.getType().getMessage(),
error.getMessage(),
error.getUrl()
Expand All @@ -187,6 +190,7 @@ private static List<String> asList(ValidationError error) {
return Arrays.asList(
error.getRecordId(),
error.getMarcPath(),
String.valueOf(error.getType().getId()),
error.getType().getMessage(),
error.getMessage(),
error.getUrl()
Expand All @@ -197,13 +201,14 @@ private static String[] asArray(ValidationError error) {
return new String[]{
error.getRecordId(),
error.getMarcPath(),
String.valueOf(error.getType().getId()),
error.getType().getMessage(),
error.getMessage(),
error.getUrl()
};
}

private static String[] headerArray() {
return new String[]{"recordId", "MarcPath", "type", "message", "url"};
return new String[]{"recordId", "MarcPath", "typeId", "type", "message", "url"};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,50 @@
public enum ValidationErrorType {

// record
RECORD_UNDETECTABLE_TYPE("undetectableType", "record: undetectable type", "record"),
RECORD_INVALID_LINKAGE("invalidLinkage", "record: invalid linkage", "record"),
RECORD_AMBIGUOUS_LINKAGE("ambiguousLinkage", "record: ambiguous linkage", "record"),
RECORD_UNDETECTABLE_TYPE(1, "undetectableType", "record: undetectable type", "record"),
RECORD_INVALID_LINKAGE(2, "invalidLinkage", "record: invalid linkage", "record"),
RECORD_AMBIGUOUS_LINKAGE(3, "ambiguousLinkage", "record: ambiguous linkage", "record"),
// control subfield
CONTROL_SUBFIELD_OBSOLETE_CODE("obsoleteControlSubfield", "control subfield: obsolete code", "control subfield"),
CONTROL_SUBFIELD_INVALID_CODE("controlValueContainsInvalidCode", "control subfield: invalid code", "control subfield"),
CONTROL_SUBFIELD_INVALID_VALUE("hasInvalidValue", "control subfield: invalid value", "control subfield"),
CONTROL_SUBFIELD_OBSOLETE_CODE(4, "obsoleteControlSubfield", "control subfield: obsolete code", "control subfield"),
CONTROL_SUBFIELD_INVALID_CODE(5, "controlValueContainsInvalidCode", "control subfield: invalid code", "control subfield"),
CONTROL_SUBFIELD_INVALID_VALUE(6, "hasInvalidValue", "control subfield: invalid value", "control subfield"),
// field
FIELD_MISSING_REFERENCE_SUBFIELD("missingSubfield", "field: missing reference subfield (880$6)", "field"),
FIELD_NONREPEATABLE("nonrepeatableField", "field: repetition of non-repeatable field", "field"),
FIELD_UNDEFINED("undefinedField", "field: undefined field", "field"),
FIELD_MISSING_REFERENCE_SUBFIELD(7, "missingSubfield", "field: missing reference subfield (880$6)", "field"),
FIELD_NONREPEATABLE(8, "nonrepeatableField", "field: repetition of non-repeatable field", "field"),
FIELD_UNDEFINED(9, "undefinedField", "field: undefined field", "field"),
// indicator
INDICATOR_OBSOLETE("obsoleteIndicator", "indicator: obsolete value", "indicator"),
INDICATOR_NON_EMPTY("nonEmptyIndicator", "indicator: non-empty indicator", "indicator"),
INDICATOR_INVALID_VALUE("hasInvalidValue", "indicator: invalid value", "indicator"),
INDICATOR_OBSOLETE(10, "obsoleteIndicator", "indicator: obsolete value", "indicator"),
INDICATOR_NON_EMPTY(11, "nonEmptyIndicator", "indicator: non-empty indicator", "indicator"),
INDICATOR_INVALID_VALUE(12, "hasInvalidValue", "indicator: invalid value", "indicator"),
// subfield
SUBFIELD_UNDEFINED("undefinedSubfield", "subfield: undefined subfield", "subfield"),
SUBFIELD_INVALID_LENGTH("invalidLength", "subfield: invalid length", "subfield"),
SUBFIELD_INVALID_CLASSIFICATION_REFERENCE("invalidReference", "subfield: invalid classification reference", "subfield"),
SUBFIELD_PATTERN_MISMATCH("patternMismatch", "subfield: content does not match any patterns", "subfield"),
SUBFIELD_NONREPEATABLE("nonrepeatableSubfield", "subfield: repetition of non-repeatable subfield", "subfield"),
SUBFIELD_ISBN("invalidISBN", "subfield: invalid ISBN", "subfield"),
SUBFIELD_ISSN("invalidISSN", "subfield: invalid ISSN", "subfield"),
SUBFIELD_UNPARSABLE_CONTENT("unparsableContent", "subfield: content is not well-formatted", "subfield"),
SUBFIELD_NULL_CODE("nullCode", "subfield: null subfield code", "subfield"),
SUBFIELD_INVALID_VALUE("hasInvalidValue", "subfield: invalid value", "subfield"),
SUBFIELD_UNDEFINED(13, "undefinedSubfield", "subfield: undefined subfield", "subfield"),
SUBFIELD_INVALID_LENGTH(14, "invalidLength", "subfield: invalid length", "subfield"),
SUBFIELD_INVALID_CLASSIFICATION_REFERENCE(15, "invalidReference", "subfield: invalid classification reference", "subfield"),
SUBFIELD_PATTERN_MISMATCH(16, "patternMismatch", "subfield: content does not match any patterns", "subfield"),
SUBFIELD_NONREPEATABLE(17, "nonrepeatableSubfield", "subfield: repetition of non-repeatable subfield", "subfield"),
SUBFIELD_ISBN(18, "invalidISBN", "subfield: invalid ISBN", "subfield"),
SUBFIELD_ISSN(19, "invalidISSN", "subfield: invalid ISSN", "subfield"),
SUBFIELD_UNPARSABLE_CONTENT(20, "unparsableContent", "subfield: content is not well-formatted", "subfield"),
SUBFIELD_NULL_CODE(21, "nullCode", "subfield: null subfield code", "subfield"),
SUBFIELD_INVALID_VALUE(22, "hasInvalidValue", "subfield: invalid value", "subfield"),
;

private String code;
private String message;
private String category;
private final int id;
private final String code;
private final String message;
private final String category;

ValidationErrorType(String code, String message, String category) {
ValidationErrorType(int id, String code, String message, String category) {
this.id = id;
this.code = code;
this.message = message;
this.category = category;
}

public int getId() {
return id;
}

public String getCode() {
return code;
}
Expand Down
23 changes: 2 additions & 21 deletions src/test/java/de/gwdg/metadataqa/marc/LeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@
*/
public class LeaderTest {

public LeaderTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

@Test
public void test00928nama2200265c4500() {
Leader leader = new Leader("00928nam a2200265 c 4500");
Expand Down Expand Up @@ -306,13 +287,13 @@ public void testBadLeaderWithDefaultType() {
assertFalse(errors.isEmpty());
assertEquals(2, errors.size());
assertEquals(
"\"Leader\"\t\"record: undetectable type\"\t\"Leader/06 (typeOfRecord): 'n', Leader/07 (bibliographicLevel): 'm'\"\t\"https://www.loc.gov/marc/bibliographic/bdleader.html\"",
"\"Leader\"\t\"1\"\t\"record: undetectable type\"\t\"Leader/06 (typeOfRecord): 'n', Leader/07 (bibliographicLevel): 'm'\"\t\"https://www.loc.gov/marc/bibliographic/bdleader.html\"",
ValidationErrorFormatter.format(
errors.get(0), ValidationErrorFormat.TAB_SEPARATED
)
);
assertEquals(
"\"Leader/06 (leader06)\"\t\"control subfield: invalid value\"\t\"n\"\t\"https://www.loc.gov/marc/bibliographic/bdleader.html\"",
"\"Leader/06 (leader06)\"\t\"6\"\t\"control subfield: invalid value\"\t\"n\"\t\"https://www.loc.gov/marc/bibliographic/bdleader.html\"",
ValidationErrorFormatter.format(
errors.get(1), ValidationErrorFormat.TAB_SEPARATED
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/gwdg/metadataqa/marc/ValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void test246_6() throws URISyntaxException, IOException {
boolean isValid = record.validate(MarcVersion.MARC21, false);
if (!isValid) {
String message = ValidationErrorFormatter.format(record.getValidationErrors(), ValidationErrorFormat.TEXT);
assertTrue(message.contains("880$6: record: ambiguous linkage 'There are multiple $6'"));
assertTrue(message.contains("880$6: 3 - record: ambiguous linkage 'There are multiple $6'"));
}
}

Expand Down

0 comments on commit 77b533e

Please sign in to comment.