Skip to content

Commit 014b8b0

Browse files
committed
refactor(CategoryUrl): move category-related values to the corresponding class.
Addressed to #927 No functional changes.
1 parent 33ae172 commit 014b8b0

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package ru.mystamps.web;
1919

2020
import ru.mystamps.web.feature.account.AccountUrl;
21+
import ru.mystamps.web.feature.category.CategoryUrl;
2122
import ru.mystamps.web.feature.collection.CollectionUrl;
2223

2324
import java.util.HashMap;
@@ -60,10 +61,6 @@ public final class Url {
6061
public static final String SUGGEST_SERIES_CATEGORY = "/suggest/series_category";
6162
public static final String SUGGEST_SERIES_COUNTRY = "/suggest/series_country";
6263

63-
public static final String ADD_CATEGORY_PAGE = "/category/add";
64-
public static final String GET_CATEGORIES_PAGE = "/categories";
65-
public static final String INFO_CATEGORY_PAGE = "/category/{slug}";
66-
6764
public static final String ADD_COUNTRY_PAGE = "/country/add";
6865
public static final String GET_COUNTRIES_PAGE = "/countries";
6966
public static final String INFO_COUNTRY_PAGE = "/country/{slug}";
@@ -78,9 +75,7 @@ public final class Url {
7875
public static final String INTERNAL_ERROR_PAGE = "/error/500";
7976

8077
// For backward compatibility
81-
public static final String LIST_CATEGORIES_PAGE = "/category/list";
8278
public static final String LIST_COUNTRIES_PAGE = "/country/list";
83-
public static final String INFO_CATEGORY_BY_ID_PAGE = "/category/{id}/{slug}";
8479
public static final String INFO_COUNTRY_BY_ID_PAGE = "/country/{id}/{slug}";
8580
public static final String ADD_SERIES_WITH_CATEGORY_PAGE = "/series/add/category/{slug}";
8681
public static final String ADD_SERIES_WITH_COUNTRY_PAGE = "/series/add/country/{slug}";
@@ -133,7 +128,7 @@ public static Map<String, String> asMap(boolean production) {
133128
// Constants sorted in an ascending order.
134129
Map<String, String> map = new HashMap<>();
135130
map.put("ACTIVATE_ACCOUNT_PAGE", AccountUrl.ACTIVATE_ACCOUNT_PAGE);
136-
map.put("ADD_CATEGORY_PAGE", ADD_CATEGORY_PAGE);
131+
map.put("ADD_CATEGORY_PAGE", CategoryUrl.ADD_CATEGORY_PAGE);
137132
map.put("ADD_COUNTRY_PAGE", ADD_COUNTRY_PAGE);
138133
map.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);
139134
map.put("ADD_PARTICIPANT_PAGE", ADD_PARTICIPANT_PAGE);
@@ -143,9 +138,9 @@ public static Map<String, String> asMap(boolean production) {
143138
map.put("BOOTSTRAP_LANGUAGE", BOOTSTRAP_LANGUAGE);
144139
map.put("DAILY_STATISTICS", DAILY_STATISTICS);
145140
map.put("ESTIMATION_COLLECTION_PAGE", CollectionUrl.ESTIMATION_COLLECTION_PAGE);
146-
map.put("GET_CATEGORIES_PAGE", GET_CATEGORIES_PAGE);
141+
map.put("GET_CATEGORIES_PAGE", CategoryUrl.GET_CATEGORIES_PAGE);
147142
map.put("GET_COUNTRIES_PAGE", GET_COUNTRIES_PAGE);
148-
map.put("INFO_CATEGORY_PAGE", INFO_CATEGORY_PAGE);
143+
map.put("INFO_CATEGORY_PAGE", CategoryUrl.INFO_CATEGORY_PAGE);
149144
map.put("INFO_COLLECTION_PAGE", CollectionUrl.INFO_COLLECTION_PAGE);
150145
map.put("INFO_COUNTRY_PAGE", INFO_COUNTRY_PAGE);
151146
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);

src/main/java/ru/mystamps/web/feature/category/CategoryController.java

+9-10
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_CATEGORY_PAGE)
64+
@GetMapping(CategoryUrl.ADD_CATEGORY_PAGE)
6665
public AddCategoryForm showForm() {
6766
return new AddCategoryForm();
6867
}
6968

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

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

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

88-
@GetMapping(Url.INFO_CATEGORY_PAGE)
87+
@GetMapping(CategoryUrl.INFO_CATEGORY_PAGE)
8988
public String showInfoBySlug(
9089
@Category @PathVariable("slug") LinkEntityDto category,
9190
Model model,
@@ -111,7 +110,7 @@ public String showInfoBySlug(
111110
return "category/info";
112111
}
113112

114-
@GetMapping(Url.INFO_CATEGORY_BY_ID_PAGE)
113+
@GetMapping(CategoryUrl.INFO_CATEGORY_BY_ID_PAGE)
115114
public View showInfoById(
116115
@Category @PathVariable("slug") LinkEntityDto country,
117116
HttpServletResponse response)
@@ -124,12 +123,12 @@ public View showInfoById(
124123

125124
RedirectView view = new RedirectView();
126125
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
127-
view.setUrl(Url.INFO_CATEGORY_PAGE);
126+
view.setUrl(CategoryUrl.INFO_CATEGORY_PAGE);
128127

129128
return view;
130129
}
131130

132-
@GetMapping(Url.GET_CATEGORIES_PAGE)
131+
@GetMapping(CategoryUrl.GET_CATEGORIES_PAGE)
133132
public String showCategories(Model model, Locale userLocale) {
134133
String lang = LocaleUtils.getLanguageOrNull(userLocale);
135134
List<LinkEntityDto> categories = categoryService.findAllAsLinkEntities(lang);
@@ -139,11 +138,11 @@ public String showCategories(Model model, Locale userLocale) {
139138
return "category/list";
140139
}
141140

142-
@GetMapping(Url.LIST_CATEGORIES_PAGE)
141+
@GetMapping(CategoryUrl.LIST_CATEGORIES_PAGE)
143142
public View list() {
144143
RedirectView view = new RedirectView();
145144
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
146-
view.setUrl(Url.GET_CATEGORIES_PAGE);
145+
view.setUrl(CategoryUrl.GET_CATEGORIES_PAGE);
147146
return view;
148147
}
149148

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.category;
19+
20+
/**
21+
* Category-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 CategoryUrl {
29+
30+
public static final String ADD_CATEGORY_PAGE = "/category/add";
31+
public static final String GET_CATEGORIES_PAGE = "/categories";
32+
public static final String INFO_CATEGORY_PAGE = "/category/{slug}";
33+
34+
// For backward compatibility
35+
static final String LIST_CATEGORIES_PAGE = "/category/list";
36+
static final String INFO_CATEGORY_BY_ID_PAGE = "/category/{id}/{slug}";
37+
38+
private CategoryUrl() {
39+
}
40+
41+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.web.bind.annotation.GetMapping;
2424
import ru.mystamps.web.Url;
2525
import ru.mystamps.web.feature.account.AccountUrl;
26+
import ru.mystamps.web.feature.category.CategoryUrl;
2627

2728
import javax.servlet.http.HttpServletResponse;
2829
import java.io.IOException;
@@ -49,7 +50,7 @@ public void getRobotsText(HttpServletResponse response) {
4950
writer.println("Disallow: " + AccountUrl.LOGIN_PAGE);
5051
writer.println("Disallow: " + Url.ADD_COUNTRY_PAGE);
5152
writer.println("Disallow: " + Url.ADD_SERIES_PAGE);
52-
writer.println("Disallow: " + Url.ADD_CATEGORY_PAGE);
53+
writer.println("Disallow: " + CategoryUrl.ADD_CATEGORY_PAGE);
5354
writer.println("Disallow: " + Url.FORBIDDEN_PAGE);
5455
writer.println("Disallow: " + Url.NOT_FOUND_PAGE);
5556
writer.println("Disallow: " + Url.INTERNAL_ERROR_PAGE);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import ru.mystamps.web.Url;
4545
import ru.mystamps.web.feature.account.AccountUrl;
4646
import ru.mystamps.web.feature.account.UserService;
47+
import ru.mystamps.web.feature.category.CategoryUrl;
4748
import ru.mystamps.web.feature.collection.CollectionUrl;
4849
import ru.mystamps.web.feature.site.SiteService;
4950

@@ -81,7 +82,7 @@ protected void configure(HttpSecurity http) throws Exception {
8182

8283
http
8384
.authorizeRequests()
84-
.mvcMatchers(Url.ADD_CATEGORY_PAGE).hasAuthority(StringAuthority.CREATE_CATEGORY)
85+
.mvcMatchers(CategoryUrl.ADD_CATEGORY_PAGE).hasAuthority(StringAuthority.CREATE_CATEGORY)
8586
.mvcMatchers(Url.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
8687
.mvcMatchers(Url.ADD_PARTICIPANT_PAGE).hasAuthority(StringAuthority.ADD_PARTICIPANT)
8788
.mvcMatchers(Url.ADD_SERIES_PAGE).hasAuthority(StringAuthority.CREATE_SERIES)

0 commit comments

Comments
 (0)