-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathPicsValidator.java
More file actions
187 lines (173 loc) · 6.02 KB
/
PicsValidator.java
File metadata and controls
187 lines (173 loc) · 6.02 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package helper;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Set;
import java.util.regex.Pattern;
public class PicsValidator {
String read = "R";
String write = "W";
String optional = "O";
String Supported = "TRUE";
String formatProperty = "%-35s%-35s%-15s%-25s";
Multimap<String, String> result = ArrayListMultimap.create();
boolean testPassed = false;
private int count = 0;
/**
* Validate a bacnet property on a bacnet object as defined by the pics statement
*
* @param bacnetObjectType Name of the BACnet Objet type to validate against
* @param bacnetObjectProperty Name of the BACnet property to validate for the specified BACnetObject
* @param conformanceCode Define the R/W/O parameter for the specified property
* @param supported TRUE/FALSE, whether or not this property is supported
* @param bacnetPointsMap Points discovered for the device being validated
* @param verboseOutput Enable/Disble verbose output
*/
public void validate(
String bacnetObjectType,
String bacnetObjectProperty,
String conformanceCode,
String supported,
Multimap bacnetPointsMap,
boolean verboseOutput) {
Set<String> mapKeySet = bacnetPointsMap.keySet();
ArrayList<String> keys = getMapKeys(mapKeySet, bacnetObjectType);
if (keys.size() == 0 && !supported.equals(Supported)) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"SKIPPED",
verboseOutput);
setResult(true);
} else if (keys.size() == 0
&& (conformanceCode.contains(read) || conformanceCode.equals(write))
&& !bacnetObjectProperty.equals("Property List")) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"FAILED",
verboseOutput);
setResult(false);
} else if (keys.size() == 0
&& conformanceCode.contains(optional)
&& !bacnetObjectProperty.equals("Property List")) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"PASSED/WARNING",
verboseOutput);
setResult(true);
} else if (keys.size() == 0 && bacnetObjectProperty.equals("Property List")) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"PASSED",
verboseOutput);
setResult(true);
}
for (String key : keys) {
String properties = bacnetPointsMap.get(key).toString();
boolean bacnetObjectPropertyIsFound =
Pattern.compile(Pattern.quote(bacnetObjectProperty), Pattern.CASE_INSENSITIVE)
.matcher(properties)
.find();
if (!supported.equals(Supported)) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"SKIPPED",
verboseOutput);
setResult(true);
} else if (!bacnetObjectPropertyIsFound
&& (conformanceCode.contains(read) || conformanceCode.equals(write))
&& supported.equals(Supported)
&& !bacnetObjectProperty.equals("Property List")) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"FAILED",
verboseOutput);
setResult(false);
} else if (!bacnetObjectPropertyIsFound
&& conformanceCode.contains(optional)
&& supported.equals(Supported)
&& !bacnetObjectProperty.equals("Property List")) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"PASSED/WARNING",
verboseOutput);
setResult(true);
} else if (bacnetObjectPropertyIsFound
&& supported.equals(Supported)
&& !bacnetObjectProperty.equals("Property List")) {
writeToAppendix(
formatProperty,
bacnetObjectType,
bacnetObjectProperty,
conformanceCode,
"PASSED",
verboseOutput);
setResult(true);
}
}
}
private void writeToAppendix(
String formatProperty,
String key,
String bacnetObjectProperty,
String conformanceCode,
String lineresult,
boolean verboseOutput) {
if (!verboseOutput & (lineresult.contains("FAILED") | lineresult.contains("PASSED/WARNING"))) {
String appendix =
String.format(formatProperty, key, bacnetObjectProperty, conformanceCode, lineresult);
this.result.put(key, appendix);
} else if (verboseOutput) {
String appendix =
String.format(formatProperty, key, bacnetObjectProperty, conformanceCode, lineresult);
this.result.put(key, appendix);
}
}
private ArrayList<String> getMapKeys(Set<String> mapKeySet, String bacnetObjectType) {
ArrayList<String> keys = new ArrayList<>();
for (String key : mapKeySet) {
if (key.contains(bacnetObjectType)) {
keys.add(key);
}
}
return keys;
}
private void setResult(boolean propertyValidated) {
if (count == 0) {
this.testPassed = propertyValidated;
} else {
if (!this.testPassed) {
return;
} else {
this.testPassed = propertyValidated;
}
}
count++;
}
public Multimap<String, String> getResultMap() {
return this.result;
}
public boolean getResult() {
return this.testPassed;
}
}