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

pkiraly / metadata-qa-api / #690

21 May 2025 09:55AM UTC coverage: 87.231% (-0.01%) from 87.245%
#690

push

pkiraly
Log errors during the content type check

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

5520 of 6328 relevant lines covered (87.23%)

0.87 hits per line

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

76.92
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/ContentTypeChecker.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
import de.gwdg.metadataqa.api.util.ContentTypeExtractor;
11

12
import java.io.IOException;
13
import java.util.List;
14
import java.util.logging.Logger;
15

16
public class ContentTypeChecker extends SingleFieldChecker {
17

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

20
  public static final String PREFIX = "contentType";
21
  protected List<String> fixedValues;
22

23
  public ContentTypeChecker(DataElement field, List<String> contentType) {
24
    this(field, field.getLabel(), contentType);
1✔
25
  }
1✔
26

27
  public ContentTypeChecker(DataElement field, String header, List<String> fixedValues) {
28
    super(field, header + ":" + PREFIX);
1✔
29
    this.fixedValues = fixedValues;
1✔
30
  }
1✔
31

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

37
    var allPassed = true;
1✔
38
    var isNA = true;
1✔
39
    int instanceCount = 0;
1✔
40
    int failureCount = 0;
1✔
41
    List<XmlFieldInstance> instances = cache.get(field);
1✔
42
    if (instances != null && !instances.isEmpty()) {
1✔
43
      for (XmlFieldInstance instance : instances) {
1✔
44
        if (instance.hasValue()) {
1✔
45
          if (countInstances())
1✔
46
            instanceCount++;
1✔
47
          isNA = false;
1✔
48
          try {
49
            String contentType = ContentTypeExtractor.getContentType(instance.getValue());
1✔
50
            if (isDebug())
1✔
51
              LOGGER.info(String.format("value: '%s' -> '%s'", instance.getValue(), contentType));
×
52
            if (contentType == null || !fixedValues.contains(contentType)) {
1✔
53
              allPassed = false;
1✔
54
              if (countInstances())
1✔
55
                failureCount++;
×
56
            }
57
          } catch (IOException e) {
×
NEW
58
            LOGGER.warning(String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()));
×
59
            allPassed = false;
×
60
            if (countInstances())
×
61
              failureCount++;
×
62
          }
1✔
63
          if (!countInstances() && !allPassed)
1✔
64
            break;
1✔
65
        }
66
      }
1✔
67
    }
68

69
    addOutput(results, isNA, allPassed, outputType, instanceCount, failureCount);
1✔
70
    if (isDebug())
1✔
71
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed, isMandatory()));
×
72
  }
1✔
73
}
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