39
39
import org .springframework .mail .javamail .MimeMessagePreparator ;
40
40
import org .springframework .scheduling .annotation .Async ;
41
41
42
+ import org .springframework .security .access .prepost .PreAuthorize ;
43
+
42
44
import ru .mystamps .web .Url ;
43
45
import ru .mystamps .web .service .dto .AdminDailyReport ;
44
46
import ru .mystamps .web .service .dto .SendUsersActivationDto ;
45
47
import ru .mystamps .web .service .exception .EmailSendingException ;
48
+ import ru .mystamps .web .support .spring .security .HasAuthority ;
46
49
47
50
public class MailServiceImpl implements MailService {
48
51
private static final Logger LOG = LoggerFactory .getLogger (MailServiceImpl .class );
@@ -101,7 +104,7 @@ public void sendDailyStatisticsToAdmin(AdminDailyReport report) {
101
104
sendMail (
102
105
adminEmail ,
103
106
getSubjectOfDailyStatisticsMail (report ),
104
- getTextOfDailyStatisticsMail (report ),
107
+ prepareDailyStatistics (report ),
105
108
"daily_statistics"
106
109
);
107
110
@@ -114,7 +117,37 @@ public void sendDailyStatisticsToAdmin(AdminDailyReport report) {
114
117
adminLang
115
118
);
116
119
}
120
+
121
+ @ Override
122
+ @ PreAuthorize (HasAuthority .VIEW_DAILY_STATS )
123
+ public String prepareDailyStatistics (AdminDailyReport report ) {
124
+ String template = messageSource .getMessage ("daily_stat.text" , null , adminLang );
125
+ String fromDate = shortDatePrinter .format (report .getStartDate ());
126
+ String tillDate = shortDatePrinter .format (report .getEndDate ());
127
+
128
+ Map <String , String > ctx = new HashMap <>();
129
+ ctx .put ("from_date" , fromDate );
130
+ ctx .put ("to_date" , tillDate );
131
+
132
+ put (ctx , "added_countries_cnt" , report .getAddedCountriesCounter ());
133
+ put (ctx , "untranslated_countries_cnt" , report .getUntranslatedCountriesCounter ());
134
+ put (ctx , "added_categories_cnt" , report .getAddedCategoriesCounter ());
135
+ put (ctx , "untranslated_categories_cnt" , report .getUntranslatedCategoriesCounter ());
136
+ put (ctx , "added_series_cnt" , report .getAddedSeriesCounter ());
137
+ put (ctx , "updated_series_cnt" , report .getUpdatedSeriesCounter ());
138
+ put (ctx , "updated_collections_cnt" , report .getUpdatedCollectionsCounter ());
139
+ put (ctx , "registration_requests_cnt" , report .getRegistrationRequestsCounter ());
140
+ put (ctx , "registered_users_cnt" , report .getRegisteredUsersCounter ());
141
+ put (ctx , "events_cnt" , report .countEvents ());
142
+ put (ctx , "not_found_cnt" , report .getNotFoundCounter ());
143
+ put (ctx , "failed_auth_cnt" , report .getFailedAuthCounter ());
144
+ put (ctx , "missing_csrf_cnt" , report .getMissingCsrfCounter ());
145
+ put (ctx , "invalid_csrf_cnt" , report .getInvalidCsrfCounter ());
146
+ put (ctx , "bad_request_cnt" , -1L ); // TODO: #122
117
147
148
+ return new StrSubstitutor (ctx ).replace (template );
149
+ }
150
+
118
151
@ SuppressWarnings ("PMD.UseObjectForClearerAPI" )
119
152
private void sendMail (
120
153
final String email ,
@@ -183,34 +216,6 @@ private String getSubjectOfDailyStatisticsMail(AdminDailyReport report) {
183
216
StrSubstitutor substitutor = new StrSubstitutor (ctx );
184
217
return substitutor .replace (template );
185
218
}
186
-
187
- private String getTextOfDailyStatisticsMail (AdminDailyReport report ) {
188
- String template = messageSource .getMessage ("daily_stat.text" , null , adminLang );
189
- String fromDate = shortDatePrinter .format (report .getStartDate ());
190
- String tillDate = shortDatePrinter .format (report .getEndDate ());
191
-
192
- Map <String , String > ctx = new HashMap <>();
193
- ctx .put ("from_date" , fromDate );
194
- ctx .put ("to_date" , tillDate );
195
-
196
- put (ctx , "added_countries_cnt" , report .getAddedCountriesCounter ());
197
- put (ctx , "untranslated_countries_cnt" , report .getUntranslatedCountriesCounter ());
198
- put (ctx , "added_categories_cnt" , report .getAddedCategoriesCounter ());
199
- put (ctx , "untranslated_categories_cnt" , report .getUntranslatedCategoriesCounter ());
200
- put (ctx , "added_series_cnt" , report .getAddedSeriesCounter ());
201
- put (ctx , "updated_series_cnt" , report .getUpdatedSeriesCounter ());
202
- put (ctx , "updated_collections_cnt" , report .getUpdatedCollectionsCounter ());
203
- put (ctx , "registration_requests_cnt" , report .getRegistrationRequestsCounter ());
204
- put (ctx , "registered_users_cnt" , report .getRegisteredUsersCounter ());
205
- put (ctx , "events_cnt" , report .countEvents ());
206
- put (ctx , "not_found_cnt" , report .getNotFoundCounter ());
207
- put (ctx , "failed_auth_cnt" , report .getFailedAuthCounter ());
208
- put (ctx , "missing_csrf_cnt" , report .getMissingCsrfCounter ());
209
- put (ctx , "invalid_csrf_cnt" , report .getInvalidCsrfCounter ());
210
- put (ctx , "bad_request_cnt" , -1L ); // TODO: #122
211
-
212
- return new StrSubstitutor (ctx ).replace (template );
213
- }
214
219
215
220
private static void put (Map <String , String > ctx , String key , long value ) {
216
221
ctx .put (key , String .valueOf (value ));
0 commit comments