• 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.21
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxLengthChecker.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

13
public class MaxLengthChecker extends SingleFieldChecker {
14

15
  private static final long serialVersionUID = -3991731520985560338L;
16
  public static final String PREFIX = "maxLength";
17
  protected Integer maxLength;
18

19
  public MaxLengthChecker(DataElement field, Integer maxLength) {
20
    this(field, field.getLabel(), maxLength);
1✔
21
  }
1✔
22

23
  public MaxLengthChecker(DataElement field, String header, Integer maxLength) {
24
    super(field, header + ":" + PREFIX);
1✔
25
    this.maxLength = maxLength;
1✔
26
  }
1✔
27

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

33
    var isNA = true;
1✔
34
    boolean hasFailed = false;
1✔
35
    int passCount = 0;
1✔
36
    List<XmlFieldInstance> instances = cache.get(field);
1✔
37
    if (instances != null && !instances.isEmpty()) {
1✔
38
      for (XmlFieldInstance instance : instances) {
1✔
39
        if (instance.hasValue()) {
1✔
40
          isNA = false;
1✔
41
          if (isDebug())
1✔
42
            LOGGER.info("value: " + instance.getValue());
×
43
          if (instance.getValue().length() > maxLength) {
1✔
44
            hasFailed = true;
1✔
45
            if (scopeIsAllOf()) {
1✔
NEW
46
              break;
×
47
            }
48
          } else {
49
            passCount++;
1✔
50
          }
51
        }
52
      }
1✔
53
    }
54
    boolean allPassed = isPassed(passCount, hasFailed);
1✔
55
    System.err.println("allPassed: " + allPassed);
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
}
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