Skip to content

Commit 59c9c83

Browse files
committed
refactor: move inclusion of series_import_request_dao_queries.properties to the appropriate package config
We also switched to using Environment.getRequiredProperty() because @value doesn't work without PropertySourcesPlaceholderConfigurer bean (that we are going to remove soon). Relate to #927
1 parent e67aca0 commit 59c9c83

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

src/main/java/ru/mystamps/web/config/ApplicationContext.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholder
5050
new ClassPathResource("sql/user_dao_queries.properties"),
5151
new ClassPathResource("sql/users_activation_dao_queries.properties"),
5252
new ClassPathResource("sql/series_dao_queries.properties"),
53-
new ClassPathResource("sql/series_import_request_dao_queries.properties"),
5453
new ClassPathResource("sql/series_sales_dao_queries.properties"),
5554
new ClassPathResource("sql/suspicious_activity_dao_queries.properties"),
5655
new ClassPathResource("sql/transaction_participants_dao_queries.properties")

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

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
*/
1818
package ru.mystamps.web.feature.series.importing;
1919

20-
import lombok.RequiredArgsConstructor;
2120
import org.apache.commons.lang3.Validate;
22-
import org.springframework.beans.factory.annotation.Value;
21+
import org.springframework.core.env.Environment;
2322
import org.springframework.dao.EmptyResultDataAccessException;
2423
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
2524
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -35,40 +34,34 @@
3534

3635
// it complains that "request_id" is present many times
3736
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
38-
@RequiredArgsConstructor
3937
public class JdbcSeriesImportDao implements SeriesImportDao {
4038

4139
private final NamedParameterJdbcTemplate jdbcTemplate;
42-
43-
@Value("${series_import_requests.create}")
44-
private String createSeriesImportRequestSql;
45-
46-
@Value("${series_import_requests.set_series_id_and_change_status}")
47-
private String setSeriesIdAndChangeStatusSql;
48-
49-
@Value("${series_import_requests.change_status}")
50-
private String changeStatusSql;
51-
52-
@Value("${series_import_requests.find_by_id}")
53-
private String findImportRequestByIdSql;
54-
55-
@Value("${series_import_requests.add_raw_content}")
56-
private String addRawContentSql;
57-
58-
@Value("${series_import_requests.find_raw_content_by_request_id}")
59-
private String findRawContentSql;
60-
61-
@Value("${series_import_requests.add_series_parsed_data}")
62-
private String addParsedDataSql;
63-
64-
@Value("${series_import_requests.find_series_parsed_data_by_request_id}")
65-
private String findParsedDataSql;
66-
67-
@Value("${series_import_requests.find_request_info_by_series_id}")
68-
private String findRequestInfoSql;
69-
70-
@Value("${series_import_requests.find_all}")
71-
private String findAllSql;
40+
private final String createSeriesImportRequestSql;
41+
private final String setSeriesIdAndChangeStatusSql;
42+
private final String changeStatusSql;
43+
private final String findImportRequestByIdSql;
44+
private final String addRawContentSql;
45+
private final String findRawContentSql;
46+
private final String addParsedDataSql;
47+
private final String findParsedDataSql;
48+
private final String findRequestInfoSql;
49+
private final String findAllSql;
50+
51+
@SuppressWarnings("checkstyle:linelength")
52+
public JdbcSeriesImportDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) {
53+
this.jdbcTemplate = jdbcTemplate;
54+
this.createSeriesImportRequestSql = env.getRequiredProperty("series_import_requests.create");
55+
this.setSeriesIdAndChangeStatusSql = env.getRequiredProperty("series_import_requests.set_series_id_and_change_status");
56+
this.changeStatusSql = env.getRequiredProperty("series_import_requests.change_status");
57+
this.findImportRequestByIdSql = env.getRequiredProperty("series_import_requests.find_by_id");
58+
this.addRawContentSql = env.getRequiredProperty("series_import_requests.add_raw_content");
59+
this.findRawContentSql = env.getRequiredProperty("series_import_requests.find_raw_content_by_request_id");
60+
this.addParsedDataSql = env.getRequiredProperty("series_import_requests.add_series_parsed_data");
61+
this.findParsedDataSql = env.getRequiredProperty("series_import_requests.find_series_parsed_data_by_request_id");
62+
this.findRequestInfoSql = env.getRequiredProperty("series_import_requests.find_request_info_by_series_id");
63+
this.findAllSql = env.getRequiredProperty("series_import_requests.find_all");
64+
}
7265

7366
@Override
7467
public Integer add(ImportSeriesDbDto importRequest) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import org.springframework.context.annotation.Bean;
2525
import org.springframework.context.annotation.Configuration;
2626
import org.springframework.context.annotation.Lazy;
27+
import org.springframework.context.annotation.PropertySource;
2728
import org.springframework.core.Ordered;
29+
import org.springframework.core.env.Environment;
2830
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2931
import ru.mystamps.web.feature.participant.ParticipantService;
3032
import ru.mystamps.web.feature.series.SeriesController;
@@ -83,13 +85,15 @@ public FilterRegistrationBean<ImportSeriesFormTrimmerFilter> importSeriesFormTri
8385
}
8486

8587
@RequiredArgsConstructor
88+
@PropertySource("classpath:sql/series_import_request_dao_queries.properties")
8689
public static class Services {
8790

8891
private final NamedParameterJdbcTemplate jdbcTemplate;
8992
private final ParticipantService participantService;
9093
private final SeriesService seriesService;
9194
private final SeriesSalesService seriesSalesService;
9295
private final ApplicationEventPublisher eventPublisher;
96+
private final Environment env;
9397

9498
@Bean
9599
public SeriesImportService seriesImportService(
@@ -109,7 +113,7 @@ public SeriesImportService seriesImportService(
109113

110114
@Bean
111115
public SeriesImportDao seriesImportDao() {
112-
return new JdbcSeriesImportDao(jdbcTemplate);
116+
return new JdbcSeriesImportDao(env, jdbcTemplate);
113117
}
114118

115119
}

0 commit comments

Comments
 (0)