25
25
26
26
import org .slf4j .Logger ;
27
27
28
+ import org .springframework .context .ApplicationEventPublisher ;
28
29
import org .springframework .transaction .annotation .Transactional ;
29
30
30
31
import org .springframework .security .access .prepost .PreAuthorize ;
31
32
32
33
import lombok .RequiredArgsConstructor ;
33
34
34
35
import ru .mystamps .web .Db .SeriesImportRequestStatus ;
36
+ import ru .mystamps .web .controller .event .ParsingFailed ;
35
37
import ru .mystamps .web .dao .SeriesImportDao ;
36
38
import ru .mystamps .web .dao .dto .ImportRequestDto ;
37
39
import ru .mystamps .web .dao .dto .ImportSeriesDbDto ;
@@ -51,6 +53,7 @@ public class SeriesImportServiceImpl implements SeriesImportService {
51
53
private final SeriesImportDao seriesImportDao ;
52
54
private final SeriesService seriesService ;
53
55
private final SeriesInfoExtractorService extractorService ;
56
+ private final ApplicationEventPublisher eventPublisher ;
54
57
55
58
@ Override
56
59
@ Transactional
@@ -175,8 +178,13 @@ public void saveParsedData(Integer requestId, RawParsedDataDto data) {
175
178
processedData .setReleaseYear (releaseYear );
176
179
}
177
180
178
- // TODO: handle it gracefully by publishing ParsingFailed event
179
- Validate .validState (processedData .hasAtLeastOneFieldFilled (), "" );
181
+ // IMPORTANT: don't add code that modifies database above this line!
182
+ // @todo #684 Series import: add integration test
183
+ // for the case when parsed value don't match database
184
+ if (!processedData .hasAtLeastOneFieldFilled ()) {
185
+ eventPublisher .publishEvent (new ParsingFailed (this , requestId ));
186
+ return ;
187
+ }
180
188
181
189
seriesImportDao .addParsedContent (requestId , processedData );
182
190
0 commit comments