Skip to content

Commit eac6eb8

Browse files
committed
NullableImageUrl: introduce the interface for zeroing image url field.
Required for adding a field for specifying image URL later. No functional changes.
1 parent 376b9bb commit eac6eb8

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/main/java/ru/mystamps/web/controller/SeriesController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import ru.mystamps.web.controller.dto.AddImageForm;
6464
import ru.mystamps.web.controller.dto.AddSeriesForm;
6565
import ru.mystamps.web.controller.dto.AddSeriesSalesForm;
66+
import ru.mystamps.web.controller.dto.NullableImageUrl;
6667
import ru.mystamps.web.controller.interceptor.DownloadImageInterceptor;
6768
import ru.mystamps.web.dao.dto.EntityWithIdDto;
6869
import ru.mystamps.web.dao.dto.LinkEntityDto;
@@ -499,7 +500,7 @@ private void addSeriesSalesFormToModel(Model model) {
499500
}
500501

501502
private static void loadErrorsFromDownloadInterceptor(
502-
AddSeriesForm form,
503+
NullableImageUrl form,
503504
BindingResult result,
504505
HttpServletRequest request) {
505506

@@ -525,7 +526,7 @@ private static void loadErrorsFromDownloadInterceptor(
525526
"image",
526527
"ru.mystamps.web.support.beanvalidation.NotEmptyFilename.message"
527528
);
528-
form.setImageUrl(null);
529+
form.nullifyImageUrl();
529530
break;
530531
default:
531532
result.rejectValue(

src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
)
7676
})
7777
@ReleaseDateIsNotInFuture(groups = AddSeriesForm.ReleaseDate3Checks.class)
78-
public class AddSeriesForm implements AddSeriesDto, HasImageOrImageUrl {
78+
public class AddSeriesForm implements AddSeriesDto, HasImageOrImageUrl, NullableImageUrl {
7979

8080
// FIXME: change type to plain Integer
8181
@NotNull
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2009-2017 Slava Semushin <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.controller.dto;
19+
20+
/**
21+
* Interface of the form that has image URL field and supports its zeroed.
22+
*/
23+
public interface NullableImageUrl {
24+
void setImageUrl(String url);
25+
26+
default void nullifyImageUrl() {
27+
setImageUrl(null);
28+
}
29+
}

0 commit comments

Comments
 (0)