Skip to content

Commit c9e3ae8

Browse files
committed
ParticipantConfig: group Spring configuration into a single config.
Addressed to #927 No functional changes.
1 parent d837707 commit c9e3ae8

File tree

4 files changed

+82
-28
lines changed

4 files changed

+82
-28
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
import ru.mystamps.web.feature.category.CategoryService;
3333
import ru.mystamps.web.feature.country.CountryConfig;
3434
import ru.mystamps.web.feature.country.CountryService;
35-
import ru.mystamps.web.feature.participant.ParticipantController;
35+
import ru.mystamps.web.feature.participant.ParticipantConfig;
36+
import ru.mystamps.web.feature.participant.ParticipantService;
3637

3738
@Configuration
3839
@RequiredArgsConstructor
3940
@Import({
4041
CategoryConfig.Controllers.class,
41-
CountryConfig.Controllers.class
42+
CountryConfig.Controllers.class,
43+
ParticipantConfig.Controllers.class
4244
})
4345
public class ControllersConfig {
4446

@@ -47,6 +49,7 @@ public class ControllersConfig {
4749
private final ApplicationEventPublisher eventPublisher;
4850
private final CategoryService categoryService;
4951
private final CountryService countryService;
52+
private final ParticipantService participantService;
5053

5154
@Bean
5255
public AccountController getAccountController() {
@@ -77,11 +80,6 @@ public ErrorController getErrorController() {
7780
return new ErrorController(servicesConfig.getSiteService());
7881
}
7982

80-
@Bean
81-
public ParticipantController getParticipantController() {
82-
return new ParticipantController(servicesConfig.getParticipantService());
83-
}
84-
8583
@Bean
8684
public RobotsTxtController getRobotsTxtController() {
8785
return new RobotsTxtController();
@@ -104,7 +102,7 @@ public SeriesController getSeriesController() {
104102
servicesConfig.getSeriesService(),
105103
servicesConfig.getSeriesImportService(),
106104
servicesConfig.getSeriesSalesService(),
107-
servicesConfig.getParticipantService()
105+
participantService
108106
);
109107
}
110108

@@ -115,7 +113,7 @@ public SeriesImportController getSeriesImportController() {
115113
servicesConfig.getSeriesSalesService(),
116114
servicesConfig.getSeriesSalesImportService(),
117115
getSeriesController(),
118-
servicesConfig.getParticipantService(),
116+
participantService,
119117
eventPublisher
120118
);
121119
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
// CheckStyle: ignore AvoidStarImportCheck for next 2 lines
2929
import ru.mystamps.web.dao.*; // NOPMD: UnusedImports
3030
import ru.mystamps.web.dao.impl.*; // NOPMD: UnusedImports
31-
import ru.mystamps.web.feature.participant.JdbcParticipantDao;
32-
import ru.mystamps.web.feature.participant.ParticipantDao;
3331

3432
@Configuration
3533
@PropertySource("classpath:/sql/stamps_catalog_dao_queries.properties")
@@ -133,11 +131,6 @@ public SuspiciousActivityDao getSuspiciousActivityDao() {
133131
return new JdbcSuspiciousActivityDao(jdbcTemplate);
134132
}
135133

136-
@Bean
137-
public ParticipantDao getParticipantDao() {
138-
return new JdbcParticipantDao(jdbcTemplate);
139-
}
140-
141134
@Bean
142135
public StampsCatalogDao getYvertCatalogDao() {
143136
return new JdbcStampsCatalogDao(

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@
3535
import ru.mystamps.web.feature.category.CategoryService;
3636
import ru.mystamps.web.feature.country.CountryConfig;
3737
import ru.mystamps.web.feature.country.CountryService;
38+
import ru.mystamps.web.feature.participant.ParticipantConfig;
3839
import ru.mystamps.web.feature.participant.ParticipantService;
39-
import ru.mystamps.web.feature.participant.ParticipantServiceImpl;
4040
// CheckStyle: ignore AvoidStarImportCheck for next 1 line
4141
import ru.mystamps.web.service.*; // NOPMD: UnusedImports
4242
import ru.mystamps.web.support.spring.security.SecurityConfig;
4343

4444
@Configuration
4545
@Import({
4646
CategoryConfig.Services.class,
47-
CountryConfig.Services.class
47+
CountryConfig.Services.class,
48+
ParticipantConfig.Services.class
4849
})
4950
@RequiredArgsConstructor
5051
@SuppressWarnings("PMD.CouplingBetweenObjects")
@@ -59,6 +60,7 @@ public class ServicesConfig {
5960
private final ApplicationEventPublisher eventPublisher;
6061
private final CategoryService categoryService;
6162
private final CountryService countryService;
63+
private final ParticipantService participantService;
6264

6365
@Bean
6466
public SuspiciousActivityService getSuspiciousActivityService() {
@@ -180,7 +182,7 @@ public SeriesImportService getSeriesImportService() {
180182
getSeriesSalesService(),
181183
getSeriesSalesImportService(),
182184
getSeriesInfoExtractorService(),
183-
getParticipantService(),
185+
participantService,
184186
eventPublisher
185187
);
186188
}
@@ -193,7 +195,7 @@ public SeriesInfoExtractorService getSeriesInfoExtractorService() {
193195
LoggerFactory.getLogger(SeriesInfoExtractorServiceImpl.class),
194196
categoryService,
195197
countryService,
196-
getParticipantService()
198+
participantService
197199
)
198200
);
199201
}
@@ -287,12 +289,4 @@ public StampsCatalogService getZagorskiCatalogService() {
287289
);
288290
}
289291

290-
@Bean
291-
public ParticipantService getParticipantService() {
292-
return new ParticipantServiceImpl(
293-
LoggerFactory.getLogger(ParticipantServiceImpl.class),
294-
daoConfig.getParticipantDao()
295-
);
296-
}
297-
298292
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (C) 2009-2018 Slava Semushin <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.feature.participant;
19+
20+
import org.slf4j.LoggerFactory;
21+
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
25+
26+
import lombok.RequiredArgsConstructor;
27+
28+
/**
29+
* Spring configuration that is required for transaction participants (buyers and sellers).
30+
*
31+
* The beans are grouped into two classes to make possible to register a controller
32+
* and the services in the separated application contexts.
33+
*/
34+
@Configuration
35+
public class ParticipantConfig {
36+
37+
@RequiredArgsConstructor
38+
public static class Controllers {
39+
40+
private final ParticipantService participantService;
41+
42+
@Bean
43+
public ParticipantController participantController() {
44+
return new ParticipantController(participantService);
45+
}
46+
47+
}
48+
49+
@RequiredArgsConstructor
50+
public static class Services {
51+
52+
private final NamedParameterJdbcTemplate jdbcTemplate;
53+
54+
@Bean
55+
public ParticipantService participantService(ParticipantDao participantDao) {
56+
return new ParticipantServiceImpl(
57+
LoggerFactory.getLogger(ParticipantServiceImpl.class),
58+
participantDao
59+
);
60+
}
61+
62+
@Bean
63+
public ParticipantDao participantDao() {
64+
return new JdbcParticipantDao(jdbcTemplate);
65+
}
66+
67+
}
68+
69+
}

0 commit comments

Comments
 (0)