Skip to content

Commit 63b3b9e

Browse files
committed
refactor(SeriesImportUrl): move values related to the series import to the corresponding class.
Addressed to #927 No functional changes.
1 parent 014ff4f commit 63b3b9e

File tree

5 files changed

+57
-15
lines changed

5 files changed

+57
-15
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import ru.mystamps.web.feature.country.CountryUrl;
2424
import ru.mystamps.web.feature.image.ImageUrl;
2525
import ru.mystamps.web.feature.participant.ParticipantUrl;
26+
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
2627
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportUrl;
2728

2829
import java.util.HashMap;
@@ -56,10 +57,6 @@ public final class Url {
5657
public static final String SERIES_INFO_PAGE_REGEXP = "/series/(\\d+|\\d+/(ask|image))";
5758
public static final String SEARCH_SERIES_BY_CATALOG = "/series/search/by_catalog";
5859

59-
public static final String REQUEST_IMPORT_SERIES_PAGE = "/series/import/request";
60-
public static final String REQUEST_IMPORT_PAGE = "/series/import/request/{id}";
61-
public static final String LIST_IMPORT_REQUESTS_PAGE = "/series/import/requests";
62-
6360
public static final String FORBIDDEN_PAGE = "/error/403";
6461
public static final String NOT_FOUND_PAGE = "/error/404";
6562
public static final String INTERNAL_ERROR_PAGE = "/error/500";
@@ -119,6 +116,7 @@ public static Map<String, String> asMap(boolean production) {
119116
CountryUrl.exposeUrlsToView(map);
120117
CollectionUrl.exposeUrlsToView(map);
121118
ParticipantUrl.exposeUrlsToView(map);
119+
SeriesImportUrl.exposeUrlsToView(map);
122120
SeriesSalesImportUrl.exposeUrlsToView(map);
123121

124122
map.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);
@@ -127,10 +125,7 @@ public static Map<String, String> asMap(boolean production) {
127125
map.put("BOOTSTRAP_LANGUAGE", BOOTSTRAP_LANGUAGE);
128126
map.put("DAILY_STATISTICS", DAILY_STATISTICS);
129127
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
130-
map.put("LIST_IMPORT_REQUESTS_PAGE", LIST_IMPORT_REQUESTS_PAGE);
131128
map.put("PUBLIC_URL", production ? PUBLIC_URL : SITE);
132-
map.put("REQUEST_IMPORT_PAGE", REQUEST_IMPORT_PAGE);
133-
map.put("REQUEST_IMPORT_SERIES_PAGE", REQUEST_IMPORT_SERIES_PAGE);
134129
map.put("SEARCH_SERIES_BY_CATALOG", SEARCH_SERIES_BY_CATALOG);
135130
map.put("SITE_EVENTS_PAGE", SITE_EVENTS_PAGE);
136131

src/main/java/ru/mystamps/web/config/MvcConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import ru.mystamps.web.feature.series.DownloadImageInterceptor;
5656
import ru.mystamps.web.feature.series.SeriesConfig;
5757
import ru.mystamps.web.feature.series.importing.SeriesImportConfig;
58+
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
5859
import ru.mystamps.web.feature.series.importing.event.EventsConfig;
5960
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportConfig;
6061
import ru.mystamps.web.feature.site.SiteConfig;
@@ -159,7 +160,7 @@ public void addInterceptors(InterceptorRegistry registry) {
159160
.addPathPatterns(
160161
Url.ADD_SERIES_PAGE,
161162
Url.ADD_IMAGE_SERIES_PAGE,
162-
Url.REQUEST_IMPORT_PAGE.replace("{id}", "*")
163+
SeriesImportUrl.REQUEST_IMPORT_PAGE.replace("{id}", "*")
163164
);
164165
}
165166

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ protected void initImportSeriesForm(WebDataBinder binder) {
7070
binder.registerCustomEditor(String.class, "michelNumbers", new ExpandCatalogNumbersEditor());
7171
}
7272

73-
@GetMapping(Url.REQUEST_IMPORT_SERIES_PAGE)
73+
@GetMapping(SeriesImportUrl.REQUEST_IMPORT_SERIES_PAGE)
7474
public void showRequestImportForm(Model model) {
7575
RequestImportForm requestImportForm = new RequestImportForm();
7676
model.addAttribute("requestImportForm", requestImportForm);
7777
}
7878

79-
@PostMapping(Url.REQUEST_IMPORT_SERIES_PAGE)
79+
@PostMapping(SeriesImportUrl.REQUEST_IMPORT_SERIES_PAGE)
8080
public String processRequestImportForm(
8181
@Valid RequestImportForm form,
8282
BindingResult result,
@@ -93,11 +93,11 @@ public String processRequestImportForm(
9393
new ImportRequestCreated(this, requestId, form.getUrl());
9494
eventPublisher.publishEvent(requestCreated);
9595

96-
return redirectTo(Url.REQUEST_IMPORT_PAGE, requestId);
96+
return redirectTo(SeriesImportUrl.REQUEST_IMPORT_PAGE, requestId);
9797
}
9898

9999
@SuppressWarnings({ "PMD.ModifiedCyclomaticComplexity", "PMD.NPathComplexity" })
100-
@GetMapping(Url.REQUEST_IMPORT_PAGE)
100+
@GetMapping(SeriesImportUrl.REQUEST_IMPORT_PAGE)
101101
public String showRequestAndImportSeriesForm(
102102
@PathVariable("id") Integer requestId,
103103
Model model,
@@ -172,7 +172,7 @@ public String showRequestAndImportSeriesForm(
172172
}
173173

174174
@SuppressWarnings("checkstyle:parameternumber")
175-
@PostMapping(Url.REQUEST_IMPORT_PAGE)
175+
@PostMapping(SeriesImportUrl.REQUEST_IMPORT_PAGE)
176176
public String processImportSeriesForm(
177177
@PathVariable("id") Integer requestId,
178178
Model model,
@@ -239,7 +239,7 @@ public String processImportSeriesForm(
239239
return redirectTo(Url.INFO_SERIES_PAGE, seriesId);
240240
}
241241

242-
@GetMapping(Url.LIST_IMPORT_REQUESTS_PAGE)
242+
@GetMapping(SeriesImportUrl.LIST_IMPORT_REQUESTS_PAGE)
243243
public String showListOfImportRequests(Model model) {
244244
model.addAttribute("requests", seriesImportService.findAll());
245245

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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;
19+
20+
import java.util.Map;
21+
22+
/**
23+
* URLs related to the series import.
24+
*
25+
* Should be used everywhere instead of hard-coded paths.
26+
*
27+
* @author Slava Semushin
28+
*/
29+
@SuppressWarnings("PMD.CommentDefaultAccessModifier")
30+
public final class SeriesImportUrl {
31+
32+
public static final String REQUEST_IMPORT_SERIES_PAGE = "/series/import/request";
33+
public static final String REQUEST_IMPORT_PAGE = "/series/import/request/{id}";
34+
static final String LIST_IMPORT_REQUESTS_PAGE = "/series/import/requests";
35+
36+
private SeriesImportUrl() {
37+
}
38+
39+
public static void exposeUrlsToView(Map<String, String> urls) {
40+
urls.put("LIST_IMPORT_REQUESTS_PAGE", LIST_IMPORT_REQUESTS_PAGE);
41+
urls.put("REQUEST_IMPORT_PAGE", REQUEST_IMPORT_PAGE);
42+
urls.put("REQUEST_IMPORT_SERIES_PAGE", REQUEST_IMPORT_SERIES_PAGE);
43+
}
44+
45+
}

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import ru.mystamps.web.feature.collection.CollectionUrl;
4949
import ru.mystamps.web.feature.country.CountryUrl;
5050
import ru.mystamps.web.feature.participant.ParticipantUrl;
51+
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
5152
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportUrl;
5253
import ru.mystamps.web.feature.site.SiteService;
5354

@@ -89,7 +90,7 @@ protected void configure(HttpSecurity http) throws Exception {
8990
.mvcMatchers(CountryUrl.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
9091
.mvcMatchers(ParticipantUrl.ADD_PARTICIPANT_PAGE).hasAuthority(StringAuthority.ADD_PARTICIPANT)
9192
.mvcMatchers(Url.ADD_SERIES_PAGE).hasAuthority(StringAuthority.CREATE_SERIES)
92-
.mvcMatchers(Url.REQUEST_IMPORT_SERIES_PAGE).hasAuthority(StringAuthority.IMPORT_SERIES)
93+
.mvcMatchers(SeriesImportUrl.REQUEST_IMPORT_SERIES_PAGE).hasAuthority(StringAuthority.IMPORT_SERIES)
9394
.mvcMatchers(Url.SITE_EVENTS_PAGE).hasAuthority(StringAuthority.VIEW_SITE_EVENTS)
9495
.mvcMatchers(CountryUrl.SUGGEST_SERIES_COUNTRY).hasAuthority(StringAuthority.CREATE_SERIES)
9596
.mvcMatchers(Url.DAILY_STATISTICS).hasAuthority(StringAuthority.VIEW_DAILY_STATS)

0 commit comments

Comments
 (0)