Skip to content

Commit

Permalink
Add support for specifying Solovyov catalog numbers.
Browse files Browse the repository at this point in the history
Fix #770
  • Loading branch information
php-coder committed Dec 29, 2017
1 parent bfa27a7 commit 14583e1
Show file tree
Hide file tree
Showing 31 changed files with 298 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- (functionality) add capability to specify image URL (as alternative to providing a file)
- (functionality) admin can import a series from an external site
- (integration) migrate from coveralls.io to codecov.io service for code coverage
- (functionality) add support for specifying Solovyov catalog numbers
- (functionality) add support for specifying Zagorski catalog numbers

0.3
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ru/mystamps/web/config/DaoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public SeriesSalesDao getSeriesSalesDao() {
return new JdbcSeriesSalesDao(jdbcTemplate);
}

@Bean
public StampsCatalogDao getSolovyovCatalogDao() {
return new JdbcStampsCatalogDao(
jdbcTemplate,
env.getRequiredProperty("solovyov.create"),
env.getRequiredProperty("series_solovyov.add"),
env.getRequiredProperty("series_solovyov.find_by_series_id")
);
}

@Bean
public UserDao getUserDao() {
return new JdbcUserDao(jdbcTemplate);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ru/mystamps/web/config/ServicesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public SeriesService getSeriesService() {
getScottCatalogService(),
getYvertCatalogService(),
getGibbonsCatalogService(),
getSolovyovCatalogService(),
getZagorskiCatalogService()
);
}
Expand Down Expand Up @@ -246,6 +247,15 @@ public StampsCatalogService getGibbonsCatalogService() {
);
}

@Bean
public StampsCatalogService getSolovyovCatalogService() {
return new StampsCatalogServiceImpl(
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
"Solovyov",
daoConfig.getSolovyovCatalogDao()
);
}

@Bean
public StampsCatalogService getZagorskiCatalogService() {
return new StampsCatalogServiceImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ protected void initSeriesFormBinder(WebDataBinder binder) {
binder.registerCustomEditor(String.class, "scottNumbers", editor);
binder.registerCustomEditor(String.class, "yvertNumbers", editor);
binder.registerCustomEditor(String.class, "gibbonsNumbers", editor);
binder.registerCustomEditor(String.class, "solovyovNumbers", editor);
binder.registerCustomEditor(String.class, "zagorskiNumbers", editor);
binder.registerCustomEditor(String.class, "comment", new StringTrimmerEditor(true));
}
Expand Down Expand Up @@ -457,6 +458,7 @@ public String searchSeriesByCatalog(
}

// @todo #769 Support search by Zagorski number
// @todo #770 Support search by Solovyov number
String lang = LocaleUtils.getLanguageOrNull(userLocale);
List<SeriesInfoDto> series;
switch (catalogName) {
Expand Down Expand Up @@ -550,11 +552,13 @@ protected static void loadErrorsFromDownloadInterceptor(
String scottNumbers = CatalogUtils.toShortForm(series.getScott().getNumbers());
String yvertNumbers = CatalogUtils.toShortForm(series.getYvert().getNumbers());
String gibbonsNumbers = CatalogUtils.toShortForm(series.getGibbons().getNumbers());
String solovyovNumbers = CatalogUtils.toShortForm(series.getSolovyov().getNumbers());
String zagorskiNumbers = CatalogUtils.toShortForm(series.getZagorski().getNumbers());
model.put("michelNumbers", michelNumbers);
model.put("scottNumbers", scottNumbers);
model.put("yvertNumbers", yvertNumbers);
model.put("gibbonsNumbers", gibbonsNumbers);
model.put("solovyovNumbers", solovyovNumbers);
model.put("zagorskiNumbers", zagorskiNumbers);

boolean isSeriesInCollection =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public class AddSeriesForm implements AddSeriesDto, HasImageOrImageUrl, Nullable
@Price
private BigDecimal gibbonsPrice;

// @todo #770 /series/add: validate that Solovyov numbers are specified only for stamps
// from USSR/Russia
@CatalogNumbers
private String solovyovNumbers;

@Price
private BigDecimal solovyovPrice;

// @todo #769 /series/add: validate that Zagorski numbers are specified only for stamps
// from USSR/Russia
@CatalogNumbers
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ru/mystamps/web/controller/dto/ImportSeriesForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ public BigDecimal getGibbonsPrice() {
return null;
}

@Override
public String getSolovyovNumbers() {
return null;
}

@Override
public BigDecimal getSolovyovPrice() {
return null;
}

@Override
public String getZagorskiNumbers() {
return null;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ru/mystamps/web/dao/dto/AddSeriesDbDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class AddSeriesDbDto {
private BigDecimal gibbonsPrice;
private String gibbonsCurrency;

private BigDecimal solovyovPrice;
private BigDecimal zagorskiPrice;

private Integer releaseDay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ public class SeriesFullInfoDto {
private final BigDecimal gibbonsPrice;
private final String gibbonsCurrency;

private final BigDecimal solovyovPrice;
private final BigDecimal zagorskiPrice;
}
1 change: 1 addition & 0 deletions src/main/java/ru/mystamps/web/dao/impl/JdbcSeriesDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public Integer add(AddSeriesDbDto series) {
params.put("yvert_currency", series.getYvertCurrency());
params.put("gibbons_price", series.getGibbonsPrice());
params.put("gibbons_currency", series.getGibbonsCurrency());
params.put("solovyov_price", series.getSolovyovPrice());
params.put("zagorski_price", series.getZagorskiPrice());
params.put("comment", series.getComment());
params.put("created_at", series.getCreatedAt());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ru/mystamps/web/dao/impl/RowMappers.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int i) throws
BigDecimal gibbonsPrice = rs.getBigDecimal("gibbons_price");
String gibbonsCurrency = rs.getString("gibbons_currency");

BigDecimal solovyovPrice = rs.getBigDecimal("solovyov_price");
BigDecimal zagorskiPrice = rs.getBigDecimal("zagorski_price");

LinkEntityDto category =
Expand Down Expand Up @@ -153,6 +154,7 @@ public static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int i) throws
yvertCurrency,
gibbonsPrice,
gibbonsCurrency,
solovyovPrice,
zagorskiPrice
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class SeriesServiceImpl implements SeriesService {
private final StampsCatalogService scottCatalogService;
private final StampsCatalogService yvertCatalogService;
private final StampsCatalogService gibbonsCatalogService;
private final StampsCatalogService solovyovCatalogService;
private final StampsCatalogService zagorskiCatalogService;

@Override
Expand Down Expand Up @@ -113,6 +114,10 @@ public Integer add(AddSeriesDto dto, Integer userId, boolean userCanAddComments)
series.setGibbonsCurrency(Currency.GBP.toString());
}

if (dto.getSolovyovPrice() != null) {
series.setSolovyovPrice(dto.getSolovyovPrice());
}

if (dto.getZagorskiPrice() != null) {
series.setZagorskiPrice(dto.getZagorskiPrice());
}
Expand Down Expand Up @@ -159,6 +164,12 @@ public Integer add(AddSeriesDto dto, Integer userId, boolean userCanAddComments)
gibbonsCatalogService.addToSeries(id, gibbonsNumbers);
}

Set<String> solovyovNumbers = CatalogUtils.parseCatalogNumbers(dto.getSolovyovNumbers());
if (!solovyovNumbers.isEmpty()) {
solovyovCatalogService.add(solovyovNumbers);
solovyovCatalogService.addToSeries(id, solovyovNumbers);
}

Set<String> zagorskiNumbers = CatalogUtils.parseCatalogNumbers(dto.getZagorskiNumbers());
if (!zagorskiNumbers.isEmpty()) {
zagorskiCatalogService.add(zagorskiNumbers);
Expand Down Expand Up @@ -276,6 +287,7 @@ public SeriesDto findFullInfoById(Integer seriesId, String lang) {
List<String> scottNumbers = scottCatalogService.findBySeriesId(seriesId);
List<String> yvertNumbers = yvertCatalogService.findBySeriesId(seriesId);
List<String> gibbonsNumbers = gibbonsCatalogService.findBySeriesId(seriesId);
List<String> solovyovNumbers = solovyovCatalogService.findBySeriesId(seriesId);
List<String> zagorskiNumbers = zagorskiCatalogService.findBySeriesId(seriesId);

List<Integer> imageIds = imageService.findBySeriesId(seriesId);
Expand All @@ -286,6 +298,7 @@ public SeriesDto findFullInfoById(Integer seriesId, String lang) {
scottNumbers,
yvertNumbers,
gibbonsNumbers,
solovyovNumbers,
zagorskiNumbers,
imageIds
);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/ru/mystamps/web/service/dto/AddSeriesDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public interface AddSeriesDto {
String getGibbonsNumbers();
BigDecimal getGibbonsPrice();

String getSolovyovNumbers();
BigDecimal getSolovyovPrice();

String getZagorskiNumbers();
BigDecimal getZagorskiPrice();

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/ru/mystamps/web/service/dto/SeriesDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class SeriesDto {
@Getter
private final CatalogInfoDto gibbons;

@Getter
private final CatalogInfoDto solovyov;

@Getter
private final CatalogInfoDto zagorski;

Expand All @@ -52,15 +55,17 @@ public SeriesDto(
List<String> scottNumbers,
List<String> yvertNumbers,
List<String> gibbonsNumbers,
List<String> solovyovNumbers,
List<String> zagorskiNumbers,
List<Integer> imageIds) {

this.info = info;
// CheckStyle: ignore LineLength for next 5 lines
// CheckStyle: ignore LineLength for next 6 lines
this.michel = new CatalogInfoDto(michelNumbers, info.getMichelPrice(), info.getMichelCurrency());
this.scott = new CatalogInfoDto(scottNumbers, info.getScottPrice(), info.getScottCurrency());
this.yvert = new CatalogInfoDto(yvertNumbers, info.getYvertPrice(), info.getYvertCurrency());
this.gibbons = new CatalogInfoDto(gibbonsNumbers, info.getGibbonsPrice(), info.getGibbonsCurrency());
this.solovyov = new CatalogInfoDto(solovyovNumbers, info.getSolovyovPrice(), null /* unused field currency */);
this.zagorski = new CatalogInfoDto(zagorskiNumbers, info.getZagorskiPrice(), null /* unused field currency */);
this.imageIds = imageIds;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--
-- Auto-generated by Maven, based on values from src/main/resources/test/spring/test-data.properties
--

INSERT INTO solovyov_catalog(id, code) VALUES(1, '@existing_solovyov_number@');
INSERT INTO series_solovyov_catalog(series_id, solovyov_id) VALUES(1, 1);
1 change: 1 addition & 0 deletions src/main/resources/liquibase/version/0.4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<include file="0.4/2017-11-15--group_participants.xml" relativeToChangelogFile="true" />
<include file="0.4/2017-11-22--import_request_series_id.xml" relativeToChangelogFile="true" />
<include file="0.4/2017-12-18--unique_series_id_in_import_requests.xml" relativeToChangelogFile="true" />
<include file="0.4/2017-12-21--solovyov_catalog.xml" relativeToChangelogFile="true" />
<include file="0.4/2017-12-21--zagorski_catalog.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

<changeSet id="create-solovyov_catalog-table" author="php-coder" context="scheme">

<createTable tableName="solovyov_catalog">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" />
</column>
<column name="code" type="VARCHAR(4)">
<constraints nullable="false" unique="true" uniqueConstraintName="uc_solovyov_catalog_code" />
</column>
</createTable>

</changeSet>

<changeSet id="create-series_solovyov_catalog-table" author="php-coder" context="scheme">

<createTable tableName="series_solovyov_catalog">
<column name="series_id" type="INTEGER">
<constraints primaryKey="true" references="series(id)" foreignKeyName="fk_series_solovyov_catalog_series_id" />
</column>
<column name="solovyov_id" type="INTEGER">
<constraints primaryKey="true" references="solovyov_catalog(id)" foreignKeyName="fk_series_solovyov_catalog_solovyov_id" />
</column>
</createTable>

</changeSet>

<changeSet id="add-solovyov_price-field-to-series-field" author="php-coder" context="scheme">

<addColumn tableName="series">
<column name="solovyov_price" type="DECIMAL(19,2)" afterColumn="gibbons_price" />
</addColumn>

</changeSet>

<changeSet id="add-solovyov-numbers-to-series" author="php-coder" context="test-data">
<sqlFile path="../../sql/test-series-with-solovyov-numbers.sql" relativeToChangelogFile="true" />
</changeSet>

</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/ru/mystamps/i18n/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ t_scott = Scott
t_yvert = Yvert
t_sg = Gibbons
t_zagorski = Zagorski
t_solovyov = Solovyov

t_add_comment = Add comment
t_comment = Comment
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/ru/mystamps/i18n/Messages_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ t_scott = Scott
t_yvert = Yvert
t_sg = Gibbons
t_zagorski = Загорский
t_solovyov = Соловьев
t_add_comment = Добавить комментарий
t_comment = Комментарий
t_image = Изображение
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/sql/series_dao_queries.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ INSERT \
, yvert_currency \
, gibbons_price \
, gibbons_currency \
, solovyov_price \
, zagorski_price \
, comment \
, created_at \
Expand All @@ -39,6 +40,7 @@ VALUES \
, :yvert_currency \
, :gibbons_price \
, :gibbons_currency \
, :solovyov_price \
, :zagorski_price \
, :comment \
, :created_at \
Expand Down Expand Up @@ -99,6 +101,7 @@ series.find_full_info_by_id = \
, s.yvert_currency \
, s.gibbons_price \
, s.gibbons_currency \
, s.solovyov_price \
, s.zagorski_price \
, s.comment \
, s.created_by \
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/sql/stamps_catalog_dao_queries.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ SELECT :code AS code \
WHERE code = :code \
)

solovyov.create = \
INSERT \
INTO solovyov_catalog(code) \
SELECT :code AS code \
FROM dual \
WHERE NOT EXISTS( \
SELECT * \
FROM solovyov_catalog \
WHERE code = :code \
)

zagorski.create = \
INSERT \
INTO zagorski_catalog(code) \
Expand Down Expand Up @@ -101,6 +112,18 @@ SELECT :series_id \
WHERE code \
IN (:numbers)

series_solovyov.add = \
INSERT \
INTO series_solovyov_catalog \
( series_id \
, solovyov_id \
) \
SELECT :series_id \
, id \
FROM solovyov_catalog \
WHERE code \
IN (:numbers)

series_zagorski.add = \
INSERT \
INTO series_zagorski_catalog \
Expand Down Expand Up @@ -141,6 +164,13 @@ SELECT c.code \
ON c.id = sc.yvert_id \
WHERE sc.series_id = :series_id

series_solovyov.find_by_series_id = \
SELECT c.code \
FROM series_solovyov_catalog sc \
JOIN solovyov_catalog c \
ON c.id = sc.solovyov_id \
WHERE sc.series_id = :series_id

series_zagorski.find_by_series_id = \
SELECT c.code \
FROM series_zagorski_catalog sc \
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/test/spring/test-data.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ existing_michel_number = 99
existing_scott_number = 99
existing_yvert_number = 99
existing_gibbons_number = 99
existing_solovyov_number = 77
existing_zagorski_number = 83

# this category should always exist
Expand Down

5 comments on commit 14583e1

@0pdd
Copy link

@0pdd 0pdd commented on 14583e1 Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 769-4310f3c0 discovered in src/test/java/ru/mystamps/web/tests/Random.java and submitted as #773. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 14583e1 Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 770-3251a080 discovered in src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java and submitted as #774. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 14583e1 Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 769-d2cdc518 discovered in src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java and submitted as #775. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 14583e1 Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 769-9c37cac2 discovered in src/main/java/ru/mystamps/web/controller/SeriesController.java and submitted as #776. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 14583e1 Dec 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 770-c8c03da2 discovered in src/main/java/ru/mystamps/web/controller/SeriesController.java and submitted as #777. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

Please sign in to comment.