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

pkiraly / metadata-qa-api / #650

10 Apr 2025 04:57PM UTC coverage: 87.139%. Remained the same
#650

push

pkiraly
Fix isNA in Pattern checker

1 of 1 new or added line in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

5468 of 6275 relevant lines covered (87.14%)

0.87 hits per line

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

85.71
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/PatternChecker.java
1
package de.gwdg.metadataqa.api.rule.singlefieldchecker;
2

3
import de.gwdg.metadataqa.api.counter.FieldCounter;
4
import de.gwdg.metadataqa.api.json.DataElement;
5
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
6
import de.gwdg.metadataqa.api.model.selector.Selector;
7
import de.gwdg.metadataqa.api.rule.RuleCheckerOutput;
8
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputStatus;
9
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputType;
10

11
import java.util.List;
12
import java.util.regex.Pattern;
13

14
public class PatternChecker extends SingleFieldChecker {
15

16
  private static final long serialVersionUID = -1432138574479246596L;
17
  public static final String PREFIX = "pattern";
18
  protected Pattern pattern;
19

20
  public PatternChecker(DataElement field, String pattern) {
21
    this(field, field.getLabel(), pattern);
1✔
22
  }
1✔
23

24
  public PatternChecker(DataElement field, String header, String pattern) {
25
    super(field, header + ":" + PREFIX);
1✔
26
    this.pattern = Pattern.compile(pattern);
1✔
27
  }
1✔
28

29
  @Override
30
  public void update(Selector cache, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) {
31
    if (isDebug())
1✔
32
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id);
×
33

34
    var isNA = true;
1✔
35
    boolean hasFailed = false;
1✔
36
    int passCount = 0;
1✔
37
    List<XmlFieldInstance> instances = cache.get(field);
1✔
38
    if (instances != null && !instances.isEmpty()) {
1✔
39
      for (XmlFieldInstance instance : instances) {
1✔
40
        isNA = false;
1✔
41
        if (instance.hasValue()) {
1✔
42
          if (isDebug())
1✔
UNCOV
43
            LOGGER.info("value: " + instance.getValue());
×
44
          if (!pattern.matcher(instance.getValue()).find()) {
1✔
45
            hasFailed = true;
1✔
46
            if (scopeIsAllOf()) {
1✔
47
              break;
×
48
            }
49
          } else {
50
            passCount++;
1✔
51
          }
52
        }
53
      }
1✔
54
    }
55
    boolean allPassed = isPassed(passCount, hasFailed);
1✔
56
    addOutput(results, isNA, allPassed, outputType);
1✔
57
    if (isDebug())
1✔
58
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed, isMandatory()));
×
59
  }
1✔
60

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