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

pkiraly / metadata-qa-api / #742

14 Jan 2026 12:45PM UTC coverage: 85.581% (-0.6%) from 86.157%
#742

push

pkiraly
Add parent check

32 of 96 new or added lines in 7 files covered. (33.33%)

2 existing lines in 2 files now uncovered.

5686 of 6644 relevant lines covered (85.58%)

0.86 hits per line

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

84.44
/src/main/java/de/gwdg/metadataqa/api/rule/BaseRuleChecker.java
1
package de.gwdg.metadataqa.api.rule;
2

3
import de.gwdg.metadataqa.api.configuration.schema.ApplicationScope;
4
import de.gwdg.metadataqa.api.counter.FieldCounter;
5
import de.gwdg.metadataqa.api.json.DataElement;
6
import de.gwdg.metadataqa.api.model.selector.Selector;
7
import org.apache.commons.lang3.StringUtils;
8

9
import java.util.logging.Logger;
10

11
public abstract class BaseRuleChecker implements RuleChecker {
1✔
12

13
  protected static final Logger LOGGER = Logger.getLogger(BaseRuleChecker.class.getCanonicalName());
1✔
14

15
  protected String id;
16
  protected Integer failureScore;
17
  protected Integer successScore;
18
  protected Integer naScore;
19
  protected String header;
20
  protected Boolean hidden = false;
1✔
21
  private Boolean debug = false;
1✔
22
  private Boolean mandatory = false;
1✔
23
  private ApplicationScope scope;
24
  private String valuePath;
25

26
  /**
27
   * A flag to denote if the RuleChecker should count the number instances and failures
28
   */
29
  private Boolean countInstances = false;
1✔
30
  private Boolean naIfNoParent;
31

32
  @Override
33
  public String getId() {
34
    return id == null ? String.valueOf(0) : id;
1✔
35
  }
36

37
  @Override
38
  public void setId(String id) {
39
    this.id = id;
1✔
40
  }
1✔
41

42
  @Override
43
  public Integer getFailureScore() {
44
    return failureScore;
1✔
45
  }
46

47
  @Override
48
  public void setFailureScore(Integer failureScore) {
49
    this.failureScore = failureScore;
1✔
50
  }
1✔
51

52
  public RuleChecker withFailureScore(Integer failureScore) {
53
    this.failureScore = failureScore;
1✔
54
    return this;
1✔
55
  }
56

57
  @Override
58
  public Integer getSuccessScore() {
59
    return successScore;
1✔
60
  }
61

62
  @Override
63
  public void setSuccessScore(Integer successScore) {
64
    this.successScore = successScore;
1✔
65
  }
1✔
66

67
  public RuleChecker withSuccessScore(Integer successScore) {
68
    this.successScore = successScore;
1✔
69
    return this;
1✔
70
  }
71

72
  public void setNaScore(Integer naScore) {
73
    this.naScore = naScore;
1✔
74
  }
1✔
75

76
  public Integer getNaScore() {
77
    return naScore;
1✔
78
  }
79

80
  public RuleChecker withNaScore(Integer naScore) {
81
    this.naScore = naScore;
1✔
82
    return this;
1✔
83
  }
84

85
  @Override
86
  public String getHeaderWithoutId() {
87
    return header;
1✔
88
  }
89

90
  public String getHeader() {
91
    return header + ":" + getId();
1✔
92
  }
93

94
  public String getIdOrHeader() {
95
    return id != null ? id : header + ":" + getId();
1✔
96
  }
97

98
  public String getHeader(RuleCheckingOutputType outputType) {
99
    return getHeader() + getKeySuffix(outputType);
1✔
100
  }
101

102
  private static String getKeySuffix(RuleCheckingOutputType outputType) {
103
    String suffix = "";
1✔
104
    if (outputType.equals(RuleCheckingOutputType.STATUS))
1✔
105
      suffix = ":status";
1✔
106
    else if (outputType.equals(RuleCheckingOutputType.SCORE))
1✔
107
      suffix = ":score";
1✔
108
    return suffix;
1✔
109
  }
110

111
  public String getIdOrHeader(RuleCheckingOutputType outputType) {
112
    return getIdOrHeader() + getKeySuffix(outputType);
1✔
113
  }
114

115
  protected void addOutput(FieldCounter<RuleCheckerOutput> results,
116
                           boolean isNA,
117
                           boolean allPassed,
118
                           RuleCheckingOutputType outputType) {
119
    addOutput(results, isNA, allPassed, outputType, null, null);
1✔
120
  }
1✔
121

122
  protected void addOutput(FieldCounter<RuleCheckerOutput> results,
123
                           boolean isNA,
124
                           boolean allPassed,
125
                           RuleCheckingOutputType outputType,
126
                           Integer instanceCount,
127
                           Integer failureCount) {
128

129
    RuleCheckerOutput output = new RuleCheckerOutput(this, isNA, allPassed);
1✔
130
    if (instanceCount != null)
1✔
131
      output.setInstanceCount(instanceCount);
1✔
132
    if (failureCount != null)
1✔
133
      output.setFailureCount(failureCount);
1✔
134

135
    addOutput(results, output, outputType);
1✔
136
  }
1✔
137

138
  /**
139
   * Add output to the result
140
   * @param results
141
   * @param output
142
   * @param outputType
143
   */
144
  protected void addOutput(FieldCounter<RuleCheckerOutput> results,
145
                           RuleCheckerOutput output,
146
                           RuleCheckingOutputType outputType) {
147
    if (outputType.equals(RuleCheckingOutputType.STATUS) || outputType.equals(RuleCheckingOutputType.SCORE)) {
1✔
148
      results.put(getIdOrHeader(), output.setOutputType(outputType));
1✔
149
    } else {
150
      try {
151
        RuleCheckerOutput output2 = (RuleCheckerOutput) output.copy();
1✔
152
        results.put(getIdOrHeader(RuleCheckingOutputType.STATUS), output.setOutputType(RuleCheckingOutputType.STATUS));
1✔
153
        results.put(getIdOrHeader(RuleCheckingOutputType.SCORE), output2.setOutputType(RuleCheckingOutputType.SCORE));
1✔
154
      } catch (CloneNotSupportedException e) {
×
155
        e.printStackTrace(System.err);
×
156
      }
1✔
157
    }
158
  }
1✔
159

160
  public void setHidden() {
161
    this.hidden = true;
1✔
162
  }
1✔
163

164
  public boolean isHidden() {
165
    return hidden;
1✔
166
  }
167

168
  public void setDebug() {
169
    this.debug = true;
1✔
170
  }
1✔
171

172
  public boolean isDebug() {
173
    return debug;
1✔
174
  }
175

176
  @Override
177
  public void setMandatory() {
178
    this.mandatory = true;
×
179
  }
×
180

181
  @Override
182
  public boolean isMandatory() {
183
    return mandatory;
1✔
184
  }
185

186
  @Override
187
  public ApplicationScope getScope() {
188
    return scope;
1✔
189
  }
190

191
  @Override
192
  public void setScope(ApplicationScope scope) {
193
    this.scope = scope;
1✔
194
  }
1✔
195

196
  @Override
197
  public boolean hasScope() {
198
    return scope != null;
1✔
199
  }
200

201
  public String getValuePath() {
202
    return valuePath;
1✔
203
  }
204

205
  @Override
206
  public void setValuePath(String valuePath) {
207
    System.err.println("setValuePath: " + valuePath);
1✔
208
    this.valuePath = valuePath;
1✔
209
  }
1✔
210

211
  @Override
212
  public boolean hasValuePath() {
213
    return StringUtils.isNotBlank(valuePath);
1✔
214
  }
215

216
  public boolean countInstances() {
217
    return countInstances;
1✔
218
  }
219

220
  public void setCountInstances(Boolean countInstances) {
221
    this.countInstances = countInstances;
1✔
222
  }
1✔
223

224
  /**
225
   * Decide if the criterium has been passed base on the results, and the scope
226
   * @param passCount The number of times the check has been passed
227
   * @param hasFailed Whether there were a failure
228
   * @return
229
   */
230
  public boolean isPassed(int passCount, boolean hasFailed) {
231
    boolean passed = false;
1✔
232
    if (hasScope()) {
1✔
233
      if (scopeIsAllOf()) {
×
234
        passed = passCount > 0 && !hasFailed;
×
235
      } else if (scopeIsAnyOf()) {
×
236
        passed = passCount > 0;
×
237
      } else if (scopeIsOneOf()) {
×
238
        passed = passCount == 1;
×
239
      }
240
    } else {
241
      passed = passCount > 0;
1✔
242
    }
243
    return passed;
1✔
244
  }
245

246
  protected boolean scopeIsAllOf() {
247
    return hasScope() && scope.equals(ApplicationScope.allOf);
1✔
248
  }
249

250
  protected boolean scopeIsAnyOf() {
251
    return hasScope() && scope.equals(ApplicationScope.anyOf);
1✔
252
  }
253

254
  protected boolean scopeIsOneOf() {
255
    return hasScope() && scope.equals(ApplicationScope.oneOf);
×
256
  }
257

258
  public void setNaIfNoParent(Boolean naIfNoParent) {
NEW
259
    this.naIfNoParent = naIfNoParent;
×
NEW
260
  }
×
261

262
  public boolean isNaIfNoParent() {
NEW
263
    return naIfNoParent != null && naIfNoParent.equals(Boolean.TRUE);
×
264
  }
265
}
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