Skip to content

Commit 8224e7c

Browse files
committed
refactor: use a separate class for a form for requesting an import of a sale of a series.
Fix #1026
1 parent ab45d0a commit 8224e7c

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

src/main/java/ru/mystamps/web/feature/series/importing/RequestSeriesImportForm.java

-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@
3737
})
3838
public class RequestSeriesImportForm implements RequestImportDto {
3939

40-
// @todo #995 Series sale import: use its own interface and form
4140
@NotEmpty(groups = Group.Level1.class)
4241
@Size(
43-
// For series sales a max length is SERIES_SALES_URL_MAX_LENGTH but since they are equal,
44-
// we use IMPORT_REQUEST_URL_MAX_LENGTH here.
45-
// Also, as the import saves nothing, this check actually isn't required. Perhaps,
46-
// we shouldn't validate on this stage and let it fail later, during a sale creation.
4742
max = SeriesImportValidation.IMPORT_REQUEST_URL_MAX_LENGTH,
4843
message = "{value.too-long}",
4944
groups = Group.Level2.class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2009-2019 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.feature.series.importing.sale;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.hibernate.validator.constraints.NotEmpty;
23+
import org.hibernate.validator.constraints.URL;
24+
import ru.mystamps.web.feature.series.importing.HasSiteParser;
25+
import ru.mystamps.web.feature.series.importing.RequestImportDto;
26+
import ru.mystamps.web.feature.series.sale.SeriesSalesValidation;
27+
import ru.mystamps.web.support.beanvalidation.Group;
28+
29+
import javax.validation.GroupSequence;
30+
import javax.validation.constraints.Size;
31+
32+
@Getter
33+
@Setter
34+
@GroupSequence({
35+
RequestSeriesSaleImportForm.class,
36+
Group.Level1.class,
37+
Group.Level2.class,
38+
Group.Level3.class,
39+
Group.Level4.class
40+
})
41+
public class RequestSeriesSaleImportForm implements RequestImportDto {
42+
43+
@NotEmpty(groups = Group.Level1.class)
44+
@Size(
45+
// Because the import saves nothing, this check actually isn't required. Perhaps,
46+
// we shouldn't validate on this stage and let it fail later, during a sale creation.
47+
max = SeriesSalesValidation.SERIES_SALES_URL_MAX_LENGTH,
48+
message = "{value.too-long}",
49+
groups = Group.Level2.class
50+
)
51+
@URL(groups = Group.Level3.class)
52+
@HasSiteParser(groups = Group.Level4.class)
53+
private String url;
54+
}

src/main/java/ru/mystamps/web/feature/series/importing/sale/SeriesSaleImportController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.web.bind.annotation.PostMapping;
2626
import org.springframework.web.bind.annotation.RequestBody;
2727
import org.springframework.web.bind.annotation.RestController;
28-
import ru.mystamps.web.feature.series.importing.RequestSeriesImportForm;
2928

3029
import javax.validation.Valid;
3130

@@ -39,7 +38,7 @@ public class SeriesSaleImportController {
3938

4039
@PostMapping(SeriesSalesImportUrl.IMPORT_SERIES_SALES)
4140
public ResponseEntity<SeriesSaleExtractedInfo> downloadAndParse(
42-
@RequestBody @Valid RequestSeriesImportForm form) {
41+
@RequestBody @Valid RequestSeriesSaleImportForm form) {
4342

4443
String url = form.getUrl();
4544

src/main/java/ru/mystamps/web/feature/series/sale/SeriesSalesValidation.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
import ru.mystamps.web.feature.series.sale.SeriesSalesDb.SeriesSales;
2121

22-
@SuppressWarnings("PMD.CommentDefaultAccessModifier")
23-
final class SeriesSalesValidation {
22+
public final class SeriesSalesValidation {
2423

25-
static final int SERIES_SALES_URL_MAX_LENGTH = SeriesSales.TRANSACTION_URL_LENGTH;
24+
public static final int SERIES_SALES_URL_MAX_LENGTH = SeriesSales.TRANSACTION_URL_LENGTH;
2625

2726
private SeriesSalesValidation() {
2827
}

0 commit comments

Comments
 (0)