@@ -496,6 +496,48 @@ protected void addYearToModel(Model model) {
496
496
model .addAttribute ("years" , YEARS );
497
497
}
498
498
499
+ protected static void loadErrorsFromDownloadInterceptor (
500
+ NullableImageUrl form ,
501
+ BindingResult result ,
502
+ HttpServletRequest request ) {
503
+
504
+ Object downloadResultErrorCode =
505
+ request .getAttribute (DownloadImageInterceptor .ERROR_CODE_ATTR_NAME );
506
+
507
+ if (downloadResultErrorCode == null ) {
508
+ return ;
509
+ }
510
+
511
+ if (downloadResultErrorCode instanceof DownloadResult .Code ) {
512
+ DownloadResult .Code code = (DownloadResult .Code )downloadResultErrorCode ;
513
+ switch (code ) {
514
+ case INVALID_URL :
515
+ // Url is being validated by @URL, to avoid showing an error message
516
+ // twice we're skipping error from an interceptor.
517
+ break ;
518
+ case INSUFFICIENT_PERMISSIONS :
519
+ // A user without permissions has tried to download a file. It means that he
520
+ // didn't specify a file but somehow provide a URL to an image. In this case,
521
+ // let's show an error message that file is required.
522
+ result .rejectValue (
523
+ "image" ,
524
+ "ru.mystamps.web.support.beanvalidation.NotEmptyFilename.message"
525
+ );
526
+ form .nullifyImageUrl ();
527
+ break ;
528
+ default :
529
+ result .rejectValue (
530
+ DownloadImageInterceptor .DOWNLOADED_IMAGE_FIELD_NAME ,
531
+ DownloadResult .class .getName () + "." + code .toString (),
532
+ "Could not download image"
533
+ );
534
+ break ;
535
+ }
536
+ }
537
+
538
+ request .removeAttribute (DownloadImageInterceptor .ERROR_CODE_ATTR_NAME );
539
+ }
540
+
499
541
// CheckStyle: ignore LineLength for next 1 line
500
542
private Map <String , ?> prepareCommonAttrsForSeriesInfo (SeriesDto series , Integer currentUserId ) {
501
543
Map <String , Object > model = new HashMap <>();
@@ -556,50 +598,6 @@ private void addSeriesSalesFormToModel(Model model) {
556
598
model .addAttribute ("buyers" , groupedBuyers );
557
599
}
558
600
559
- // false positive on Travis CI
560
- @ SuppressWarnings ("PMD.UnusedPrivateMethod" )
561
- private static void loadErrorsFromDownloadInterceptor (
562
- NullableImageUrl form ,
563
- BindingResult result ,
564
- HttpServletRequest request ) {
565
-
566
- Object downloadResultErrorCode =
567
- request .getAttribute (DownloadImageInterceptor .ERROR_CODE_ATTR_NAME );
568
-
569
- if (downloadResultErrorCode == null ) {
570
- return ;
571
- }
572
-
573
- if (downloadResultErrorCode instanceof DownloadResult .Code ) {
574
- DownloadResult .Code code = (DownloadResult .Code )downloadResultErrorCode ;
575
- switch (code ) {
576
- case INVALID_URL :
577
- // Url is being validated by @URL, to avoid showing an error message
578
- // twice we're skipping error from an interceptor.
579
- break ;
580
- case INSUFFICIENT_PERMISSIONS :
581
- // A user without permissions has tried to download a file. It means that he
582
- // didn't specify a file but somehow provide a URL to an image. In this case,
583
- // let's show an error message that file is required.
584
- result .rejectValue (
585
- "image" ,
586
- "ru.mystamps.web.support.beanvalidation.NotEmptyFilename.message"
587
- );
588
- form .nullifyImageUrl ();
589
- break ;
590
- default :
591
- result .rejectValue (
592
- DownloadImageInterceptor .DOWNLOADED_IMAGE_FIELD_NAME ,
593
- DownloadResult .class .getName () + "." + code .toString (),
594
- "Could not download image"
595
- );
596
- break ;
597
- }
598
- }
599
-
600
- request .removeAttribute (DownloadImageInterceptor .ERROR_CODE_ATTR_NAME );
601
- }
602
-
603
601
private static void addImageFormToModel (Model model ) {
604
602
AddImageForm form = new AddImageForm ();
605
603
model .addAttribute ("addImageForm" , form );
0 commit comments