Commit fd1f0bf
fix: reject invalid/negative lastUpdatedDuration on dataValueSets export instead of silently ignoring it (#24470)
* fix: reject invalid/negative lastUpdatedDuration on dataValueSets export instead of silently ignoring it
DateUtils.getDuration() returns null on any parse failure (its regex requires
unsigned digits, so negative durations like "-5d" never match), and
DefaultDataExportService.decodeParams() called it unchecked, so a malformed or
negative lastUpdatedDuration was silently discarded - indistinguishable from
"not provided". If it was the client's only time filter, this surfaced as the
unrelated E2002 error instead of pointing at the actual problem; otherwise it
was dropped with no error at all.
ErrorCode.E2005 ("Duration is not valid: `{0}`") already exists for exactly
this and is used by the sibling DefaultCompleteDataSetRegistrationExchangeService
for its createdDuration parameter, but was never wired up here.
decodeParams() now throws ConflictException(E2005, rawValue) when
lastUpdatedDuration is non-blank but fails to parse. lastUpdatedDuration=0d
is deliberately left valid - it parses successfully (Duration.ZERO) and is a
well-defined (if narrow) "as of right now" filter, analogous to
startDate == endDate being a valid zero-width date range.
Verified via mutation testing: temporarily disabled the new guard, confirmed
only the two negative-case tests failed (the 0d-is-valid test stayed green),
then restored. No regressions in DataExportServiceExportTest,
DataValueServiceTest, or DataValueSetControllerTest.
Related to DHIS2-21821.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix: reduce decodeParams cognitive complexity and cover blank duration branch
Extracts attribute-option-combo, order, and lastUpdatedDuration resolution
into their own methods so decodeParams stays under the complexity limit,
and adds a test for the blank (non-null) lastUpdatedDuration case that the
isBlank() guard exists to handle.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent ab98e01 commit fd1f0bf
2 files changed
Lines changed: 157 additions & 22 deletions
File tree
- dhis-2/dhis-services/dhis-service-dxf2/src
- main/java/org/hisp/dhis/dxf2/datavalueset
- test/java/org/hisp/dhis/dxf2/datavalueset
Lines changed: 39 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
345 | 346 | | |
346 | 347 | | |
347 | 348 | | |
348 | | - | |
| 349 | + | |
349 | 350 | | |
350 | 351 | | |
351 | 352 | | |
| |||
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | 362 | | |
380 | 363 | | |
381 | 364 | | |
| |||
384 | 367 | | |
385 | 368 | | |
386 | 369 | | |
387 | | - | |
| 370 | + | |
388 | 371 | | |
389 | 372 | | |
390 | 373 | | |
391 | 374 | | |
392 | 375 | | |
393 | 376 | | |
394 | | - | |
| 377 | + | |
395 | 378 | | |
396 | 379 | | |
397 | | - | |
| 380 | + | |
398 | 381 | | |
399 | 382 | | |
400 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
401 | 418 | | |
402 | 419 | | |
403 | 420 | | |
| |||
Lines changed: 118 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments