Skip to content

Commit 08621f4

Browse files
committed
CollectionConfig: group Spring configuration into a single config.
Addressed to #927 No functional changes.
1 parent d779f93 commit 08621f4

File tree

4 files changed

+95
-32
lines changed

4 files changed

+95
-32
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import ru.mystamps.web.controller.*; // NOPMD: UnusedImports
3131
import ru.mystamps.web.feature.category.CategoryConfig;
3232
import ru.mystamps.web.feature.category.CategoryService;
33-
import ru.mystamps.web.feature.collection.CollectionController;
33+
import ru.mystamps.web.feature.collection.CollectionConfig;
34+
import ru.mystamps.web.feature.collection.CollectionService;
3435
import ru.mystamps.web.feature.country.CountryConfig;
3536
import ru.mystamps.web.feature.country.CountryService;
3637
import ru.mystamps.web.feature.participant.ParticipantConfig;
@@ -40,6 +41,7 @@
4041
@RequiredArgsConstructor
4142
@Import({
4243
CategoryConfig.Controllers.class,
44+
CollectionConfig.Controllers.class,
4345
CountryConfig.Controllers.class,
4446
ParticipantConfig.Controllers.class
4547
})
@@ -49,6 +51,7 @@ public class ControllersConfig {
4951
private final MessageSource messageSource;
5052
private final ApplicationEventPublisher eventPublisher;
5153
private final CategoryService categoryService;
54+
private final CollectionService collectionService;
5255
private final CountryService countryService;
5356
private final ParticipantService participantService;
5457

@@ -60,17 +63,6 @@ public AccountController getAccountController() {
6063
);
6164
}
6265

63-
@Bean
64-
public CollectionController getCollectionController() {
65-
return new CollectionController(
66-
categoryService,
67-
servicesConfig.getCollectionService(),
68-
countryService,
69-
servicesConfig.getSeriesService(),
70-
messageSource
71-
);
72-
}
73-
7466
@Bean
7567
public ImageController getImageController() {
7668
return new ImageController(servicesConfig.getImageService());
@@ -98,7 +90,7 @@ public ReportController getReportController() {
9890
public SeriesController getSeriesController() {
9991
return new SeriesController(
10092
categoryService,
101-
servicesConfig.getCollectionService(),
93+
collectionService,
10294
countryService,
10395
servicesConfig.getSeriesService(),
10496
servicesConfig.getSeriesImportService(),
@@ -123,7 +115,7 @@ public SeriesImportController getSeriesImportController() {
123115
public SiteController getSiteController() {
124116
return new SiteController(
125117
categoryService,
126-
servicesConfig.getCollectionService(),
118+
collectionService,
127119
countryService,
128120
servicesConfig.getSeriesService(),
129121
servicesConfig.getSuspiciousActivityService()

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.collection.CollectionDao;
32-
import ru.mystamps.web.feature.collection.JdbcCollectionDao;
3331

3432
@Configuration
3533
@PropertySource("classpath:/sql/stamps_catalog_dao_queries.properties")
@@ -39,11 +37,6 @@ public class DaoConfig {
3937
private final NamedParameterJdbcTemplate jdbcTemplate;
4038
private final Environment env;
4139

42-
@Bean
43-
public CollectionDao getCollectionDao() {
44-
return new JdbcCollectionDao(jdbcTemplate);
45-
}
46-
4740
@Bean
4841
public StampsCatalogDao getGibbonsCatalogDao() {
4942
return new JdbcStampsCatalogDao(

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
import ru.mystamps.web.feature.category.CategoryConfig;
3535
import ru.mystamps.web.feature.category.CategoryService;
36+
import ru.mystamps.web.feature.collection.CollectionConfig;
3637
import ru.mystamps.web.feature.collection.CollectionService;
37-
import ru.mystamps.web.feature.collection.CollectionServiceImpl;
3838
import ru.mystamps.web.feature.country.CountryConfig;
3939
import ru.mystamps.web.feature.country.CountryService;
4040
import ru.mystamps.web.feature.participant.ParticipantConfig;
@@ -46,6 +46,7 @@
4646
@Configuration
4747
@Import({
4848
CategoryConfig.Services.class,
49+
CollectionConfig.Services.class,
4950
CountryConfig.Services.class,
5051
ParticipantConfig.Services.class
5152
})
@@ -61,6 +62,7 @@ public class ServicesConfig {
6162
private final MessageSource messageSource;
6263
private final ApplicationEventPublisher eventPublisher;
6364
private final CategoryService categoryService;
65+
private final CollectionService collectionService;
6466
private final CountryService countryService;
6567
private final ParticipantService participantService;
6668

@@ -69,21 +71,13 @@ public SuspiciousActivityService getSuspiciousActivityService() {
6971
return new SuspiciousActivityServiceImpl(daoConfig.getSuspiciousActivityDao());
7072
}
7173

72-
@Bean
73-
public CollectionService getCollectionService() {
74-
return new CollectionServiceImpl(
75-
LoggerFactory.getLogger(CollectionServiceImpl.class),
76-
daoConfig.getCollectionDao()
77-
);
78-
}
79-
8074
@Bean
8175
public CronService getCronService() {
8276
return new CronServiceImpl(
8377
LoggerFactory.getLogger(CronServiceImpl.class),
8478
categoryService,
8579
countryService,
86-
getCollectionService(),
80+
collectionService,
8781
getSeriesService(),
8882
getSuspiciousActivityService(),
8983
getUserService(),
@@ -232,7 +226,7 @@ public UserService getUserService() {
232226
LoggerFactory.getLogger(UserServiceImpl.class),
233227
daoConfig.getUserDao(),
234228
getUsersActivationService(),
235-
getCollectionService(),
229+
collectionService,
236230
securityConfig.getPasswordEncoder()
237231
);
238232
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.collection;
19+
20+
import org.slf4j.LoggerFactory;
21+
22+
import org.springframework.context.MessageSource;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
26+
27+
import lombok.RequiredArgsConstructor;
28+
29+
import ru.mystamps.web.feature.category.CategoryService;
30+
import ru.mystamps.web.feature.country.CountryService;
31+
import ru.mystamps.web.service.SeriesService;
32+
33+
/**
34+
* Spring configuration that is required for using collections in an application.
35+
*
36+
* The beans are grouped into two classes to make possible to register a controller
37+
* and the services in the separated application contexts.
38+
*/
39+
@Configuration
40+
public class CollectionConfig {
41+
42+
@RequiredArgsConstructor
43+
public static class Controllers {
44+
45+
private final CategoryService categoryService;
46+
private final CollectionService collectionService;
47+
private final CountryService countryService;
48+
private final SeriesService seriesService;
49+
private final MessageSource messageSource;
50+
51+
@Bean
52+
public CollectionController collectionController() {
53+
return new CollectionController(
54+
categoryService,
55+
collectionService,
56+
countryService,
57+
seriesService,
58+
messageSource
59+
);
60+
}
61+
62+
}
63+
64+
@RequiredArgsConstructor
65+
public static class Services {
66+
67+
private final NamedParameterJdbcTemplate jdbcTemplate;
68+
69+
@Bean
70+
public CollectionService collectionService(CollectionDao collectionDao) {
71+
return new CollectionServiceImpl(
72+
LoggerFactory.getLogger(CollectionServiceImpl.class),
73+
collectionDao
74+
);
75+
}
76+
77+
@Bean
78+
public CollectionDao collectionDao() {
79+
return new JdbcCollectionDao(jdbcTemplate);
80+
}
81+
82+
}
83+
84+
}

0 commit comments

Comments
 (0)