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

burningwave / json / #7

25 Oct 2023 06:36AM UTC coverage: 45.756% (-3.2%) from 48.947%
#7

push

Roberto-Gentili
Releasing new version

372 of 813 relevant lines covered (45.76%)

0.46 hits per line

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

54.33
/src/main/java/org/burningwave/json/Validator.java
1
/*
2
 * This file is part of Burningwave JSON.
3
 *
4
 * Author: Roberto Gentili
5
 *
6
 * Hosted at: https://github.com/burningwave/json
7
 *
8
 * --
9
 *
10
 * The MIT License (MIT)
11
 *
12
 * Copyright (c) 2023 Roberto Gentili
13
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
15
 * documentation files (the "Software"), to deal in the Software without restriction, including without
16
 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17
 * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
18
 * conditions:
19
 *
20
 * The above copyright notice and this permission notice shall be included in all copies or substantial
21
 * portions of the Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25
 * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
27
 * OR OTHER DEALINGS IN THE SOFTWARE.
28
 */
29
package org.burningwave.json;
30

31
import static org.burningwave.json.Path.Segment.root;
32

33
import java.util.ArrayList;
34
import java.util.Collection;
35
import java.util.LinkedHashMap;
36
import java.util.Map;
37
import java.util.concurrent.atomic.AtomicInteger;
38
import java.util.function.Function;
39
import java.util.function.Supplier;
40
import java.util.stream.Collectors;
41
import java.util.stream.Stream;
42

43
import org.burningwave.Strings;
44
import org.burningwave.Throwables;
45
import org.json.JSONException;
46

47
import com.fasterxml.jackson.databind.ObjectMapper;
48
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
49
import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema;
50
import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema.Items;
51
import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema.SingleItems;
52
import com.fasterxml.jackson.module.jsonSchema.types.BooleanSchema;
53
import com.fasterxml.jackson.module.jsonSchema.types.IntegerSchema;
54
import com.fasterxml.jackson.module.jsonSchema.types.NumberSchema;
55
import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema;
56
import com.fasterxml.jackson.module.jsonSchema.types.StringSchema;
57

58
@SuppressWarnings({"unchecked"})
59
public class Validator {
60
        public static final Function<Path.Validation.Context<?, ?>, Function<String, Function<String, Function<Object[], Throwable>>>> DEFAULT_EXCEPTION_BUILDER;
61

62

63
        private static final String DEFAULT_LEAF_CHECKS_ID;
64
        private static final String DEFAULT_OBJECT_CHECKS_ID;
65
        private static final String DEFAULT_INDEXED_OBJECT_CHECKS_ID;
66
        protected static final Object logger;
67

68
        static {
69
                DEFAULT_LEAF_CHECKS_ID = Strings.INSTANCE.toStringWithRandomUUIDSuffix("defaultLeafChecks");
1✔
70
                DEFAULT_OBJECT_CHECKS_ID = Strings.INSTANCE.toStringWithRandomUUIDSuffix("defaultObjectChecks");
1✔
71
                DEFAULT_INDEXED_OBJECT_CHECKS_ID = Strings.INSTANCE.toStringWithRandomUUIDSuffix("defaultIndexedObjectChecks");
1✔
72
                DEFAULT_EXCEPTION_BUILDER = pathValidationContext -> checkType -> message -> messageArguments -> {
1✔
73
                        Strings.INSTANCE.compile(checkType, messageArguments);
×
74
                        return new Validation.Exception(
×
75
                                pathValidationContext.getPath(), checkType, Strings.INSTANCE.compile(message, messageArguments)
×
76
                        );
77
                };
78
                logger = SLF4J.INSTANCE.tryToInitLogger(Validator.class);
1✔
79
        }
1✔
80

81

82

83
        protected final ObjectMapper objectMapper;
84
        protected final SchemaHolder schemaHolder;
85
        protected Function<Path.Validation.Context<?, ?>, Function<String, Function<String, Function<Object[], Throwable>>>> exceptionBuilder;
86
        protected final Map<String, Collection<ObjectCheck>> objectChecks;
87
        protected final Map<String, Collection<IndexedObjectCheck<?>>> indexedObjectChecks;
88
        protected final Map<String, Collection<LeafCheck<?, ?>>> leafChecks;
89
        protected final Collection<LeafCheck<?, ?>> defaultLeafChecks;
90
        protected final Collection<ObjectCheck> defaultObjectChecks;
91
        protected final Collection<IndexedObjectCheck<?>> defaultIndexedObjectChecks;
92

93
        public Validator(
94
                ObjectMapper objectMapper
95
        ) {
96
                this(objectMapper, new SchemaHolder(objectMapper), DEFAULT_EXCEPTION_BUILDER);
×
97
        }
×
98

99
        public Validator(
100
                SchemaHolder schemaHolder
101
        ) {
102
                this(
1✔
103
                        schemaHolder.objectMapper,
104
                        schemaHolder,
105
                        DEFAULT_EXCEPTION_BUILDER
106
                );
107
        }
1✔
108

109
        public Validator(
110
                SchemaHolder schemaHolder,
111
                Function<Path.Validation.Context<?, ?>, Function<String, Function<String, Function<Object[], Throwable>>>> exceptionBuilder
112
        ) {
113
                this(
×
114
                        schemaHolder.objectMapper,
115
                        schemaHolder,
116
                        exceptionBuilder
117
                );
118
        }
×
119

120
        public Validator(
121
                ObjectMapper objectMapper,
122
                SchemaHolder schemaHolder,
123
                Function<Path.Validation.Context<?, ?>, Function<String, Function<String, Function<Object[], Throwable>>>> exceptionBuilder
124
        ) {
1✔
125
                this.objectMapper = objectMapper;
1✔
126
                this.schemaHolder = schemaHolder;
1✔
127
                this.exceptionBuilder = exceptionBuilder;
1✔
128
                this.leafChecks = new LinkedHashMap<>();
1✔
129
                this.leafChecks.put(
1✔
130
                        DEFAULT_LEAF_CHECKS_ID,
131
                        this.defaultLeafChecks = new ArrayList<>()
132
                );
133
                this.objectChecks = new LinkedHashMap<>();
1✔
134
                this.objectChecks.put(
1✔
135
                        DEFAULT_OBJECT_CHECKS_ID,
136
                        this.defaultObjectChecks = new ArrayList<>()
137
                );
138
                this.indexedObjectChecks = new LinkedHashMap<>();
1✔
139
                this.indexedObjectChecks.put(
1✔
140
                        DEFAULT_INDEXED_OBJECT_CHECKS_ID,
141
                        this.defaultIndexedObjectChecks = new ArrayList<>()
142
                );
143
        }
1✔
144

145
        public void setExceptionBuilder(Function<Path.Validation.Context<?, ?>, Function<String, Function<String, Function<Object[], Throwable>>>> exceptionBuilder) {
146
                this.exceptionBuilder = exceptionBuilder;
×
147
        }
×
148

149
        public synchronized Validator registerCheck(Check<?, ?, ?>... items) {
150
                return registerCheck(null, items);
1✔
151
        }
152

153
        /*
154
         * L'ordine di esecuzione controlli rispetta l'ordine in cui vengono registrati
155
         * qualora l'input fornito sia di tipo raw (Map, Collection o tipi primitivi).
156
         * Qualora l'input è invece rappresentato da un'oggetto di una classe
157
         * non raw l'ordine in cui vengono eseguiti i controlli segue l'ordine
158
         * in cui vengono definiti i campi all'interno di tale classe
159
         */
160
        public synchronized Validator registerCheck(
161
                String checkGroupId,
162
                Check<?, ?, ?>... items
163
        ) {
164
                for (Check<?, ?, ?> item : items) {
1✔
165
                        Map<String, ?> checkMap = null;
1✔
166
                        String defaultCheckListName = null;
1✔
167
                        if (item instanceof ObjectCheck) {
1✔
168
                                checkMap = this.objectChecks;
1✔
169
                                defaultCheckListName = DEFAULT_OBJECT_CHECKS_ID;
1✔
170
                        } else if (item instanceof IndexedObjectCheck) {
1✔
171
                                checkMap = this.indexedObjectChecks;
1✔
172
                                defaultCheckListName = DEFAULT_INDEXED_OBJECT_CHECKS_ID;
1✔
173
                        } else if (item instanceof LeafCheck) {
1✔
174
                                checkMap = this.leafChecks;
1✔
175
                                defaultCheckListName = DEFAULT_LEAF_CHECKS_ID;
1✔
176
                        }
177
                        if (item instanceof Check.Group) {
1✔
178
                                for (Check<?, ?, ?> nestedItem : ((Check.Group)item).items) {
1✔
179
                                        registerCheck(checkGroupId, nestedItem);
1✔
180
                                }
1✔
181
                        } else if (checkMap != null) {
1✔
182
                                String classNameForRegistration = checkGroupId != null? checkGroupId : defaultCheckListName;
1✔
183
                                Collection<Check<?, ?, ?>> checkList =
1✔
184
                                        ((Map<String, Collection<Check<?, ?, ?>>>)checkMap)
185
                                                .computeIfAbsent(classNameForRegistration, clsName -> new ArrayList<>());
1✔
186
                                checkList.add(item);
1✔
187
                        } else {
1✔
188
                                throw new IllegalArgumentException(item + " is not a valid check type");
×
189
                        }
190
                }
191
                return this;
1✔
192
        }
193

194
        public Collection<Throwable> validate(Object jsonObject) {
195
                return validate(Validation.Config.forJsonObject(jsonObject));
×
196
        }
197

198
        public <I> Collection<Throwable> validate(
199
                Validation.Config<I> config
200
        ) {
201
                try {
202
                        Object jsonObject = config.jsonObjectOrSupplier;
1✔
203
                        if (jsonObject instanceof Supplier) {
1✔
204
                                jsonObject = ((Supplier<?>)config.jsonObjectOrSupplier).get();
×
205
                        }
206
                        ObjectHandler objectHandler;
207
                        if (jsonObject instanceof ObjectHandler) {
1✔
208
                                objectHandler = (ObjectHandler)jsonObject;
×
209
                        } else {
210
                                objectHandler = ObjectHandler.create(objectMapper, jsonObject);
1✔
211
                        }
212
                        Validation.Context validationContext = createValidationContext(
1✔
213
                                config,
214
                                objectHandler
215
                        );
216
                        if (ObjectHandler.isConvertible(objectHandler.getValue())) {
1✔
217
                                validate(
1✔
218
                                        root,
219
                                        schemaHolder.getJsonSchema(objectHandler.getValue()),
1✔
220
                                        objectHandler.getRawValue(),
1✔
221
                                        validationContext
222
                                );
223
                        } else {
224
                                validateRaw(
×
225
                                        validationContext
226
                                );
227
                        }
228
                        return validationContext.exceptions;
1✔
229
                } catch (JSONException exc) {
×
230
                        return Throwables.INSTANCE.throwException(exc);
×
231
                }
232
        }
233

234
        protected void validateRaw(Validation.Context validationContext) {
235
                validateRaw(
×
236
                        validationContext,
237
                        validationContext.objectChecks,
238
                        check -> buildSchemaMock(check.schemaClass, null)
×
239
                );
240
                validateRaw(
×
241
                        validationContext,
242
                        (Collection)validationContext.indexedObjectChecks,
243
                        (Function)check -> buildSchemaMock(((IndexedObjectCheck)check).schemaClass, ((IndexedObjectCheck)check).itemsSchemaClass)
×
244
                );
245
                validateRaw(
×
246
                        validationContext,
247
                        (Collection)validationContext.leafChecks,
248
                        (Function)check -> buildSchemaMock(((LeafCheck)check).schemaClass, null)
×
249
                );
250
        }
×
251

252
        protected <S extends JsonSchema, T, C extends Check.Abst<S, T, C>> void validateRaw(
253
                Validation.Context validationContext,
254
                Collection<C> checkList,
255
                Function<C, S> schemaMockBuilder
256
        ) {
257
                for (C check : checkList) {
×
258
                        if (check.predicate instanceof Path.Predicate) {
×
259
                                processPathCheck(validationContext, schemaMockBuilder, check);
×
260
                        } else {
261
                                processCheck(validationContext, schemaMockBuilder, check);
×
262
                        }
263
                }
×
264
        }
×
265

266
        protected <S extends JsonSchema, T, C extends Check.Abst<S, T, C>> void processPathCheck(
267
                Validation.Context validationContext,
268
                Function<C, S> schemaMockBuilder,
269
                C check
270
        ) {
271
                Path.Predicate<Path.Validation.Context<S,T>> pathPredicate =
×
272
                        (Path.Predicate<Path.Validation.Context<S,T>>) check.predicate;
273
                Collection<ObjectHandler> objectHandlers = new ArrayList<>();
×
274
                Collection<Map.Entry<String, String>> pathForRegExColl = pathPredicate.pathForRegEx;
×
275
                for (Map.Entry<String, String> pathForRegEx : pathForRegExColl) {
×
276
                        objectHandlers.addAll(validationContext.inputHandler.newFinder().findForPathMatches(pathForRegEx.getValue()));
×
277
                }
×
278
                if (!objectHandlers.isEmpty()) {
×
279
                        for (ObjectHandler objectHandler : objectHandlers) {
×
280
                                Path.Validation.Context<S,T> pathValidationContext =
×
281
                                        new Path.Validation.Context<>(
282
                                                validationContext,
283
                                                objectHandler.path,
284
                                                schemaMockBuilder.apply(check),
×
285
                                                objectHandler.rawValue
286
                                        );
287
                                if (pathPredicate.test(pathValidationContext)) {
×
288
                                        check.action.accept(pathValidationContext);
×
289
                                }
290
                        }
×
291
                } else {
292
                        for (Map.Entry<String, String> pathForRegEx : pathForRegExColl) {
×
293
                                Path.Validation.Context<S,T> pathValidationContext =
×
294
                                        new Path.Validation.Context<>(validationContext, pathForRegEx.getKey(), schemaMockBuilder.apply(check), null);
×
295
                                check.action.accept(pathValidationContext);
×
296
                        }
×
297
                }
298
        }
×
299

300
        protected <S extends JsonSchema, T, C extends Check.Abst<S, T, C>> void processCheck(
301
                Validation.Context validationContext,
302
                Function<C, S> schemaMockBuilder,
303
                C check
304
        ) {
305
                Collection<ObjectHandler> objectHandlers = validationContext.inputHandler.newFinder().findForPathMatches(".*?");
×
306
                S schemaMock = schemaMockBuilder.apply(check);
×
307
                for (ObjectHandler objectHandler : objectHandlers) {
×
308
                        if (validationContext.checkValue(schemaMock, objectHandler.rawValue)) {
×
309
                                Path.Validation.Context<S,T> pathValidationContext =
×
310
                                        new Path.Validation.Context<>(
311
                                                validationContext,
312
                                                objectHandler.path,
313
                                                schemaMock,
314
                                                objectHandler.rawValue
315
                                        );
316
                                if (check.predicate.test(pathValidationContext)) {
×
317
                                        check.action.accept(pathValidationContext);
×
318
                                }
319
                        }
320
                }
×
321
        }
×
322

323
        protected <S extends JsonSchema> S buildSchemaMock(Class<S> schemaClass, Class<? extends JsonSchema> nestedTypeSchema) {
324
                S schema = null;
×
325
                if (schemaClass != null) {
×
326
                        if (schemaClass.equals(ObjectSchema.class)) {
×
327
                                schema = (S)new ObjectSchema();
×
328
                        } else if (schemaClass.equals(StringSchema.class)) {
×
329
                                schema = (S)new StringSchema();
×
330
                        } else if (schemaClass.equals(IntegerSchema.class)) {
×
331
                                schema = (S)new IntegerSchema();
×
332
                        } else if (schemaClass.equals(NumberSchema.class)) {
×
333
                                schema = (S)new NumberSchema();
×
334
                        } else if (schemaClass.equals(BooleanSchema.class)) {
×
335
                                schema = (S)new BooleanSchema();
×
336
                        } else if (schemaClass.equals(ArraySchema.class)) {
×
337
                                ArraySchema arraySchema = new ArraySchema();
×
338
                                SingleItems singleItems = new SingleItems(buildSchemaMock(nestedTypeSchema, null));
×
339
                                arraySchema.setItems(new Items() {
×
340
                                        @Override
341
                                        public SingleItems asSingleItems() {
342
                                                return singleItems;
×
343
                                        }
344
                                });
345
                                schema = (S)arraySchema;
×
346
                        }
347
                        if (schema != null) {
×
348
                                schema.setDescription(Validation.Context.MOCK_SCHEMA_LABEL);
×
349
                        }
350
                }
351
                return schema;
×
352
        }
353

354
        protected <I> void validate(
355
                String path,
356
                JsonSchema jsonSchema,
357
                Object jsonObject,
358
                Validation.Context validationContext
359
        ) {
360
                if (jsonSchema instanceof ObjectSchema) {
1✔
361
                        validate(
1✔
362
                                path,
363
                                (ObjectSchema)jsonSchema,
364
                                (Map<String, Object>)jsonObject,
365
                                validationContext
366
                        );
367
                } else if (jsonSchema instanceof ArraySchema) {
1✔
368
                        validate(
1✔
369
                                path,
370
                                (ArraySchema)jsonSchema,
371
                                (Collection<I>)jsonObject,
372
                                validationContext
373
                        );
374
                } else {
375
                        validateValue(
1✔
376
                                path,
377
                                jsonSchema,
378
                                jsonObject,
379
                                validationContext
380
                        );
381
                }
382
        }
1✔
383

384
        protected void validate(
385
                String path,
386
                ObjectSchema jsonSchema,
387
                Map<String, Object> jSonObject,
388
                Validation.Context validationContext
389
        ) {
390
                Path.Validation.Context<ObjectSchema,Map<String, Object>> pathValidationContext =
1✔
391
                        new Path.Validation.Context<>(validationContext, path, jsonSchema, jSonObject);
392
                if (validationContext.validationConfig.pathFilter.test(pathValidationContext)) {
1✔
393
                        tryToExecuteChecks(
1✔
394
                                validationContext.objectChecks,
395
                                pathValidationContext
396
                        );
397
                        for (Map.Entry<String, JsonSchema> descriptor : jsonSchema.getProperties().entrySet()) {
1✔
398
                                JsonSchema iteratedItemSchema = descriptor.getValue();
1✔
399
                                String iteratedPath = (!path.isEmpty() ?
1✔
400
                                        path + "." :
401
                                        path
402
                                ) + descriptor.getKey();
1✔
403
                                validate(
1✔
404
                                        iteratedPath,
405
                                        iteratedItemSchema,
406
                                        getObject(
1✔
407
                                                () -> jSonObject::get,
1✔
408
                                                descriptor.getKey()
1✔
409
                                        ),
410
                                        validationContext
411
                                );
412
                        }
1✔
413
                } else {
414
                        logSkippingValidation(pathValidationContext);
×
415
                }
416
        }
1✔
417

418
        protected <I> I getObject(Supplier<Function<String, I>> fieldRetriever, String fieldName) {
419
                try {
420
                        return fieldRetriever.get().apply(fieldName);
1✔
421
                } catch (NullPointerException exc) {
×
422

423
                }
424
                return null;
×
425
        }
426

427
        protected <I, S extends JsonSchema, T, C extends Check.Abst<S, T, C>> void validate(
428
                String path,
429
                ArraySchema jsonSchema,
430
                Collection<I> jSonObject,
431
                Validation.Context validationContext
432
        ) {
433
                Path.Validation.Context<ArraySchema,?> pathValidationContext =
1✔
434
                        new Path.Validation.Context<>(validationContext, path, jsonSchema, jSonObject);
435
                if (validationContext.validationConfig.pathFilter.test(pathValidationContext)) {
1✔
436
                        Stream<I> indexedObjectStream = jSonObject != null?
1✔
437
                                (jSonObject).stream():
1✔
438
                                Stream.of((I)null);
1✔
439
                        Collection<C> checkList = (Collection<C>)validationContext.indexedObjectChecks;
1✔
440
                        tryToExecuteChecks(
1✔
441
                                checkList,
442
                                (Path.Validation.Context<S, T>)pathValidationContext
443
                        );
444
                        JsonSchema itemSchema = jsonSchema.getItems().asSingleItems().getSchema();
1✔
445
                        AtomicInteger index = new AtomicInteger(0);
1✔
446
                        indexedObjectStream.forEach(value ->
1✔
447
                                validate(
1✔
448
                                        path +"[" + index.getAndIncrement() + "]",
1✔
449
                                        itemSchema,
450
                                        value,
451
                                        validationContext
452
                                )
453
                        );
454
                } else {
1✔
455
                        logSkippingValidation(pathValidationContext);
×
456
                }
457
        }
1✔
458

459
        protected <S extends JsonSchema, T, C extends Check.Abst<S, T, C>> void validateValue(
460
                String path,
461
                JsonSchema jsonSchema,
462
                Object value,
463
                Validation.Context validationContext
464
        ) {
465
                Path.Validation.Context<?, ?> pathValidationContext = new Path.Validation.Context<>(validationContext, path, jsonSchema, value);
1✔
466
                if (validationContext.validationConfig.pathFilter.test(pathValidationContext)) {
1✔
467
                        Collection<C> checkList = (Collection<C>)validationContext.leafChecks;
1✔
468
                        tryToExecuteChecks(
1✔
469
                                checkList,
470
                                (Path.Validation.Context<S, T>)pathValidationContext
471
                        );
472
                } else {
1✔
473
                        logSkippingValidation(pathValidationContext);
×
474
                }
475
        }
1✔
476

477
        protected <S extends JsonSchema, T, C extends Check.Abst<S, T, C>> void tryToExecuteChecks(
478
                Collection<C> checkList,
479
                Path.Validation.Context<S, T> pathValidationContext
480
        ) {
481
                int executedChecks = 0;
1✔
482
                for (C check : checkList) {
1✔
483
                        if (pathValidationContext.validationContext.validationConfig.checkFilter.apply(check).test(pathValidationContext) &&
1✔
484
                                check.predicate.test(pathValidationContext)
1✔
485
                        ) {
486
                                if (executedChecks++ == 0 && logger != null && pathValidationContext.validationContext.validationConfig.isDeepLoggingEnabled()) {
1✔
487
                                        ((org.slf4j.Logger)logger).debug(
×
488
                                                "Starting validation of path {} with value {}",
489
                                                pathValidationContext.path,
490
                                                pathValidationContext.validationContext.inputHandler.valueToString(pathValidationContext.rawValue)
×
491
                                        );
492
                                }
493
                                check.action.accept(pathValidationContext);
1✔
494
                        }
495
                }
1✔
496
                if (executedChecks > 0) {
1✔
497
                        if (pathValidationContext.validationContext.exceptions == null || pathValidationContext.validationContext.exceptions.isEmpty()) {
1✔
498
                                if (logger != null && pathValidationContext.validationContext.validationConfig.isDeepLoggingEnabled()) {
1✔
499
                                        ((org.slf4j.Logger)logger).debug(
×
500
                                                "Validation of path {} successfully completed",
501
                                                pathValidationContext.path
502
                                        );
503
                                }
504
                        } else if (logger != null && pathValidationContext.validationContext.validationConfig.isErrorLoggingEnabled()) {
×
505
                                ((org.slf4j.Logger)logger).debug(
×
506
                                        "Validation of path {} completed with errors",
507
                                        pathValidationContext.path
508
                                );
509
                        }
510
                } else if (logger != null && pathValidationContext.validationContext.validationConfig.isDeepLoggingEnabled()){
×
511
                        ((org.slf4j.Logger)logger).debug(
×
512
                                "No custom check executed for path {} with value {}",
513
                                pathValidationContext.path,
514
                                pathValidationContext.validationContext.inputHandler.valueToString(pathValidationContext.rawValue)
×
515
                        );
516
                }
517
        }
1✔
518

519
        protected <I> Validation.Context createValidationContext(
520
                Validation.Config<I> config,
521
                ObjectHandler objectHandler
522
        ) {
523
                return new Validation.Context(
1✔
524
                        exceptionBuilder,
525
                        config,
526
                        objectHandler,
527
                        computeChecks(config.getGroupIds(), objectChecks, defaultObjectChecks),
1✔
528
                        computeChecks(config.getGroupIds(), (Map)indexedObjectChecks, (Collection)defaultIndexedObjectChecks),
1✔
529
                        computeChecks(config.getGroupIds(), (Map)leafChecks, (Collection)defaultLeafChecks)
1✔
530
                );
531
        }
532

533
        protected <C extends Check<?, ?, C>> Collection<C> computeChecks(
534
                Collection<String> groupIds,
535
                Map<String, Collection<C>> registeredChecks,
536
                Collection<C> defaultChecks
537
        ) {
538
                return (Collection<C>)groupIds.stream().map(registeredChecks::get)
1✔
539
                .collect(
1✔
540
                        Collectors.collectingAndThen(
1✔
541
                                Collectors.toList(),
1✔
542
                                list ->
543
                                        list.isEmpty() ? defaultChecks : list
1✔
544
                        )
545
                );
546
        }
547

548
        protected void logSkippingValidation(
549
                Path.Validation.Context<?, ?> pathValidationContext
550
        ) {
551
                if (logger != null && pathValidationContext.validationContext.validationConfig.isDeepLoggingEnabled()){
×
552
                        ((org.slf4j.Logger)logger).debug(
×
553
                                "Skipping validation of path {} with value {}",
554
                                pathValidationContext.path,
555
                                pathValidationContext.validationContext.inputHandler.valueToString(pathValidationContext.rawValue)
×
556
                        );
557
                }
558
        }
×
559

560
}
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

© 2025 Coveralls, Inc