-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPredicate.java
More file actions
100 lines (88 loc) · 3.29 KB
/
Predicate.java
File metadata and controls
100 lines (88 loc) · 3.29 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.checkmarx.ast.predicate;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.type.TypeFactory;
import lombok.Value;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
@Value
@JsonDeserialize()
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Predicate {
String id;
String similarityId;
String projectId;
String state;
String severity;
String comment;
String createdBy;
String createdAt;
String updatedAt;
Integer stateId;
@JsonCreator
public Predicate(@JsonProperty("ID") String id, @JsonProperty("SimilarityID") String similarityId,
@JsonProperty("ProjectID") String projectId, @JsonProperty("State") String state,
@JsonProperty("Severity") String severity, @JsonProperty("Comment") String comment,
@JsonProperty("CreatedBy") String createdBy, @JsonProperty("CreatedAt") String createdAt,
@JsonProperty("UpdatedAt") String updatedAt, @JsonProperty("StateId") Integer stateId) {
this.id = id;
this.similarityId = similarityId;
this.projectId = projectId;
this.state = state;
this.severity = severity;
this.comment = comment;
this.createdBy = createdBy;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.stateId = stateId;
}
public static <T> T fromLine(String line) {
return parse(line, TypeFactory.defaultInstance().constructType(Predicate.class));
}
public static <T> List<T> listFromLine(String line) {
return parse(line, TypeFactory.defaultInstance().constructCollectionType(List.class, Predicate.class));
}
protected static <T> T parse(String line, JavaType type) {
T result = null;
try {
if (!StringUtils.isBlank(line) && isValidJSON(line)) {
result = new ObjectMapper().readValue(line, type);
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public static boolean validator(List<String> arguments, Object parsedLine) {
{
for (Field field : parsedLine.getClass().getDeclaredFields()) {
field.setAccessible(true);
try {
if (field.get(parsedLine) == null && !field.getName().equals("stateId")) {
return false;
}
} catch (IllegalAccessException e) {
return false;
}
}
return true;
}
}
private static boolean isValidJSON(final String json) {
try {
final ObjectMapper mapper = new ObjectMapper();
mapper.readTree(json);
return true;
} catch (IOException e) {
return false;
}
}
}