1
1
package gov .cms .qpp .conversion .validate ;
2
2
3
+ import com .google .common .base .Strings ;
4
+ import gov .cms .qpp .conversion .model .Node ;
5
+ import gov .cms .qpp .conversion .model .TemplateId ;
6
+ import gov .cms .qpp .conversion .model .error .Detail ;
7
+ import gov .cms .qpp .conversion .model .error .LocalizedError ;
8
+ import org .slf4j .Logger ;
9
+ import org .slf4j .LoggerFactory ;
10
+
3
11
import java .util .Arrays ;
4
12
import java .util .EnumMap ;
5
13
import java .util .EnumSet ;
10
18
import java .util .Set ;
11
19
import java .util .concurrent .atomic .AtomicInteger ;
12
20
13
- import org .slf4j .Logger ;
14
- import org .slf4j .LoggerFactory ;
15
-
16
- import com .google .common .base .Strings ;
17
-
18
- import gov .cms .qpp .conversion .model .Node ;
19
- import gov .cms .qpp .conversion .model .TemplateId ;
20
- import gov .cms .qpp .conversion .model .error .Detail ;
21
- import gov .cms .qpp .conversion .model .error .LocalizedError ;
22
-
23
21
/**
24
22
* Node checker DSL to help abbreviate / simplify single node validations
25
23
*/
@@ -77,7 +75,7 @@ private boolean shouldShortcut() {
77
75
/**
78
76
* checks target node for the existence of a value with the given name key
79
77
*
80
- * @param message error message if searched value is not found
78
+ * @param code that identifies the error
81
79
* @param name key of expected value
82
80
* @return The checker, for chaining method calls.
83
81
*/
@@ -92,11 +90,11 @@ public Checker value(LocalizedError code, String name) {
92
90
/**
93
91
* checks target node to ensure a value is retrieved with given name key
94
92
*
95
- * @param message error message if value is empty
93
+ * @param code that identifies the error
96
94
* @param name key of expected value
97
95
* @return The checker, for chaining method calls.
98
96
*/
99
- public Checker valueIsNotEmpty (LocalizedError code , String name ) {
97
+ Checker valueIsNotEmpty (LocalizedError code , String name ) {
100
98
lastAppraised = node .getValue (name );
101
99
if (!shouldShortcut () && Strings .isNullOrEmpty ((String ) lastAppraised )) {
102
100
details .add (detail (code ));
@@ -107,7 +105,7 @@ public Checker valueIsNotEmpty(LocalizedError code, String name) {
107
105
/**
108
106
* checks target node for the existence of a single value with the given name key
109
107
*
110
- * @param message error message if searched value is not found
108
+ * @param code that identifies the error
111
109
* @param name key of expected value
112
110
* @return The checker, for chaining method calls.
113
111
*/
@@ -124,25 +122,25 @@ public Checker singleValue(LocalizedError code, String name) {
124
122
* checks target node for the existence of a value with the given name key
125
123
* and matches that value with one of the supplied values.
126
124
*
127
- * @param message error message if searched value is not found
125
+ * @param code that identifies the error
128
126
* @param name key of expected value
129
127
* @param expected the expected value
130
128
* @return The checker, for chaining method calls.
131
129
*/
132
- public Checker valueIs (LocalizedError code , String name , String expected ) {
130
+ Checker valueIs (LocalizedError code , String name , String expected ) {
133
131
return valueIn (code , name , expected );
134
132
}
135
133
136
134
/**
137
135
* checks target node for the existence of a value with the given name key
138
136
* and matches that value with one of the supplied values.
139
137
*
140
- * @param message error message if searched value is not found
138
+ * @param code that identifies the error
141
139
* @param name key of expected value
142
140
* @param values List of strings to check for the existence of.
143
141
* @return The checker, for chaining method calls.
144
142
*/
145
- public Checker valueIn (LocalizedError code , String name , String ... values ) {
143
+ Checker valueIn (LocalizedError code , String name , String ... values ) {
146
144
boolean contains = false ;
147
145
if (name == null ) {
148
146
details .add (detail (code ));
@@ -168,11 +166,11 @@ public Checker valueIn(LocalizedError code, String name, String... values) {
168
166
/**
169
167
* Checks target node for the existence of an integer value with the given name key.
170
168
*
171
- * @param message error message if searched value is not found or is not appropriately typed
169
+ * @param code that identifies the error
172
170
* @param name key of expected value
173
171
* @return The checker, for chaining method calls.
174
172
*/
175
- public Checker intValue (LocalizedError code , String name ) {
173
+ Checker intValue (LocalizedError code , String name ) {
176
174
if (!shouldShortcut ()) {
177
175
try {
178
176
lastAppraised = Integer .parseInt (node .getValue (name ));
@@ -187,12 +185,12 @@ public Checker intValue(LocalizedError code, String name) {
187
185
/**
188
186
* Allow for compound comparisons of Node values.
189
187
*
190
- * @param message error message should comparison fail
188
+ * @param code that identifies the error
191
189
* @param value to be compared against
192
190
* @return The checker, for chaining method calls.
193
191
*/
194
192
@ SuppressWarnings ("unchecked" )
195
- public Checker greaterThan (LocalizedError code , Comparable <?> value ) {
193
+ Checker greaterThan (LocalizedError code , Comparable <?> value ) {
196
194
if (!shouldShortcut () && lastAppraised != null && ((Comparable <Object >) lastAppraised ).compareTo (value ) <= 0 ) {
197
195
details .add (detail (code ));
198
196
}
@@ -203,12 +201,12 @@ public Checker greaterThan(LocalizedError code, Comparable<?> value) {
203
201
/**
204
202
* Allow for compound comparisons of Node values.
205
203
*
206
- * @param message error message should comparison fail
204
+ * @param code that identifies the error
207
205
* @param value to be compared against
208
206
* @return The checker, for chaining method calls.
209
207
*/
210
208
@ SuppressWarnings ("unchecked" )
211
- public Checker lessThanOrEqualTo (LocalizedError code , Comparable <?> value ) {
209
+ Checker lessThanOrEqualTo (LocalizedError code , Comparable <?> value ) {
212
210
if (!shouldShortcut () && lastAppraised != null && ((Comparable <Object >) lastAppraised ).compareTo (value ) > 0 ) {
213
211
details .add (detail (code ));
214
212
}
@@ -219,14 +217,14 @@ public Checker lessThanOrEqualTo(LocalizedError code, Comparable<?> value) {
219
217
/**
220
218
* Checks target node value to be between a specific range
221
219
*
222
- * @param message error message should comparison fail
220
+ * @param code that identifies the error
223
221
* @param name key of expected value
224
222
* @param startValue starting value for range
225
223
* @param endValue ending value for range
226
224
* @return The checker, for chaining method calls
227
225
*/
228
226
@ SuppressWarnings ("unchecked" )
229
- public Checker inDecimalRangeOf (LocalizedError code , String name , float startValue , float endValue ) {
227
+ Checker inDecimalRangeOf (LocalizedError code , String name , float startValue , float endValue ) {
230
228
if (!shouldShortcut ()) {
231
229
try {
232
230
lastAppraised = Float .parseFloat (node .getValue (name ));
@@ -245,10 +243,10 @@ public Checker inDecimalRangeOf(LocalizedError code, String name, float startVal
245
243
/**
246
244
* Checks target node for the existence of a specified parent.
247
245
*
248
- * @param message validation error message
246
+ * @param code that identifies the error
249
247
* @return The checker, for chaining method calls.
250
248
*/
251
- public Checker hasParent (LocalizedError code , TemplateId type ) {
249
+ Checker hasParent (LocalizedError code , TemplateId type ) {
252
250
if (!shouldShortcut ()) {
253
251
TemplateId parentType = Optional .ofNullable (node .getParent ())
254
252
.orElse (new Node ()).getType ();
@@ -262,10 +260,10 @@ public Checker hasParent(LocalizedError code, TemplateId type) {
262
260
/**
263
261
* Checks target node for the existence of any child nodes.
264
262
*
265
- * @param message validation error message
263
+ * @param code that identifies the error
266
264
* @return The checker, for chaining method calls.
267
265
*/
268
- public Checker hasChildren (LocalizedError code ) {
266
+ Checker hasChildren (LocalizedError code ) {
269
267
if (!shouldShortcut () && node .getChildNodes ().isEmpty ()) {
270
268
details .add (detail (code ));
271
269
}
@@ -275,7 +273,7 @@ public Checker hasChildren(LocalizedError code) {
275
273
/**
276
274
* Verifies that the target node has at least the given minimum or more of the given {@link TemplateId}s.
277
275
*
278
- * @param message validation error message
276
+ * @param code that identifies the error
279
277
* @param minimum minimum required children of specified types
280
278
* @param types types of children to filter by
281
279
* @return The checker, for chaining method calls.
@@ -293,7 +291,7 @@ public Checker childMinimum(LocalizedError code, int minimum, TemplateId... type
293
291
/**
294
292
* Verifies that the target node has less than the given maximum of the given {@link TemplateId}s.
295
293
*
296
- * @param message validation error message
294
+ * @param code that identifies the error
297
295
* @param maximum maximum required children of specified types
298
296
* @param types types of children to filter by
299
297
* @return The checker, for chaining method calls.
@@ -311,13 +309,16 @@ public Checker childMaximum(LocalizedError code, int maximum, TemplateId... type
311
309
/**
312
310
* Verifies that the measures specified are contained within the current node's children
313
311
*
314
- * @param message validation error message
312
+ * @param code that identifies the error
315
313
* @param measureIds measures specified for given node
316
314
* @return The checker, for chaining method calls
317
315
*/
318
- public Checker hasMeasures (LocalizedError code , String ... measureIds ) {
316
+ Checker hasMeasures (LocalizedError code , String ... measureIds ) {
317
+ return hasMeasures (code , measureIds .length , measureIds );
318
+ }
319
+
320
+ Checker hasMeasures (LocalizedError code , int numberOfMeasuresRequired , String ... measureIds ) {
319
321
if (!shouldShortcut ()) {
320
- int numberOfMeasuresRequired = Arrays .asList (measureIds ).size ();
321
322
322
323
long numNodesWithWantedMeasureIds = node .getChildNodes (currentNode -> {
323
324
String measureIdOfNode = currentNode .getValue ("measureId" );
@@ -332,7 +333,7 @@ public Checker hasMeasures(LocalizedError code, String... measureIds) {
332
333
return false ;
333
334
}).count ();
334
335
335
- if (numberOfMeasuresRequired != numNodesWithWantedMeasureIds ) {
336
+ if (numNodesWithWantedMeasureIds < numberOfMeasuresRequired ) {
336
337
details .add (detail (code ));
337
338
}
338
339
}
@@ -342,11 +343,11 @@ public Checker hasMeasures(LocalizedError code, String... measureIds) {
342
343
/**
343
344
* Verifies that the target node contains only children of specified template ids
344
345
*
345
- * @param message validation error message
346
+ * @param code that identifies the error
346
347
* @param types types of template ids to filter
347
348
* @return The checker, for chaining method calls.
348
349
*/
349
- public Checker onlyHasChildren (LocalizedError code , TemplateId ... types ) {
350
+ Checker onlyHasChildren (LocalizedError code , TemplateId ... types ) {
350
351
if (!shouldShortcut ()) {
351
352
Set <TemplateId > templateIds = EnumSet .noneOf (TemplateId .class );
352
353
for (TemplateId templateId : types ) {
@@ -368,7 +369,7 @@ public Checker onlyHasChildren(LocalizedError code, TemplateId... types) {
368
369
*
369
370
* @return The checker, for chaining method calls.
370
371
*/
371
- public Checker incompleteValidation () {
372
+ Checker incompleteValidation () {
372
373
node .setValidated (false );
373
374
return this ;
374
375
}
0 commit comments