-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.java
More file actions
executable file
·82 lines (66 loc) · 2.25 KB
/
Variable.java
File metadata and controls
executable file
·82 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.devcycle.sdk.server.common.model;
import java.util.HashMap;
import java.util.LinkedHashMap;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Variable<T> {
@Schema(required = true, description = "Unique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.")
private String key;
@Schema(required = true, description = "Variable value can be a string, number, boolean, or JSON")
private T value;
@Schema(required = true, description = "Variable type")
private TypeEnum type;
@Schema(required = true, description = "Variable default value")
private T defaultValue;
@Builder.Default
private Boolean isDefaulted = false;
@Schema(description = "Evaluation reason")
@JsonProperty("eval")
private EvalReason eval;
@Deprecated()
@JsonIgnore
private final String evalReason = null;
public enum TypeEnum {
STRING("String"),
BOOLEAN("Boolean"),
NUMBER("Number"),
JSON("JSON");
private final String value;
TypeEnum(String value) {
this.value = value;
}
public static TypeEnum fromClass(Class<?> clazz) {
if (clazz == LinkedHashMap.class || clazz == HashMap.class) {
return JSON;
} else if (clazz == Boolean.class) {
return BOOLEAN;
} else if (clazz == Integer.class || clazz == Double.class || clazz == Float.class) {
return NUMBER;
} else if (clazz == String.class) {
return STRING;
} else {
return null;
}
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
}
}