Skip to content

Commit 040eff2

Browse files
committed
refactor(SeriesConfig): group Spring configuration into a single config.
Addressed to #927 No functional changes.
1 parent 6d4e10a commit 040eff2

File tree

4 files changed

+149
-51
lines changed

4 files changed

+149
-51
lines changed

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import ru.mystamps.web.feature.image.ImageConfig;
3737
import ru.mystamps.web.feature.participant.ParticipantConfig;
3838
import ru.mystamps.web.feature.participant.ParticipantService;
39+
import ru.mystamps.web.feature.series.SeriesConfig;
3940
import ru.mystamps.web.feature.series.SeriesController;
41+
import ru.mystamps.web.feature.series.SeriesService;
4042

4143
@Configuration
4244
@RequiredArgsConstructor
@@ -45,7 +47,8 @@
4547
CollectionConfig.Controllers.class,
4648
CountryConfig.Controllers.class,
4749
ImageConfig.Controllers.class,
48-
ParticipantConfig.Controllers.class
50+
ParticipantConfig.Controllers.class,
51+
SeriesConfig.Controllers.class
4952
})
5053
public class ControllersConfig {
5154

@@ -56,6 +59,8 @@ public class ControllersConfig {
5659
private final CollectionService collectionService;
5760
private final CountryService countryService;
5861
private final ParticipantService participantService;
62+
private final SeriesService seriesService;
63+
private final SeriesController seriesController;
5964

6065
@Bean
6166
public AccountController getAccountController() {
@@ -83,25 +88,12 @@ public ReportController getReportController() {
8388
);
8489
}
8590

86-
@Bean
87-
public SeriesController getSeriesController() {
88-
return new SeriesController(
89-
categoryService,
90-
collectionService,
91-
countryService,
92-
servicesConfig.getSeriesService(),
93-
servicesConfig.getSeriesImportService(),
94-
servicesConfig.getSeriesSalesService(),
95-
participantService
96-
);
97-
}
98-
9991
@Bean
10092
public SeriesImportController getSeriesImportController() {
10193
return new SeriesImportController(
10294
servicesConfig.getSeriesImportService(),
10395
servicesConfig.getSeriesSalesImportService(),
104-
getSeriesController(),
96+
seriesController,
10597
participantService,
10698
eventPublisher
10799
);
@@ -113,14 +105,14 @@ public SiteController getSiteController() {
113105
categoryService,
114106
collectionService,
115107
countryService,
116-
servicesConfig.getSeriesService(),
108+
seriesService,
117109
servicesConfig.getSuspiciousActivityService()
118110
);
119111
}
120112

121113
@Bean
122114
public SitemapController getSitemapController() {
123-
return new SitemapController(servicesConfig.getSeriesService());
115+
return new SitemapController(seriesService);
124116
}
125117

126118
}

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.series.JdbcSeriesDao;
32-
import ru.mystamps.web.feature.series.SeriesDao;
3331

3432
@Configuration
3533
@PropertySource("classpath:/sql/stamps_catalog_dao_queries.properties")
@@ -72,11 +70,6 @@ public StampsCatalogDao getScottCatalogDao() {
7270
);
7371
}
7472

75-
@Bean
76-
public SeriesDao getSeriesDao() {
77-
return new JdbcSeriesDao(jdbcTemplate);
78-
}
79-
8073
@Bean
8174
public SeriesImportDao getSeriesImportDao() {
8275
return new JdbcSeriesImportDao(jdbcTemplate);

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

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@
3838
import ru.mystamps.web.feature.country.CountryConfig;
3939
import ru.mystamps.web.feature.country.CountryService;
4040
import ru.mystamps.web.feature.image.ImageConfig;
41-
import ru.mystamps.web.feature.image.ImageService;
4241
import ru.mystamps.web.feature.participant.ParticipantConfig;
4342
import ru.mystamps.web.feature.participant.ParticipantService;
43+
import ru.mystamps.web.feature.series.SeriesConfig;
4444
import ru.mystamps.web.feature.series.SeriesService;
45-
import ru.mystamps.web.feature.series.SeriesServiceImpl;
4645
// CheckStyle: ignore AvoidStarImportCheck for next 1 line
4746
import ru.mystamps.web.service.*; // NOPMD: UnusedImports
4847
import ru.mystamps.web.support.spring.security.SecurityConfig;
@@ -53,7 +52,8 @@
5352
CollectionConfig.Services.class,
5453
CountryConfig.Services.class,
5554
ImageConfig.Services.class,
56-
ParticipantConfig.Services.class
55+
ParticipantConfig.Services.class,
56+
SeriesConfig.Services.class
5757
})
5858
@RequiredArgsConstructor
5959
@SuppressWarnings("PMD.CouplingBetweenObjects")
@@ -68,8 +68,8 @@ public class ServicesConfig {
6868
private final CategoryService categoryService;
6969
private final CollectionService collectionService;
7070
private final CountryService countryService;
71-
private final ImageService imageService;
7271
private final ParticipantService participantService;
72+
private final SeriesService seriesService;
7373

7474
@Bean
7575
public SuspiciousActivityService getSuspiciousActivityService() {
@@ -83,7 +83,7 @@ public CronService getCronService() {
8383
categoryService,
8484
countryService,
8585
collectionService,
86-
getSeriesService(),
86+
seriesService,
8787
getSuspiciousActivityService(),
8888
getUserService(),
8989
getUsersActivationService(),
@@ -146,27 +146,12 @@ public ReportService getReportService() {
146146
);
147147
}
148148

149-
@Bean
150-
public SeriesService getSeriesService() {
151-
return new SeriesServiceImpl(
152-
LoggerFactory.getLogger(SeriesServiceImpl.class),
153-
daoConfig.getSeriesDao(),
154-
imageService,
155-
getMichelCatalogService(),
156-
getScottCatalogService(),
157-
getYvertCatalogService(),
158-
getGibbonsCatalogService(),
159-
getSolovyovCatalogService(),
160-
getZagorskiCatalogService()
161-
);
162-
}
163-
164149
@Bean
165150
public SeriesImportService getSeriesImportService() {
166151
return new SeriesImportServiceImpl(
167152
LoggerFactory.getLogger(SeriesImportServiceImpl.class),
168153
daoConfig.getSeriesImportDao(),
169-
getSeriesService(),
154+
seriesService,
170155
getSeriesSalesService(),
171156
getSeriesSalesImportService(),
172157
getSeriesInfoExtractorService(),
@@ -223,7 +208,7 @@ public UserService getUserService() {
223208
);
224209
}
225210

226-
@Bean
211+
@Bean(name = "michelCatalog")
227212
public StampsCatalogService getMichelCatalogService() {
228213
return new StampsCatalogServiceImpl(
229214
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
@@ -232,7 +217,7 @@ public StampsCatalogService getMichelCatalogService() {
232217
);
233218
}
234219

235-
@Bean
220+
@Bean(name = "scottCatalog")
236221
public StampsCatalogService getScottCatalogService() {
237222
return new StampsCatalogServiceImpl(
238223
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
@@ -241,7 +226,7 @@ public StampsCatalogService getScottCatalogService() {
241226
);
242227
}
243228

244-
@Bean
229+
@Bean(name = "yvertCatalog")
245230
public StampsCatalogService getYvertCatalogService() {
246231
return new StampsCatalogServiceImpl(
247232
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
@@ -250,7 +235,7 @@ public StampsCatalogService getYvertCatalogService() {
250235
);
251236
}
252237

253-
@Bean
238+
@Bean(name = "gibbonsCatalog")
254239
public StampsCatalogService getGibbonsCatalogService() {
255240
return new StampsCatalogServiceImpl(
256241
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
@@ -259,7 +244,7 @@ public StampsCatalogService getGibbonsCatalogService() {
259244
);
260245
}
261246

262-
@Bean
247+
@Bean(name = "solovyovCatalog")
263248
public StampsCatalogService getSolovyovCatalogService() {
264249
return new StampsCatalogServiceImpl(
265250
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
@@ -268,7 +253,7 @@ public StampsCatalogService getSolovyovCatalogService() {
268253
);
269254
}
270255

271-
@Bean
256+
@Bean(name = "zagorskiCatalog")
272257
public StampsCatalogService getZagorskiCatalogService() {
273258
return new StampsCatalogServiceImpl(
274259
LoggerFactory.getLogger(StampsCatalogServiceImpl.class),
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (C) 2009-2018 Slava Semushin <slava.semushin@gmail.com>
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.series;
19+
20+
import org.slf4j.LoggerFactory;
21+
22+
import org.springframework.beans.factory.annotation.Qualifier;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.context.annotation.Lazy;
26+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
27+
28+
import lombok.RequiredArgsConstructor;
29+
30+
import ru.mystamps.web.feature.category.CategoryService;
31+
import ru.mystamps.web.feature.collection.CollectionService;
32+
import ru.mystamps.web.feature.country.CountryService;
33+
import ru.mystamps.web.feature.image.ImageService;
34+
import ru.mystamps.web.feature.participant.ParticipantService;
35+
import ru.mystamps.web.service.SeriesImportService;
36+
import ru.mystamps.web.service.SeriesSalesService;
37+
import ru.mystamps.web.service.StampsCatalogService;
38+
39+
/**
40+
* Spring configuration that is required for using series in an application.
41+
*
42+
* The beans are grouped into two classes to make possible to register a controller
43+
* and the services in the separated application contexts.
44+
*/
45+
@Configuration
46+
public class SeriesConfig {
47+
48+
@RequiredArgsConstructor
49+
public static class Controllers {
50+
51+
private final CategoryService categoryService;
52+
private final CollectionService collectionService;
53+
private final CountryService countryService;
54+
private final SeriesService seriesService;
55+
private final SeriesImportService seriesImportService;
56+
private final SeriesSalesService seriesSalesService;
57+
private final ParticipantService participantService;
58+
59+
@Bean
60+
public SeriesController seriesController() {
61+
return new SeriesController(
62+
categoryService,
63+
collectionService,
64+
countryService,
65+
seriesService,
66+
seriesImportService,
67+
seriesSalesService,
68+
participantService
69+
);
70+
}
71+
72+
}
73+
74+
public static class Services {
75+
76+
private final ImageService imageService;
77+
private final StampsCatalogService michelCatalogService;
78+
private final StampsCatalogService scottCatalogService;
79+
private final StampsCatalogService yvertCatalogService;
80+
private final StampsCatalogService gibbonsCatalogService;
81+
private final StampsCatalogService solovyovCatalogService;
82+
private final StampsCatalogService zagorskiCatalogService;
83+
private final NamedParameterJdbcTemplate jdbcTemplate;
84+
85+
@SuppressWarnings("checkstyle:parameternumber")
86+
public Services(
87+
ImageService imageService,
88+
@Lazy @Qualifier("michelCatalog") StampsCatalogService michelCatalogService,
89+
@Lazy @Qualifier("scottCatalog") StampsCatalogService scottCatalogService,
90+
@Lazy @Qualifier("yvertCatalog") StampsCatalogService yvertCatalogService,
91+
@Lazy @Qualifier("gibbonsCatalog") StampsCatalogService gibbonsCatalogService,
92+
@Lazy @Qualifier("solovyovCatalog") StampsCatalogService solovyovCatalogService,
93+
@Lazy @Qualifier("zagorskiCatalog") StampsCatalogService zagorskiCatalogService,
94+
NamedParameterJdbcTemplate jdbcTemplate
95+
) {
96+
this.imageService = imageService;
97+
this.michelCatalogService = michelCatalogService;
98+
this.scottCatalogService = scottCatalogService;
99+
this.yvertCatalogService = yvertCatalogService;
100+
this.gibbonsCatalogService = gibbonsCatalogService;
101+
this.solovyovCatalogService = solovyovCatalogService;
102+
this.zagorskiCatalogService = zagorskiCatalogService;
103+
this.jdbcTemplate = jdbcTemplate;
104+
}
105+
106+
@Bean
107+
public SeriesService seriesService(SeriesDao seriesDao) {
108+
return new SeriesServiceImpl(
109+
LoggerFactory.getLogger(SeriesServiceImpl.class),
110+
seriesDao,
111+
imageService,
112+
michelCatalogService,
113+
scottCatalogService,
114+
yvertCatalogService,
115+
gibbonsCatalogService,
116+
solovyovCatalogService,
117+
zagorskiCatalogService
118+
);
119+
}
120+
121+
@Bean
122+
public SeriesDao seriesDao() {
123+
return new JdbcSeriesDao(jdbcTemplate);
124+
}
125+
126+
}
127+
128+
}

0 commit comments

Comments
 (0)