• 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.26
/src/main/java/de/gwdg/metadataqa/marc/cli/parameters/FormatterParameters.java
1
package de.gwdg.metadataqa.marc.cli.parameters;
2

3
import de.gwdg.metadataqa.marc.definition.bibliographic.SchemaType;
4
import de.gwdg.metadataqa.marc.utils.SchemaSpec;
5
import de.gwdg.metadataqa.marc.utils.marcspec.MarcSpecParser;
6
import de.gwdg.metadataqa.marc.utils.pica.path.PicaSpec;
7
import org.apache.commons.cli.ParseException;
8
import org.apache.commons.lang3.StringUtils;
9

10
import java.util.ArrayList;
11
import java.util.List;
12

13
public class FormatterParameters extends CommonParameters {
14
  public static final String DEFAULT_FILE_NAME = "extracted.csv";
15

16
  private String format = null;
1✔
17
  private int countNr = -1;
1✔
18
  private String search = null;
1✔
19
  private String path = null;
1✔
20
  private String query = null;
1✔
21
  private List<SchemaSpec> selector = null;
1✔
22
  private boolean withId = false;
1✔
23
  private String separator = "\t";
1✔
24
  private String fileName = DEFAULT_FILE_NAME;
1✔
25
  private List<String> ids;
26

27
  private boolean isOptionSet = false;
1✔
28

29
  @Override
30
  protected void setOptions() {
31
    if (!isOptionSet) {
1✔
32
      super.setOptions();
1✔
33
      options.addOption("f", "format", true, "specify a format");
1✔
34
      options.addOption("c", "countNr", true, "count number of the record (e.g. 1 means the first record)");
1✔
35
      options.addOption("s", "search", true, "search string ([path]=[value])");
1✔
36
      options.addOption("l", "selector", true, "selectors");
1✔
37
      options.addOption("w", "withId", false, "the generated CSV should contain record ID as first field");
1✔
38
      options.addOption("p", "separator", true, "separator between the parts (default: TAB)");
1✔
39
      options.addOption("A", "ids", true, "list of identifiers separated by comma");
1✔
40
      options.addOption("e", "fileName", true, String.format("output file (default: %s)", DEFAULT_FILE_NAME));
1✔
41
      isOptionSet = true;
1✔
42
    }
43
  }
1✔
44

45
  public FormatterParameters() {
46
    super();
1✔
47
  }
1✔
48

49
  public FormatterParameters(String[] arguments) throws ParseException {
50
    super(arguments);
1✔
51

52
    if (cmd.hasOption("format"))
1✔
53
      format = cmd.getOptionValue("format");
1✔
54

55
    if (cmd.hasOption("countNr"))
1✔
UNCOV
56
      countNr = Integer.parseInt(cmd.getOptionValue("countNr"));
×
57

58
    if (cmd.hasOption("search")) {
1✔
59
      search = cmd.getOptionValue("search");
1✔
60
      String[] parts = search.split("=", 2);
1✔
61
      path = parts[0];
1✔
62
      query = parts[1];
1✔
63
    }
64

65
    if (cmd.hasOption("selector")) {
1✔
66
      String rawSelector = cmd.getOptionValue("selector");
1✔
67
      String[] rawSelectors = rawSelector.split(";");
1✔
68
      selector = new ArrayList<>();
1✔
69
      if (getSchemaType().equals(SchemaType.PICA)) {
1✔
70
        for (String _rawSelector : rawSelectors)
1✔
71
          selector.add(new PicaSpec(_rawSelector));
1✔
72
      } else {
73
        for (String _rawSelector : rawSelectors)
1✔
74
          selector.add(MarcSpecParser.parse(_rawSelector));
1✔
75
      }
76
    }
77

78
    withId = cmd.hasOption("withId");
1✔
79

80
    if (cmd.hasOption("separator"))
1✔
81
      separator = cmd.getOptionValue("separator");
1✔
82

83
    if (cmd.hasOption("fileName"))
1✔
84
      fileName = cmd.getOptionValue("fileName");
1✔
85

86
    if (cmd.hasOption("ids")) {
1✔
NEW
87
      ids = List.of(cmd.getOptionValue("ids").split(","));
×
88
    }
89
  }
1✔
90

91
  public String getFormat() {
92
    return format;
1✔
93
  }
94

95
  public int getCountNr() {
96
    return countNr;
1✔
97
  }
98

99
  public String getSearch() {
100
    return search;
1✔
101
  }
102

103
  public boolean hasSearch() {
104
    return StringUtils.isNotBlank(path) && StringUtils.isNotBlank(query);
1✔
105
  }
106

107
  public String getPath() {
108
    return path;
1✔
109
  }
110

111
  public String getQuery() {
112
    return query;
1✔
113
  }
114

115
  public List<SchemaSpec> getSelector() {
116
    return selector;
1✔
117
  }
118

119
  public boolean hasSelector() {
120
    return selector != null && !selector.isEmpty();
1✔
121
  }
122

123
  public boolean withId() {
124
    return withId;
1✔
125
  }
126

127
  public String getSeparator() {
128
    return separator;
1✔
129
  }
130

131
  public String getFileName() {
132
    return fileName;
1✔
133
  }
134

135
  public List<String> getIds() {
136
    return ids;
1✔
137
  }
138

139
  @Override
140
  public String formatParameters() {
141
    String text = super.formatParameters();
1✔
142
    text += String.format("format: %s%n", format);
1✔
143
    text += String.format("countNr: %s%n", countNr);
1✔
144
    text += String.format("search: %s%n", search);
1✔
145
    text += String.format("selector: %s%n", selector);
1✔
146
    text += String.format("withId: %s%n", withId);
1✔
147
    text += String.format("separator: %s%n", separator);
1✔
148
    text += String.format("outputFile: %s%n", fileName);
1✔
149
    text += String.format("ids: %s%n", StringUtils.join(ids, ", "));
1✔
150
    return text;
1✔
151
  }
152

153
}
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