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

DataBiosphere / consent / #5166

24 Jun 2024 06:02PM UTC coverage: 76.663% (-0.02%) from 76.68%
#5166

push

web-flow
DCJ-445: Update Row Helper Conditional (#2347)

60 of 69 new or added lines in 14 files covered. (86.96%)

2 existing lines in 2 files now uncovered.

9901 of 12915 relevant lines covered (76.66%)

0.77 hits per line

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

78.38
/src/main/java/org/broadinstitute/consent/http/enumeration/PropertyType.java
1
package org.broadinstitute.consent.http.enumeration;
2

3
import com.google.gson.Gson;
4
import com.google.gson.JsonElement;
5
import com.google.gson.JsonSyntaxException;
6
import java.time.Instant;
7
import java.time.format.DateTimeParseException;
8

9
public enum PropertyType {
1✔
10
  String("string"),
1✔
11
  Boolean("boolean"),
1✔
12
  Number("number"),
1✔
13
  Json("json"),
1✔
14
  Date("date");
1✔
15

16
  private final String value;
17

18
  PropertyType(String value) {
1✔
19
    this.value = value;
1✔
20
  }
1✔
21

22
  @Override
23
  public String toString() {
24
    return this.value;
1✔
25
  }
26

27
  public static PropertyType parse(String type) {
28
    if (type == null) {
1✔
UNCOV
29
      return PropertyType.String;
×
30
    }
31
    switch (type) {
1✔
32
      case "boolean":
33
        return PropertyType.Boolean;
1✔
34
      case "json":
35
        return PropertyType.Json;
1✔
36
      case "date":
37
        return PropertyType.Date;
1✔
38
      case "number":
39
        return PropertyType.Number;
1✔
40
      default: // always default to string.
41
        return PropertyType.String;
1✔
42
    }
43
  }
44

45
  public Object coerce(String value) throws IllegalArgumentException {
46
    switch (this) {
1✔
47
      case Boolean:
48
        return coerceToBoolean(value);
1✔
49
      case String:
50
        return value;
1✔
51
      case Date:
52
        return coerceToDate(value);
1✔
53
      case Json:
54
        return coerceToJson(value);
1✔
55
      case Number:
56
        return coerceToNumber(value);
1✔
57
      default:
58
        throw new IllegalArgumentException("Invalid DatasetPropertyType");
×
59
    }
60
  }
61

62
  public static Boolean coerceToBoolean(String value) throws IllegalArgumentException {
63
    return java.lang.Boolean.valueOf(value);
1✔
64
  }
65

66
  public static Instant coerceToDate(String value) throws IllegalArgumentException {
67
    try {
68

69
      return Instant.parse(value);
1✔
70
    } catch (DateTimeParseException e) {
1✔
71
      try {
72
        return Instant.parse(value + "T00:00:00Z"); // try adding timezones
1✔
73
      } catch (DateTimeParseException e2) {
×
74
        throw new IllegalArgumentException("Could not parse as Date: " + e.getMessage());
×
75
      }
76
    }
77
  }
78

79
  public static Number coerceToNumber(String value) throws IllegalArgumentException {
80
    try {
81
      return Integer.valueOf(value);
1✔
82
    } catch (NumberFormatException e) {
×
83
      throw new IllegalArgumentException("Could not parse as Integer: " + e.getMessage());
×
84
    }
85
  }
86

87
  public static JsonElement coerceToJson(String value) throws IllegalArgumentException {
88
    try {
89
      return new Gson().fromJson(value, JsonElement.class);
1✔
90
    } catch (JsonSyntaxException e) {
×
91
      throw new IllegalArgumentException("Could not parse as Json: " + e.getMessage());
×
92
    }
93
  }
94
}
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