Skip to content

Commit 4741948

Browse files
committed
refactor(ReportConfig): group Spring configuration into a single config.
Addressed to #927 No functional changes.
1 parent 8adab74 commit 4741948

File tree

3 files changed

+73
-19
lines changed

3 files changed

+73
-19
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import ru.mystamps.web.feature.country.CountryService;
3535
import ru.mystamps.web.feature.image.ImageConfig;
3636
import ru.mystamps.web.feature.participant.ParticipantConfig;
37-
import ru.mystamps.web.feature.report.ReportController;
37+
import ru.mystamps.web.feature.report.ReportConfig;
3838
import ru.mystamps.web.feature.series.SeriesConfig;
3939
import ru.mystamps.web.feature.series.SeriesService;
4040
import ru.mystamps.web.feature.series.importing.SeriesImportConfig;
@@ -48,6 +48,7 @@
4848
CountryConfig.Controllers.class,
4949
ImageConfig.Controllers.class,
5050
ParticipantConfig.Controllers.class,
51+
ReportConfig.Controllers.class,
5152
SeriesConfig.Controllers.class,
5253
SeriesImportConfig.Controllers.class
5354
})
@@ -68,14 +69,6 @@ public ErrorController getErrorController() {
6869
public RobotsTxtController getRobotsTxtController() {
6970
return new RobotsTxtController();
7071
}
71-
72-
@Bean
73-
public ReportController getReportController() {
74-
return new ReportController(
75-
servicesConfig.getReportService(),
76-
servicesConfig.getCronService()
77-
);
78-
}
7972

8073
@Bean
8174
public SiteController getSiteController() {

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import ru.mystamps.web.feature.country.CountryService;
3838
import ru.mystamps.web.feature.image.ImageConfig;
3939
import ru.mystamps.web.feature.participant.ParticipantConfig;
40+
import ru.mystamps.web.feature.report.ReportConfig;
4041
import ru.mystamps.web.feature.report.ReportService;
41-
import ru.mystamps.web.feature.report.ReportServiceImpl;
4242
import ru.mystamps.web.feature.series.DownloaderService;
4343
import ru.mystamps.web.feature.series.HttpURLConnectionDownloaderService;
4444
import ru.mystamps.web.feature.series.SeriesConfig;
@@ -66,6 +66,7 @@
6666
CountryConfig.Services.class,
6767
ImageConfig.Services.class,
6868
ParticipantConfig.Services.class,
69+
ReportConfig.Services.class,
6970
SeriesConfig.Services.class,
7071
SeriesImportConfig.Services.class,
7172
SeriesSalesConfig.Services.class,
@@ -82,6 +83,7 @@ public class ServicesConfig {
8283
private final CategoryService categoryService;
8384
private final CollectionService collectionService;
8485
private final CountryService countryService;
86+
private final ReportService reportService;
8587
private final SeriesService seriesService;
8688
private final UserService userService;
8789

@@ -136,7 +138,7 @@ public MailService getMailService() {
136138
boolean enableTestMode = !isProductionEnvironment;
137139

138140
return new MailServiceImpl(
139-
getReportService(),
141+
reportService,
140142
mailSender,
141143
messageSource,
142144
env.getProperty("app.mail.admin.email", "root@localhost"),
@@ -146,14 +148,6 @@ public MailService getMailService() {
146148
);
147149
}
148150

149-
@Bean
150-
public ReportService getReportService() {
151-
return new ReportServiceImpl(
152-
messageSource,
153-
new Locale(env.getProperty("app.mail.admin.lang", "en"))
154-
);
155-
}
156-
157151
@Bean
158152
public SiteService getSiteService() {
159153
return new SiteServiceImpl(
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2009-2019 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.report;
19+
20+
import lombok.RequiredArgsConstructor;
21+
import org.springframework.context.MessageSource;
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.core.env.Environment;
25+
import ru.mystamps.web.service.CronService;
26+
27+
import java.util.Locale;
28+
29+
/**
30+
* Spring configuration that is required for sending reports.
31+
*
32+
* The beans are grouped into two classes to make possible to register a controller
33+
* and the services in the separated application contexts.
34+
*/
35+
@Configuration
36+
public class ReportConfig {
37+
38+
@RequiredArgsConstructor
39+
public static class Controllers {
40+
41+
private final ReportService reportService;
42+
private final CronService cronService;
43+
44+
@Bean
45+
public ReportController reportController() {
46+
return new ReportController(reportService, cronService);
47+
}
48+
49+
}
50+
51+
@RequiredArgsConstructor
52+
public static class Services {
53+
54+
private final Environment env;
55+
private final MessageSource messageSource;
56+
57+
@Bean
58+
public ReportService reportService() {
59+
return new ReportServiceImpl(
60+
messageSource,
61+
new Locale(env.getProperty("app.mail.admin.lang", "en"))
62+
);
63+
}
64+
65+
}
66+
67+
}

0 commit comments

Comments
 (0)