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

pkiraly / metadata-qa-api / #625

29 Jan 2025 12:12PM UTC coverage: 87.702% (-0.003%) from 87.705%
#625

push

pkiraly
Set up optional dependency between 'and' and 'dependencies' checkers #215

5 of 7 new or added lines in 2 files covered. (71.43%)

4 existing lines in 2 files now uncovered.

5327 of 6074 relevant lines covered (87.7%)

0.88 hits per line

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

73.33
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/DependencyChecker.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.Map;
13
import java.util.logging.Logger;
14

15
public class DependencyChecker extends SingleFieldChecker {
16

17
  private static final Logger LOGGER = Logger.getLogger(DependencyChecker.class.getCanonicalName());
1✔
18

19
  public static final String PREFIX = "dependency";
20
  protected List<String> dependencies;
21
  private RuleCheckingOutputStatus failedDepencencyStatus;
22

23
  public DependencyChecker(DataElement field, List<String> dependencies) {
24
    this(field, field.getLabel(), dependencies, RuleCheckingOutputStatus.FAILED);
1✔
25
  }
1✔
26

27
  public DependencyChecker(DataElement field,
28
                           List<String> dependencies,
29
                           RuleCheckingOutputStatus failedDepencencyStatus) {
30
    this(field, field.getLabel(), dependencies, failedDepencencyStatus);
×
31
  }
×
32

33
  public DependencyChecker(DataElement field,
34
                           String header,
35
                           List<String> dependencies,
36
                           RuleCheckingOutputStatus failedDepencencyStatus) {
37
    super(field, header + ":" + PREFIX);
1✔
38
    this.dependencies = dependencies;
1✔
39
    this.failedDepencencyStatus = failedDepencencyStatus;
1✔
40
  }
1✔
41

42
  @Override
43
  public void update(Selector cache, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) {
44
    update(cache, results, outputType, null);
×
45
  }
×
46

47
  public void update(Selector cache,
48
                     FieldCounter<RuleCheckerOutput> localResults,
49
                     RuleCheckingOutputType outputType,
50
                     FieldCounter<RuleCheckerOutput> globalResults) {
51
    if (isDebug())
1✔
52
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id);
×
53

54
    if (globalResults == null)
1✔
55
      globalResults = localResults;
×
56

57
    var isNA = true;
1✔
58
    var allPassed = true;
1✔
59
    List<XmlFieldInstance> instances = cache.get(field);
1✔
60
    if (instances != null && !instances.isEmpty()) {
1✔
61
      for (XmlFieldInstance instance : instances) {
1✔
62
        if (instance.hasValue()) {
1✔
63
          isNA = false;
1✔
64
          allPassed = getResult(outputType, globalResults);
1✔
65
          /*
66
          for (String ruleId : dependencies) {
67
            String keyEnd = outputType.equals(RuleCheckingOutputType.BOTH) ? ruleId + ":status" : ruleId;
68
            boolean found = false;
69
            for (Map.Entry<String, RuleCheckerOutput> entry : globalResults.getMap().entrySet()) {
70
              if (entry.getKey().endsWith(keyEnd)) {
71
                found = true;
72
                if (entry.getValue().getStatus().equals(RuleCheckingOutputStatus.FAILED)) {
73
                  allPassed = false;
74
                  break;
75
                }
76
              }
77
            }
78
            if (!found) {
79
              allPassed = false;
80
              break;
81
            }
82
          }
83
           */
84
        }
85
      }
1✔
86
    }
87

88
    addOutput(localResults, isNA, allPassed, outputType);
1✔
89
    if (isDebug())
1✔
90
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed));
×
91
  }
1✔
92

93
  public List<String> getDependencies() {
94
    return dependencies;
×
95
  }
96

97
  public boolean getResult(RuleCheckingOutputType outputType,
98
                           FieldCounter<RuleCheckerOutput> globalResults) {
99
    boolean allPassed = true;
1✔
100
    for (String ruleId : dependencies) {
1✔
101
      String keyEnd = outputType.equals(RuleCheckingOutputType.BOTH) ? ruleId + ":status" : ruleId;
1✔
102
      boolean found = false;
1✔
103
      for (Map.Entry<String, RuleCheckerOutput> entry : globalResults.getMap().entrySet()) {
1✔
104
        if (entry.getKey().endsWith(keyEnd)) {
1✔
105
          found = true;
1✔
106
          if (entry.getValue().getStatus().equals(RuleCheckingOutputStatus.FAILED)) {
1✔
UNCOV
107
            allPassed = false;
×
UNCOV
108
            break;
×
109
          }
110
        }
111
      }
1✔
112
      if (!found) {
1✔
113
        allPassed = false;
×
114
        break;
×
115
      }
116
    }
1✔
117
    return allPassed;
1✔
118
  }
119
}
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