Skip to content

Commit 29d5961

Browse files
committed
image should be required for user; image or imageUrl should be required for admin
1 parent 9a866e0 commit 29d5961

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,25 @@ public View showFormWithCountry(
179179
return view;
180180
}
181181

182-
@PostMapping(Url.ADD_SERIES_PAGE)
182+
@PostMapping(path = Url.ADD_SERIES_PAGE, params = "imageUrl")
183+
public String processInputWithImageUrl(
184+
@Validated({ Default.class,
185+
AddSeriesForm.ImageUrlChecks.class,
186+
AddSeriesForm.ReleaseDateChecks.class,
187+
AddSeriesForm.ImageChecks.class }) AddSeriesForm form,
188+
BindingResult result,
189+
@CurrentUser Integer currentUserId,
190+
Locale userLocale,
191+
Model model,
192+
HttpServletRequest request) {
193+
194+
return processInput(form, result, currentUserId, userLocale, model, request);
195+
}
196+
197+
@PostMapping(path = Url.ADD_SERIES_PAGE, params = "!imageUrl")
183198
public String processInput(
184199
@Validated({ Default.class,
200+
AddSeriesForm.RequireImageCheck.class,
185201
AddSeriesForm.ReleaseDateChecks.class,
186202
AddSeriesForm.ImageChecks.class }) AddSeriesForm form,
187203
BindingResult result,

src/main/java/ru/mystamps/web/model/AddSeriesForm.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import ru.mystamps.web.validation.jsr303.MaxFileSize;
4646
import ru.mystamps.web.validation.jsr303.MaxFileSize.Unit;
4747
import ru.mystamps.web.validation.jsr303.NotEmptyFile;
48+
import ru.mystamps.web.validation.jsr303.NotEmptyFilename;
4849
import ru.mystamps.web.validation.jsr303.NotNullIfFirstField;
4950
import ru.mystamps.web.validation.jsr303.Price;
5051
import ru.mystamps.web.validation.jsr303.ReleaseDateIsNotInFuture;
@@ -63,7 +64,7 @@
6364
// TODO: image and downloadedImage should be filled together
6465
// TODO: combine price with currency to separate class
6566
@SuppressWarnings({"PMD.TooManyFields", "PMD.AvoidDuplicateLiterals"})
66-
@RequireImageOrImageUrl
67+
@RequireImageOrImageUrl(groups = AddSeriesForm.ImageUrl1Checks.class)
6768
@NotNullIfFirstField.List({
6869
@NotNullIfFirstField(
6970
first = "month", second = "year", message = "{month.requires.year}",
@@ -136,22 +137,21 @@ public class AddSeriesForm implements AddSeriesDto, HasImageOrImageUrl {
136137

137138
// Name of this field should match with the value of
138139
// DownloadImageInterceptor.UPLOADED_IMAGE_FIELD_NAME.
139-
//@NotEmptyFilename(groups = Image1Checks.class)
140-
@NotEmptyFile(groups = Image2Checks.class)
141-
@MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Image3Checks.class)
140+
@NotEmptyFilename(groups = RequireImageCheck.class)
141+
@NotEmptyFile(groups = Image1Checks.class)
142+
@MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Image2Checks.class)
142143
@ImageFile(groups = Image3Checks.class)
143144
private MultipartFile image;
144145

145146
// Name of this field must match with the value of DownloadImageInterceptor.URL_PARAMETER_NAME.
146-
@URL
147+
@URL(groups = AddSeriesForm.ImageUrl2Checks.class)
147148
private String imageUrl;
148149

149150
// This field holds a file that was downloaded from imageUrl.
150151
// Name of this field must match with the value of
151152
// DownloadImageInterceptor.DOWNLOADED_IMAGE_FIELD_NAME.
152-
//@NotEmptyFilename(groups = Image1Checks.class)
153-
@NotEmptyFile(groups = Image2Checks.class)
154-
@MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Image3Checks.class)
153+
@NotEmptyFile(groups = Image1Checks.class)
154+
@MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Image2Checks.class)
155155
@ImageFile(groups = Image3Checks.class)
156156
private MultipartFile downloadedImage;
157157

@@ -195,6 +195,22 @@ public interface ReleaseDate2Checks {
195195
public interface ReleaseDate3Checks {
196196
}
197197

198+
public interface RequireImageCheck {
199+
}
200+
201+
@GroupSequence({
202+
ImageUrl1Checks.class,
203+
ImageUrl2Checks.class,
204+
})
205+
public interface ImageUrlChecks {
206+
}
207+
208+
public interface ImageUrl1Checks {
209+
}
210+
211+
public interface ImageUrl2Checks {
212+
}
213+
198214
@GroupSequence({
199215
Image1Checks.class,
200216
Image2Checks.class,

0 commit comments

Comments
 (0)