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

pkiraly / metadata-qa-api / #692

04 Jun 2025 11:56AM UTC coverage: 86.93% (-0.3%) from 87.231%
#692

push

pkiraly
Merge branch 'main' of github.com:pkiraly/metadata-qa-api

5547 of 6381 relevant lines covered (86.93%)

0.87 hits per line

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

96.67
/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 selector, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) {
31
    if (isDebug())
1✔
32
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id);
1✔
33

34
    if (this.hasValuePath())
1✔
35
      LOGGER.info("valuePath: " + this.getValuePath());
1✔
36
    var isNA = true;
1✔
37
    boolean hasFailed = false;
1✔
38
    int passCount = 0;
1✔
39

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

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