• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkiraly / metadata-qa-marc / #1527

22 Aug 2025 02:21PM UTC coverage: 90.345%. Remained the same
#1527

push

pkiraly
Improve timeline handling

5191 of 6416 new or added lines in 219 files covered. (80.91%)

886 existing lines in 78 files now uncovered.

36717 of 40641 relevant lines covered (90.34%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.22
/src/main/java/de/gwdg/metadataqa/marc/cli/plugin/UnimarcCompletenessPlugin.java
1
package de.gwdg.metadataqa.marc.cli.plugin;
2

3
import de.gwdg.metadataqa.marc.cli.parameters.CompletenessParameters;
4
import de.gwdg.metadataqa.marc.dao.DataField;
5
import de.gwdg.metadataqa.marc.dao.MarcLeader;
6
import de.gwdg.metadataqa.marc.dao.record.BibliographicRecord;
7
import de.gwdg.metadataqa.marc.dao.record.UnimarcRecord;
8
import de.gwdg.metadataqa.marc.definition.structure.ControlfieldPositionDefinition;
9
import de.gwdg.metadataqa.marc.definition.structure.SubfieldDefinition;
10
import de.gwdg.metadataqa.marc.definition.tags.TagCategory;
11
import de.gwdg.metadataqa.marc.utils.TagHierarchy;
12
import de.gwdg.metadataqa.marc.utils.unimarc.UnimarcFieldDefinition;
13
import de.gwdg.metadataqa.marc.utils.unimarc.UnimarcLeaderDefinition;
14
import de.gwdg.metadataqa.marc.utils.unimarc.UnimarcSchemaManager;
15

16
import java.io.Serializable;
17

18
public class UnimarcCompletenessPlugin implements CompletenessPlugin, Serializable {
19

20
  private final CompletenessParameters parameters;
21
  private final UnimarcSchemaManager unimarcSchema;
22

23
  public UnimarcCompletenessPlugin(CompletenessParameters parameters, UnimarcSchemaManager unimarcSchema) {
1✔
24
    this.parameters = parameters;
1✔
25
    this.unimarcSchema = unimarcSchema;
1✔
26
  }
1✔
27

28
  @Override
29
  public String getDocumentType(BibliographicRecord marcRecord) {
30

31
    // marcRecord != null checked with this instanceof condition
32
    if (!(marcRecord instanceof UnimarcRecord)) {
1✔
NEW
33
      return MarcLeader.Type.BOOKS.getValue();
×
34
    }
35

36
    return ((UnimarcRecord) marcRecord)
1✔
37
        .getLeader()
1✔
38
        .getType()
1✔
39
        .getValue();
1✔
40
  }
41

42
  @Override
43
  public TagHierarchy getTagHierarchy(String path) {
44
    // There isn't the same detailed distinction as with MARC21.
45
    // Here the main distinction is if the tag is a:
46
    // - leader - The category could be defined as
47
    // - any other field
48

49
    if (path.startsWith("leader")) {
1✔
50
      UnimarcLeaderDefinition leaderDefinition = unimarcSchema.getLeaderDefinition();
1✔
51
      ControlfieldPositionDefinition positionDefinition = leaderDefinition.getPositionDefinitionById(path);
1✔
52
      return new TagHierarchy(TagCategory.UNIMARC_0, path, positionDefinition.getLabel());
1✔
53
    }
54

55
    // Get one of unimarc categories from the TagCategory enum. The first character of the path is the digit the enum
56
    // name ends with.
57

58
    TagCategory category = TagCategory.valueOf("UNIMARC_" + path.charAt(0));
1✔
59
    String[] paths = path.split("\\$");
1✔
60
    String fieldTag = paths[0];
1✔
61

62
    UnimarcFieldDefinition fieldDefinition = unimarcSchema.lookup(fieldTag);
1✔
63

64
    if (fieldDefinition == null) {
1✔
65
      return null;
1✔
66
    }
67
    String fieldLabel = fieldDefinition.getLabel();
1✔
68
    if (paths.length == 1) {
1✔
69
      return new TagHierarchy(category, fieldLabel, null);
1✔
70
    }
71

72
    String subfieldCode = paths[1];
1✔
73

74
    // This subfield code is either indicator or subfield code. E.g. "ind1" or "a"
75
    // This is an indicator
76
    if (subfieldCode.startsWith("ind")) {
1✔
77
      String indicatorNumber = subfieldCode.substring(3);
1✔
78
      int indicatorIndex = Integer.parseInt(indicatorNumber) - 1;
1✔
79

80
      String indicatorLabel = fieldDefinition.getIndicators().get(indicatorIndex).getLabel();
1✔
81
      return new TagHierarchy(category, fieldLabel, indicatorLabel);
1✔
82
    }
83

84
    // This is a subfield
85
    SubfieldDefinition subfieldDefinition = fieldDefinition.getSubfield(subfieldCode);
1✔
86
    if (subfieldDefinition == null) {
1✔
87
      return new TagHierarchy(category, fieldLabel, "");
1✔
88
    }
89

90
    String subfieldLabel = subfieldDefinition.getLabel();
1✔
91

92
    return new TagHierarchy(category, fieldLabel, subfieldLabel);
1✔
93
  }
94

95
  @Override
96
  public String getPackageName(DataField field) {
97
    TagCategory category = TagCategory.valueOf("UNIMARC_" + field.getTag().charAt(0));
1✔
98
    return category.getPackageName();
1✔
99
  }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc