-
Notifications
You must be signed in to change notification settings - Fork 34
#620_refactoring_method #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2009-2017 Slava Semushin <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package ru.mystamps.web.service; | ||
|
||
import ru.mystamps.web.service.dto.AdminDailyReport; | ||
|
||
/** | ||
*@author Maxim Shestakov | ||
*/ | ||
public interface ReportService { | ||
String prepareDailyStatistics(AdminDailyReport report); | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/ru/mystamps/web/service/ReportServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (C) 2009-2017 Slava Semushin <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package ru.mystamps.web.service; | ||
|
||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.text.StrSubstitutor; | ||
import org.apache.commons.lang3.time.DatePrinter; | ||
import org.apache.commons.lang3.time.FastDateFormat; | ||
|
||
import org.springframework.context.MessageSource; | ||
|
||
import ru.mystamps.web.service.dto.AdminDailyReport; | ||
|
||
/** | ||
* @author Maxim Shestakov | ||
*/ | ||
public class ReportServiceImpl implements ReportService { | ||
|
||
private final MessageSource messageSource; | ||
private final DatePrinter shortDatePrinter; | ||
private final Locale adminLang; | ||
|
||
public ReportServiceImpl( | ||
MessageSource messageSource, | ||
Locale adminLang) { | ||
|
||
this.messageSource = messageSource; | ||
this.adminLang = adminLang; | ||
|
||
this.shortDatePrinter = FastDateFormat.getInstance("dd.MM.yyyy", adminLang); | ||
} | ||
|
||
// This method should have @PreAuthorize(VIEW_DAILY_STATS) but we can't put it here because it | ||
// breaks MailServiceImpl.sendDailyStatisticsToAdmin() method that is being executed by cron. | ||
@Override | ||
public String prepareDailyStatistics(AdminDailyReport report) { | ||
String template = messageSource.getMessage("daily_stat.text", null, adminLang); | ||
String fromDate = shortDatePrinter.format(report.getStartDate()); | ||
String tillDate = shortDatePrinter.format(report.getEndDate()); | ||
|
||
Map<String, String> ctx = new HashMap<>(); | ||
ctx.put("from_date", fromDate); | ||
ctx.put("to_date", tillDate); | ||
|
||
put(ctx, "added_countries_cnt", report.getAddedCountriesCounter()); | ||
put(ctx, "untranslated_countries_cnt", report.getUntranslatedCountriesCounter()); | ||
put(ctx, "added_categories_cnt", report.getAddedCategoriesCounter()); | ||
put(ctx, "untranslated_categories_cnt", report.getUntranslatedCategoriesCounter()); | ||
put(ctx, "added_series_cnt", report.getAddedSeriesCounter()); | ||
put(ctx, "updated_series_cnt", report.getUpdatedSeriesCounter()); | ||
put(ctx, "updated_collections_cnt", report.getUpdatedCollectionsCounter()); | ||
put(ctx, "registration_requests_cnt", report.getRegistrationRequestsCounter()); | ||
put(ctx, "registered_users_cnt", report.getRegisteredUsersCounter()); | ||
put(ctx, "events_cnt", report.countEvents()); | ||
put(ctx, "not_found_cnt", report.getNotFoundCounter()); | ||
put(ctx, "failed_auth_cnt", report.getFailedAuthCounter()); | ||
put(ctx, "missing_csrf_cnt", report.getMissingCsrfCounter()); | ||
put(ctx, "invalid_csrf_cnt", report.getInvalidCsrfCounter()); | ||
put(ctx, "bad_request_cnt", -1L); // TODO: #122 | ||
|
||
return new StrSubstitutor(ctx).replace(template); | ||
} | ||
|
||
private static void put(Map<String, String> ctx, String key, long value) { | ||
ctx.put(key, String.valueOf(value)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that it won't fail because of the
@PreAuthorize
? Have you test it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it doesn't work:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do i can run these test ?
I tried run "mvn test" , but i get no error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no test for that. You can modify
CronServiceImpl
:this will run
sendDailyStatistics()
every second. Now start the server and look at the console.(Note that when you fix this error it will still fail because there is no SMTP server configured.)