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

pkiraly / metadata-qa-api / #644

03 Apr 2025 09:28AM UTC coverage: 87.234% (-0.2%) from 87.454%
#644

push

pkiraly
Add mandatory and scope as generic rule properties #225

70 of 87 new or added lines in 12 files covered. (80.46%)

6 existing lines in 4 files now uncovered.

5453 of 6251 relevant lines covered (87.23%)

0.87 hits per line

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

86.67
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MinWordsChecker.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.StringTokenizer;
13

14
public class MinWordsChecker extends SingleFieldChecker {
15

16
  private static final long serialVersionUID = 3259638493041988749L;
17
  public static final String PREFIX = "minWords";
18
  protected Integer minWords;
19

20
  public MinWordsChecker(DataElement field, int minWords) {
21
    this(field, field.getLabel(), minWords);
1✔
22
  }
1✔
23

24
  public MinWordsChecker(DataElement field, String header, int minWords) {
25
    super(field, header + ":" + PREFIX);
1✔
26
    this.minWords = minWords;
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
        if (instance.hasValue()) {
1✔
41
          isNA = false;
1✔
42
          if (isDebug())
1✔
43
            LOGGER.info("value: " + instance.getValue());
×
44
          LOGGER.info("countWords: " + countWords(instance.getValue()));
1✔
45
          if (countWords(instance.getValue()) < minWords) {
1✔
46
            hasFailed = true;
1✔
47
            if (scopeIsAllOf()) {
1✔
NEW
48
              break;
×
49
            }
50
          } else {
51
            passCount++;
1✔
52
          }
53
        }
54
      }
1✔
55
    }
56
    boolean allPassed = isPassed(passCount, hasFailed);
1✔
57
    addOutput(results, isNA, allPassed, outputType);
1✔
58
    if (isDebug())
1✔
59
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed, isMandatory()));
×
60
  }
1✔
61

62
  private int countWords(String value) {
63
    return new StringTokenizer(value).countTokens();
1✔
64
  }
65
}
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