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

pkiraly / metadata-qa-api / #738

03 Dec 2025 10:03PM UTC coverage: 86.157% (-0.1%) from 86.256%
#738

push

pkiraly
Improve OR

0 of 8 new or added lines in 1 file covered. (0.0%)

42 existing lines in 3 files now uncovered.

5670 of 6581 relevant lines covered (86.16%)

0.86 hits per line

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

87.36
/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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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