Skip to content

Commit 9153c9b

Browse files
committed
feat: a series condition is supported for series import, series sale import and creation.
This commit adds support only for series import. Series sales supported has already been added in previous commits. Fix #1326
1 parent 3b8d537 commit 9153c9b

13 files changed

+74
-7
lines changed

NEWS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- (feature) admin can add a comment to a series
66
- (feature) admin can add a release year to a series
77
- (improvement) on a country info page show the series with an image
8+
- (feature) add a condition (MNH/MNHOG/MVLH/CTO/cancelled) to a series sale
89

910
0.4.3
1011
- (feature) add support for Ukrainian hryvnia

src/main/java/ru/mystamps/web/feature/series/importing/ImportSeriesSalesForm.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class ImportSeriesSalesForm implements AddSeriesSalesDto {
4949
private BigDecimal altPrice;
5050
private Currency altCurrency;
5151

52+
// @todo #1326 Series import: add integration test for series condition
53+
private SeriesCondition condition;
54+
5255
// We don't expose these fields to a form because we know already what
5356
// values should be. Even if user will try to provide its own values, it's not
5457
// a problem as we always rewrite them in the controller.
@@ -65,9 +68,4 @@ public Integer getBuyerId() {
6568
return null;
6669
}
6770

68-
@Override
69-
public SeriesCondition getCondition() {
70-
return null;
71-
}
72-
7371
}

src/main/java/ru/mystamps/web/feature/series/importing/SeriesImportController.java

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public String showRequestAndImportSeriesForm(
171171
seriesSaleForm.setCurrency(seriesSale.getCurrency());
172172
seriesSaleForm.setAltPrice(seriesSale.getAltPrice());
173173
seriesSaleForm.setAltCurrency(seriesSale.getAltCurrency());
174+
seriesSaleForm.setCondition(seriesSale.getCondition());
174175

175176
ImportSellerForm sellerForm = new ImportSellerForm();
176177
sellerForm.setName(seriesSale.getSellerName());

src/main/java/ru/mystamps/web/feature/series/importing/SeriesImportServiceImpl.java

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportService;
3636
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesParsedDataDbDto;
3737
import ru.mystamps.web.feature.series.sale.AddSeriesSalesDto;
38+
import ru.mystamps.web.feature.series.sale.SeriesCondition;
3839
import ru.mystamps.web.feature.series.sale.SeriesSalesService;
3940
import ru.mystamps.web.support.spring.security.HasAuthority;
4041

@@ -231,6 +232,12 @@ public void saveParsedData(Integer requestId, SeriesExtractedInfo seriesInfo, St
231232
seriesSalesParsedData.setAltCurrency(seriesInfo.getAltCurrency());
232233
}
233234

235+
// @todo #1326 SeriesImportServiceImpl.saveParsedData(): add unit test for condition
236+
SeriesCondition condition = seriesInfo.getCondition();
237+
if (condition != null) {
238+
seriesSalesParsedData.setCondition(condition.toString());
239+
}
240+
234241
// IMPORTANT: don't add code that modifies database above this line!
235242
// @todo #684 Series import: add integration test
236243
// for the case when parsed value don't match database

src/main/java/ru/mystamps/web/feature/series/importing/sale/JdbcSeriesSalesImportDao.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void addParsedData(Integer requestId, SeriesSalesParsedDataDbDto data) {
5050
params.put("currency", data.getCurrency());
5151
params.put("alt_price", data.getAltPrice());
5252
params.put("alt_currency", data.getAltCurrency());
53+
params.put("condition", data.getCondition());
5354
params.put("created_at", data.getCreatedAt());
5455
params.put("updated_at", data.getUpdatedAt());
5556

src/main/java/ru/mystamps/web/feature/series/importing/sale/RowMappers.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import ru.mystamps.web.common.Currency;
2121
import ru.mystamps.web.common.JdbcUtils;
22+
import ru.mystamps.web.feature.series.sale.SeriesCondition;
2223

2324
import java.math.BigDecimal;
2425
import java.sql.ResultSet;
@@ -41,6 +42,10 @@ private RowMappers() {
4142
Currency currency = JdbcUtils.getCurrency(rs, "currency");
4243
BigDecimal altPrice = rs.getBigDecimal("alt_price");
4344
Currency altCurrency = JdbcUtils.getCurrency(rs, "alt_currency");
45+
46+
// LATER: consider extracting this into a helper method
47+
String conditionField = rs.getString("cond");
48+
SeriesCondition condition = rs.wasNull() ? null : SeriesCondition.valueOf(conditionField);
4449

4550
return new SeriesSaleParsedDataDto(
4651
sellerId,
@@ -50,7 +55,8 @@ private RowMappers() {
5055
price,
5156
currency,
5257
altPrice,
53-
altCurrency
58+
altCurrency,
59+
condition
5460
);
5561
}
5662

src/main/java/ru/mystamps/web/feature/series/importing/sale/SeriesSaleParsedDataDto.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lombok.Getter;
2121
import lombok.RequiredArgsConstructor;
2222
import ru.mystamps.web.common.Currency;
23+
import ru.mystamps.web.feature.series.sale.SeriesCondition;
2324

2425
import java.math.BigDecimal;
2526

@@ -34,4 +35,5 @@ public class SeriesSaleParsedDataDto {
3435
private final Currency currency;
3536
private final BigDecimal altPrice;
3637
private final Currency altCurrency;
38+
private final SeriesCondition condition;
3739
}

src/main/java/ru/mystamps/web/feature/series/importing/sale/SeriesSalesParsedDataDbDto.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class SeriesSalesParsedDataDbDto {
3636
private String currency;
3737
private BigDecimal altPrice;
3838
private String altCurrency;
39+
private String condition;
3940
private Date createdAt;
4041
private Date updatedAt;
4142

src/main/resources/liquibase/version/0.4.4.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<include file="0.4.4/2020-05-04--collections_series_condition.xml" relativeToChangelogFile="true" />
1111
<include file="0.4.4/2020-05-23--modify_condition_field.xml" relativeToChangelogFile="true" />
1212
<include file="0.4.4/2020-06-01--yvert_code_length.xml" relativeToChangelogFile="true" />
13+
<include file="0.4.4/2020-06-03--series_sales_import_parsed_data_condition.xml" relativeToChangelogFile="true" />
1314

1415
</databaseChangeLog>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
6+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
7+
8+
<changeSet id="add-condition-field-to-series_sales_import_parsed_data" author="php-coder" context="scheme">
9+
10+
<addColumn tableName="series_sales_import_parsed_data">
11+
<column name="cond"
12+
type="VARCHAR(9)"
13+
afterColumn="alt_currency"
14+
remarks="Must match to the series_sales.cond field" />
15+
</addColumn>
16+
17+
</changeSet>
18+
19+
</databaseChangeLog>

src/main/resources/sql/series_import_request_dao_queries.properties

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ INSERT \
160160
, currency \
161161
, alt_price \
162162
, alt_currency \
163+
, cond \
163164
, created_at \
164165
, updated_at \
165166
) \
@@ -173,6 +174,7 @@ VALUES \
173174
, :currency \
174175
, :alt_price \
175176
, :alt_currency \
177+
, :condition \
176178
, :created_at \
177179
, :updated_at \
178180
)
@@ -186,5 +188,6 @@ SELECT seller_id \
186188
, currency \
187189
, alt_price \
188190
, alt_currency \
191+
, cond \
189192
FROM series_sales_import_parsed_data \
190193
WHERE request_id = :request_id

src/main/webapp/WEB-INF/views/series/import/info.html

+26
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,32 @@ <h3 th:text="#{t_gathered_data}">
522522
</td>
523523
</tr>
524524

525+
<tr th:if="${hasSalesInfo and (importSeriesForm.seriesSale.condition != null)}"
526+
th:classappend="${#fields.hasErrors('seriesSale.condition') ? 'has-error' : ''}">
527+
<th>
528+
<label for="condition" class="control-label" th:text="#{t_condition}">
529+
Condition
530+
</label>
531+
</th>
532+
<td>
533+
<select id="condition" class="form-control" th:field="*{seriesSale.condition}" th:disabled="${disabled}">
534+
<option value=""></option>
535+
<option value="MNH">MNH</option>
536+
<option value="MNHOG">MNHOG</option>
537+
<option value="MVLH">MVLH</option>
538+
<option value="CTO">CTO</option>
539+
<option value="CANCELLED" th:text="#{t_cancelled}">Сancelled</option>
540+
</select>
541+
<!--/*/
542+
<span id="condition.errors"
543+
class="help-block"
544+
th:if="${#fields.hasErrors('seriesSale.condition')}"
545+
th:each="error : ${#fields.errors('seriesSale.condition')}"
546+
th:text="${error}"></span>
547+
/*/-->
548+
</td>
549+
</tr>
550+
525551
<tr th:if="${hasSalesInfo and (importSeriesForm.seriesSale.price != null or !disabled)}" th:classappend="${#fields.hasErrors('seriesSale.price') or #fields.hasErrors('seriesSale.currency') ? 'has-error' : ''}">
526552
<th>
527553
<label for="price" class="control-label" th:text="#{t_price}">

src/test/java/ru/mystamps/web/service/TestObjects.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ public static SeriesSaleParsedDataDto createSeriesSaleParsedDataDto() {
436436
Random.currency(),
437437
Random.price(),
438438
// FIXME: alternative currency shouldn't match with currency
439-
Random.currency()
439+
Random.currency(),
440+
nullOr(Random.seriesCondition())
440441
);
441442
}
442443

0 commit comments

Comments
 (0)