Skip to content

Commit

Permalink
issue #137: fixing code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Jun 22, 2022
1 parent a7e0c11 commit 262504a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 57 deletions.
14 changes: 7 additions & 7 deletions src/main/java/de/gwdg/metadataqa/marc/cli/Completeness.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void processLeader(MarcRecord marcRecord, Map<String, Integer> recordFre
count(marcPath, elementCardinality.get(documentType));
count(marcPath, elementCardinality.get("all"));
count(marcPath, recordFrequency);
count(TagCategory.tags00x.getPackageName(), recordPackageCounter);
count(TagCategory.TAGS_00X.getPackageName(), recordPackageCounter);
}
}
}
Expand All @@ -161,7 +161,7 @@ private void processSimpleControlfields(MarcRecord marcRecord, Map<String, Integ
count(marcPath, elementCardinality.get(documentType));
count(marcPath, elementCardinality.get("all"));
count(marcPath, recordFrequency);
count(TagCategory.tags00x.getPackageName(), recordPackageCounter);
count(TagCategory.TAGS_00X.getPackageName(), recordPackageCounter);
}
}
}
Expand All @@ -174,7 +174,7 @@ private void processPositionalControlFields(MarcRecord marcRecord, Map<String, I
count(marcPath, elementCardinality.get(documentType));
count(marcPath, elementCardinality.get("all"));
count(marcPath, recordFrequency);
count(TagCategory.tags00x.getPackageName(), recordPackageCounter);
count(TagCategory.TAGS_00X.getPackageName(), recordPackageCounter);
}
}
}
Expand Down Expand Up @@ -227,12 +227,12 @@ private String getPackageName(DataField field) {
packageName = plugin.getPackageName(field);
if (StringUtils.isBlank(packageName)) {
logger.warning(String.format("%s has no package. /%s", field, field.getDefinition().getClass()));
packageName = TagCategory.other.getPackageName();
packageName = TagCategory.OTHER.getPackageName();
}
packageNameCache.put(field.getDefinition(), packageName);
}
} else {
packageName = TagCategory.other.getPackageName();
packageName = TagCategory.OTHER.getPackageName();
}
return packageName;
}
Expand Down Expand Up @@ -406,8 +406,8 @@ private String formatCardinality(char separator,
}

String marcPathLabel = marcPath.replace("!ind", "ind").replaceAll("\\|(\\d)$", "$1");
int packageId = TagCategory.other.getId();
String packageLabel = TagCategory.other.getLabel();
int packageId = TagCategory.OTHER.getId();
String packageLabel = TagCategory.OTHER.getLabel();
String tagLabel = "";
String subfieldLabel = "";
TagHierarchy tagHierarchy = plugin.getTagHierarchy(marcPathLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import de.gwdg.metadataqa.marc.dao.MarcRecord;
import de.gwdg.metadataqa.marc.utils.TagHierarchy;

import java.util.regex.Pattern;

public class Marc21CompletenessPlugin implements CompletenessPlugin {
private final CompletenessParameters parameters;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public TagHierarchy getTagHierarchy(String rawpath) {
String fieldLabel = "";
String subfieldLabel = "";
PicaFieldDefinition fieldDefinition = picaSchema.get(path.getField());
TagCategory category = TagCategory.other;
TagCategory category = TagCategory.OTHER;
if (fieldDefinition != null) {
category = getTagCategory(fieldDefinition);
fieldLabel = fieldDefinition.getLabel();
Expand All @@ -81,16 +81,16 @@ public String getPackageName(DataField field) {
if (field.getDefinition() != null) {
return getTagCategory((PicaFieldDefinition) field.getDefinition()).getPackageName();
}
return TagCategory.other.getPackageName();
return TagCategory.OTHER.getPackageName();
}

private TagCategory getTagCategory(PicaFieldDefinition field) {
switch (field.getTag().substring(0, 1)) {
case "0": return TagCategory.pica0;
case "1": return TagCategory.pica1;
case "2": return TagCategory.pica2;
case "0": return TagCategory.PICA_0;
case "1": return TagCategory.PICA_1;
case "2": return TagCategory.PICA_2;
default:
return TagCategory.other;
return TagCategory.OTHER;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,25 @@ protected boolean met(MarcRecord marcRecord) {
List<DataField> recordFields = marcRecord.getDatafield(condition.getTag());
if (recordFields == null || recordFields.isEmpty())
continue;
boolean passed = metCondition(condition, recordFields);
if (passed)
return true;
}
return false;
}

for (DataField recordField : recordFields) {
MarcSubfield subfieldCond = condition.getSubfields().get(0);
String code = subfieldCond.getCode();
List<MarcSubfield> recordSubfields = recordField.getSubfield(code);
private boolean metCondition(DataField condition, List<DataField> recordFields) {
for (DataField recordField : recordFields) {
MarcSubfield subfieldCond = condition.getSubfields().get(0);
String code = subfieldCond.getCode();
List<MarcSubfield> recordSubfields = recordField.getSubfield(code);

if (recordSubfields == null || recordSubfields.isEmpty())
continue;
if (recordSubfields == null || recordSubfields.isEmpty())
continue;

for (MarcSubfield recordSubfield : recordSubfields)
if (recordSubfield.getValue().equals(subfieldCond.getValue()))
return true;
}
for (MarcSubfield recordSubfield : recordSubfields)
if (recordSubfield.getValue().equals(subfieldCond.getValue()))
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import de.gwdg.metadataqa.marc.dao.MarcRecord;

import java.io.Serializable;

public interface RecordIgnorator {
boolean isEmpty();
boolean isIgnorable(MarcRecord marcRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@

public enum TagCategory {

tags00x(0, "tags00x", "00X", "Control Fields", true),
tags01x(1, "tags01x", "01X-09X", "Numbers and Code", true),
tags1xx(2, "tags1xx", "1XX", "Main Entry", true),
tags20x(3, "tags20x", "20X-24X", "Title", true),
tags25x(4, "tags25x", "25X-28X", "Edition, Imprint", true),
tags3xx(5, "tags3xx", "3XX", "Physical Description", true),
tags4xx(6, "tags4xx", "4XX", "Series Statement", true),
tags5xx(7, "tags5xx", "5XX", "Note", true),
tags6xx(8, "tags6xx", "6XX", "Subject Access", true),
tags70x(9, "tags70x", "70X-75X", "Added Entry", true),
tags76x(10, "tags76x", "76X-78X", "Linking Entry", true),
tags80x(11, "tags80x", "80X-83X", "Series Added Entry", true),
tags84x(12, "tags84x", "841-88X", "Holdings, Location, Alternate Graphics", true),
holdings(13, "holdings", "Holdings", "MARC Holdings tags", true),
oclc(14, "oclctags", "OCLC", "OCLCMARC tags", false),
dnb(15, "dnbtags", "DNB", "Locally defined tags of DNB", false),
fennica(16, "fennicatags", "Fennica", "Locally defined tags of Fennica", false),
gent(17, "genttags", "Gent", "Locally defined tags of Gent", false),
szte(18, "sztetags", "SZTE", "Locally defined tags of SZTE", false),
nkcr(19, "nkcrtags", "NKCR", "Locally defined tags of NKCR", false),
bl(20, "bltags", "BL", "Locally defined tags of the British Library", false),
uva(21, "uvatags", "UvA", "Locally defined tags of University of Amsterdam", false),
b3kat(22, "b3kattags", "B3Kat", "Locally defined tags of a German union cataogue B3Kat", false),
pica0(50, "pica0", "0...", "PICA+ bibliograhic description", false),
pica1(51, "pica1", "1...", "PICA+ holding", false),
pica2(52, "pica2", "2...", "PICA+ item", false),
other(99, "unknown", "unknown", "unknown origin", false)
TAGS_00X(0, "tags00x", "00X", "Control Fields", true),
TAGS_01X(1, "tags01x", "01X-09X", "Numbers and Code", true),
TAGS_1XX(2, "tags1xx", "1XX", "Main Entry", true),
TAGS_20X(3, "tags20x", "20X-24X", "Title", true),
TAGS_25X(4, "tags25x", "25X-28X", "Edition, Imprint", true),
TAGS_3XX(5, "tags3xx", "3XX", "Physical Description", true),
TAGS_4XX(6, "tags4xx", "4XX", "Series Statement", true),
TAGS_5XX(7, "tags5xx", "5XX", "Note", true),
TAGS_6XX(8, "tags6xx", "6XX", "Subject Access", true),
TAGS_70X(9, "tags70x", "70X-75X", "Added Entry", true),
TAGS_76X(10, "tags76x", "76X-78X", "Linking Entry", true),
TAGS_80X(11, "tags80x", "80X-83X", "Series Added Entry", true),
TAGS_84X(12, "tags84x", "841-88X", "Holdings, Location, Alternate Graphics", true),
HOLDINGS(13, "holdings", "Holdings", "MARC Holdings tags", true),
OCLC(14, "oclctags", "OCLC", "OCLCMARC tags", false),
DNB(15, "dnbtags", "DNB", "Locally defined tags of DNB", false),
FENNICA(16, "fennicatags", "Fennica", "Locally defined tags of Fennica", false),
GENT(17, "genttags", "Gent", "Locally defined tags of Gent", false),
SZTE(18, "sztetags", "SZTE", "Locally defined tags of SZTE", false),
NKCR(19, "nkcrtags", "NKCR", "Locally defined tags of NKCR", false),
BL(20, "bltags", "BL", "Locally defined tags of the British Library", false),
UVA(21, "uvatags", "UvA", "Locally defined tags of University of Amsterdam", false),
B3KAT(22, "b3kattags", "B3Kat", "Locally defined tags of a German union cataogue B3Kat", false),
PICA_0(50, "pica0", "0...", "PICA+ bibliograhic description", false),
PICA_1(51, "pica1", "1...", "PICA+ holding", false),
PICA_2(52, "pica2", "2...", "PICA+ item", false),
OTHER(99, "unknown", "unknown", "unknown origin", false)
;

private static Map<String, TagCategory> index = new HashMap<>();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/gwdg/metadataqa/marc/utils/TagHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static TagHierarchy createFromPath(String path, MarcVersion version) {
ControlfieldPositionDefinition positionDefinition = definition.getPositionDefinitionById(path);
if (positionDefinition != null) {
String subfieldLabel = positionDefinition.getLabel();
return new TagHierarchy(TagCategory.tags00x, definition.getLabel(), subfieldLabel);
return new TagHierarchy(TagCategory.TAGS_00X, definition.getLabel(), subfieldLabel);
}
} else {
matcher = controlFieldPattern.matcher(path);
Expand All @@ -85,7 +85,7 @@ public static TagHierarchy createFromPath(String path, MarcVersion version) {
if (StringUtils.isNotBlank(position)) {
subfieldLabel = position;
}
return new TagHierarchy(TagCategory.tags00x, tagLabel, subfieldLabel);
return new TagHierarchy(TagCategory.TAGS_00X, tagLabel, subfieldLabel);
}
} else {
matcher = controlFieldIdPattern.matcher(path);
Expand All @@ -102,7 +102,7 @@ public static TagHierarchy createFromPath(String path, MarcVersion version) {
ControlfieldPositionDefinition positionDefinition = fieldDefinition.getPositionDefinitionById(path);
if (positionDefinition != null) {
String subfieldLabel = positionDefinition.getLabel();
return new TagHierarchy(TagCategory.tags00x, tagLabel, subfieldLabel);
return new TagHierarchy(TagCategory.TAGS_00X, tagLabel, subfieldLabel);
}
}
}
Expand Down

0 comments on commit 262504a

Please sign in to comment.