Skip to content

Commit 232d41e

Browse files
committed
refactor(CountryUrl): move country-related values to the corresponding class.
Addressed to #927 No functional changes.
1 parent 014b8b0 commit 232d41e

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import ru.mystamps.web.feature.account.AccountUrl;
2121
import ru.mystamps.web.feature.category.CategoryUrl;
2222
import ru.mystamps.web.feature.collection.CollectionUrl;
23+
import ru.mystamps.web.feature.country.CountryUrl;
2324

2425
import java.util.HashMap;
2526
import java.util.Map;
@@ -61,10 +62,6 @@ public final class Url {
6162
public static final String SUGGEST_SERIES_CATEGORY = "/suggest/series_category";
6263
public static final String SUGGEST_SERIES_COUNTRY = "/suggest/series_country";
6364

64-
public static final String ADD_COUNTRY_PAGE = "/country/add";
65-
public static final String GET_COUNTRIES_PAGE = "/countries";
66-
public static final String INFO_COUNTRY_PAGE = "/country/{slug}";
67-
6865
public static final String GET_IMAGE_PAGE = "/image/{id}";
6966
public static final String GET_IMAGE_PREVIEW_PAGE = "/image/preview/{id}";
7067

@@ -75,8 +72,6 @@ public final class Url {
7572
public static final String INTERNAL_ERROR_PAGE = "/error/500";
7673

7774
// For backward compatibility
78-
public static final String LIST_COUNTRIES_PAGE = "/country/list";
79-
public static final String INFO_COUNTRY_BY_ID_PAGE = "/country/{id}/{slug}";
8075
public static final String ADD_SERIES_WITH_CATEGORY_PAGE = "/series/add/category/{slug}";
8176
public static final String ADD_SERIES_WITH_COUNTRY_PAGE = "/series/add/country/{slug}";
8277

@@ -129,7 +124,7 @@ public static Map<String, String> asMap(boolean production) {
129124
Map<String, String> map = new HashMap<>();
130125
map.put("ACTIVATE_ACCOUNT_PAGE", AccountUrl.ACTIVATE_ACCOUNT_PAGE);
131126
map.put("ADD_CATEGORY_PAGE", CategoryUrl.ADD_CATEGORY_PAGE);
132-
map.put("ADD_COUNTRY_PAGE", ADD_COUNTRY_PAGE);
127+
map.put("ADD_COUNTRY_PAGE", CountryUrl.ADD_COUNTRY_PAGE);
133128
map.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);
134129
map.put("ADD_PARTICIPANT_PAGE", ADD_PARTICIPANT_PAGE);
135130
map.put("ADD_SERIES_ASK_PAGE", ADD_SERIES_ASK_PAGE);
@@ -139,10 +134,10 @@ public static Map<String, String> asMap(boolean production) {
139134
map.put("DAILY_STATISTICS", DAILY_STATISTICS);
140135
map.put("ESTIMATION_COLLECTION_PAGE", CollectionUrl.ESTIMATION_COLLECTION_PAGE);
141136
map.put("GET_CATEGORIES_PAGE", CategoryUrl.GET_CATEGORIES_PAGE);
142-
map.put("GET_COUNTRIES_PAGE", GET_COUNTRIES_PAGE);
137+
map.put("GET_COUNTRIES_PAGE", CountryUrl.GET_COUNTRIES_PAGE);
143138
map.put("INFO_CATEGORY_PAGE", CategoryUrl.INFO_CATEGORY_PAGE);
144139
map.put("INFO_COLLECTION_PAGE", CollectionUrl.INFO_COLLECTION_PAGE);
145-
map.put("INFO_COUNTRY_PAGE", INFO_COUNTRY_PAGE);
140+
map.put("INFO_COUNTRY_PAGE", CountryUrl.INFO_COUNTRY_PAGE);
146141
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
147142
map.put("LIST_IMPORT_REQUESTS_PAGE", LIST_IMPORT_REQUESTS_PAGE);
148143
map.put("IMPORT_SERIES_SALES", IMPORT_SERIES_SALES);

src/main/java/ru/mystamps/web/feature/country/CountryController.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.springframework.web.servlet.View;
3131
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
3232
import org.springframework.web.servlet.view.RedirectView;
33-
import ru.mystamps.web.Url;
3433
import ru.mystamps.web.common.LinkEntityDto;
3534
import ru.mystamps.web.common.LocaleUtils;
3635
import ru.mystamps.web.feature.series.SeriesInfoDto;
@@ -62,12 +61,12 @@ protected void initBinder(WebDataBinder binder) {
6261
binder.registerCustomEditor(String.class, "nameRu", editor);
6362
}
6463

65-
@GetMapping(Url.ADD_COUNTRY_PAGE)
64+
@GetMapping(CountryUrl.ADD_COUNTRY_PAGE)
6665
public AddCountryForm showForm() {
6766
return new AddCountryForm();
6867
}
6968

70-
@PostMapping(Url.ADD_COUNTRY_PAGE)
69+
@PostMapping(CountryUrl.ADD_COUNTRY_PAGE)
7170
public String processInput(
7271
@Valid AddCountryForm form,
7372
BindingResult result,
@@ -82,10 +81,10 @@ public String processInput(
8281

8382
redirectAttributes.addFlashAttribute("justAddedCountry", true);
8483

85-
return redirectTo(Url.INFO_COUNTRY_PAGE, slug);
84+
return redirectTo(CountryUrl.INFO_COUNTRY_PAGE, slug);
8685
}
8786

88-
@GetMapping(Url.INFO_COUNTRY_PAGE)
87+
@GetMapping(CountryUrl.INFO_COUNTRY_PAGE)
8988
public String showInfoBySlug(
9089
@Country @PathVariable("slug") LinkEntityDto country,
9190
Model model,
@@ -114,7 +113,7 @@ public String showInfoBySlug(
114113
/**
115114
* @author Aleksander Parkhomenko
116115
*/
117-
@GetMapping(Url.INFO_COUNTRY_BY_ID_PAGE)
116+
@GetMapping(CountryUrl.INFO_COUNTRY_BY_ID_PAGE)
118117
public View showInfoById(
119118
@Country @PathVariable("slug") LinkEntityDto country,
120119
HttpServletResponse response)
@@ -127,12 +126,12 @@ public View showInfoById(
127126

128127
RedirectView view = new RedirectView();
129128
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
130-
view.setUrl(Url.INFO_COUNTRY_PAGE);
129+
view.setUrl(CountryUrl.INFO_COUNTRY_PAGE);
131130

132131
return view;
133132
}
134133

135-
@GetMapping(Url.GET_COUNTRIES_PAGE)
134+
@GetMapping(CountryUrl.GET_COUNTRIES_PAGE)
136135
public String showCountries(Model model, Locale userLocale) {
137136
String lang = LocaleUtils.getLanguageOrNull(userLocale);
138137
List<LinkEntityDto> countries = countryService.findAllAsLinkEntities(lang);
@@ -142,11 +141,11 @@ public String showCountries(Model model, Locale userLocale) {
142141
return "country/list";
143142
}
144143

145-
@GetMapping(Url.LIST_COUNTRIES_PAGE)
144+
@GetMapping(CountryUrl.LIST_COUNTRIES_PAGE)
146145
public View list() {
147146
RedirectView view = new RedirectView();
148147
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
149-
view.setUrl(Url.GET_COUNTRIES_PAGE);
148+
view.setUrl(CountryUrl.GET_COUNTRIES_PAGE);
150149
return view;
151150
}
152151

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2009-2019 Slava Semushin <slava.semushin@gmail.com>
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.country;
19+
20+
/**
21+
* Country-related URLs.
22+
*
23+
* Should be used everywhere instead of hard-coded paths.
24+
*
25+
* @author Slava Semushin
26+
*/
27+
@SuppressWarnings("PMD.CommentDefaultAccessModifier")
28+
public final class CountryUrl {
29+
30+
public static final String ADD_COUNTRY_PAGE = "/country/add";
31+
public static final String GET_COUNTRIES_PAGE = "/countries";
32+
public static final String INFO_COUNTRY_PAGE = "/country/{slug}";
33+
34+
// For backward compatibility
35+
static final String LIST_COUNTRIES_PAGE = "/country/list";
36+
static final String INFO_COUNTRY_BY_ID_PAGE = "/country/{id}/{slug}";
37+
38+
private CountryUrl() {
39+
}
40+
41+
}

src/main/java/ru/mystamps/web/feature/site/RobotsTxtController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import ru.mystamps.web.Url;
2525
import ru.mystamps.web.feature.account.AccountUrl;
2626
import ru.mystamps.web.feature.category.CategoryUrl;
27+
import ru.mystamps.web.feature.country.CountryUrl;
2728

2829
import javax.servlet.http.HttpServletResponse;
2930
import java.io.IOException;
@@ -48,7 +49,7 @@ public void getRobotsText(HttpServletResponse response) {
4849
writer.println("Disallow: " + AccountUrl.ACTIVATE_ACCOUNT_PAGE);
4950
writer.println("Disallow: " + AccountUrl.AUTHENTICATION_PAGE);
5051
writer.println("Disallow: " + AccountUrl.LOGIN_PAGE);
51-
writer.println("Disallow: " + Url.ADD_COUNTRY_PAGE);
52+
writer.println("Disallow: " + CountryUrl.ADD_COUNTRY_PAGE);
5253
writer.println("Disallow: " + Url.ADD_SERIES_PAGE);
5354
writer.println("Disallow: " + CategoryUrl.ADD_CATEGORY_PAGE);
5455
writer.println("Disallow: " + Url.FORBIDDEN_PAGE);

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
@@ -46,6 +46,7 @@
4646
import ru.mystamps.web.feature.account.UserService;
4747
import ru.mystamps.web.feature.category.CategoryUrl;
4848
import ru.mystamps.web.feature.collection.CollectionUrl;
49+
import ru.mystamps.web.feature.country.CountryUrl;
4950
import ru.mystamps.web.feature.site.SiteService;
5051

5152
import javax.servlet.Filter;
@@ -83,7 +84,7 @@ protected void configure(HttpSecurity http) throws Exception {
8384
http
8485
.authorizeRequests()
8586
.mvcMatchers(CategoryUrl.ADD_CATEGORY_PAGE).hasAuthority(StringAuthority.CREATE_CATEGORY)
86-
.mvcMatchers(Url.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
87+
.mvcMatchers(CountryUrl.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
8788
.mvcMatchers(Url.ADD_PARTICIPANT_PAGE).hasAuthority(StringAuthority.ADD_PARTICIPANT)
8889
.mvcMatchers(Url.ADD_SERIES_PAGE).hasAuthority(StringAuthority.CREATE_SERIES)
8990
.mvcMatchers(Url.REQUEST_IMPORT_SERIES_PAGE).hasAuthority(StringAuthority.IMPORT_SERIES)

0 commit comments

Comments
 (0)