28
28
import ru .mystamps .web .feature .country .CountryValidation ;
29
29
import ru .mystamps .web .feature .participant .ParticipantService ;
30
30
import ru .mystamps .web .feature .series .SeriesValidation ;
31
+ import ru .mystamps .web .feature .series .sale .SeriesCondition ;
31
32
32
33
import java .math .BigDecimal ;
33
34
import java .net .MalformedURLException ;
@@ -116,6 +117,7 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
116
117
String currency = extractCurrency (data .getCurrency ());
117
118
BigDecimal altPrice = extractPrice (data .getAltPrice ());
118
119
String altCurrency = extractCurrency (data .getAltCurrency ());
120
+ SeriesCondition condition = extractCondition (data .getCondition ());
119
121
120
122
return new SeriesExtractedInfo (
121
123
categoryIds ,
@@ -133,7 +135,8 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
133
135
price ,
134
136
currency ,
135
137
altPrice ,
136
- altCurrency
138
+ altCurrency ,
139
+ condition
137
140
);
138
141
}
139
142
@@ -494,6 +497,33 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
494
497
return null ;
495
498
}
496
499
500
+ // @todo #1326 SeriesInfoExtractorServiceImpl.extractCondition(): add unit tests
501
+ @ SuppressWarnings ({
502
+ "checkstyle:missingswitchdefault" ,
503
+ "PMD.TooFewBranchesForASwitchStatement" ,
504
+ "PMD.SwitchStmtsShouldHaveDefault"
505
+ })
506
+ /* default */ SeriesCondition extractCondition (String fragment ) {
507
+ if (StringUtils .isBlank (fragment )) {
508
+ return null ;
509
+ }
510
+
511
+ String [] candidates = StringUtils .split (fragment , ' ' );
512
+ for (String candidate : candidates ) {
513
+ switch (candidate ) {
514
+ case "MNH" :
515
+ case "MVLH" :
516
+ SeriesCondition condition = SeriesCondition .valueOf (candidate );
517
+ log .debug ("Condition is {}" , condition );
518
+ return condition ;
519
+ }
520
+ }
521
+
522
+ log .debug ("Could not extract condition from a fragment" );
523
+
524
+ return null ;
525
+ }
526
+
497
527
private Integer extractSellerByNameAndUrl (String name , String url ) {
498
528
log .debug ("Determine seller by name '{}' and url '{}'" , name , url );
499
529
0 commit comments