Skip to content

Commit c5e733b

Browse files
cssruphp-coder
authored andcommitted
/series/{id}: show info about sellers/buyers of this series.
Addressed to #198
1 parent e0341e3 commit c5e733b

File tree

22 files changed

+370
-3
lines changed

22 files changed

+370
-3
lines changed

Diff for: src/main/java/ru/mystamps/web/controller/SeriesController.java

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import ru.mystamps.web.controller.converter.annotation.Country;
5555
import ru.mystamps.web.controller.converter.annotation.CurrentUser;
5656
import ru.mystamps.web.dao.dto.LinkEntityDto;
57+
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
5758
import ru.mystamps.web.dao.dto.SeriesInfoDto;
5859
import ru.mystamps.web.dao.dto.UrlEntityDto;
5960
import ru.mystamps.web.model.AddImageForm;
@@ -220,6 +221,12 @@ public String showInfo(
220221
model.addAttribute("allowAddingImages", userCanAddImagesToSeries);
221222
model.addAttribute("maxQuantityOfImagesExceeded", false);
222223

224+
if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) {
225+
// CheckStyle: ignore LineLength for next 1 line
226+
List<PurchaseAndSaleDto> purchasesAndSales = seriesService.findPurchasesAndSales(series.getId());
227+
model.addAttribute("purchasesAndSales", purchasesAndSales);
228+
}
229+
223230
return "series/info";
224231
}
225232

@@ -270,6 +277,13 @@ public String processImage(
270277
if (result.hasErrors() || maxQuantityOfImagesExceeded) {
271278
// don't try to re-display file upload field
272279
form.setImage(null);
280+
281+
if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) {
282+
// CheckStyle: ignore LineLength for next 1 line
283+
List<PurchaseAndSaleDto> purchasesAndSales = seriesService.findPurchasesAndSales(series.getId());
284+
model.addAttribute("purchasesAndSales", purchasesAndSales);
285+
}
286+
273287
return "series/info";
274288
}
275289

Diff for: src/main/java/ru/mystamps/web/dao/SeriesDao.java

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222

2323
import ru.mystamps.web.dao.dto.AddSeriesDbDto;
24+
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
2425
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
2526
import ru.mystamps.web.dao.dto.SeriesInfoDto;
2627
import ru.mystamps.web.dao.dto.SitemapInfoDto;
@@ -37,6 +38,8 @@ public interface SeriesDao {
3738
List<SeriesInfoDto> findByCategorySlugAsSeriesInfo(String slug, String lang);
3839
List<SeriesInfoDto> findByCountrySlugAsSeriesInfo(String slug, String lang);
3940
List<SeriesInfoDto> findByCollectionIdAsSeriesInfo(Integer collectionId, String lang);
41+
List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId);
42+
4043
long countAll();
4144
long countAllStamps();
4245
long countSeriesOfCollection(Integer collectionId);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2009-2016 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.dao.dto;
19+
20+
import java.math.BigDecimal;
21+
import java.util.Date;
22+
23+
import lombok.Getter;
24+
import lombok.RequiredArgsConstructor;
25+
26+
import ru.mystamps.web.service.dto.Currency;
27+
28+
/**
29+
* @author Sergey Chechenev
30+
*/
31+
@Getter
32+
@RequiredArgsConstructor
33+
public class PurchaseAndSaleDto {
34+
private final Date date;
35+
private final String sellerName;
36+
private final String sellerUrl;
37+
private final String buyerName;
38+
private final String buyerUrl;
39+
private final String transactionUrl;
40+
private final BigDecimal firstPrice;
41+
private final Currency firstCurrency;
42+
private final BigDecimal secondPrice;
43+
private final Currency secondCurrency;
44+
}

Diff for: src/main/java/ru/mystamps/web/dao/impl/JdbcSeriesDao.java

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import ru.mystamps.web.dao.SeriesDao;
3838
import ru.mystamps.web.dao.dto.AddSeriesDbDto;
39+
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
3940
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
4041
import ru.mystamps.web.dao.dto.SeriesInfoDto;
4142
import ru.mystamps.web.dao.dto.SitemapInfoDto;
@@ -79,6 +80,9 @@ public class JdbcSeriesDao implements SeriesDao {
7980
@Value("${series.find_by_collection_id}")
8081
private String findByCollectionIdSql;
8182

83+
@Value("${series.find_purchases_and_sales_by_series_id}")
84+
private String findPurchasesAndSalesBySeriesIdSql;
85+
8286
@Value("${series.count_all_series}")
8387
private String countAllSql;
8488

@@ -249,6 +253,18 @@ public List<SeriesInfoDto> findByCollectionIdAsSeriesInfo(Integer collectionId,
249253
return jdbcTemplate.query(findByCollectionIdSql, params, RowMappers::forSeriesInfoDto);
250254
}
251255

256+
/**
257+
* @author Sergey Chechenev
258+
*/
259+
@Override
260+
public List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId) {
261+
return jdbcTemplate.query(
262+
findPurchasesAndSalesBySeriesIdSql,
263+
Collections.singletonMap("series_id", seriesId),
264+
RowMappers::forPurchaseAndSaleDto
265+
);
266+
}
267+
252268
@Override
253269
public long countAll() {
254270
return jdbcTemplate.queryForObject(

Diff for: src/main/java/ru/mystamps/web/dao/impl/JdbcUtils.java

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.sql.ResultSet;
2121
import java.sql.SQLException;
2222

23+
import ru.mystamps.web.service.dto.Currency;
24+
2325
public final class JdbcUtils {
2426

2527
private JdbcUtils() {
@@ -36,4 +38,16 @@ public static Integer getInteger(ResultSet resultSet, String fieldName) throws S
3638
return Integer.valueOf(value);
3739
}
3840

41+
/**
42+
* @author Sergey Chechenev
43+
*/
44+
@SuppressWarnings("PMD.PrematureDeclaration")
45+
public static Currency getCurrency(ResultSet resultSet, String fieldName) throws SQLException {
46+
String value = resultSet.getString(fieldName);
47+
if (resultSet.wasNull()) {
48+
return null;
49+
}
50+
51+
return Currency.valueOf(value);
52+
}
3953
}

Diff for: src/main/java/ru/mystamps/web/dao/impl/RowMappers.java

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import ru.mystamps.web.dao.dto.DbImageDto;
2727
import ru.mystamps.web.dao.dto.ImageInfoDto;
2828
import ru.mystamps.web.dao.dto.LinkEntityDto;
29+
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
2930
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
3031
import ru.mystamps.web.dao.dto.SeriesInfoDto;
3132
import ru.mystamps.web.dao.dto.SitemapInfoDto;
@@ -34,6 +35,7 @@
3435
import ru.mystamps.web.dao.dto.UserDetails;
3536
import ru.mystamps.web.dao.dto.UsersActivationDto;
3637
import ru.mystamps.web.dao.dto.UsersActivationFullDto;
38+
import ru.mystamps.web.service.dto.Currency;
3739

3840
@SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods" })
3941
final class RowMappers {
@@ -100,6 +102,36 @@ public static SeriesInfoDto forSeriesInfoDto(ResultSet rs, int i) throws SQLExce
100102
);
101103
}
102104

105+
/**
106+
* @author Sergey Chechenev
107+
*/
108+
// CheckStyle: ignore LineLength for next 1 line
109+
public static PurchaseAndSaleDto forPurchaseAndSaleDto(ResultSet rs, int i) throws SQLException {
110+
Date date = rs.getDate("date");
111+
String sellerName = rs.getString("seller_name");
112+
String sellerUrl = rs.getString("seller_url");
113+
String buyerName = rs.getString("buyer_name");
114+
String buyerUrl = rs.getString("buyer_url");
115+
String transactionUrl = rs.getString("transaction_url");
116+
BigDecimal firstPrice = rs.getBigDecimal("first_price");
117+
Currency firstCurrency = JdbcUtils.getCurrency(rs, "first_currency");
118+
BigDecimal secondPrice = rs.getBigDecimal("second_price");
119+
Currency secondCurrency = JdbcUtils.getCurrency(rs, "second_currency");
120+
121+
return new PurchaseAndSaleDto(
122+
date,
123+
sellerName,
124+
sellerUrl,
125+
buyerName,
126+
buyerUrl,
127+
transactionUrl,
128+
firstPrice,
129+
firstCurrency,
130+
secondPrice,
131+
secondCurrency
132+
);
133+
}
134+
103135
public static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int i) throws SQLException {
104136
Integer seriesId = rs.getInt("id");
105137
Integer releaseDay = JdbcUtils.getInteger(rs, "release_day");

Diff for: src/main/java/ru/mystamps/web/service/SeriesService.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Date;
2121
import java.util.List;
2222

23+
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
2324
import ru.mystamps.web.dao.dto.SeriesInfoDto;
2425
import ru.mystamps.web.dao.dto.SitemapInfoDto;
2526
import ru.mystamps.web.service.dto.AddImageDto;
@@ -51,4 +52,6 @@ public interface SeriesService {
5152
List<SeriesInfoDto> findByCollectionId(Integer collectionId, String lang);
5253
List<SeriesInfoDto> findRecentlyAdded(int quantity, String lang);
5354
List<SitemapInfoDto> findAllForSitemap();
55+
56+
List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId);
5457
}

Diff for: src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import ru.mystamps.web.dao.SeriesDao;
3737
import ru.mystamps.web.dao.dto.AddSeriesDbDto;
38+
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
3839
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
3940
import ru.mystamps.web.dao.dto.SeriesInfoDto;
4041
import ru.mystamps.web.dao.dto.SitemapInfoDto;
@@ -46,7 +47,9 @@
4647
import ru.mystamps.web.util.CatalogUtils;
4748

4849
// TODO: move stamps related methods to separate interface (#88)
49-
@SuppressWarnings("PMD.TooManyMethods")
50+
// The String literal "Series id must be non null" appears N times in this file
51+
// and we think that it's OK.
52+
@SuppressWarnings({ "PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals" })
5053
@RequiredArgsConstructor
5154
public class SeriesServiceImpl implements SeriesService {
5255
private static final Logger LOG = LoggerFactory.getLogger(SeriesServiceImpl.class);
@@ -348,7 +351,19 @@ public List<SeriesInfoDto> findRecentlyAdded(int quantity, String lang) {
348351
public List<SitemapInfoDto> findAllForSitemap() {
349352
return seriesDao.findAllForSitemap();
350353
}
354+
355+
/**
356+
* @author Sergey Chechenev
357+
*/
358+
@Override
359+
@Transactional(readOnly = true)
360+
@PreAuthorize(HasAuthority.VIEW_SERIES_SALES)
361+
public List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId) {
362+
Validate.isTrue(seriesId != null, "Series id must be non null");
351363

364+
return seriesDao.findPurchasesAndSales(seriesId);
365+
}
366+
352367
private static void setDateOfReleaseIfProvided(AddSeriesDto dto, AddSeriesDbDto series) {
353368
if (dto.getYear() == null) {
354369
return;

Diff for: src/main/java/ru/mystamps/web/service/dto/Currency.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
package ru.mystamps.web.service.dto;
1919

2020
public enum Currency {
21-
EUR, USD, GBP
21+
EUR, USD, GBP, RUB
2222
}

Diff for: src/main/java/ru/mystamps/web/support/spring/security/Authority.java

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public final class Authority {
3030
public static final GrantedAuthority CREATE_SERIES = new SimpleGrantedAuthority(StringAuthority.CREATE_SERIES);
3131
public static final GrantedAuthority UPDATE_COLLECTION = new SimpleGrantedAuthority(StringAuthority.UPDATE_COLLECTION);
3232
public static final GrantedAuthority VIEW_SITE_EVENTS = new SimpleGrantedAuthority(StringAuthority.VIEW_SITE_EVENTS);
33+
public static final GrantedAuthority VIEW_SERIES_SALES = new SimpleGrantedAuthority(StringAuthority.VIEW_SERIES_SALES);
3334

3435
private Authority() {
3536
}

Diff for: src/main/java/ru/mystamps/web/support/spring/security/CustomUserDetailsService.java

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private static Collection<? extends GrantedAuthority> getAuthorities(UserDetails
7777
authorities.add(Authority.ADD_COMMENTS_TO_SERIES);
7878
authorities.add(Authority.ADD_IMAGES_TO_SERIES);
7979
authorities.add(Authority.VIEW_SITE_EVENTS);
80+
authorities.add(Authority.VIEW_SERIES_SALES);
8081
authorities.add(Authority.MANAGE_TOGGLZ);
8182
}
8283

Diff for: src/main/java/ru/mystamps/web/support/spring/security/HasAuthority.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class HasAuthority {
2424
public static final String CREATE_COUNTRY = "hasAuthority('" + StringAuthority.CREATE_COUNTRY + "')";
2525
public static final String UPDATE_COLLECTION = "hasAuthority('" + StringAuthority.UPDATE_COLLECTION + "')";
2626
public static final String VIEW_SITE_EVENTS = "hasAuthority('" + StringAuthority.VIEW_SITE_EVENTS + "')";
27+
public static final String VIEW_SERIES_SALES = "hasAuthority('" + StringAuthority.VIEW_SERIES_SALES + "')";
2728

2829
private HasAuthority() {
2930
}

Diff for: src/main/java/ru/mystamps/web/support/spring/security/StringAuthority.java

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public final class StringAuthority {
2626
public static final String CREATE_SERIES = "CREATE_SERIES";
2727
public static final String UPDATE_COLLECTION = "UPDATE_COLLECTION";
2828
public static final String VIEW_SITE_EVENTS = "VIEW_SITE_EVENTS";
29+
public static final String VIEW_SERIES_SALES = "VIEW_SERIES_SALES";
2930

3031
private StringAuthority() {
3132
}

Diff for: src/main/java/ru/mystamps/web/support/togglz/Features.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public enum Features implements Feature {
6666

6767
@Label("Show link to list of countries on index page")
6868
@EnabledByDefault
69-
LIST_COUNTRIES;
69+
LIST_COUNTRIES,
70+
71+
@Label("Show series purchases and sales on series info page")
72+
@EnabledByDefault
73+
PURCHASES_AND_SALES;
7074

7175
public boolean isActive() {
7276
return FeatureContext.getFeatureManager().isActive(this);

Diff for: src/main/resources/liquibase/version/0.4.xml

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<include file="0.4/2016-01-14--unique_slug_in_countries.xml" relativeToChangelogFile="true" />
1717
<include file="0.4/2016-07-22--unique_slug_in_categories.xml" relativeToChangelogFile="true" />
1818
<include file="0.4/2016-08-18--unique_slug_in_collections.xml" relativeToChangelogFile="true" />
19+
<include file="0.4/2016-08-22--series_sales.xml" relativeToChangelogFile="true" />
1920

2021
</databaseChangeLog>

0 commit comments

Comments
 (0)