Skip to content

Commit 33ae172

Browse files
committed
refactor(CollectionUrl): move collection-related values to the corresponding class.
Addressed to #927 No functional changes.
1 parent 0c6f156 commit 33ae172

File tree

6 files changed

+53
-15
lines changed

6 files changed

+53
-15
lines changed

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

+3-6
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.collection.CollectionUrl;
2122

2223
import java.util.HashMap;
2324
import java.util.Map;
@@ -67,9 +68,6 @@ public final class Url {
6768
public static final String GET_COUNTRIES_PAGE = "/countries";
6869
public static final String INFO_COUNTRY_PAGE = "/country/{slug}";
6970

70-
public static final String INFO_COLLECTION_PAGE = "/collection/{slug}";
71-
public static final String ESTIMATION_COLLECTION_PAGE = "/collection/{slug}/estimation";
72-
7371
public static final String GET_IMAGE_PAGE = "/image/{id}";
7472
public static final String GET_IMAGE_PREVIEW_PAGE = "/image/preview/{id}";
7573

@@ -84,7 +82,6 @@ public final class Url {
8482
public static final String LIST_COUNTRIES_PAGE = "/country/list";
8583
public static final String INFO_CATEGORY_BY_ID_PAGE = "/category/{id}/{slug}";
8684
public static final String INFO_COUNTRY_BY_ID_PAGE = "/country/{id}/{slug}";
87-
public static final String INFO_COLLECTION_BY_ID_PAGE = "/collection/{id}/{slug}";
8885
public static final String ADD_SERIES_WITH_CATEGORY_PAGE = "/series/add/category/{slug}";
8986
public static final String ADD_SERIES_WITH_COUNTRY_PAGE = "/series/add/country/{slug}";
9087

@@ -145,11 +142,11 @@ public static Map<String, String> asMap(boolean production) {
145142
map.put("AUTHENTICATION_PAGE", AccountUrl.AUTHENTICATION_PAGE);
146143
map.put("BOOTSTRAP_LANGUAGE", BOOTSTRAP_LANGUAGE);
147144
map.put("DAILY_STATISTICS", DAILY_STATISTICS);
148-
map.put("ESTIMATION_COLLECTION_PAGE", ESTIMATION_COLLECTION_PAGE);
145+
map.put("ESTIMATION_COLLECTION_PAGE", CollectionUrl.ESTIMATION_COLLECTION_PAGE);
149146
map.put("GET_CATEGORIES_PAGE", GET_CATEGORIES_PAGE);
150147
map.put("GET_COUNTRIES_PAGE", GET_COUNTRIES_PAGE);
151148
map.put("INFO_CATEGORY_PAGE", INFO_CATEGORY_PAGE);
152-
map.put("INFO_COLLECTION_PAGE", INFO_COLLECTION_PAGE);
149+
map.put("INFO_COLLECTION_PAGE", CollectionUrl.INFO_COLLECTION_PAGE);
153150
map.put("INFO_COUNTRY_PAGE", INFO_COUNTRY_PAGE);
154151
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
155152
map.put("LIST_IMPORT_REQUESTS_PAGE", LIST_IMPORT_REQUESTS_PAGE);

src/main/java/ru/mystamps/web/feature/collection/CollectionController.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.web.bind.annotation.PathVariable;
2727
import org.springframework.web.servlet.View;
2828
import org.springframework.web.servlet.view.RedirectView;
29-
import ru.mystamps.web.Url;
3029
import ru.mystamps.web.common.LocaleUtils;
3130
import ru.mystamps.web.feature.category.CategoryService;
3231
import ru.mystamps.web.feature.country.CountryService;
@@ -45,7 +44,7 @@ public class CollectionController {
4544
private final CountryService countryService;
4645
private final MessageSource messageSource;
4746

48-
@GetMapping(Url.INFO_COLLECTION_PAGE)
47+
@GetMapping(CollectionUrl.INFO_COLLECTION_PAGE)
4948
public String showInfoBySlug(
5049
@PathVariable("slug") String slug,
5150
Model model,
@@ -95,7 +94,7 @@ public String showInfoBySlug(
9594
}
9695

9796
// @todo #884 Add integration tests for collection estimation page
98-
@GetMapping(Url.ESTIMATION_COLLECTION_PAGE)
97+
@GetMapping(CollectionUrl.ESTIMATION_COLLECTION_PAGE)
9998
public String showPrices(
10099
@PathVariable("slug") String slug,
101100
Model model,
@@ -126,7 +125,7 @@ public String showPrices(
126125
return "collection/estimation";
127126
}
128127

129-
@GetMapping(Url.INFO_COLLECTION_BY_ID_PAGE)
128+
@GetMapping(CollectionUrl.INFO_COLLECTION_BY_ID_PAGE)
130129
public View showInfoById(
131130
@PathVariable("slug") String slug,
132131
HttpServletResponse response)
@@ -145,7 +144,7 @@ public View showInfoById(
145144

146145
RedirectView view = new RedirectView();
147146
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
148-
view.setUrl(Url.INFO_COLLECTION_PAGE);
147+
view.setUrl(CollectionUrl.INFO_COLLECTION_PAGE);
149148

150149
return view;
151150
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.collection;
19+
20+
/**
21+
* Collection-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 CollectionUrl {
29+
30+
public static final String INFO_COLLECTION_PAGE = "/collection/{slug}";
31+
public static final String ESTIMATION_COLLECTION_PAGE = "/collection/{slug}/estimation";
32+
33+
// For backward compatibility
34+
static final String INFO_COLLECTION_BY_ID_PAGE = "/collection/{id}/{slug}";
35+
36+
private CollectionUrl() {
37+
}
38+
39+
}

src/main/java/ru/mystamps/web/feature/series/SeriesController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import ru.mystamps.web.feature.category.CategoryService;
4444
import ru.mystamps.web.feature.collection.AddToCollectionForm;
4545
import ru.mystamps.web.feature.collection.CollectionService;
46+
import ru.mystamps.web.feature.collection.CollectionUrl;
4647
import ru.mystamps.web.feature.country.Country;
4748
import ru.mystamps.web.feature.country.CountryService;
4849
import ru.mystamps.web.feature.participant.ParticipantService;
@@ -391,7 +392,7 @@ public String addToCollection(
391392
redirectAttributes.addFlashAttribute("justAddedSeriesId", seriesId);
392393

393394
String collectionSlug = currentUserDetails.getUserCollectionSlug();
394-
return redirectTo(Url.INFO_COLLECTION_PAGE, collectionSlug);
395+
return redirectTo(CollectionUrl.INFO_COLLECTION_PAGE, collectionSlug);
395396
}
396397

397398
@PostMapping(path = Url.INFO_SERIES_PAGE, params = "action=REMOVE")
@@ -419,7 +420,7 @@ public String removeFromCollection(
419420
redirectAttributes.addFlashAttribute("justRemovedSeries", true);
420421

421422
String collectionSlug = currentUserDetails.getUserCollectionSlug();
422-
return redirectTo(Url.INFO_COLLECTION_PAGE, collectionSlug);
423+
return redirectTo(CollectionUrl.INFO_COLLECTION_PAGE, collectionSlug);
423424
}
424425

425426
@PostMapping(Url.ADD_SERIES_ASK_PAGE)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lombok.RequiredArgsConstructor;
2121
import org.springframework.security.web.header.HeaderWriter;
2222
import ru.mystamps.web.Url;
23+
import ru.mystamps.web.feature.collection.CollectionUrl;
2324

2425
import javax.servlet.http.HttpServletRequest;
2526
import javax.servlet.http.HttpServletResponse;
@@ -33,7 +34,7 @@
3334
class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
3435

3536
private static final String COLLECTION_INFO_PAGE_PATTERN =
36-
Url.INFO_COLLECTION_PAGE.replace("{slug}", "");
37+
CollectionUrl.INFO_COLLECTION_PAGE.replace("{slug}", "");
3738

3839
private static final Pattern SERIES_INFO_PAGE_PATTERN =
3940
Pattern.compile(Url.SERIES_INFO_PAGE_REGEXP);

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.collection.CollectionUrl;
4748
import ru.mystamps.web.feature.site.SiteService;
4849

4950
import javax.servlet.Filter;
@@ -89,7 +90,7 @@ protected void configure(HttpSecurity http) throws Exception {
8990
.mvcMatchers(Url.SUGGEST_SERIES_COUNTRY).hasAuthority(StringAuthority.CREATE_SERIES)
9091
.mvcMatchers(Url.DAILY_STATISTICS).hasAuthority(StringAuthority.VIEW_DAILY_STATS)
9192
// @todo #884 /collection/{slug}/estimation: only owner should have access to estimation page
92-
.mvcMatchers(Url.ESTIMATION_COLLECTION_PAGE).hasAuthority(StringAuthority.ADD_SERIES_PRICE)
93+
.mvcMatchers(CollectionUrl.ESTIMATION_COLLECTION_PAGE).hasAuthority(StringAuthority.ADD_SERIES_PRICE)
9394
.regexMatchers(HttpMethod.POST, "/series/[0-9]+")
9495
.hasAnyAuthority(
9596
StringAuthority.UPDATE_COLLECTION,

0 commit comments

Comments
 (0)