From 95b68b01bc812a6ff8eca0ec828db6ea5889725d Mon Sep 17 00:00:00 2001 From: Maxim Shestakov Date: Tue, 1 Aug 2017 10:53:01 +0300 Subject: [PATCH 001/463] fix_errors --- src/main/java/ru/mystamps/web/Url.java | 4 +- .../web/config/ControllersConfig.java | 8 +++ .../web/controller/ReportController.java | 65 +++++++++++++++++++ .../ru/mystamps/web/service/CronService.java | 3 + .../mystamps/web/service/CronServiceImpl.java | 21 ++++-- .../ru/mystamps/web/service/MailService.java | 1 + .../support/spring/security/Authority.java | 1 + .../security/CustomUserDetailsService.java | 1 + .../support/spring/security/HasAuthority.java | 1 + .../spring/security/SecurityConfig.java | 2 + .../spring/security/StringAuthority.java | 1 + .../ru/mystamps/i18n/Messages.properties | 1 + .../ru/mystamps/i18n/Messages_ru.properties | 1 + src/main/webapp/WEB-INF/views/site/index.html | 3 + 14 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 src/main/java/ru/mystamps/web/controller/ReportController.java diff --git a/src/main/java/ru/mystamps/web/Url.java b/src/main/java/ru/mystamps/web/Url.java index 38676e04e1..843c8f596e 100644 --- a/src/main/java/ru/mystamps/web/Url.java +++ b/src/main/java/ru/mystamps/web/Url.java @@ -37,7 +37,8 @@ public final class Url { public static final String INDEX_PAGE = "/"; public static final String ROBOTS_TXT = "/robots.txt"; public static final String SITEMAP_XML = "/sitemap.xml"; - + + public static final String DAILY_STATISTICS = "/report/daily"; public static final String SITE_EVENTS_PAGE = "/site/events"; public static final String REGISTRATION_PAGE = "/account/register"; @@ -136,6 +137,7 @@ public static Map asMap(boolean serveContentFromSingleHost) { map.put("INFO_COLLECTION_PAGE", INFO_COLLECTION_PAGE); map.put("SITE_EVENTS_PAGE", SITE_EVENTS_PAGE); map.put("BOOTSTRAP_LANGUAGE", BOOTSTRAP_LANGUAGE); + map.put("DAILY_STATISTICS", DAILY_STATISTICS); if (serveContentFromSingleHost) { map.put("BOOTSTRAP_CSS", BOOTSTRAP_CSS); diff --git a/src/main/java/ru/mystamps/web/config/ControllersConfig.java b/src/main/java/ru/mystamps/web/config/ControllersConfig.java index 80bce6dbf9..31db809c04 100644 --- a/src/main/java/ru/mystamps/web/config/ControllersConfig.java +++ b/src/main/java/ru/mystamps/web/config/ControllersConfig.java @@ -84,6 +84,14 @@ public RobotsTxtController getRobotsTxtController() { return new RobotsTxtController(); } + @Bean + public ReportController getReportController() { + return new ReportController( + servicesConfig.getMailService(), + servicesConfig.getCronService() + ); + } + @Bean public SeriesController getSeriesController() { return new SeriesController( diff --git a/src/main/java/ru/mystamps/web/controller/ReportController.java b/src/main/java/ru/mystamps/web/controller/ReportController.java new file mode 100644 index 0000000000..356e94da6c --- /dev/null +++ b/src/main/java/ru/mystamps/web/controller/ReportController.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.controller; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import lombok.RequiredArgsConstructor; + +import ru.mystamps.web.Url; +import ru.mystamps.web.service.CronService; +import ru.mystamps.web.service.MailService; + +/** + * @author Maxim Shestakov + */ +@Controller +@RequiredArgsConstructor +public class ReportController { + private static final Logger LOG = LoggerFactory.getLogger(RobotsTxtController.class); + + private final MailService mailService; + private final CronService cronService; + + @RequestMapping(Url.DAILY_STATISTICS) + public void adminDailyReport(HttpServletResponse response) { + response.setContentType("text/plain"); + response.setCharacterEncoding("UTF-8"); + + try { + PrintWriter printWriter = response.getWriter(); + String stats = mailService.getTextOfDailyStatisticsMail( + cronService.getDailyStatistics() + ); + printWriter.println(stats); + } catch (IOException e) { + LOG.error("Can't get Daily Reports", e.getMessage()); + } + } + +} diff --git a/src/main/java/ru/mystamps/web/service/CronService.java b/src/main/java/ru/mystamps/web/service/CronService.java index 9f91114f32..a9c3d5bcb7 100644 --- a/src/main/java/ru/mystamps/web/service/CronService.java +++ b/src/main/java/ru/mystamps/web/service/CronService.java @@ -17,9 +17,12 @@ */ package ru.mystamps.web.service; +import ru.mystamps.web.service.dto.AdminDailyReport; + public interface CronService { int PURGE_AFTER_DAYS = 3; void sendDailyStatistics(); + AdminDailyReport getDailyStatistics(); void purgeUsersActivations(); } diff --git a/src/main/java/ru/mystamps/web/service/CronServiceImpl.java b/src/main/java/ru/mystamps/web/service/CronServiceImpl.java index a2cb4040f0..65399e5e80 100644 --- a/src/main/java/ru/mystamps/web/service/CronServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CronServiceImpl.java @@ -50,14 +50,21 @@ public class CronServiceImpl implements CronService { private final UsersActivationService usersActivationService; private final MailService mailService; + private AdminDailyReport report; + @Override @Scheduled(cron = EVERY_DAY_AT_00_00) @Transactional(readOnly = true) public void sendDailyStatistics() { + mailService.sendDailyStatisticsToAdmin(report); + } + + @Override + public AdminDailyReport getDailyStatistics() { Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); Date yesterday = DateUtils.addDays(today, -1); - - AdminDailyReport report = new AdminDailyReport(); + + report = new AdminDailyReport(); report.setStartDate(yesterday); report.setEndDate(today); report.setAddedCategoriesCounter(categoryService.countAddedSince(yesterday)); @@ -66,32 +73,32 @@ public void sendDailyStatistics() { report.setUpdatedSeriesCounter(seriesService.countUpdatedSince(yesterday)); report.setRegistrationRequestsCounter(usersActivationService.countCreatedSince(yesterday)); report.setRegisteredUsersCounter(userService.countRegisteredSince(yesterday)); - + long notFoundCounter = suspiciousActivityService.countByTypeSince( SiteServiceImpl.PAGE_NOT_FOUND, yesterday ); report.setNotFoundCounter(notFoundCounter); - + long failedAuthCounter = suspiciousActivityService.countByTypeSince( SiteServiceImpl.AUTHENTICATION_FAILED, yesterday ); report.setFailedAuthCounter(failedAuthCounter); - + long missingCsrfCounter = suspiciousActivityService.countByTypeSince( SiteServiceImpl.MISSING_CSRF_TOKEN, yesterday ); report.setMissingCsrfCounter(missingCsrfCounter); - + long invalidCsrfCounter = suspiciousActivityService.countByTypeSince( SiteServiceImpl.INVALID_CSRF_TOKEN, yesterday ); report.setInvalidCsrfCounter(invalidCsrfCounter); - mailService.sendDailyStatisticsToAdmin(report); + return report; } @Override diff --git a/src/main/java/ru/mystamps/web/service/MailService.java b/src/main/java/ru/mystamps/web/service/MailService.java index b426aacba1..a5fa435341 100644 --- a/src/main/java/ru/mystamps/web/service/MailService.java +++ b/src/main/java/ru/mystamps/web/service/MailService.java @@ -23,4 +23,5 @@ public interface MailService { void sendActivationKeyToUser(SendUsersActivationDto activation); void sendDailyStatisticsToAdmin(AdminDailyReport report); + String getTextOfDailyStatisticsMail(AdminDailyReport report); } diff --git a/src/main/java/ru/mystamps/web/support/spring/security/Authority.java b/src/main/java/ru/mystamps/web/support/spring/security/Authority.java index dda4b88853..4b1ca5e2b2 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/Authority.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/Authority.java @@ -31,6 +31,7 @@ public final class Authority { public static final GrantedAuthority UPDATE_COLLECTION = new SimpleGrantedAuthority(StringAuthority.UPDATE_COLLECTION); public static final GrantedAuthority VIEW_SITE_EVENTS = new SimpleGrantedAuthority(StringAuthority.VIEW_SITE_EVENTS); public static final GrantedAuthority VIEW_SERIES_SALES = new SimpleGrantedAuthority(StringAuthority.VIEW_SERIES_SALES); + public static final GrantedAuthority VIEW_DAILY_STATS = new SimpleGrantedAuthority(StringAuthority.VIEW_DAILY_STATS); private Authority() { } diff --git a/src/main/java/ru/mystamps/web/support/spring/security/CustomUserDetailsService.java b/src/main/java/ru/mystamps/web/support/spring/security/CustomUserDetailsService.java index fb5d2ac31d..6fd0339954 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/CustomUserDetailsService.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/CustomUserDetailsService.java @@ -79,6 +79,7 @@ private static Collection getAuthorities(UserDetails authorities.add(Authority.VIEW_SITE_EVENTS); authorities.add(Authority.VIEW_SERIES_SALES); authorities.add(Authority.MANAGE_TOGGLZ); + authorities.add(Authority.VIEW_DAILY_STATS); } return authorities; diff --git a/src/main/java/ru/mystamps/web/support/spring/security/HasAuthority.java b/src/main/java/ru/mystamps/web/support/spring/security/HasAuthority.java index 8c5ec04799..8cc16e982b 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/HasAuthority.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/HasAuthority.java @@ -22,6 +22,7 @@ public final class HasAuthority { public static final String CREATE_SERIES = "hasAuthority('" + StringAuthority.CREATE_SERIES + "')"; public static final String CREATE_CATEGORY = "hasAuthority('" + StringAuthority.CREATE_CATEGORY + "')"; public static final String CREATE_COUNTRY = "hasAuthority('" + StringAuthority.CREATE_COUNTRY + "')"; + public static final String VIEW_DAILY_STATS = "hasAuthority('" + StringAuthority.VIEW_DAILY_STATS + "')"; public static final String UPDATE_COLLECTION = "hasAuthority('" + StringAuthority.UPDATE_COLLECTION + "')"; public static final String VIEW_SITE_EVENTS = "hasAuthority('" + StringAuthority.VIEW_SITE_EVENTS + "')"; public static final String VIEW_SERIES_SALES = "hasAuthority('" + StringAuthority.VIEW_SERIES_SALES + "')"; diff --git a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java index 62d4b35260..daf6b77609 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java @@ -66,6 +66,8 @@ public void configure(WebSecurity web) throws Exception { protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() + .antMatchers(Url.DAILY_STATISTICS) + .hasAuthority(StringAuthority.VIEW_DAILY_STATS) .antMatchers(Url.ADD_CATEGORY_PAGE) .hasAuthority(StringAuthority.CREATE_CATEGORY) .antMatchers(Url.ADD_COUNTRY_PAGE) diff --git a/src/main/java/ru/mystamps/web/support/spring/security/StringAuthority.java b/src/main/java/ru/mystamps/web/support/spring/security/StringAuthority.java index 250dd2a1cb..e5bb3a0ef1 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/StringAuthority.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/StringAuthority.java @@ -27,6 +27,7 @@ public final class StringAuthority { public static final String UPDATE_COLLECTION = "UPDATE_COLLECTION"; public static final String VIEW_SITE_EVENTS = "VIEW_SITE_EVENTS"; public static final String VIEW_SERIES_SALES = "VIEW_SERIES_SALES"; + public static final String VIEW_DAILY_STATS = "VIEW_DAILY_STATS"; private StringAuthority() { } diff --git a/src/main/resources/ru/mystamps/i18n/Messages.properties b/src/main/resources/ru/mystamps/i18n/Messages.properties index 42fa3c0568..c4544b24a1 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages.properties @@ -64,6 +64,7 @@ t_example = Example t_catalog = Catalog t_search = Search t_watch_suspicious_activities = view suspicious activities +t_daily_statistics = view daily statistics # account/register.html t_registration_on_site = Register on site diff --git a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties index 1d76c28fd3..6d933b12ab 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties @@ -64,6 +64,7 @@ t_example = Пример t_catalog = Каталог t_search = Найти t_watch_suspicious_activities = посмотреть подозрительные события +t_daily_statistics = посмотреть дневную статистику # account/register.html t_registration_on_site = Регистрация на сайте diff --git a/src/main/webapp/WEB-INF/views/site/index.html b/src/main/webapp/WEB-INF/views/site/index.html index 1459470889..01764039c3 100644 --- a/src/main/webapp/WEB-INF/views/site/index.html +++ b/src/main/webapp/WEB-INF/views/site/index.html @@ -108,6 +108,9 @@
  • view suspicious activities
  • +
  • + view daily statistics +
  • From 7439171cdbc1b46c9ece3d2542ffa2544034f79f Mon Sep 17 00:00:00 2001 From: Maxim Shestakov Date: Tue, 1 Aug 2017 16:51:54 +0300 Subject: [PATCH 002/463] minor_fix --- .../ru/mystamps/web/config/ControllersConfig.java | 2 +- .../ru/mystamps/web/controller/ReportController.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/mystamps/web/config/ControllersConfig.java b/src/main/java/ru/mystamps/web/config/ControllersConfig.java index 31db809c04..c94b41959b 100644 --- a/src/main/java/ru/mystamps/web/config/ControllersConfig.java +++ b/src/main/java/ru/mystamps/web/config/ControllersConfig.java @@ -89,7 +89,7 @@ public ReportController getReportController() { return new ReportController( servicesConfig.getMailService(), servicesConfig.getCronService() - ); + ); } @Bean diff --git a/src/main/java/ru/mystamps/web/controller/ReportController.java b/src/main/java/ru/mystamps/web/controller/ReportController.java index 356e94da6c..45ba651816 100644 --- a/src/main/java/ru/mystamps/web/controller/ReportController.java +++ b/src/main/java/ru/mystamps/web/controller/ReportController.java @@ -41,24 +41,24 @@ @Controller @RequiredArgsConstructor public class ReportController { - private static final Logger LOG = LoggerFactory.getLogger(RobotsTxtController.class); + private static final Logger LOG = LoggerFactory.getLogger(ReportController.class); private final MailService mailService; private final CronService cronService; @RequestMapping(Url.DAILY_STATISTICS) - public void adminDailyReport(HttpServletResponse response) { + public void showDailyReport(HttpServletResponse response) { response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); try { - PrintWriter printWriter = response.getWriter(); + PrintWriter writer = response.getWriter(); String stats = mailService.getTextOfDailyStatisticsMail( cronService.getDailyStatistics() ); - printWriter.println(stats); - } catch (IOException e) { - LOG.error("Can't get Daily Reports", e.getMessage()); + writer.println(stats); + } catch (IOException ex) { + LOG.error("Can't get daily report", ex.getMessage()); } } From f00f9b7ae748ddc62fc16e531b0b2da26f169da6 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 28 Aug 2016 12:54:43 +0200 Subject: [PATCH 003/463] MaxFileSize: use @Getter and @RequiredArgsConstructor. Should be in c58dc519d4df03bcc9867b563bbd314a4db34048 commit. No functional changes. --- .../web/validation/jsr303/MaxFileSize.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/MaxFileSize.java b/src/main/java/ru/mystamps/web/validation/jsr303/MaxFileSize.java index 3a1fdb7548..82acbf19c1 100644 --- a/src/main/java/ru/mystamps/web/validation/jsr303/MaxFileSize.java +++ b/src/main/java/ru/mystamps/web/validation/jsr303/MaxFileSize.java @@ -24,6 +24,9 @@ import javax.validation.Constraint; import javax.validation.Payload; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; @@ -43,17 +46,11 @@ long value(); Unit unit(); + @Getter + @RequiredArgsConstructor enum Unit { bytes(1), Kbytes(1024), Mbytes(1024 * 1024); - private long size; - - Unit(long size) { - this.size = size; - } - - public long getSize() { - return size; - } + private final long size; } } From 1d5df8efffd38dface83055bdb237d8d464b0dd2 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 28 Aug 2016 13:32:08 +0200 Subject: [PATCH 004/463] SeriesService.addImageToSeries(): protect against anonymouses. Should be in ae0822435926d53ab8674f7e5b46c17346a10cfa commit. No functional changes. --- src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java b/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java index b93bb5b44b..8cd9d0d35f 100644 --- a/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java @@ -159,6 +159,7 @@ public Integer add(AddSeriesDto dto, Integer userId, boolean userCanAddComments) @Override @Transactional + @PreAuthorize("isAuthenticated()") public void addImageToSeries(AddImageDto dto, Integer seriesId, Integer userId) { Validate.isTrue(dto != null, "DTO must be non null"); Validate.isTrue(seriesId != null, "Series id must be non null"); From 1f9707b9371008e6e4bccb3b3b0a6b772651e741 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 28 Aug 2016 13:34:43 +0200 Subject: [PATCH 005/463] ImageService.save(): protect against anonymouses. No functional changes. --- src/main/java/ru/mystamps/web/service/ImageServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ru/mystamps/web/service/ImageServiceImpl.java b/src/main/java/ru/mystamps/web/service/ImageServiceImpl.java index 09f9e4ea93..6bfa6d1741 100644 --- a/src/main/java/ru/mystamps/web/service/ImageServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/ImageServiceImpl.java @@ -50,6 +50,7 @@ public class ImageServiceImpl implements ImageService { @Override @Transactional + @PreAuthorize("isAuthenticated()") public Integer save(MultipartFile file) { Validate.isTrue(file != null, "File must be non null"); Validate.isTrue(file.getSize() > 0, "Image size must be greater than zero"); From f3c88d30b6dcf7f76d702d1ca94f8908b989a6fc Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 28 Aug 2016 13:55:31 +0200 Subject: [PATCH 006/463] SeriesController.prepareCommonAttrsForSeriesInfo(): extract method. No functional changes. --- .../web/controller/SeriesController.java | 85 +++++++++---------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 55f1836996..4263ef93f7 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -21,6 +21,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -200,34 +201,14 @@ public String showInfo( return null; } - String michelNumbers = CatalogUtils.toShortForm(series.getMichel().getNumbers()); - String scottNumbers = CatalogUtils.toShortForm(series.getScott().getNumbers()); - String yvertNumbers = CatalogUtils.toShortForm(series.getYvert().getNumbers()); - String gibbonsNumbers = CatalogUtils.toShortForm(series.getGibbons().getNumbers()); + Map commonAttrs = prepareCommonAttrsForSeriesInfo(series, currentUserId); + model.addAllAttributes(commonAttrs); - // CheckStyle: ignore LineLength for next 1 lines - boolean isSeriesInCollection = collectionService.isSeriesInCollection(currentUserId, series.getId()); - boolean userCanAddImagesToSeries = isUserCanAddImagesToSeries(series); AddImageForm form = new AddImageForm(); - - model.addAttribute("series", series); model.addAttribute("addImageForm", form); - model.addAttribute("michelNumbers", michelNumbers); - model.addAttribute("scottNumbers", scottNumbers); - model.addAttribute("yvertNumbers", yvertNumbers); - model.addAttribute("gibbonsNumbers", gibbonsNumbers); - - model.addAttribute("isSeriesInCollection", isSeriesInCollection); - model.addAttribute("allowAddingImages", userCanAddImagesToSeries); model.addAttribute("maxQuantityOfImagesExceeded", false); - if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) { - // CheckStyle: ignore LineLength for next 1 line - List purchasesAndSales = seriesService.findPurchasesAndSales(series.getId()); - model.addAttribute("purchasesAndSales", purchasesAndSales); - } - return "series/info"; } @@ -254,37 +235,15 @@ public String processImage( return null; } - String michelNumbers = CatalogUtils.toShortForm(series.getMichel().getNumbers()); - String scottNumbers = CatalogUtils.toShortForm(series.getScott().getNumbers()); - String yvertNumbers = CatalogUtils.toShortForm(series.getYvert().getNumbers()); - String gibbonsNumbers = CatalogUtils.toShortForm(series.getGibbons().getNumbers()); - - // CheckStyle: ignore LineLength for next 1 lines - boolean isSeriesInCollection = collectionService.isSeriesInCollection(currentUserId, series.getId()); - boolean userCanAddImagesToSeries = isUserCanAddImagesToSeries(series); boolean maxQuantityOfImagesExceeded = !isAdmin() && !isAllowedToAddingImages(series); - - model.addAttribute("series", series); - - model.addAttribute("michelNumbers", michelNumbers); - model.addAttribute("scottNumbers", scottNumbers); - model.addAttribute("yvertNumbers", yvertNumbers); - model.addAttribute("gibbonsNumbers", gibbonsNumbers); - - model.addAttribute("isSeriesInCollection", isSeriesInCollection); - model.addAttribute("allowAddingImages", userCanAddImagesToSeries); model.addAttribute("maxQuantityOfImagesExceeded", maxQuantityOfImagesExceeded); + Map commonAttrs = prepareCommonAttrsForSeriesInfo(series, currentUserId); + model.addAllAttributes(commonAttrs); + if (result.hasErrors() || maxQuantityOfImagesExceeded) { // don't try to re-display file upload field form.setImage(null); - - if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) { - // CheckStyle: ignore LineLength for next 1 line - List purchasesAndSales = seriesService.findPurchasesAndSales(series.getId()); - model.addAttribute("purchasesAndSales", purchasesAndSales); - } - return "series/info"; } @@ -392,6 +351,38 @@ public String searchSeriesByCatalog( return "series/search_result"; } + private Map prepareCommonAttrsForSeriesInfo(SeriesDto series, Integer currentUserId) { + Map model = new HashMap<>(); + + model.put("series", series); + + String michelNumbers = CatalogUtils.toShortForm(series.getMichel().getNumbers()); + String scottNumbers = CatalogUtils.toShortForm(series.getScott().getNumbers()); + String yvertNumbers = CatalogUtils.toShortForm(series.getYvert().getNumbers()); + String gibbonsNumbers = CatalogUtils.toShortForm(series.getGibbons().getNumbers()); + model.put("michelNumbers", michelNumbers); + model.put("scottNumbers", scottNumbers); + model.put("yvertNumbers", yvertNumbers); + model.put("gibbonsNumbers", gibbonsNumbers); + + boolean isSeriesInCollection = + collectionService.isSeriesInCollection(currentUserId, series.getId()); + + boolean userCanAddImagesToSeries = + isUserCanAddImagesToSeries(series); + + model.put("isSeriesInCollection", isSeriesInCollection); + model.put("allowAddingImages", userCanAddImagesToSeries); + + if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) { + List purchasesAndSales = + seriesService.findPurchasesAndSales(series.getId()); + model.put("purchasesAndSales", purchasesAndSales); + } + + return model; + } + private static boolean isAllowedToAddingImages(SeriesDto series) { return series.getImageIds().size() <= series.getQuantity(); } From 228837371268a14f6016b6ad4d8a5bbd573bf222 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 28 Aug 2016 13:58:04 +0200 Subject: [PATCH 007/463] SeriesController.processImage(): prepare common attributes only when we're redisplaying page. No functional changes. --- .../java/ru/mystamps/web/controller/SeriesController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 4263ef93f7..6889d35680 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -238,12 +238,13 @@ public String processImage( boolean maxQuantityOfImagesExceeded = !isAdmin() && !isAllowedToAddingImages(series); model.addAttribute("maxQuantityOfImagesExceeded", maxQuantityOfImagesExceeded); - Map commonAttrs = prepareCommonAttrsForSeriesInfo(series, currentUserId); - model.addAllAttributes(commonAttrs); - if (result.hasErrors() || maxQuantityOfImagesExceeded) { + Map commonAttrs = prepareCommonAttrsForSeriesInfo(series, currentUserId); + model.addAllAttributes(commonAttrs); + // don't try to re-display file upload field form.setImage(null); + return "series/info"; } From 8a4efccb355e28991649683417d3667e8b1b04bd Mon Sep 17 00:00:00 2001 From: Sergey Chechenev Date: Fri, 26 Aug 2016 22:17:31 +0300 Subject: [PATCH 008/463] SecurityConfig: simplify configuration by using ignoringAntMatchers() method. Fix #343 No functional changes. --- .../spring/security/SecurityConfig.java | 39 +------------------ 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java index daf6b77609..ca5c0b86e9 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java @@ -17,8 +17,6 @@ */ package ru.mystamps.web.support.spring.security; -import javax.servlet.http.HttpServletRequest; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.MessageSource; @@ -40,7 +38,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.access.AccessDeniedHandler; -import org.springframework.security.web.util.matcher.RequestMatcher; import ru.mystamps.web.Url; import ru.mystamps.web.config.ServicesConfig; @@ -110,7 +107,7 @@ protected void configure(HttpSecurity http) throws Exception { .and() .csrf() // Allow unsecured requests to H2 consoles. - .requireCsrfProtectionMatcher(new AllExceptUrlsStartedWith("/console")) + .ignoringAntMatchers("/console/**") .and() .rememberMe() // TODO: GH #27 @@ -156,38 +153,4 @@ private AuthenticationProvider getAuthenticationProvider() { return provider; } - private static class AllExceptUrlsStartedWith implements RequestMatcher { - - private static final String[] ALLOWED_METHODS = - new String[] {"GET", "HEAD", "TRACE", "OPTIONS"}; - - private final String[] allowedUrls; - - AllExceptUrlsStartedWith(String... allowedUrls) { - this.allowedUrls = allowedUrls; - } - - @Override - public boolean matches(HttpServletRequest request) { - // replicate default behavior (see CsrfFilter.DefaultRequiresCsrfMatcher class) - String method = request.getMethod(); - for (String allowedMethod : ALLOWED_METHODS) { - if (allowedMethod.equals(method)) { - return false; - } - } - - // apply our own exceptions - String uri = request.getRequestURI(); - for (String allowedUrl : allowedUrls) { - if (uri.startsWith(allowedUrl)) { - return false; - } - } - - return true; - } - - } - } From 18462d9ef0d1857a3d51dc01b99e14545e0933c3 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 17 Sep 2016 14:40:44 +0200 Subject: [PATCH 009/463] CategoryService.add(): change return type from UrlEntityDto to String. Addressed to #440 No functional changes. --- .../ru/mystamps/web/controller/CategoryController.java | 5 ++--- src/main/java/ru/mystamps/web/service/CategoryService.java | 3 +-- .../java/ru/mystamps/web/service/CategoryServiceImpl.java | 4 ++-- .../ru/mystamps/web/service/CategoryServiceImplTest.groovy | 7 ++----- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/CategoryController.java b/src/main/java/ru/mystamps/web/controller/CategoryController.java index 2cf23f6d92..71c47f1ee7 100644 --- a/src/main/java/ru/mystamps/web/controller/CategoryController.java +++ b/src/main/java/ru/mystamps/web/controller/CategoryController.java @@ -45,7 +45,6 @@ import ru.mystamps.web.controller.converter.annotation.CurrentUser; import ru.mystamps.web.dao.dto.LinkEntityDto; import ru.mystamps.web.dao.dto.SeriesInfoDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.model.AddCategoryForm; import ru.mystamps.web.service.CategoryService; import ru.mystamps.web.service.SeriesService; @@ -83,11 +82,11 @@ public String processInput( return null; } - UrlEntityDto categoryUrl = categoryService.add(form, currentUserId); + String slug = categoryService.add(form, currentUserId); redirectAttributes.addFlashAttribute("justAddedCategory", true); - return redirectTo(Url.INFO_CATEGORY_PAGE, categoryUrl.getSlug()); + return redirectTo(Url.INFO_CATEGORY_PAGE, slug); } @RequestMapping(Url.INFO_CATEGORY_PAGE) diff --git a/src/main/java/ru/mystamps/web/service/CategoryService.java b/src/main/java/ru/mystamps/web/service/CategoryService.java index af930705ab..39502d0a37 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryService.java +++ b/src/main/java/ru/mystamps/web/service/CategoryService.java @@ -21,11 +21,10 @@ import java.util.List; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.service.dto.AddCategoryDto; public interface CategoryService { - UrlEntityDto add(AddCategoryDto dto, Integer userId); + String add(AddCategoryDto dto, Integer userId); List findAllAsLinkEntities(String lang); LinkEntityDto findOneAsLinkEntity(String slug, String lang); long countAll(); diff --git a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java index 52e68c8378..dccbc9b027 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java @@ -51,7 +51,7 @@ public class CategoryServiceImpl implements CategoryService { @Override @Transactional @PreAuthorize(HasAuthority.CREATE_CATEGORY) - public UrlEntityDto add(AddCategoryDto dto, Integer userId) { + public String add(AddCategoryDto dto, Integer userId) { Validate.isTrue(dto != null, "DTO must be non null"); Validate.isTrue(dto.getName() != null, "Category name in English must be non null"); Validate.isTrue(dto.getNameRu() != null, "Category name in Russian must be non null"); @@ -78,7 +78,7 @@ public UrlEntityDto add(AddCategoryDto dto, Integer userId) { Integer id = categoryDao.add(category); LOG.info("Category #{} has been created ({})", id, category); - return new UrlEntityDto(id, slug); + return slug; } @Override diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index 4c63108679..9a7ddc4952 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -24,7 +24,6 @@ import ru.mystamps.web.dao.CategoryDao import ru.mystamps.web.dao.dto.AddCategoryDbDto import ru.mystamps.web.model.AddCategoryForm import ru.mystamps.web.dao.dto.LinkEntityDto -import ru.mystamps.web.dao.dto.UrlEntityDto import ru.mystamps.web.tests.DateUtils import ru.mystamps.web.util.SlugUtils @@ -87,12 +86,10 @@ class CategoryServiceImplTest extends Specification { String expectedSlug = 'example-category' and: categoryDao.add(_ as AddCategoryDbDto) >> expectedId - and: - UrlEntityDto expected = new UrlEntityDto(expectedId, expectedSlug) when: - UrlEntityDto actual = service.add(form, userId) + String actualSlug = service.add(form, userId) then: - actual == expected + actualSlug == expectedSlug } def "add() should pass English category name to dao"() { From f75ee84dae19a762f7c820350b23ed40ff0d3881 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 17 Sep 2016 14:45:34 +0200 Subject: [PATCH 010/463] CountryService.add(): change return type from UrlEntityDto to String. Addressed to #440 No functional changes. --- .../java/ru/mystamps/web/controller/CountryController.java | 5 ++--- src/main/java/ru/mystamps/web/service/CountryService.java | 3 +-- .../java/ru/mystamps/web/service/CountryServiceImpl.java | 5 ++--- .../ru/mystamps/web/service/CountryServiceImplTest.groovy | 6 ++---- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/CountryController.java b/src/main/java/ru/mystamps/web/controller/CountryController.java index e27fba6156..41f58d7ad4 100644 --- a/src/main/java/ru/mystamps/web/controller/CountryController.java +++ b/src/main/java/ru/mystamps/web/controller/CountryController.java @@ -45,7 +45,6 @@ import ru.mystamps.web.controller.converter.annotation.CurrentUser; import ru.mystamps.web.dao.dto.LinkEntityDto; import ru.mystamps.web.dao.dto.SeriesInfoDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.model.AddCountryForm; import ru.mystamps.web.service.CountryService; import ru.mystamps.web.service.SeriesService; @@ -83,11 +82,11 @@ public String processInput( return null; } - UrlEntityDto countryUrl = countryService.add(form, currentUserId); + String slug = countryService.add(form, currentUserId); redirectAttributes.addFlashAttribute("justAddedCountry", true); - return redirectTo(Url.INFO_COUNTRY_PAGE, countryUrl.getSlug()); + return redirectTo(Url.INFO_COUNTRY_PAGE, slug); } @RequestMapping(Url.INFO_COUNTRY_PAGE) diff --git a/src/main/java/ru/mystamps/web/service/CountryService.java b/src/main/java/ru/mystamps/web/service/CountryService.java index c3fa2057ea..80b0d2bda2 100644 --- a/src/main/java/ru/mystamps/web/service/CountryService.java +++ b/src/main/java/ru/mystamps/web/service/CountryService.java @@ -21,11 +21,10 @@ import java.util.List; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.service.dto.AddCountryDto; public interface CountryService { - UrlEntityDto add(AddCountryDto dto, Integer userId); + String add(AddCountryDto dto, Integer userId); List findAllAsLinkEntities(String lang); LinkEntityDto findOneAsLinkEntity(String slug, String lang); long countAll(); diff --git a/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java index 9a5bb72164..12100b1ae9 100644 --- a/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java @@ -36,7 +36,6 @@ import ru.mystamps.web.dao.CountryDao; import ru.mystamps.web.dao.dto.AddCountryDbDto; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.service.dto.AddCountryDto; import ru.mystamps.web.support.spring.security.HasAuthority; import ru.mystamps.web.util.LocaleUtils; @@ -51,7 +50,7 @@ public class CountryServiceImpl implements CountryService { @Override @Transactional @PreAuthorize(HasAuthority.CREATE_COUNTRY) - public UrlEntityDto add(AddCountryDto dto, Integer userId) { + public String add(AddCountryDto dto, Integer userId) { Validate.isTrue(dto != null, "DTO must be non null"); Validate.isTrue(dto.getName() != null, "Country name in English must be non null"); Validate.isTrue(dto.getNameRu() != null, "Country name in Russian must be non null"); @@ -79,7 +78,7 @@ public UrlEntityDto add(AddCountryDto dto, Integer userId) { LOG.info("Country #{} has been created ({})", id, country); - return new UrlEntityDto(id, slug); + return slug; } @Override diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index da98a8d801..180ec3a714 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -87,12 +87,10 @@ class CountryServiceImplTest extends Specification { String expectedSlug = 'example-country' and: countryDao.add(_ as AddCountryDbDto) >> expectedId - and: - UrlEntityDto expected = new UrlEntityDto(expectedId, expectedSlug) when: - UrlEntityDto actual = service.add(form, userId) + String actualSlug = service.add(form, userId) then: - actual == expected + actualSlug == expectedSlug } def "add() should pass country name in English to dao"() { From 4ea601c2c76b4e785136f145528374d7d37bd638 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 17 Sep 2016 14:47:47 +0200 Subject: [PATCH 011/463] CategoryServiceImpl: remove unused import. Should be in 1f15395410affefeab507e44590070620ff98d6d commit. Reported by CheckStyle. No functional changes. --- src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java index dccbc9b027..47bc2a7604 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java @@ -36,7 +36,6 @@ import ru.mystamps.web.dao.CategoryDao; import ru.mystamps.web.dao.dto.AddCategoryDbDto; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.service.dto.AddCategoryDto; import ru.mystamps.web.support.spring.security.HasAuthority; import ru.mystamps.web.util.LocaleUtils; From 93ef95fed776605ea2cd916e391c86a73b1d7e8b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 17 Sep 2016 14:51:11 +0200 Subject: [PATCH 012/463] SeriesController: suppress CheckStyle warning about long line. Should be in 0f47d6eef196c701db876c7eb2a5bc8f829eb34f commit. No functional changes. --- src/main/java/ru/mystamps/web/controller/SeriesController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 6889d35680..04e3b8fbc5 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -352,6 +352,7 @@ public String searchSeriesByCatalog( return "series/search_result"; } + // CheckStyle: ignore LineLength for next 1 line private Map prepareCommonAttrsForSeriesInfo(SeriesDto series, Integer currentUserId) { Map model = new HashMap<>(); From 3081d0317d7e0d87377876d6a4f861e60eddd952 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 19 Sep 2016 23:50:34 +0200 Subject: [PATCH 013/463] CollectionDao.addSeriesToCollection(): replace argument collectionId by collectionSlug. Addressed to #440 No functional changes. --- .../java/ru/mystamps/web/dao/CollectionDao.java | 2 +- .../ru/mystamps/web/dao/impl/JdbcCollectionDao.java | 8 ++++---- .../mystamps/web/service/CollectionServiceImpl.java | 7 +++---- .../resources/sql/collection_dao_queries.properties | 13 +++++-------- .../web/service/CollectionServiceImplTest.groovy | 6 +++--- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/mystamps/web/dao/CollectionDao.java b/src/main/java/ru/mystamps/web/dao/CollectionDao.java index d1e65c131d..08370d4581 100644 --- a/src/main/java/ru/mystamps/web/dao/CollectionDao.java +++ b/src/main/java/ru/mystamps/web/dao/CollectionDao.java @@ -30,7 +30,7 @@ public interface CollectionDao { Integer add(AddCollectionDbDto collection); boolean isSeriesInUserCollection(Integer userId, Integer seriesId); UrlEntityDto findCollectionUrlEntityByUserId(Integer userId); - void addSeriesToCollection(Integer collectionId, Integer seriesId); + void addSeriesToCollection(String collectionSlug, Integer seriesId); void removeSeriesFromCollection(Integer collectionId, Integer seriesId); CollectionInfoDto findCollectionInfoBySlug(String slug); } diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java index c3261dfc15..754362be35 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java @@ -138,17 +138,17 @@ public UrlEntityDto findCollectionUrlEntityByUserId(Integer userId) { } @Override - public void addSeriesToCollection(Integer collectionId, Integer seriesId) { + public void addSeriesToCollection(String collectionSlug, Integer seriesId) { Map params = new HashMap<>(); - params.put("collection_id", collectionId); + params.put("collection_slug", collectionSlug); params.put("series_id", seriesId); int affected = jdbcTemplate.update(addSeriesToCollectionSql, params); Validate.validState( affected == 1, - "Unexpected number of affected rows after adding series #%d to collection #%d: %d", + "Unexpected number of affected rows after adding series #%d to collection '%s': %d", seriesId, - collectionId, + collectionSlug, affected ); } diff --git a/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java b/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java index 490ca7b12e..b50479c47b 100644 --- a/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java @@ -74,14 +74,13 @@ public UrlEntityDto addToCollection(Integer userId, Integer seriesId) { Validate.isTrue(seriesId != null, "Series id must be non null"); UrlEntityDto url = collectionDao.findCollectionUrlEntityByUserId(userId); - Integer collectionId = url.getId(); + String collectionSlug = url.getSlug(); - collectionDao.addSeriesToCollection(collectionId, seriesId); + collectionDao.addSeriesToCollection(collectionSlug, seriesId); LOG.info( - "Series #{} has been added to collection #{} of user #{}", + "Series #{} has been added to collection of user #{}", seriesId, - collectionId, userId ); diff --git a/src/main/resources/sql/collection_dao_queries.properties b/src/main/resources/sql/collection_dao_queries.properties index 59a992d57f..72784c8bfb 100644 --- a/src/main/resources/sql/collection_dao_queries.properties +++ b/src/main/resources/sql/collection_dao_queries.properties @@ -45,14 +45,11 @@ SELECT id, slug \ collection.add_series_to_collection = \ INSERT \ - INTO collections_series \ - ( collection_id \ - , series_id \ - ) \ -VALUES \ - ( :collection_id \ - , :series_id \ - ) + INTO collections_series(collection_id, series_id) \ +SELECT c.id AS collection_id \ + , :series_id AS series_id \ + FROM collections c \ + WHERE c.slug = :collection_slug collection.remove_series_from_collection = \ DELETE \ diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index 9c637dc272..f7c1086553 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -122,14 +122,14 @@ class CollectionServiceImplTest extends Specification { and: UrlEntityDto url = TestObjects.createUrlEntityDto() and: - Integer expectedCollectionId = url.getId() + String expectedCollectionSlug = url.getSlug() and: collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> url when: service.addToCollection(123, expectedSeriesId) then: - 1 * collectionDao.addSeriesToCollection({ Integer collectionId -> - assert collectionId == expectedCollectionId + 1 * collectionDao.addSeriesToCollection({ String collectionSlug -> + assert collectionSlug == expectedCollectionSlug return true }, { Integer seriesId -> assert seriesId == expectedSeriesId From 65a16a7eab0932f27d504cb9fd163823f8aebb90 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 20 Sep 2016 00:52:45 +0200 Subject: [PATCH 014/463] CollectionService.addToCollection(): don't return UrlEntityDto. Addressed to #440 No functional changes. --- .../web/controller/SeriesController.java | 13 ++++--- .../ru/mystamps/web/dao/CollectionDao.java | 2 +- .../web/dao/impl/JdbcCollectionDao.java | 10 +++--- .../web/service/CollectionService.java | 2 +- .../web/service/CollectionServiceImpl.java | 15 ++------ .../sql/collection_dao_queries.properties | 2 +- .../service/CollectionServiceImplTest.groovy | 36 +++---------------- 7 files changed, 25 insertions(+), 55 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 04e3b8fbc5..e831c658c2 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -48,6 +48,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import org.springframework.security.core.annotation.AuthenticationPrincipal; + import lombok.RequiredArgsConstructor; import ru.mystamps.web.Url; @@ -66,6 +68,7 @@ import ru.mystamps.web.service.SeriesService; import ru.mystamps.web.service.dto.SeriesDto; import ru.mystamps.web.support.spring.security.Authority; +import ru.mystamps.web.support.spring.security.CustomUserDetails; import ru.mystamps.web.support.spring.security.SecurityContextUtils; import ru.mystamps.web.util.CatalogUtils; import ru.mystamps.web.util.LocaleUtils; @@ -260,7 +263,7 @@ public String processImage( ) public String addToCollection( @PathVariable("id") Integer seriesId, - @CurrentUser Integer currentUserId, + @AuthenticationPrincipal CustomUserDetails currentUserDetails, RedirectAttributes redirectAttributes, HttpServletResponse response) throws IOException { @@ -276,12 +279,14 @@ public String addToCollection( return null; } - UrlEntityDto collection = collectionService.addToCollection(currentUserId, seriesId); + Integer userId = currentUserDetails.getUserId(); + collectionService.addToCollection(userId, seriesId); redirectAttributes.addFlashAttribute("justAddedSeries", true); redirectAttributes.addFlashAttribute("justAddedSeriesId", seriesId); - - return redirectTo(Url.INFO_COLLECTION_PAGE, collection.getSlug()); + + String collectionSlug = currentUserDetails.getUserCollectionSlug(); + return redirectTo(Url.INFO_COLLECTION_PAGE, collectionSlug); } @RequestMapping( diff --git a/src/main/java/ru/mystamps/web/dao/CollectionDao.java b/src/main/java/ru/mystamps/web/dao/CollectionDao.java index 08370d4581..8efcc042b6 100644 --- a/src/main/java/ru/mystamps/web/dao/CollectionDao.java +++ b/src/main/java/ru/mystamps/web/dao/CollectionDao.java @@ -30,7 +30,7 @@ public interface CollectionDao { Integer add(AddCollectionDbDto collection); boolean isSeriesInUserCollection(Integer userId, Integer seriesId); UrlEntityDto findCollectionUrlEntityByUserId(Integer userId); - void addSeriesToCollection(String collectionSlug, Integer seriesId); + void addSeriesToUserCollection(Integer userId, Integer seriesId); void removeSeriesFromCollection(Integer collectionId, Integer seriesId); CollectionInfoDto findCollectionInfoBySlug(String slug); } diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java index 754362be35..9378831fe8 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java @@ -138,17 +138,19 @@ public UrlEntityDto findCollectionUrlEntityByUserId(Integer userId) { } @Override - public void addSeriesToCollection(String collectionSlug, Integer seriesId) { + public void addSeriesToUserCollection(Integer userId, Integer seriesId) { Map params = new HashMap<>(); - params.put("collection_slug", collectionSlug); + params.put("user_id", userId); params.put("series_id", seriesId); int affected = jdbcTemplate.update(addSeriesToCollectionSql, params); + + // CheckStyle: ignore LineLength for next 3 lines Validate.validState( affected == 1, - "Unexpected number of affected rows after adding series #%d to collection '%s': %d", + "Unexpected number of affected rows after adding series #%d to collection of user #%d: %d", seriesId, - collectionSlug, + userId, affected ); } diff --git a/src/main/java/ru/mystamps/web/service/CollectionService.java b/src/main/java/ru/mystamps/web/service/CollectionService.java index c750c104bb..5e58811de4 100644 --- a/src/main/java/ru/mystamps/web/service/CollectionService.java +++ b/src/main/java/ru/mystamps/web/service/CollectionService.java @@ -25,7 +25,7 @@ public interface CollectionService { void createCollection(Integer ownerId, String ownerLogin); - UrlEntityDto addToCollection(Integer userId, Integer seriesId); + void addToCollection(Integer userId, Integer seriesId); UrlEntityDto removeFromCollection(Integer userId, Integer seriesId); boolean isSeriesInCollection(Integer userId, Integer seriesId); long countCollectionsOfUsers(); diff --git a/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java b/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java index b50479c47b..cea18c9267 100644 --- a/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java @@ -69,22 +69,13 @@ public void createCollection(Integer ownerId, String ownerLogin) { @Override @Transactional @PreAuthorize(HasAuthority.UPDATE_COLLECTION) - public UrlEntityDto addToCollection(Integer userId, Integer seriesId) { + public void addToCollection(Integer userId, Integer seriesId) { Validate.isTrue(userId != null, "User id must be non null"); Validate.isTrue(seriesId != null, "Series id must be non null"); - UrlEntityDto url = collectionDao.findCollectionUrlEntityByUserId(userId); - String collectionSlug = url.getSlug(); - - collectionDao.addSeriesToCollection(collectionSlug, seriesId); - - LOG.info( - "Series #{} has been added to collection of user #{}", - seriesId, - userId - ); + collectionDao.addSeriesToUserCollection(userId, seriesId); - return url; + LOG.info("Series #{} has been added to collection of user #{}", seriesId, userId); } @Override diff --git a/src/main/resources/sql/collection_dao_queries.properties b/src/main/resources/sql/collection_dao_queries.properties index 72784c8bfb..a95457eb79 100644 --- a/src/main/resources/sql/collection_dao_queries.properties +++ b/src/main/resources/sql/collection_dao_queries.properties @@ -49,7 +49,7 @@ INSERT \ SELECT c.id AS collection_id \ , :series_id AS series_id \ FROM collections c \ - WHERE c.slug = :collection_slug + WHERE c.user_id = :user_id collection.remove_series_from_collection = \ DELETE \ diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index f7c1086553..1a785fd2fa 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -104,32 +104,15 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } - def "addToCollection() should find collection by user id"() { + def "addToCollection() should pass arguments to dao"() { given: Integer expectedUserId = 123 - when: - service.addToCollection(expectedUserId, 321) - then: - 1 * collectionDao.findCollectionUrlEntityByUserId({ Integer userId -> - assert userId == expectedUserId - return true - }) >> TestObjects.createUrlEntityDto() - } - - def "addToCollection() should add series to collection"() { - given: Integer expectedSeriesId = 456 - and: - UrlEntityDto url = TestObjects.createUrlEntityDto() - and: - String expectedCollectionSlug = url.getSlug() - and: - collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> url when: - service.addToCollection(123, expectedSeriesId) + service.addToCollection(expectedUserId, expectedSeriesId) then: - 1 * collectionDao.addSeriesToCollection({ String collectionSlug -> - assert collectionSlug == expectedCollectionSlug + 1 * collectionDao.addSeriesToUserCollection({ Integer userId -> + assert userId == expectedUserId return true }, { Integer seriesId -> assert seriesId == expectedSeriesId @@ -137,17 +120,6 @@ class CollectionServiceImplTest extends Specification { }) } - def "addToCollection() should return result from dao"() { - given: - UrlEntityDto expectedUrl = TestObjects.createUrlEntityDto() - and: - collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> expectedUrl - when: - UrlEntityDto serviceResult = service.addToCollection(123, 456) - then: - serviceResult == expectedUrl - } - // // Tests for removeFromCollection() // From 0492d7df50377ef4b29cd114ebdae8833ba35d22 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 22 Sep 2016 21:09:47 +0200 Subject: [PATCH 015/463] AuthenticationFailureListener: use constructor-injection instead of @Autowired. No functional changes. --- .../spring/security/AuthenticationFailureListener.java | 7 ++++--- .../web/support/spring/security/SecurityConfig.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/mystamps/web/support/spring/security/AuthenticationFailureListener.java b/src/main/java/ru/mystamps/web/support/spring/security/AuthenticationFailureListener.java index 81d78af5f3..f6f75712db 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/AuthenticationFailureListener.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/AuthenticationFailureListener.java @@ -24,22 +24,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; +import lombok.RequiredArgsConstructor; + import ru.mystamps.web.service.SiteService; +@RequiredArgsConstructor public class AuthenticationFailureListener implements ApplicationListener { private static final Logger LOG = LoggerFactory.getLogger(AuthenticationFailureListener.class); - @Autowired - private SiteService siteService; + private final SiteService siteService; @Override public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) { diff --git a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java index ca5c0b86e9..e5bf4c52ac 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java @@ -130,7 +130,7 @@ public PasswordEncoder getPasswordEncoder() { @Bean public ApplicationListener getApplicationListener() { - return new AuthenticationFailureListener(); + return new AuthenticationFailureListener(servicesConfig.getSiteService()); } @Bean From 514b3e5d91a0809e1134c37d2398d88f85e92f95 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 24 Sep 2016 01:20:00 +0200 Subject: [PATCH 016/463] SecurityConfig: ignore all /public/** URLs. No functional changes. --- .../ru/mystamps/web/support/spring/security/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java index e5bf4c52ac..bd36a6061d 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java @@ -55,7 +55,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public void configure(WebSecurity web) throws Exception { - web.ignoring().antMatchers("/static/**"); + web.ignoring().antMatchers("/static/**", "/public/**"); } @Override From 3def5479fa266df4b9104cd7d6a5434f7075408e Mon Sep 17 00:00:00 2001 From: Maxim Shestakov Date: Mon, 26 Sep 2016 13:39:25 +0300 Subject: [PATCH 017/463] /category/add: prohibit repeated special characters. Fix #465 --- .../web/controller/CategoryController.java | 6 ++- .../editor/ReplaceRepeatingSpacesEditor.java | 48 +++++++++++++++++++ .../mystamps/web/model/AddCategoryForm.java | 22 +++++++-- .../java/ru/mystamps/web/model/Group.java | 3 ++ .../web/validation/ValidationRules.java | 2 + .../i18n/ValidationMessages.properties | 1 + .../i18n/ValidationMessages_ru.properties | 1 + .../web/tests/cases/WhenAdminAddCategory.java | 28 +++++++++++ 8 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java diff --git a/src/main/java/ru/mystamps/web/controller/CategoryController.java b/src/main/java/ru/mystamps/web/controller/CategoryController.java index 71c47f1ee7..dc36a60f25 100644 --- a/src/main/java/ru/mystamps/web/controller/CategoryController.java +++ b/src/main/java/ru/mystamps/web/controller/CategoryController.java @@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import org.springframework.beans.propertyeditors.StringTrimmerEditor; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -43,6 +42,7 @@ import ru.mystamps.web.Url; import ru.mystamps.web.controller.converter.annotation.Category; import ru.mystamps.web.controller.converter.annotation.CurrentUser; +import ru.mystamps.web.controller.editor.ReplaceRepeatingSpacesEditor; import ru.mystamps.web.dao.dto.LinkEntityDto; import ru.mystamps.web.dao.dto.SeriesInfoDto; import ru.mystamps.web.model.AddCategoryForm; @@ -61,7 +61,9 @@ public class CategoryController { @InitBinder("addCategoryForm") protected void initBinder(WebDataBinder binder) { - StringTrimmerEditor editor = new StringTrimmerEditor(false); + // CheckStyle: ignore LineLength for next 1 line + // We can't use StringTrimmerEditor here because "only one single registered custom editor per property path is supported". + ReplaceRepeatingSpacesEditor editor = new ReplaceRepeatingSpacesEditor(true); binder.registerCustomEditor(String.class, "name", editor); binder.registerCustomEditor(String.class, "nameRu", editor); } diff --git a/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java b/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java new file mode 100644 index 0000000000..2d450e6ca5 --- /dev/null +++ b/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.controller.editor; + +import java.beans.PropertyEditorSupport; +import java.util.regex.Pattern; + +import lombok.RequiredArgsConstructor; + +/** + * @author Maxim Shestakov + */ +@RequiredArgsConstructor +public class ReplaceRepeatingSpacesEditor extends PropertyEditorSupport { + private static final Pattern REPEATING_SPACES = Pattern.compile("[ ]{2,}"); + private final boolean performTrimming; + + @Override + public void setAsText(String name) throws IllegalArgumentException { + String text = name; + + if (performTrimming) { + text = name.trim(); + } + + if (text.contains(" ")) { + text = REPEATING_SPACES.matcher(text).replaceAll(" "); + } + + setValue(text); + } + +} diff --git a/src/main/java/ru/mystamps/web/model/AddCategoryForm.java b/src/main/java/ru/mystamps/web/model/AddCategoryForm.java index f6d2a43c61..c32ef08e8f 100644 --- a/src/main/java/ru/mystamps/web/model/AddCategoryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCategoryForm.java @@ -34,6 +34,7 @@ import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_MAX_LENGTH; import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_MIN_LENGTH; import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_NO_HYPHEN_REGEXP; +import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_NO_REPEATING_HYPHENS_REGEXP; import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_RU_REGEXP; @Getter @@ -44,7 +45,8 @@ Group.Level2.class, Group.Level3.class, Group.Level4.class, - Group.Level5.class + Group.Level5.class, + Group.Level6.class }) public class AddCategoryForm implements AddCategoryDto { @@ -67,13 +69,18 @@ public class AddCategoryForm implements AddCategoryDto { message = "{category-name-en.invalid}", groups = Group.Level3.class ), + @Pattern( + regexp = CATEGORY_NAME_NO_REPEATING_HYPHENS_REGEXP, + message = "{value.repeating_hyphen}", + groups = Group.Level4.class + ), @Pattern( regexp = CATEGORY_NAME_NO_HYPHEN_REGEXP, message = "{value.hyphen}", - groups = Group.Level4.class + groups = Group.Level5.class ) }) - @UniqueCategoryName(lang = Lang.EN, groups = Group.Level5.class) + @UniqueCategoryName(lang = Lang.EN, groups = Group.Level6.class) private String name; @NotEmpty(groups = Group.Level1.class) @@ -95,13 +102,18 @@ public class AddCategoryForm implements AddCategoryDto { message = "{category-name-ru.invalid}", groups = Group.Level3.class ), + @Pattern( + regexp = CATEGORY_NAME_NO_REPEATING_HYPHENS_REGEXP, + message = "{value.repeating_hyphen}", + groups = Group.Level4.class + ), @Pattern( regexp = CATEGORY_NAME_NO_HYPHEN_REGEXP, message = "{value.hyphen}", - groups = Group.Level4.class + groups = Group.Level5.class ) }) - @UniqueCategoryName(lang = Lang.RU, groups = Group.Level5.class) + @UniqueCategoryName(lang = Lang.RU, groups = Group.Level6.class) private String nameRu; } diff --git a/src/main/java/ru/mystamps/web/model/Group.java b/src/main/java/ru/mystamps/web/model/Group.java index e7c8376431..fb8f92b750 100644 --- a/src/main/java/ru/mystamps/web/model/Group.java +++ b/src/main/java/ru/mystamps/web/model/Group.java @@ -33,5 +33,8 @@ interface Level4 { interface Level5 { } + + interface Level6 { + } } diff --git a/src/main/java/ru/mystamps/web/validation/ValidationRules.java b/src/main/java/ru/mystamps/web/validation/ValidationRules.java index e4135de02b..306639a272 100644 --- a/src/main/java/ru/mystamps/web/validation/ValidationRules.java +++ b/src/main/java/ru/mystamps/web/validation/ValidationRules.java @@ -42,6 +42,8 @@ public final class ValidationRules { public static final String CATEGORY_NAME_EN_REGEXP = "[- a-zA-Z]+"; public static final String CATEGORY_NAME_RU_REGEXP = "[- а-яёА-ЯЁ]+"; public static final String CATEGORY_NAME_NO_HYPHEN_REGEXP = "[ \\p{L}]([- \\p{L}]+[ \\p{L}])*"; + @SuppressWarnings({"PMD.LongVariable", "checkstyle:linelength"}) + public static final String CATEGORY_NAME_NO_REPEATING_HYPHENS_REGEXP = "(?!.+[-]{2,}).+"; public static final int COUNTRY_NAME_MIN_LENGTH = 3; public static final int COUNTRY_NAME_MAX_LENGTH = Db.Country.NAME_LENGTH; diff --git a/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties b/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties index 5c03208374..c56d33a980 100644 --- a/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties +++ b/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties @@ -24,6 +24,7 @@ value.too-short = Value is less than allowable minimum of {min} characters value.too-long = Value is greater than allowable maximum of {max} characters value.invalid-length = Value length must be equals to {max} characters value.hyphen = Value must not start or end with hyphen +value.repeating_hyphen = Value must not contain repetition of hyphen value.empty = Value must not be empty category-name-en.invalid = Category name must consist only latin letters, hyphen or spaces diff --git a/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties b/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties index d293a762b2..ce55e644c3 100644 --- a/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties @@ -24,6 +24,7 @@ value.too-short = Значение должно быть не менее {min} value.too-long = Значение должно быть не более {max} символов value.invalid-length = Значение должно быть длинной {max} символов value.hyphen = Значение не должно начинаться или заканчиваться знаком дефиса +value.repeating_hyphen = Значение не должно содержать повторяющиеся знаки дефиса value.empty = Значение не должно быть пустым category-name-en.invalid = Название категории может содержать только латинские буквы, дефис или пробел diff --git a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java index 8207a1dccc..d5086f62cd 100644 --- a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java +++ b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java @@ -184,6 +184,20 @@ public void categoryNameRuShouldNotEndsWithHyphen() { assertThat(page).field("nameRu").hasError(tr("value.hyphen")); } + + @Test(groups = "invalid", dependsOnGroups = "std") + public void categoryNameEnShouldNotContainRepeatedHyphens() { + page.addCategory("te--st", TEST_CATEGORY_NAME_RU); + + assertThat(page).field("name").hasError(tr("value.repeating_hyphen")); + } + + @Test(groups = "invalid", dependsOnGroups = "std") + public void categoryNameRuShouldNotContainRepeatedHyphens() { + page.addCategory(TEST_CATEGORY_NAME_EN, "те--ст"); + + assertThat(page).field("nameRu").hasError(tr("value.repeating_hyphen")); + } @Test(groups = "misc", dependsOnGroups = "std") public void categoryNameEnShouldBeStripedFromLeadingAndTrailingSpaces() { @@ -198,6 +212,20 @@ public void categoryNameRuShouldBeStripedFromLeadingAndTrailingSpaces() { assertThat(page).field("nameRu").hasValue("т3ст"); } + + @Test(groups = "misc", dependsOnGroups = "std") + public void categoryNameEnShouldReplaceRepeatedSpacesByOne() { + page.addCategory("t3 st", TEST_CATEGORY_NAME_RU); + + assertThat(page).field("name").hasValue("t3 st"); + } + + @Test(groups = "misc", dependsOnGroups = "std") + public void categoryNameRuShouldReplaceRepeatedSpacesByOne() { + page.addCategory(TEST_CATEGORY_NAME_EN, "т3 ст"); + + assertThat(page).field("nameRu").hasValue("т3 ст"); + } @Test(groups = "logic", dependsOnGroups = { "std", "invalid", "valid", "misc" }) public void shouldBeRedirectedToPageWithInfoAboutCategoryAfterCreation() { From f6cd397ae0e7eec53a1c94171b22262ed5c4ced5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 26 Sep 2016 14:07:27 +0200 Subject: [PATCH 018/463] CategoryController: fix CheckStyle warning about long line properly. Should be in c8f2dca3c477cdedc66157c2a7827f586b652d8f commit. Addressed to #465 No code changes. --- .../java/ru/mystamps/web/controller/CategoryController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/CategoryController.java b/src/main/java/ru/mystamps/web/controller/CategoryController.java index dc36a60f25..e664ac8320 100644 --- a/src/main/java/ru/mystamps/web/controller/CategoryController.java +++ b/src/main/java/ru/mystamps/web/controller/CategoryController.java @@ -61,8 +61,8 @@ public class CategoryController { @InitBinder("addCategoryForm") protected void initBinder(WebDataBinder binder) { - // CheckStyle: ignore LineLength for next 1 line - // We can't use StringTrimmerEditor here because "only one single registered custom editor per property path is supported". + // We can't use StringTrimmerEditor here because "only one single registered custom + // editor per property path is supported". ReplaceRepeatingSpacesEditor editor = new ReplaceRepeatingSpacesEditor(true); binder.registerCustomEditor(String.class, "name", editor); binder.registerCustomEditor(String.class, "nameRu", editor); From 0a659b45d97c8e7de846c06335610164ad4cfc45 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 26 Sep 2016 14:12:38 +0200 Subject: [PATCH 019/463] ValidationRules: rename constant. No functional changes. --- src/main/java/ru/mystamps/web/model/ActivateAccountForm.java | 2 +- src/main/java/ru/mystamps/web/validation/ValidationRules.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/mystamps/web/model/ActivateAccountForm.java b/src/main/java/ru/mystamps/web/model/ActivateAccountForm.java index c3c9163eb1..b319bf1242 100644 --- a/src/main/java/ru/mystamps/web/model/ActivateAccountForm.java +++ b/src/main/java/ru/mystamps/web/model/ActivateAccountForm.java @@ -69,7 +69,7 @@ public class ActivateAccountForm implements ActivateAccountDto { groups = Login3Checks.class ), @Pattern( - regexp = ValidationRules.LOGIN_REPEATING_CHARS_REGEXP, + regexp = ValidationRules.LOGIN_NO_REPEATING_CHARS_REGEXP, message = "{login.repetition_chars}", groups = Login4Checks.class ) diff --git a/src/main/java/ru/mystamps/web/validation/ValidationRules.java b/src/main/java/ru/mystamps/web/validation/ValidationRules.java index 306639a272..3dd9cd61d2 100644 --- a/src/main/java/ru/mystamps/web/validation/ValidationRules.java +++ b/src/main/java/ru/mystamps/web/validation/ValidationRules.java @@ -24,7 +24,8 @@ public final class ValidationRules { public static final int LOGIN_MIN_LENGTH = 2; public static final int LOGIN_MAX_LENGTH = Db.User.LOGIN_LENGTH; public static final String LOGIN_REGEXP = "[-_\\.a-zA-Z0-9]+"; - public static final String LOGIN_REPEATING_CHARS_REGEXP = "(?!.+[-_.]{2,}).+"; + @SuppressWarnings("PMD.LongVariable") + public static final String LOGIN_NO_REPEATING_CHARS_REGEXP = "(?!.+[-_.]{2,}).+"; public static final int NAME_MAX_LENGTH = Db.User.NAME_LENGTH; public static final String NAME_REGEXP = "[- \\p{L}]+"; From 112f6e885bfb6158f347763c337586fffcf03f9d Mon Sep 17 00:00:00 2001 From: Maxim Shestakov Date: Mon, 26 Sep 2016 17:46:34 +0300 Subject: [PATCH 020/463] /country/add: prohibit repeated special characters. Fix #403 --- .../web/controller/CountryController.java | 4 +-- .../ru/mystamps/web/model/AddCountryForm.java | 15 ++++++++-- .../web/validation/ValidationRules.java | 2 ++ .../web/tests/cases/WhenAdminAddCountry.java | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/CountryController.java b/src/main/java/ru/mystamps/web/controller/CountryController.java index 41f58d7ad4..199326c90f 100644 --- a/src/main/java/ru/mystamps/web/controller/CountryController.java +++ b/src/main/java/ru/mystamps/web/controller/CountryController.java @@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import org.springframework.beans.propertyeditors.StringTrimmerEditor; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -43,6 +42,7 @@ import ru.mystamps.web.Url; import ru.mystamps.web.controller.converter.annotation.Country; import ru.mystamps.web.controller.converter.annotation.CurrentUser; +import ru.mystamps.web.controller.editor.ReplaceRepeatingSpacesEditor; import ru.mystamps.web.dao.dto.LinkEntityDto; import ru.mystamps.web.dao.dto.SeriesInfoDto; import ru.mystamps.web.model.AddCountryForm; @@ -61,7 +61,7 @@ public class CountryController { @InitBinder("addCountryForm") protected void initBinder(WebDataBinder binder) { - StringTrimmerEditor editor = new StringTrimmerEditor(false); + ReplaceRepeatingSpacesEditor editor = new ReplaceRepeatingSpacesEditor(true); binder.registerCustomEditor(String.class, "name", editor); binder.registerCustomEditor(String.class, "nameRu", editor); } diff --git a/src/main/java/ru/mystamps/web/model/AddCountryForm.java b/src/main/java/ru/mystamps/web/model/AddCountryForm.java index 86e02dd6ed..baf9e39405 100644 --- a/src/main/java/ru/mystamps/web/model/AddCountryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCountryForm.java @@ -34,6 +34,7 @@ import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_MAX_LENGTH; import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_MIN_LENGTH; import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_NO_HYPHEN_REGEXP; +import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_NO_REPEATING_HYPHENS_REGEXP; import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_RU_REGEXP; @Getter @@ -67,10 +68,15 @@ public class AddCountryForm implements AddCountryDto { message = "{country-name-en.invalid}", groups = Group.Level3.class ), + @Pattern( + regexp = COUNTRY_NAME_NO_REPEATING_HYPHENS_REGEXP, + message = "{value.repeating_hyphen}", + groups = Group.Level4.class + ), @Pattern( regexp = COUNTRY_NAME_NO_HYPHEN_REGEXP, message = "{value.hyphen}", - groups = Group.Level4.class + groups = Group.Level5.class ) }) @UniqueCountryName(lang = Lang.EN, groups = Group.Level5.class) @@ -95,10 +101,15 @@ public class AddCountryForm implements AddCountryDto { message = "{country-name-ru.invalid}", groups = Group.Level3.class ), + @Pattern( + regexp = COUNTRY_NAME_NO_REPEATING_HYPHENS_REGEXP, + message = "{value.repeating_hyphen}", + groups = Group.Level4.class + ), @Pattern( regexp = COUNTRY_NAME_NO_HYPHEN_REGEXP, message = "{value.hyphen}", - groups = Group.Level4.class + groups = Group.Level5.class ) }) @UniqueCountryName(lang = Lang.RU, groups = Group.Level5.class) diff --git a/src/main/java/ru/mystamps/web/validation/ValidationRules.java b/src/main/java/ru/mystamps/web/validation/ValidationRules.java index 3dd9cd61d2..fb1839a2df 100644 --- a/src/main/java/ru/mystamps/web/validation/ValidationRules.java +++ b/src/main/java/ru/mystamps/web/validation/ValidationRules.java @@ -51,6 +51,8 @@ public final class ValidationRules { public static final String COUNTRY_NAME_EN_REGEXP = "[- a-zA-Z]+"; public static final String COUNTRY_NAME_RU_REGEXP = "[- а-яёА-ЯЁ]+"; public static final String COUNTRY_NAME_NO_HYPHEN_REGEXP = "[ \\p{L}]([- \\p{L}]+[ \\p{L}])*"; + @SuppressWarnings({"PMD.LongVariable", "checkstyle:linelength"}) + public static final String COUNTRY_NAME_NO_REPEATING_HYPHENS_REGEXP = "(?!.+[-]{2,}).+"; public static final int MIN_STAMPS_IN_SERIES = 1; public static final int MAX_STAMPS_IN_SERIES = 50; diff --git a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java index c18f54a94a..f726924b18 100644 --- a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java +++ b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java @@ -207,6 +207,20 @@ public void countryNameRuShouldNotEndsWithHyphen() { .field("nameRu") .hasError(tr("value.hyphen")); } + + @Test(groups = "invalid", dependsOnGroups = "std") + public void countryNameEnShouldNotContainRepeatedHyphens() { + page.addCountry("te--st", TEST_COUNTRY_NAME_RU); + + assertThat(page).field("name").hasError(tr("value.repeating_hyphen")); + } + + @Test(groups = "invalid", dependsOnGroups = "std") + public void countryNameRuShouldNotContainRepeatedHyphens() { + page.addCountry(TEST_COUNTRY_NAME_EN, "те--ст"); + + assertThat(page).field("nameRu").hasError(tr("value.repeating_hyphen")); + } @Test(groups = "misc", dependsOnGroups = "std") public void countryNameEnShouldBeStripedFromLeadingAndTrailingSpaces() { @@ -221,6 +235,20 @@ public void countryNameRuShouldBeStripedFromLeadingAndTrailingSpaces() { assertThat(page).field("nameRu").hasValue("т3ст"); } + + @Test(groups = "misc", dependsOnGroups = "std") + public void countryNameEnShouldReplaceRepeatedSpacesByOne() { + page.addCountry("t3 st", TEST_COUNTRY_NAME_RU); + + assertThat(page).field("name").hasValue("t3 st"); + } + + @Test(groups = "misc", dependsOnGroups = "std") + public void countryNameRuShouldReplaceRepeatedSpacesByOne() { + page.addCountry(TEST_COUNTRY_NAME_EN, "т3 ст"); + + assertThat(page).field("nameRu").hasValue("т3 ст"); + } @Test(groups = "logic", dependsOnGroups = { "std", "invalid", "valid", "misc" }) public void shouldBeRedirectedToPageWithInfoAboutCountryAfterCreation() { From 744d8e9846bbffc5775b03326fe19bb9e3163ea6 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 12:40:12 +0200 Subject: [PATCH 021/463] pom.xml: update Lombok to 1.16.10 @see https://projectlombok.org/changelog.html No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ad129a4027..a90dd53d60 100644 --- a/pom.xml +++ b/pom.xml @@ -396,7 +396,7 @@ 3.4.2 - 1.16.8 + 1.16.10 1.7.4 From df5788eeffc24200cc227c162a479c340d9b4ab8 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 12:51:09 +0200 Subject: [PATCH 022/463] pom.xml: update htmlunit-driver to 2.21 No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a90dd53d60..cdb1cc7669 100644 --- a/pom.xml +++ b/pom.xml @@ -409,7 +409,7 @@ 0.12.1 - 2.20 + 2.21 2.53.1 From b61df3feb08041382566307307d3fe47474d3a6f Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 12:57:41 +0200 Subject: [PATCH 023/463] pom.xml(maven-war-plugin): update to 3.0.0 @see https://mail-archives.apache.org/mod_mbox/maven-announce/201608.mbox/%3C20160828105459.DF6991911F%40minotaur.apache.org%3E No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cdb1cc7669..91c82ce226 100644 --- a/pom.xml +++ b/pom.xml @@ -441,7 +441,7 @@ 2.1.5.RELEASE 2.2.0.Final - 2.6 + 3.0.0 From d8daed6dda7e56f705cfca76cff018d1be160b82 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 13:00:21 +0200 Subject: [PATCH 024/463] pom.xml(jasmine-maven-plugin): update to 2.2 @see https://github.com/searls/jasmine-maven-plugin/releases/tag/jasmine-maven-plugin-2.2 No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 91c82ce226..88f94055ad 100644 --- a/pom.xml +++ b/pom.xml @@ -373,7 +373,7 @@ 5.2.4.Final 0.7.7.201606060606 - 2.1 + 2.2 1.8 From 22d141fb0212292882ca70ef6560386098684083 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 13:25:09 +0200 Subject: [PATCH 025/463] pom.xml: update Togglz to 2.3.0.RELEASE @see https://www.togglz.org/whats-new.html No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 88f94055ad..1a8f207206 100644 --- a/pom.xml +++ b/pom.xml @@ -440,7 +440,7 @@ 2.1.5.RELEASE - 2.2.0.Final + 2.3.0.Final 3.0.0 From d9abc0502ae5efd2f4c60f92f4db21818edbcb99 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 13:32:22 +0200 Subject: [PATCH 026/463] pom.xml: update thymeleaf-extras-togglz to 1.1.0.RELEASE No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1a8f207206..e9374d8ddf 100644 --- a/pom.xml +++ b/pom.xml @@ -435,7 +435,7 @@ 2.1.2.RELEASE - 1.0.1.RELEASE + 1.1.0.RELEASE 2.1.5.RELEASE From 4aea781d91158616bc0029c2a8c3aa438303e0e1 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 13:42:13 +0200 Subject: [PATCH 027/463] pom.xml: update Selectize.JS to 0.12.3 @see https://github.com/selectize/selectize.js/releases/tag/v0.12.2 @see https://github.com/selectize/selectize.js/releases/tag/v0.12.3 No functional changes. --- pom.xml | 2 +- src/main/java/ru/mystamps/web/Url.java | 8 ++++---- src/main/webapp/WEB-INF/views/series/add.html | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index e9374d8ddf..b4fde06218 100644 --- a/pom.xml +++ b/pom.xml @@ -407,7 +407,7 @@ 2.7 - 0.12.1 + 0.12.3 2.21 2.53.1 diff --git a/src/main/java/ru/mystamps/web/Url.java b/src/main/java/ru/mystamps/web/Url.java index 843c8f596e..1b8e075ddf 100644 --- a/src/main/java/ru/mystamps/web/Url.java +++ b/src/main/java/ru/mystamps/web/Url.java @@ -96,16 +96,16 @@ public final class Url { // CheckStyle: ignore LineLength for next 3 lines // TODO: use minimal version of CSS file when it will be available (https://github.com/webjars/selectize.js/issues/3) - public static final String SELECTIZE_CSS = "/public/selectize/0.12.1/css/selectize.bootstrap3.css"; - public static final String SELECTIZE_JS = "/public/selectize/0.12.1/js/standalone/selectize.min.js"; + public static final String SELECTIZE_CSS = "/public/selectize/0.12.3/css/selectize.bootstrap3.css"; + public static final String SELECTIZE_JS = "/public/selectize/0.12.3/js/standalone/selectize.min.js"; // see also pom.xml and ru.mystamps.web.config.MvcConfig#addResourceHandlers() // CheckStyle: ignore LineLength for next 5 lines public static final String BOOTSTRAP_CSS_CDN = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"; public static final String BOOTSTRAP_JS_CDN = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"; public static final String JQUERY_JS_CDN = "https://yandex.st/jquery/1.9.1/jquery.min.js"; - public static final String SELECTIZE_CSS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css"; - public static final String SELECTIZE_JS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js"; + public static final String SELECTIZE_CSS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.3/css/selectize.bootstrap3.min.css"; + public static final String SELECTIZE_JS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.3/js/standalone/selectize.min.js"; // see also ru.mystamps.web.support.togglz.TogglzConfig#getTogglzConsole() public static final String TOGGLZ_CONSOLE_PAGE = "/togglz"; diff --git a/src/main/webapp/WEB-INF/views/series/add.html b/src/main/webapp/WEB-INF/views/series/add.html index a60c55252b..30e030a104 100644 --- a/src/main/webapp/WEB-INF/views/series/add.html +++ b/src/main/webapp/WEB-INF/views/series/add.html @@ -13,7 +13,7 @@ - +
    @@ -461,7 +461,7 @@

    - + From c883990672cf450cebe629bee0343147b7013691 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 13:52:50 +0200 Subject: [PATCH 028/463] .travis.yml: publish code coverage for all branches. This should allow Codecoverage bot to show messages in pull requests. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da2b7649a2..baba937105 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ script: fi after_success: - - if [ "$TRAVIS_BRANCH" = 'master' -a "$TRAVIS_PULL_REQUEST" = 'false' -a "$SPRING_PROFILES_ACTIVE" = 'travis' ]; then + - if [ "$SPRING_PROFILES_ACTIVE" = 'travis' ]; then ./src/main/scripts/ci/publish-code-coverage.sh; fi From 682e2e7090266e112e334f01bf85189e78afbf59 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 14:20:17 +0200 Subject: [PATCH 029/463] pom.xml: update Liquinase to 3.5.1 @see http://www.liquibase.org/2016/04/liquibase-3-5-0-released.html @see http://www.liquibase.org/2016/05/liquibase-3-5-1-released.html No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b4fde06218..84a7273f8c 100644 --- a/pom.xml +++ b/pom.xml @@ -394,7 +394,7 @@ 1.9.0 - 3.4.2 + 3.5.1 1.16.10 1.7.4 From 4b630132ed993b514f5d16846807ab872a203c56 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 14:50:55 +0200 Subject: [PATCH 030/463] TranslationUtils: replace IOUtils.closeQuietly() by try-with-resources. No functional changes. --- pom.xml | 8 -------- .../ru/mystamps/web/tests/TranslationUtils.java | 16 +++++++--------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 84a7273f8c..1f6a7ca640 100644 --- a/pom.xml +++ b/pom.xml @@ -16,13 +16,6 @@ ${thymeleaf.togglz.version} - - - commons-io - commons-io - ${commons.io.version} - - javax.validation validation-api @@ -353,7 +346,6 @@ 1.5.4 - 2.4 3.4 3.5.1 2.2.0 diff --git a/src/test/java/ru/mystamps/web/tests/TranslationUtils.java b/src/test/java/ru/mystamps/web/tests/TranslationUtils.java index ec0eabd688..515df41d27 100644 --- a/src/test/java/ru/mystamps/web/tests/TranslationUtils.java +++ b/src/test/java/ru/mystamps/web/tests/TranslationUtils.java @@ -25,8 +25,6 @@ import java.util.PropertyResourceBundle; import java.util.ResourceBundle; -import org.apache.commons.io.IOUtils; - public final class TranslationUtils { private static final String [] PROPERTIES_FILE_NAMES = new String[] { @@ -49,19 +47,19 @@ private TranslationUtils() { } private static ResourceBundle getResourceBundleForFile(String filename) { - FileInputStream stream = null; + File file; try { - File file = new File( + file = new File( TranslationUtils.class.getClassLoader().getResource(filename).toURI() ); - stream = new FileInputStream(file); + } catch (URISyntaxException ex) { + throw new RuntimeException(ex); + } + try (FileInputStream stream = new FileInputStream(file)) { return new PropertyResourceBundle(stream); - } catch (IOException | URISyntaxException ex) { + } catch (IOException ex) { throw new RuntimeException(ex); - - } finally { - IOUtils.closeQuietly(stream); } } From 9bb4d703deab983e45a9f7ecd5da5a6d0b368ff9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 27 Sep 2016 15:00:26 +0200 Subject: [PATCH 031/463] pom.xml(sortpom-maven-plugin): update to 2.5.0 @see https://github.com/Ekryd/sortpom#news No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1f6a7ca640..77fc1b85fa 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ 1.7.21 - 2.4.0 + 2.5.0 1.0-groovy-2.0 From c9e9f6b195c1d824b3a0aaea9b51cdff7188eac6 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 17:17:02 +0200 Subject: [PATCH 032/463] Configure MySQL connector to log messages in slf4j. See also: http://stackoverflow.com/questions/10903206/enabling-mysql-general-query-log-with-jdbc Related to #420 --- src/main/resources/application-prod.properties | 2 +- src/main/resources/application-travis.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index d70b1f12d8..c742691a62 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,6 +1,6 @@ spring.profiles: prod -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger spring.datasource.username: mystamps spring.datasource.password: q1 spring.datasource.driver-class-name: com.mysql.jdbc.Driver diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index 729eaea12c..4c33e3430d 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -1,6 +1,6 @@ spring.profiles: travis -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger spring.datasource.username: travis spring.datasource.password: spring.datasource.driver-class-name: com.mysql.jdbc.Driver From 3e9ba2b3f48563e0b4fc187b6c4214b84854b702 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 17:20:09 +0200 Subject: [PATCH 033/463] Configure MySQL connector to not try to use SSL. This removes the following warning from the logs: WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Fix #420 --- src/main/resources/application-prod.properties | 2 +- src/main/resources/application-travis.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index c742691a62..6857ea8d26 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,6 +1,6 @@ spring.profiles: prod -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false spring.datasource.username: mystamps spring.datasource.password: q1 spring.datasource.driver-class-name: com.mysql.jdbc.Driver diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index 4c33e3430d..762a197eeb 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -1,6 +1,6 @@ spring.profiles: travis -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false spring.datasource.username: travis spring.datasource.password: spring.datasource.driver-class-name: com.mysql.jdbc.Driver From f00a1adf916687545b03164873a9b5588ea72435 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 17:36:07 +0200 Subject: [PATCH 034/463] Configure MySQL connector to log queries that are slower than 500ms. For travis profile I also enabled explainSlowQueries parameter. @see http://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html No functional changes. --- src/main/resources/application-prod.properties | 2 +- src/main/resources/application-travis.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 6857ea8d26..447c523fa5 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,6 +1,6 @@ spring.profiles: prod -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false&logSlowQueries=true&slowQueryThresholdMillis=500&autoSlowLog=false spring.datasource.username: mystamps spring.datasource.password: q1 spring.datasource.driver-class-name: com.mysql.jdbc.Driver diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index 762a197eeb..92a521f864 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -1,6 +1,6 @@ spring.profiles: travis -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false&logSlowQueries=true&slowQueryThresholdMillis=500&autoSlowLog=false&explainSlowQueries=true spring.datasource.username: travis spring.datasource.password: spring.datasource.driver-class-name: com.mysql.jdbc.Driver From 26bab71f5f156957fc8b5e7d28d066090425a102 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 17:46:51 +0200 Subject: [PATCH 035/463] application-prod.properties: sync Vagrant's version of the configuration. Should be in 581f592cd64f0d928d532dec038f9a5a3de1b5b1, 423f0da6f1772e56822557199c435df8337d8599 and e9473ae8a99fd6176b07b2d793969be26f5c5689 commits. Addressed to #420 [ci skip] --- .../roles/mystamps-app/templates/application-prod.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties index 66e1336d8f..b49313fab2 100644 --- a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties +++ b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties @@ -1,6 +1,6 @@ spring.profiles: prod -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps +spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false&logSlowQueries=true&slowQueryThresholdMillis=500&autoSlowLog=false spring.datasource.username: mystamps spring.datasource.password: {{ user_db_password }} spring.datasource.driver-class-name: com.mysql.jdbc.Driver From 9b72ad69fb0301f92a5b0598ae4c5f3a866d1f42 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 21:41:31 +0200 Subject: [PATCH 036/463] src/main/resources/application-prod.properties: remove. Use vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties instead. [ci skip] --- .../resources/application-prod.properties | 97 ------------------- 1 file changed, 97 deletions(-) delete mode 100644 src/main/resources/application-prod.properties diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties deleted file mode 100644 index 447c523fa5..0000000000 --- a/src/main/resources/application-prod.properties +++ /dev/null @@ -1,97 +0,0 @@ -spring.profiles: prod - -spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false&logSlowQueries=true&slowQueryThresholdMillis=500&autoSlowLog=false -spring.datasource.username: mystamps -spring.datasource.password: q1 -spring.datasource.driver-class-name: com.mysql.jdbc.Driver -spring.datasource.initialize: false -spring.datasource.validation-query: SELECT 1 -spring.datasource.test-on-borrow: true - -spring.mail.host: 127.0.0.1 -spring.mail.port: 25 -spring.mail.username: test -spring.mail.password: test - -spring.messages.cache-seconds: -1 -spring.messages.fallback-to-system-locale: false -spring.messages.basename: \ - ru/mystamps/i18n/Messages, \ - ru/mystamps/i18n/ValidationMessages, \ - ru/mystamps/i18n/SpringSecurityMessages, \ - ru/mystamps/i18n/MailTemplates - -spring.thymeleaf.prefix: /WEB-INF/views/ -spring.thymeleaf.suffix: .html -spring.thymeleaf.cache: true - -# see also duplicate definition at pom.xml -liquibase.contexts: scheme, init-data, prod-data -liquibase.change-log: classpath:/liquibase/changelog.xml - -logging.file: /data/logs/mystamps.log -logging.level.: INFO -logging.level.ru.mystamps: DEBUG - -app.upload.dir: /data/uploads - -server.session.cookie.secure: true - -# the difference between test profile is that we don't need SpringApplicationAdminJmxAutoConfiguration -spring.autoconfigure.exclude: \ - org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration \ - , org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration \ - , org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration \ - , org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration \ - , org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration \ - , org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration \ - , org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration \ - , org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration \ - , org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration \ - , org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration \ - , org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration \ - , org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration \ - , org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration \ - , org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration \ - , org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration \ - , org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration \ - , org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration \ - , org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration \ - , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ - , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ - , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ - , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ - , org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration \ - , org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration \ - , org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration \ - , org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration \ - , org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration \ - , org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration \ - , org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration \ - , org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration \ - , org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration \ - , org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration \ - , org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration \ - , org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration \ - , org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration \ - , org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration \ - , org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration \ - , org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration \ - , org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration \ - , org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration \ - , org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration \ - , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ - , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ - \ - , org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration \ - # From f8a3fd6a4352adf5cb5bdf34fde7b8a1171d5a2d Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 23:18:46 +0200 Subject: [PATCH 037/463] Exclude snakeyaml from WAR file. Correction for d4be7581dcea3630e240d10c7ca5c83a66bab59d commit. [ci skip] No functional changes. --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 77fc1b85fa..15b9c35842 100644 --- a/pom.xml +++ b/pom.xml @@ -196,6 +196,12 @@ liquibase-core ${liquibase.version} runtime + + + org.yaml + snakeyaml + + From a21dc8e4217127e5827cd334193f262521d9e61b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 23:22:57 +0200 Subject: [PATCH 038/463] pom.xml: ban snakeyaml artifact. No functional changes. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 15b9c35842..ee0db610bd 100644 --- a/pom.xml +++ b/pom.xml @@ -628,6 +628,7 @@ commons-logging junit:*:*:*:compile + org.yaml:snakeyaml From 66be9201ecf223ef9826db85d3f36d5ccf0851a5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 30 Sep 2016 23:30:11 +0200 Subject: [PATCH 039/463] Unbreak deploy. With ansible 2.1.2.0 deployment fails with assertion: TASK [Ensuring that WAR file exists] ******************************************* fatal: [my-stamps.ru -> 127.0.0.1]: FAILED! => {"assertion": "war_file.stat.exists", "changed": false, "evaluated_to": false, "failed": true} --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index baba937105..14989e98aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_script: - if [ "$SPRING_PROFILES_ACTIVE" = 'travis' ]; then mysql -u travis -e 'CREATE DATABASE mystamps CHARACTER SET utf8;'; if [ "$TRAVIS_BRANCH" = 'prod' ]; then - pip install --user ansible; + pip install --user ansible==2.1.1.0; fi; npm install -g bootlint; pip install --user html5validator; From 597e719917c8bd213c72edbffec7b097fec8f863 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 22 Sep 2016 18:20:20 +0200 Subject: [PATCH 040/463] pom.xml: update Spring Boot to 1.4.1.RELEASE. @see https://spring.io/blog/2016/02/26/spring-boot-1-3-3-and-1-4-0-m1-available-now @see https://spring.io/blog/2016/04/13/spring-boot-1-4-0-m2-available-now @see https://spring.io/blog/2016/05/17/spring-boot-1-4-0-m3-available-now @see https://spring.io/blog/2016/07/05/spring-boot-1-4-0-rc1-available-now @see https://spring.io/blog/2016/07/28/spring-boot-1-4-released @see https://spring.io/blog/2016/09/21/spring-boot-1-4-1-and-1-3-8-available-now @see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes @see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Configuration-Changelog This also updates: * Spring Framework to 4.3.3.RELEASE - https://spring.io/blog/2016/04/06/spring-framework-4-3-goes-rc1 - https://spring.io/blog/2016/05/06/spring-framework-4-3-rc2-4-2-6-and-3-2-17-available-now - https://spring.io/blog/2016/06/10/spring-framework-4-3-goes-ga - https://spring.io/blog/2016/07/04/spring-framework-4-3-1-and-4-2-7-available-now - https://spring.io/blog/2016/09/19/spring-framework-4-3-3-and-4-2-8-available-now * Spring Security to 4.1.3.RELEASE - https://spring.io/blog/2016/03/24/spring-security-4-1-0-rc1-released - https://spring.io/blog/2016/04/21/spring-security-4-1-0-rc2-released - https://spring.io/blog/2016/05/05/spring-security-4-1-0-released - https://spring.io/blog/2016/07/07/spring-security-4-1-1-released - https://spring.io/blog/2016/08/12/spring-security-4-1-2-released - https://spring.io/blog/2016/08/24/spring-security-4-1-3-released No functional changes. --- pom.xml | 64 +++++++++++-------- .../FilesystemImagePersistenceStrategy.java | 3 +- .../resources/application-travis.properties | 4 +- src/main/resources/application.properties | 10 +-- src/test/resources/logback-test.xml | 2 +- .../templates/application-prod.properties | 4 +- 6 files changed, 49 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index ee0db610bd..1a3547e7a5 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ ${slf4j.version} - + org.springframework.boot spring-boot-starter @@ -52,7 +52,7 @@ - + org.springframework.boot spring-boot-starter-jdbc @@ -64,7 +64,7 @@ - + org.springframework.boot spring-boot-starter-jetty @@ -80,25 +80,25 @@ - + org.springframework.boot spring-boot-starter-logging - + org.springframework.boot spring-boot-starter-mail - + org.springframework.boot spring-boot-starter-security - + org.springframework.boot spring-boot-starter-thymeleaf @@ -110,13 +110,13 @@ - + org.springframework.boot spring-boot-starter-validation - + org.springframework.boot spring-boot-starter-web @@ -308,6 +308,16 @@ test + + + org.springframework.boot + spring-boot-test + test + + org.subethamail subethasmtp @@ -332,10 +342,10 @@ - + org.springframework.boot spring-boot-starter-parent - 1.3.7.RELEASE + 1.4.1.RELEASE @@ -346,10 +356,10 @@ 2.17 3.0.0 - + 1.4 - + 1.5.4 3.4 @@ -361,29 +371,29 @@ 1.4 1.5 - + 2.0.8 - + 1.4.192 - + 5.2.4.Final 0.7.7.201606060606 2.2 - + 1.8 2.10.4 - + 1.5.4 1.1.0.Final - + 9.2.18.v20160721 @@ -391,13 +401,13 @@ 1.9.0 - + 3.5.1 1.16.10 1.7.4 - + 5.1.39 1.0-beta-1 @@ -410,32 +420,32 @@ 2.21 2.53.1 - + 3.1.0 false - + 1.7.21 2.5.0 - + 1.0-groovy-2.0 - + ru.mystamps.web.support.spring.boot.ApplicationBootstrap 3.1.7 2.19.1 6.8.8 - + 2.1.2.RELEASE 1.1.0.RELEASE - + 2.1.5.RELEASE 2.3.0.Final diff --git a/src/main/java/ru/mystamps/web/service/FilesystemImagePersistenceStrategy.java b/src/main/java/ru/mystamps/web/service/FilesystemImagePersistenceStrategy.java index 082109758d..a6b48bb0f9 100644 --- a/src/main/java/ru/mystamps/web/service/FilesystemImagePersistenceStrategy.java +++ b/src/main/java/ru/mystamps/web/service/FilesystemImagePersistenceStrategy.java @@ -99,7 +99,8 @@ protected Path createFile(ImageInfoDto image) { // protected to allow spying protected void writeToFile(MultipartFile file, Path dest) throws IOException { // we can't use file.transferTo(dest) there because it creates file - // relatively to directory from multipart.location in application.properties + // relatively to directory from spring.http.multipart.location + // in application.properties // See for details: https://jira.spring.io/browse/SPR-12650 Files.copy(file.getInputStream(), dest); } diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index 92a521f864..f95e0e5ec6 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -5,8 +5,8 @@ spring.datasource.username: travis spring.datasource.password: spring.datasource.driver-class-name: com.mysql.jdbc.Driver spring.datasource.initialize: false -spring.datasource.validation-query: SELECT 1 -spring.datasource.test-on-borrow: true +spring.datasource.dbcp.validation-query: SELECT 1 +spring.datasource.dbcp.test-on-borrow: true spring.mail.host: 127.0.0.1 spring.mail.port: 1025 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c7d1bd38e3..bfe22d27ce 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -12,11 +12,11 @@ spring.mvc.favicon.enabled: false spring.cache.type: none -# See for details: http://docs.spring.io/autorepo/docs/spring-boot/current/api/org/springframework/boot/autoconfigure/web/MultipartProperties.html -multipart.location: /tmp -multipart.max-request-size: 10Mb -multipart.max-file-size: 5Mb -multipart.file-size-threshold: 1Mb +# See for details: http://docs.spring.io/autorepo/docs/spring-boot/1.4.1.RELEASE/api/org/springframework/boot/autoconfigure/web/MultipartProperties.html +spring.http.multipart.location: /tmp +spring.http.multipart.max-request-size: 10Mb +spring.http.multipart.max-file-size: 5Mb +spring.http.multipart.file-size-threshold: 1Mb server.session.cookie.http-only: true diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index 306e2321ab..ae4bbf222d 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -3,7 +3,7 @@ diff --git a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties index b49313fab2..7d2e144aa6 100644 --- a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties +++ b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties @@ -5,8 +5,8 @@ spring.datasource.username: mystamps spring.datasource.password: {{ user_db_password }} spring.datasource.driver-class-name: com.mysql.jdbc.Driver spring.datasource.initialize: false -spring.datasource.validation-query: SELECT 1 -spring.datasource.test-on-borrow: true +spring.datasource.dbcp.validation-query: SELECT 1 +spring.datasource.dbcp.test-on-borrow: true spring.mail.host: smtp.mailgun.org spring.mail.port: 25 From 8f11bea8f35a215784aa0c050ca0c421ce19549b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 22 Sep 2016 18:35:34 +0200 Subject: [PATCH 041/463] Fix warnings about using deprecated classes. No functional changes. --- .../spring/boot/ErrorPagesServletContainerCustomizer.java | 2 +- src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java | 2 +- .../java/ru/mystamps/web/tests/cases/WhenAnyUserAtAnyPage.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/mystamps/web/support/spring/boot/ErrorPagesServletContainerCustomizer.java b/src/main/java/ru/mystamps/web/support/spring/boot/ErrorPagesServletContainerCustomizer.java index 6d0167fedb..17420478ff 100644 --- a/src/main/java/ru/mystamps/web/support/spring/boot/ErrorPagesServletContainerCustomizer.java +++ b/src/main/java/ru/mystamps/web/support/spring/boot/ErrorPagesServletContainerCustomizer.java @@ -22,7 +22,7 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.ErrorPage; +import org.springframework.boot.web.servlet.ErrorPage; import ru.mystamps.web.Url; diff --git a/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java b/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java index eed0ffd5a3..d80b52aece 100644 --- a/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java +++ b/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.boot.context.embedded.ServletRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; import com.github.heneke.thymeleaf.togglz.TogglzDialect; import org.togglz.console.TogglzConsoleServlet; diff --git a/src/test/java/ru/mystamps/web/tests/cases/WhenAnyUserAtAnyPage.java b/src/test/java/ru/mystamps/web/tests/cases/WhenAnyUserAtAnyPage.java index bb9e8f9d03..75c32bc467 100644 --- a/src/test/java/ru/mystamps/web/tests/cases/WhenAnyUserAtAnyPage.java +++ b/src/test/java/ru/mystamps/web/tests/cases/WhenAnyUserAtAnyPage.java @@ -21,7 +21,7 @@ import org.openqa.selenium.support.PageFactory; -import org.springframework.boot.test.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.support.AnnotationConfigContextLoader; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; From 0993d449e9a69df96247c294e8113ceb71e387c6 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 22 Sep 2016 19:56:52 +0200 Subject: [PATCH 042/463] Use implicit constructor injection instead of @Autowired on fields. @see https://spring.io/blog/2016/03/04/core-container-refinements-in-spring-framework-4-3#implicit-constructor-injection-for-single-constructor-scenarios No functional changes. --- .../web/config/ControllersConfig.java | 11 ++++---- .../ru/mystamps/web/config/DaoConfig.java | 11 ++++---- .../ru/mystamps/web/config/MvcConfig.java | 7 ++--- .../mystamps/web/config/ServicesConfig.java | 27 +++++++------------ .../mystamps/web/config/StrategiesConfig.java | 11 ++++---- .../web/support/togglz/TogglzConfig.java | 8 +++--- .../ExistingActivationKeyValidator.java | 6 ++--- .../jsr303/UniqueCategoryNameValidator.java | 6 ++--- .../jsr303/UniqueCountryNameValidator.java | 6 ++--- .../jsr303/UniqueLoginValidator.java | 6 ++--- 10 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/main/java/ru/mystamps/web/config/ControllersConfig.java b/src/main/java/ru/mystamps/web/config/ControllersConfig.java index c94b41959b..8681c3836d 100644 --- a/src/main/java/ru/mystamps/web/config/ControllersConfig.java +++ b/src/main/java/ru/mystamps/web/config/ControllersConfig.java @@ -17,22 +17,21 @@ */ package ru.mystamps.web.config; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import lombok.RequiredArgsConstructor; + // CheckStyle: ignore AvoidStarImportCheck for next 1 line import ru.mystamps.web.controller.*; // NOPMD: UnusedImports @Configuration +@RequiredArgsConstructor public class ControllersConfig { - @Autowired - private ServicesConfig servicesConfig; - - @Autowired - private MessageSource messageSource; + private final ServicesConfig servicesConfig; + private final MessageSource messageSource; @Bean public AccountController getAccountController() { diff --git a/src/main/java/ru/mystamps/web/config/DaoConfig.java b/src/main/java/ru/mystamps/web/config/DaoConfig.java index 511be360e8..cfc1a8531c 100644 --- a/src/main/java/ru/mystamps/web/config/DaoConfig.java +++ b/src/main/java/ru/mystamps/web/config/DaoConfig.java @@ -17,26 +17,25 @@ */ package ru.mystamps.web.config; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import lombok.RequiredArgsConstructor; + // CheckStyle: ignore AvoidStarImportCheck for next 2 lines import ru.mystamps.web.dao.*; // NOPMD: UnusedImports import ru.mystamps.web.dao.impl.*; // NOPMD: UnusedImports @Configuration @PropertySource("classpath:/sql/stamps_catalog_dao_queries.properties") +@RequiredArgsConstructor public class DaoConfig { - @Autowired - private NamedParameterJdbcTemplate jdbcTemplate; - - @Autowired - private Environment env; + private final NamedParameterJdbcTemplate jdbcTemplate; + private final Environment env; @Bean public CategoryDao getCategoryDao() { diff --git a/src/main/java/ru/mystamps/web/config/MvcConfig.java b/src/main/java/ru/mystamps/web/config/MvcConfig.java index 72f8f6e8a4..cf6a42613f 100755 --- a/src/main/java/ru/mystamps/web/config/MvcConfig.java +++ b/src/main/java/ru/mystamps/web/config/MvcConfig.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Locale; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -41,6 +40,8 @@ import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.servlet.i18n.SessionLocaleResolver; +import lombok.RequiredArgsConstructor; + import ru.mystamps.web.Url; import ru.mystamps.web.controller.converter.LinkEntityDtoGenericConverter; import ru.mystamps.web.support.spring.security.CurrentUserArgumentResolver; @@ -48,10 +49,10 @@ @Configuration @EnableScheduling @Import(ControllersConfig.class) +@RequiredArgsConstructor public class MvcConfig extends WebMvcConfigurerAdapter { - @Autowired - private ServicesConfig servicesConfig; + private final ServicesConfig servicesConfig; @Override public void addFormatters(FormatterRegistry registry) { diff --git a/src/main/java/ru/mystamps/web/config/ServicesConfig.java b/src/main/java/ru/mystamps/web/config/ServicesConfig.java index 4413942734..fac9963555 100644 --- a/src/main/java/ru/mystamps/web/config/ServicesConfig.java +++ b/src/main/java/ru/mystamps/web/config/ServicesConfig.java @@ -19,7 +19,6 @@ import java.util.Locale; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -27,31 +26,23 @@ import org.springframework.mail.javamail.JavaMailSender; import org.springframework.scheduling.annotation.EnableAsync; +import lombok.RequiredArgsConstructor; + // CheckStyle: ignore AvoidStarImportCheck for next 1 line import ru.mystamps.web.service.*; // NOPMD: UnusedImports import ru.mystamps.web.support.spring.security.SecurityConfig; @Configuration @EnableAsync +@RequiredArgsConstructor public class ServicesConfig { - @Autowired - private DaoConfig daoConfig; - - @Autowired - private SecurityConfig securityConfig; - - @Autowired - private StrategiesConfig strategiesConfig; - - @Autowired - private JavaMailSender mailSender; - - @Autowired - private Environment env; - - @Autowired - private MessageSource messageSource; + private final DaoConfig daoConfig; + private final SecurityConfig securityConfig; + private final StrategiesConfig strategiesConfig; + private final JavaMailSender mailSender; + private final Environment env; + private final MessageSource messageSource; @Bean public SuspiciousActivityService getSuspiciousActivityService() { diff --git a/src/main/java/ru/mystamps/web/config/StrategiesConfig.java b/src/main/java/ru/mystamps/web/config/StrategiesConfig.java index 22b3cd189c..1d2c22aecb 100644 --- a/src/main/java/ru/mystamps/web/config/StrategiesConfig.java +++ b/src/main/java/ru/mystamps/web/config/StrategiesConfig.java @@ -17,12 +17,13 @@ */ package ru.mystamps.web.config; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; +import lombok.RequiredArgsConstructor; + import ru.mystamps.web.service.DatabaseImagePersistenceStrategy; import ru.mystamps.web.service.FilesystemImagePersistenceStrategy; import ru.mystamps.web.service.ImagePersistenceStrategy; @@ -33,10 +34,10 @@ public interface StrategiesConfig { ImagePersistenceStrategy getImagePersistenceStrategy(); @Profile("test") + @RequiredArgsConstructor class DbStrategiesConfig implements StrategiesConfig { - @Autowired - private DaoConfig daoConfig; + private final DaoConfig daoConfig; @Bean @Override @@ -47,10 +48,10 @@ public ImagePersistenceStrategy getImagePersistenceStrategy() { } @Profile({ "prod", "travis" }) + @RequiredArgsConstructor class FsStrategiesConfig implements StrategiesConfig { - @Autowired - private Environment env; + private final Environment env; @Bean @Override diff --git a/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java b/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java index d80b52aece..b4a0f33f1d 100644 --- a/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java +++ b/src/main/java/ru/mystamps/web/support/togglz/TogglzConfig.java @@ -21,7 +21,6 @@ import javax.sql.DataSource; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,14 +34,15 @@ import org.togglz.core.repository.jdbc.JDBCStateRepository; import org.togglz.spring.security.SpringSecurityUserProvider; +import lombok.RequiredArgsConstructor; + import ru.mystamps.web.Url; import ru.mystamps.web.support.spring.security.StringAuthority; @Configuration +@RequiredArgsConstructor public class TogglzConfig { - - @Autowired - private DataSource dataSource; + private final DataSource dataSource; @Bean public FeatureManager getFeatureManager() { diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/ExistingActivationKeyValidator.java b/src/main/java/ru/mystamps/web/validation/jsr303/ExistingActivationKeyValidator.java index 25033baa13..e1228e12ca 100644 --- a/src/main/java/ru/mystamps/web/validation/jsr303/ExistingActivationKeyValidator.java +++ b/src/main/java/ru/mystamps/web/validation/jsr303/ExistingActivationKeyValidator.java @@ -20,15 +20,15 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import ru.mystamps.web.service.UsersActivationService; +@RequiredArgsConstructor public class ExistingActivationKeyValidator implements ConstraintValidator { - @Autowired - private UsersActivationService usersActivationService; + private final UsersActivationService usersActivationService; @Override public void initialize(ExistingActivationKey annotation) { diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategoryNameValidator.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategoryNameValidator.java index cb6da8def9..3d45ac0bc4 100644 --- a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategoryNameValidator.java +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategoryNameValidator.java @@ -20,16 +20,16 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import ru.mystamps.web.service.CategoryService; import ru.mystamps.web.validation.jsr303.UniqueCategoryName.Lang; +@RequiredArgsConstructor public class UniqueCategoryNameValidator implements ConstraintValidator { - @Autowired - private CategoryService categoryService; + private final CategoryService categoryService; private Lang lang; diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountryNameValidator.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountryNameValidator.java index e54fde42d2..80eb85e8a4 100644 --- a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountryNameValidator.java +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountryNameValidator.java @@ -20,15 +20,15 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import ru.mystamps.web.service.CountryService; import ru.mystamps.web.validation.jsr303.UniqueCountryName.Lang; +@RequiredArgsConstructor public class UniqueCountryNameValidator implements ConstraintValidator { - @Autowired - private CountryService countryService; + private final CountryService countryService; private Lang lang; diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueLoginValidator.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueLoginValidator.java index f8141fe94c..71aa594063 100644 --- a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueLoginValidator.java +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueLoginValidator.java @@ -20,14 +20,14 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import ru.mystamps.web.service.UserService; +@RequiredArgsConstructor public class UniqueLoginValidator implements ConstraintValidator { - @Autowired - private UserService userService; + private final UserService userService; @Override public void initialize(UniqueLogin annotation) { From 3f68816e89ad0d8109df3a4567604c53a21a5133 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 23 Sep 2016 13:57:28 +0200 Subject: [PATCH 043/463] MvcConfig: remove temporary workaround for CVE-2016-5007. No functional changes. --- src/main/java/ru/mystamps/web/config/MvcConfig.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/ru/mystamps/web/config/MvcConfig.java b/src/main/java/ru/mystamps/web/config/MvcConfig.java index cf6a42613f..a23d019768 100755 --- a/src/main/java/ru/mystamps/web/config/MvcConfig.java +++ b/src/main/java/ru/mystamps/web/config/MvcConfig.java @@ -26,7 +26,6 @@ import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.springframework.format.FormatterRegistry; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.util.AntPathMatcher; import org.springframework.validation.Validator; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -120,13 +119,6 @@ public void addInterceptors(InterceptorRegistry registry) { @Override public void configurePathMatch(PathMatchConfigurer configurer) { - // This is a temporary guard against CVE-2016-5007. - // Should be removed after upgrading to Spring MVC 4.3.1+ and Spring Security 4.1.1+. - // See also: http://pivotal.io/security/cve-2016-5007 - AntPathMatcher pathMatcher = new AntPathMatcher(); - pathMatcher.setTrimTokens(false); - configurer.setPathMatcher(pathMatcher); - // If enabled a method mapped to "/users" also matches to "/users/" configurer.setUseTrailingSlashMatch(false); // If enabled a method mapped to "/users" also matches to "/users.*" From 60f666a8e560c5e1daeb06f817465d658e6679b7 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 23 Sep 2016 23:27:45 +0200 Subject: [PATCH 044/463] Replace @RequestMapping by @GetMapping/@PostMapping. No functional changes. --- .../web/controller/AccountController.java | 14 ++++----- .../web/controller/CategoryController.java | 14 ++++----- .../web/controller/CollectionController.java | 6 ++-- .../web/controller/CountryController.java | 14 ++++----- .../web/controller/ImageController.java | 4 +-- .../web/controller/RobotsTxtController.java | 4 +-- .../web/controller/SeriesController.java | 30 +++++++------------ .../web/controller/SiteController.java | 6 ++-- .../web/controller/SitemapController.java | 4 +-- 9 files changed, 44 insertions(+), 52 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/AccountController.java b/src/main/java/ru/mystamps/web/controller/AccountController.java index ffe1bf3e2b..4c22d1136b 100644 --- a/src/main/java/ru/mystamps/web/controller/AccountController.java +++ b/src/main/java/ru/mystamps/web/controller/AccountController.java @@ -27,10 +27,10 @@ import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import lombok.RequiredArgsConstructor; @@ -65,12 +65,12 @@ protected void activationInitBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, "name", new StringTrimmerEditor(true)); } - @RequestMapping(Url.REGISTRATION_PAGE) + @GetMapping(Url.REGISTRATION_PAGE) public RegisterAccountForm showRegistrationForm() { return new RegisterAccountForm(); } - @RequestMapping(value = Url.REGISTRATION_PAGE, method = RequestMethod.POST) + @PostMapping(Url.REGISTRATION_PAGE) public String processRegistrationForm( @Valid RegisterAccountForm form, BindingResult result, @@ -88,12 +88,12 @@ public String processRegistrationForm( return "redirect:" + Url.ACTIVATE_ACCOUNT_PAGE; } - @RequestMapping(Url.ACTIVATE_ACCOUNT_PAGE) + @GetMapping(Url.ACTIVATE_ACCOUNT_PAGE) public ActivateAccountForm showActivationForm() { return new ActivateAccountForm(); } - @RequestMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY) + @GetMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY) public String showActivationFormWithKey( @PathVariable("key") String activationKey, Model model) { @@ -105,7 +105,7 @@ public String showActivationFormWithKey( return "account/activate"; } - @RequestMapping(value = Url.ACTIVATE_ACCOUNT_PAGE, method = RequestMethod.POST) + @PostMapping(Url.ACTIVATE_ACCOUNT_PAGE) public String processActivationForm( @Validated({ LoginChecks.class, NameChecks.class, PasswordChecks.class, diff --git a/src/main/java/ru/mystamps/web/controller/CategoryController.java b/src/main/java/ru/mystamps/web/controller/CategoryController.java index e664ac8320..841464026b 100644 --- a/src/main/java/ru/mystamps/web/controller/CategoryController.java +++ b/src/main/java/ru/mystamps/web/controller/CategoryController.java @@ -29,10 +29,10 @@ import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.View; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; @@ -68,12 +68,12 @@ protected void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, "nameRu", editor); } - @RequestMapping(Url.ADD_CATEGORY_PAGE) + @GetMapping(Url.ADD_CATEGORY_PAGE) public AddCategoryForm showForm() { return new AddCategoryForm(); } - @RequestMapping(value = Url.ADD_CATEGORY_PAGE, method = RequestMethod.POST) + @PostMapping(Url.ADD_CATEGORY_PAGE) public String processInput( @Valid AddCategoryForm form, BindingResult result, @@ -91,7 +91,7 @@ public String processInput( return redirectTo(Url.INFO_CATEGORY_PAGE, slug); } - @RequestMapping(Url.INFO_CATEGORY_PAGE) + @GetMapping(Url.INFO_CATEGORY_PAGE) public String showInfoBySlug( @Category @PathVariable("slug") LinkEntityDto category, Model model, @@ -117,7 +117,7 @@ public String showInfoBySlug( return "category/info"; } - @RequestMapping(Url.INFO_CATEGORY_BY_ID_PAGE) + @GetMapping(Url.INFO_CATEGORY_BY_ID_PAGE) public View showInfoById( @Category @PathVariable("slug") LinkEntityDto country, HttpServletResponse response) @@ -135,7 +135,7 @@ public View showInfoById( return view; } - @RequestMapping(Url.LIST_CATEGORIES_PAGE) + @GetMapping(Url.LIST_CATEGORIES_PAGE) public void list(Model model, Locale userLocale) { String lang = LocaleUtils.getLanguageOrNull(userLocale); List categories = categoryService.findAllAsLinkEntities(lang); diff --git a/src/main/java/ru/mystamps/web/controller/CollectionController.java b/src/main/java/ru/mystamps/web/controller/CollectionController.java index c19e1bfb3c..f2d761868f 100644 --- a/src/main/java/ru/mystamps/web/controller/CollectionController.java +++ b/src/main/java/ru/mystamps/web/controller/CollectionController.java @@ -27,8 +27,8 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.RedirectView; @@ -53,7 +53,7 @@ public class CollectionController { private final SeriesService seriesService; private final MessageSource messageSource; - @RequestMapping(Url.INFO_COLLECTION_PAGE) + @GetMapping(Url.INFO_COLLECTION_PAGE) public String showInfoBySlug( @PathVariable("slug") String slug, Model model, @@ -102,7 +102,7 @@ public String showInfoBySlug( return "collection/info"; } - @RequestMapping(Url.INFO_COLLECTION_BY_ID_PAGE) + @GetMapping(Url.INFO_COLLECTION_BY_ID_PAGE) public View showInfoById( @PathVariable("slug") String slug, HttpServletResponse response) diff --git a/src/main/java/ru/mystamps/web/controller/CountryController.java b/src/main/java/ru/mystamps/web/controller/CountryController.java index 199326c90f..c0f1706b96 100644 --- a/src/main/java/ru/mystamps/web/controller/CountryController.java +++ b/src/main/java/ru/mystamps/web/controller/CountryController.java @@ -29,10 +29,10 @@ import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.View; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; @@ -66,12 +66,12 @@ protected void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, "nameRu", editor); } - @RequestMapping(Url.ADD_COUNTRY_PAGE) + @GetMapping(Url.ADD_COUNTRY_PAGE) public AddCountryForm showForm() { return new AddCountryForm(); } - @RequestMapping(value = Url.ADD_COUNTRY_PAGE, method = RequestMethod.POST) + @PostMapping(Url.ADD_COUNTRY_PAGE) public String processInput( @Valid AddCountryForm form, BindingResult result, @@ -89,7 +89,7 @@ public String processInput( return redirectTo(Url.INFO_COUNTRY_PAGE, slug); } - @RequestMapping(Url.INFO_COUNTRY_PAGE) + @GetMapping(Url.INFO_COUNTRY_PAGE) public String showInfoBySlug( @Country @PathVariable("slug") LinkEntityDto country, Model model, @@ -118,7 +118,7 @@ public String showInfoBySlug( /** * @author Aleksander Parkhomenko */ - @RequestMapping(Url.INFO_COUNTRY_BY_ID_PAGE) + @GetMapping(Url.INFO_COUNTRY_BY_ID_PAGE) public View showInfoById( @Country @PathVariable("slug") LinkEntityDto country, HttpServletResponse response) @@ -136,7 +136,7 @@ public View showInfoById( return view; } - @RequestMapping(Url.LIST_COUNTRIES_PAGE) + @GetMapping(Url.LIST_COUNTRIES_PAGE) public void list(Model model, Locale userLocale) { String lang = LocaleUtils.getLanguageOrNull(userLocale); List countries = countryService.findAllAsLinkEntities(lang); diff --git a/src/main/java/ru/mystamps/web/controller/ImageController.java b/src/main/java/ru/mystamps/web/controller/ImageController.java index d21f95719d..919017858e 100644 --- a/src/main/java/ru/mystamps/web/controller/ImageController.java +++ b/src/main/java/ru/mystamps/web/controller/ImageController.java @@ -22,8 +22,8 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; import lombok.RequiredArgsConstructor; @@ -37,7 +37,7 @@ public class ImageController { private final ImageService imageService; - @RequestMapping(Url.GET_IMAGE_PAGE) + @GetMapping(Url.GET_IMAGE_PAGE) public void getImage(@PathVariable("id") Integer imageId, HttpServletResponse response) throws IOException { diff --git a/src/main/java/ru/mystamps/web/controller/RobotsTxtController.java b/src/main/java/ru/mystamps/web/controller/RobotsTxtController.java index cb86224395..a22fba5c7b 100644 --- a/src/main/java/ru/mystamps/web/controller/RobotsTxtController.java +++ b/src/main/java/ru/mystamps/web/controller/RobotsTxtController.java @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import ru.mystamps.web.Url; @@ -34,7 +34,7 @@ public class RobotsTxtController { private static final Logger LOG = LoggerFactory.getLogger(RobotsTxtController.class); - @RequestMapping(Url.ROBOTS_TXT) + @GetMapping(Url.ROBOTS_TXT) @SuppressWarnings("PMD.AvoidDuplicateLiterals") public void getRobotsText(HttpServletResponse response) { response.setContentType("text/plain"); diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index e831c658c2..13d0c5cadc 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -40,11 +40,11 @@ import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @@ -124,7 +124,7 @@ public List getCountries(Locale userLocale) { return countryService.findAllAsLinkEntities(lang); } - @RequestMapping(Url.ADD_SERIES_PAGE) + @GetMapping(Url.ADD_SERIES_PAGE) public AddSeriesForm showForm() { AddSeriesForm addSeriesForm = new AddSeriesForm(); @@ -133,7 +133,7 @@ public AddSeriesForm showForm() { return addSeriesForm; } - @RequestMapping(Url.ADD_SERIES_WITH_CATEGORY_PAGE) + @GetMapping(Url.ADD_SERIES_WITH_CATEGORY_PAGE) public String showFormWithCategory( @Category @PathVariable("slug") LinkEntityDto category, Model model) { @@ -147,7 +147,7 @@ public String showFormWithCategory( return "series/add"; } - @RequestMapping(Url.ADD_SERIES_WITH_COUNTRY_PAGE) + @GetMapping(Url.ADD_SERIES_WITH_COUNTRY_PAGE) public String showFormWithCountry( @Country @PathVariable("slug") LinkEntityDto country, Model model) { @@ -161,7 +161,7 @@ public String showFormWithCountry( return "series/add"; } - @RequestMapping(value = Url.ADD_SERIES_PAGE, method = RequestMethod.POST) + @PostMapping(Url.ADD_SERIES_PAGE) public String processInput( @Validated({ Default.class, AddSeriesForm.ReleaseDateChecks.class, @@ -183,7 +183,7 @@ public String processInput( return redirectTo(Url.INFO_SERIES_PAGE, seriesId); } - @RequestMapping(Url.INFO_SERIES_PAGE) + @GetMapping(Url.INFO_SERIES_PAGE) public String showInfo( @PathVariable("id") Integer seriesId, Model model, @@ -215,7 +215,7 @@ public String showInfo( return "series/info"; } - @RequestMapping(value = Url.ADD_IMAGE_SERIES_PAGE, method = RequestMethod.POST) + @PostMapping(Url.ADD_IMAGE_SERIES_PAGE) public String processImage( @Valid AddImageForm form, BindingResult result, @@ -256,11 +256,7 @@ public String processImage( return redirectTo(Url.INFO_SERIES_PAGE, series.getId()); } - @RequestMapping( - value = Url.INFO_SERIES_PAGE, - method = RequestMethod.POST, - params = "action=ADD" - ) + @PostMapping(value = Url.INFO_SERIES_PAGE, params = "action=ADD") public String addToCollection( @PathVariable("id") Integer seriesId, @AuthenticationPrincipal CustomUserDetails currentUserDetails, @@ -289,11 +285,7 @@ public String addToCollection( return redirectTo(Url.INFO_COLLECTION_PAGE, collectionSlug); } - @RequestMapping( - value = Url.INFO_SERIES_PAGE, - method = RequestMethod.POST, - params = "action=REMOVE" - ) + @PostMapping(value = Url.INFO_SERIES_PAGE, params = "action=REMOVE") public String removeFromCollection( @PathVariable("id") Integer seriesId, @CurrentUser Integer currentUserId, @@ -319,7 +311,7 @@ public String removeFromCollection( return redirectTo(Url.INFO_COLLECTION_PAGE, collection.getSlug()); } - @RequestMapping(value = Url.SEARCH_SERIES_BY_CATALOG, method = RequestMethod.POST) + @PostMapping(Url.SEARCH_SERIES_BY_CATALOG) public String searchSeriesByCatalog( @RequestParam("catalogNumber") String catalogNumber, @RequestParam("catalogName") String catalogName, diff --git a/src/main/java/ru/mystamps/web/controller/SiteController.java b/src/main/java/ru/mystamps/web/controller/SiteController.java index 69ad81a669..b9d18d73d7 100644 --- a/src/main/java/ru/mystamps/web/controller/SiteController.java +++ b/src/main/java/ru/mystamps/web/controller/SiteController.java @@ -22,7 +22,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import lombok.RequiredArgsConstructor; @@ -57,7 +57,7 @@ public class SiteController { private final SeriesService seriesService; private final SuspiciousActivityService suspiciousActivityService; - @RequestMapping(Url.INDEX_PAGE) + @GetMapping(Url.INDEX_PAGE) public String showIndexPage(Model model, Locale userLocale) { long categoryCounter = categoryService.countAll(); long countryCounter = countryService.countAll(); @@ -87,7 +87,7 @@ public String showIndexPage(Model model, Locale userLocale) { * @author Sergey Chechenev * @author Slava Semushin */ - @RequestMapping(Url.SITE_EVENTS_PAGE) + @GetMapping(Url.SITE_EVENTS_PAGE) public void viewSiteEvents( @RequestParam(value = "page", defaultValue = "1") int pageNum, Model model) { diff --git a/src/main/java/ru/mystamps/web/controller/SitemapController.java b/src/main/java/ru/mystamps/web/controller/SitemapController.java index d15fe25f63..87db0d8126 100644 --- a/src/main/java/ru/mystamps/web/controller/SitemapController.java +++ b/src/main/java/ru/mystamps/web/controller/SitemapController.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import lombok.RequiredArgsConstructor; @@ -48,7 +48,7 @@ public class SitemapController { private final SeriesService seriesService; - @RequestMapping(Url.SITEMAP_XML) + @GetMapping(Url.SITEMAP_XML) public void getSitemapXml(HttpServletResponse response) { response.setContentType("application/xml"); response.setCharacterEncoding("UTF-8"); From 46cf7b6edf74255fa3ca007ec21e70f13a4fef86 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 24 Sep 2016 00:04:50 +0200 Subject: [PATCH 045/463] application.properties: use configuration from Spring Boot for compressable MIME types. @see spring-boot GH #3592 No functional changes. --- src/main/resources/application.properties | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bfe22d27ce..b4f37c7002 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,11 +24,6 @@ server.use-forward-headers: true server.compression.enabled: true server.compression.min-response-size: 512 -server.compression.mime-types[0]: text/html -server.compression.mime-types[1]: text/plain -server.compression.mime-types[2]: text/css -server.compression.mime-types[3]: application/javascript -server.compression.mime-types[4]: application/xml security.filter-dispatcher-types: REQUEST, ERROR From f24b87e188ebf82e4a8c8bb6911dd2ece08fb13e Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 24 Sep 2016 00:50:02 +0200 Subject: [PATCH 046/463] pom.xml: use versions from POM for Lombok and Selenium. @see spring-boot GH #4598 @see spring-boot GH #5520 @see spring-boot GH #5721 No functional changes. --- pom.xml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1a3547e7a5..e55ea8392c 100644 --- a/pom.xml +++ b/pom.xml @@ -271,7 +271,7 @@ org.seleniumhq.selenium htmlunit-driver - ${selenium.htmlunit.version} + ${htmlunit.version} test @@ -380,6 +380,9 @@ 5.2.4.Final + + 2.20 + 0.7.7.201606060606 2.2 @@ -404,7 +407,9 @@ 3.5.1 + 1.16.10 + 1.7.4 @@ -417,7 +422,7 @@ 0.12.3 - 2.21 + 2.53.1 From 227b32cf3a95a5ffad6154fc28e3b63bbd58d920 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 24 Sep 2016 01:17:04 +0200 Subject: [PATCH 047/463] application.properties: add trace and debug options. @see http://docs.spring.io/spring-boot/docs/1.4.x/reference/htmlsingle/#boot-features-logging-console-output They're disabled by default but can be uncommented during debugging session. No functional changes. --- src/main/resources/application.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b4f37c7002..174d549c79 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,6 +3,9 @@ spring.profiles.active: test server.address: 127.0.0.1 server.port: 8080 +debug: false +trace: false + spring.main.banner-mode: off # In favour of our own mappings, see ru.mystamps.web.config.MvcConfig.addResourceHandlers() From bf944a0d7b2d19df174135af4b442a1dbf3114d5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 25 Sep 2016 21:13:26 +0200 Subject: [PATCH 048/463] Update list of excluded autoconfiguration classes. No functional changes. --- .../resources/application-test.properties | 19 +++++++++++++++++ .../resources/application-travis.properties | 19 +++++++++++++++++ .../templates/application-prod.properties | 21 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index d8fe52bf80..3f84cb21f4 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -36,14 +36,22 @@ logging.level.liquibase: WARN logging.level.org.springframework.web.servlet.handler.SimpleUrlHandlerMapping: WARN logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping: WARN +# Full list of autoconfiguration classes: +# http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/auto-configuration-classes.html spring.autoconfigure.exclude: \ org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration \ + , org.springframework.boot.autoconfigure.aop.AopAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration \ , org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration \ + , org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration \ , org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration \ , org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration \ , org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration \ + , org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration \ + , org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration \ , org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration \ @@ -63,23 +71,32 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ + , org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ , org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration \ , org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration \ , org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration \ , org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration \ , org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration \ , org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration \ + , org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration \ + , org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration \ + , org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration \ , org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration \ , org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration \ , org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration \ , org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration \ + , org.springframework.boot.autoconfigure.session.SessionAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration \ , org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration \ , org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration \ @@ -87,6 +104,8 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration \ , org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration \ , org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration \ + , org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration \ + , org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index f95e0e5ec6..a244f92e97 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -35,14 +35,22 @@ logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappi app.upload.dir: /tmp +# Full list of autoconfiguration classes: +# http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/auto-configuration-classes.html spring.autoconfigure.exclude: \ org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration \ + , org.springframework.boot.autoconfigure.aop.AopAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration \ , org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration \ + , org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration \ , org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration \ , org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration \ , org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration \ + , org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration \ + , org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration \ , org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration \ @@ -62,23 +70,32 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ + , org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ , org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration \ , org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration \ , org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration \ , org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration \ , org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration \ , org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration \ + , org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration \ + , org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration \ + , org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration \ , org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration \ , org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration \ , org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration \ , org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration \ + , org.springframework.boot.autoconfigure.session.SessionAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration \ , org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration \ , org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration \ @@ -86,6 +103,8 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration \ , org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration \ , org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration \ + , org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration \ + , org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ diff --git a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties index 7d2e144aa6..2dc37c4fbf 100644 --- a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties +++ b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties @@ -37,15 +37,23 @@ app.upload.dir: /data/uploads server.session.cookie.secure: true -# the difference between test profile is that we don't need SpringApplicationAdminJmxAutoConfiguration +# Full list of autoconfiguration classes: +# http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/auto-configuration-classes.html +# The difference between test profile is that we don't need SpringApplicationAdminJmxAutoConfiguration spring.autoconfigure.exclude: \ org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration \ + , org.springframework.boot.autoconfigure.aop.AopAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration \ , org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration \ + , org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration \ , org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration \ , org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration \ , org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration \ + , org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration \ + , org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration \ , org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration \ @@ -65,23 +73,32 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ + , org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ , org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration \ , org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration \ , org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration \ , org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration \ , org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration \ , org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration \ + , org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration \ + , org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration \ + , org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration \ , org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration \ , org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration \ , org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration \ + , org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration \ , org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration \ , org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration \ + , org.springframework.boot.autoconfigure.session.SessionAutoConfiguration \ , org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration \ , org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration \ , org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration \ @@ -89,6 +106,8 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration \ , org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration \ , org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration \ + , org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration \ + , org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ From 7c384a21cd626392e2612a300630d9ca24735aad Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 25 Sep 2016 21:36:47 +0200 Subject: [PATCH 049/463] Exclude H2 auto configuration from prod/travis profiles. No functional changes. --- src/main/resources/application-travis.properties | 3 +++ .../roles/mystamps-app/templates/application-prod.properties | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index a244f92e97..e092e7e66a 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -37,6 +37,7 @@ app.upload.dir: /tmp # Full list of autoconfiguration classes: # http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/auto-configuration-classes.html +# The difference between test profile is that we don't need H2ConsoleAutoConfiguration spring.autoconfigure.exclude: \ org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration \ , org.springframework.boot.autoconfigure.aop.AopAutoConfiguration \ @@ -108,4 +109,6 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ + \ + , org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration \ # diff --git a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties index 2dc37c4fbf..1e8e44ec73 100644 --- a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties +++ b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties @@ -39,7 +39,8 @@ server.session.cookie.secure: true # Full list of autoconfiguration classes: # http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/auto-configuration-classes.html -# The difference between test profile is that we don't need SpringApplicationAdminJmxAutoConfiguration +# The difference between test profile is that we don't need +# SpringApplicationAdminJmxAutoConfiguration and H2ConsoleAutoConfiguration spring.autoconfigure.exclude: \ org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration \ , org.springframework.boot.autoconfigure.aop.AopAutoConfiguration \ @@ -112,5 +113,6 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ \ + , org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration \ , org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration \ # From 1b7f947364c0664270824c088283b7f5f91a928b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 26 Sep 2016 11:54:48 +0200 Subject: [PATCH 050/463] Fix exclusion of the last auto configuration in the list. Before it didn't work because of hash sign. No functional changes. --- src/main/resources/application-test.properties | 3 +-- src/main/resources/application-travis.properties | 3 +-- .../roles/mystamps-app/templates/application-prod.properties | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 3f84cb21f4..07e525446f 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -108,5 +108,4 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ - , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ - # + , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index e092e7e66a..f950ded0d4 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -110,5 +110,4 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ \ - , org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration \ - # + , org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration diff --git a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties index 1e8e44ec73..9567876b3a 100644 --- a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties +++ b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties @@ -114,5 +114,4 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration \ \ , org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration \ - , org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration \ - # + , org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration From d85462d2d71db8e98762b613fd7a136ea42cc4ef Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 3 Oct 2016 11:11:26 +0200 Subject: [PATCH 051/463] SecurityConfig: simplify AuthenticationProvider configuration. @see http://docs.spring.io/spring-security/site/docs/4.1.x/reference/htmlsingle/#jc-authentication-authenticationprovider No functional changes. --- .../spring/security/SecurityConfig.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java index bd36a6061d..70cc6faf9d 100644 --- a/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java +++ b/src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java @@ -26,8 +26,7 @@ import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; -// CheckStyle: ignore LineLength for next 2 lines -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +// CheckStyle: ignore LineLength for next 1 line import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; @@ -117,12 +116,6 @@ protected void configure(HttpSecurity http) throws Exception { .disable(); } - @Autowired - @Override - protected void configure(AuthenticationManagerBuilder auth) { - auth.authenticationProvider(getAuthenticationProvider()); - } - // Used in ServicesConfig.getUserService() public PasswordEncoder getPasswordEncoder() { return new BCryptPasswordEncoder(); @@ -141,11 +134,8 @@ public AccessDeniedHandler getAccessDeniedHandler() { ); } - private UserDetailsService getUserDetailsService() { - return new CustomUserDetailsService(servicesConfig.getUserService()); - } - - private AuthenticationProvider getAuthenticationProvider() { + @Bean + public AuthenticationProvider getAuthenticationProvider() { DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); provider.setPasswordEncoder(getPasswordEncoder()); provider.setUserDetailsService(getUserDetailsService()); @@ -153,4 +143,8 @@ private AuthenticationProvider getAuthenticationProvider() { return provider; } + private UserDetailsService getUserDetailsService() { + return new CustomUserDetailsService(servicesConfig.getUserService()); + } + } From ffc076a76c8b91aa0ca0b851beda7ed07a0e2850 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 3 Oct 2016 20:49:40 +0200 Subject: [PATCH 052/463] Use alised attributes instead of value. No functional changes. --- src/main/java/ru/mystamps/web/controller/ErrorController.java | 4 ++-- .../java/ru/mystamps/web/controller/SeriesController.java | 4 ++-- src/main/java/ru/mystamps/web/controller/SiteController.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/ErrorController.java b/src/main/java/ru/mystamps/web/controller/ErrorController.java index b58dbb9b12..b39f789a59 100644 --- a/src/main/java/ru/mystamps/web/controller/ErrorController.java +++ b/src/main/java/ru/mystamps/web/controller/ErrorController.java @@ -43,8 +43,8 @@ public class ErrorController { public void notFound( HttpServletRequest request, @CurrentUser Integer currentUserId, - @RequestHeader(value = "referer", required = false) String referer, - @RequestHeader(value = "user-agent", required = false) String agent) { + @RequestHeader(name = "referer", required = false) String referer, + @RequestHeader(name = "user-agent", required = false) String agent) { // TODO: sanitize all user's values (#60) String page = (String)request.getAttribute("javax.servlet.error.request_uri"); diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 13d0c5cadc..5da8943efc 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -256,7 +256,7 @@ public String processImage( return redirectTo(Url.INFO_SERIES_PAGE, series.getId()); } - @PostMapping(value = Url.INFO_SERIES_PAGE, params = "action=ADD") + @PostMapping(path = Url.INFO_SERIES_PAGE, params = "action=ADD") public String addToCollection( @PathVariable("id") Integer seriesId, @AuthenticationPrincipal CustomUserDetails currentUserDetails, @@ -285,7 +285,7 @@ public String addToCollection( return redirectTo(Url.INFO_COLLECTION_PAGE, collectionSlug); } - @PostMapping(value = Url.INFO_SERIES_PAGE, params = "action=REMOVE") + @PostMapping(path = Url.INFO_SERIES_PAGE, params = "action=REMOVE") public String removeFromCollection( @PathVariable("id") Integer seriesId, @CurrentUser Integer currentUserId, diff --git a/src/main/java/ru/mystamps/web/controller/SiteController.java b/src/main/java/ru/mystamps/web/controller/SiteController.java index b9d18d73d7..f41aa44286 100644 --- a/src/main/java/ru/mystamps/web/controller/SiteController.java +++ b/src/main/java/ru/mystamps/web/controller/SiteController.java @@ -89,7 +89,7 @@ public String showIndexPage(Model model, Locale userLocale) { */ @GetMapping(Url.SITE_EVENTS_PAGE) public void viewSiteEvents( - @RequestParam(value = "page", defaultValue = "1") int pageNum, + @RequestParam(name = "page", defaultValue = "1") int pageNum, Model model) { int page = Math.max(1, pageNum); From 1329ea068c3d1297904c4a36bb05dc6beb2731b1 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 3 Oct 2016 21:17:20 +0200 Subject: [PATCH 053/463] Propagate @RequestAttribute annotation. No functional changes. --- .../mystamps/web/controller/ErrorController.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/ErrorController.java b/src/main/java/ru/mystamps/web/controller/ErrorController.java index b39f789a59..afd70e180f 100644 --- a/src/main/java/ru/mystamps/web/controller/ErrorController.java +++ b/src/main/java/ru/mystamps/web/controller/ErrorController.java @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; @@ -43,11 +44,12 @@ public class ErrorController { public void notFound( HttpServletRequest request, @CurrentUser Integer currentUserId, + // CheckStyle: ignore LineLength for next 1 line + @RequestAttribute(name = "javax.servlet.error.request_uri", required = false) String page, @RequestHeader(name = "referer", required = false) String referer, @RequestHeader(name = "user-agent", required = false) String agent) { // TODO: sanitize all user's values (#60) - String page = (String)request.getAttribute("javax.servlet.error.request_uri"); String ip = request.getRemoteAddr(); String method = request.getMethod(); @@ -55,13 +57,13 @@ public void notFound( } @RequestMapping(Url.INTERNAL_ERROR_PAGE) - public void internalError(HttpServletRequest request) { - // TODO: log to database (with *.status_code, *.message, *.servlet_name and user details) + public void internalError( + // CheckStyle: ignore LineLength for next 2 lines + @RequestAttribute(name = "javax.servlet.error.exception_type", required = false) Class exceptionType, + @RequestAttribute(name = "javax.servlet.error.exception", required = false) Exception exception, + @RequestAttribute(name = "javax.servlet.error.request_uri", required = false) String page) { - // CheckStyle: ignore LineLength for next 1 line - Class exceptionType = (Class)request.getAttribute("javax.servlet.error.exception_type"); - Exception exception = (Exception)request.getAttribute("javax.servlet.error.exception"); - String page = (String)request.getAttribute("javax.servlet.error.request_uri"); + // TODO: log to database (with *.status_code, *.message, *.servlet_name and user details) if (page != null && !Url.INTERNAL_ERROR_PAGE.equals(page)) { String msg = String.format( From a19d9f058195ef7d70220983c98ff3c47c9ee6d4 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 3 Oct 2016 22:18:16 +0200 Subject: [PATCH 054/463] ErrorController: use constants from RequestDispatcher class. No functional changes. --- .../ru/mystamps/web/controller/ErrorController.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/ErrorController.java b/src/main/java/ru/mystamps/web/controller/ErrorController.java index afd70e180f..b9db9f9bd1 100644 --- a/src/main/java/ru/mystamps/web/controller/ErrorController.java +++ b/src/main/java/ru/mystamps/web/controller/ErrorController.java @@ -17,6 +17,7 @@ */ package ru.mystamps.web.controller; +import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; @@ -45,7 +46,7 @@ public void notFound( HttpServletRequest request, @CurrentUser Integer currentUserId, // CheckStyle: ignore LineLength for next 1 line - @RequestAttribute(name = "javax.servlet.error.request_uri", required = false) String page, + @RequestAttribute(name = RequestDispatcher.ERROR_REQUEST_URI, required = false) String page, @RequestHeader(name = "referer", required = false) String referer, @RequestHeader(name = "user-agent", required = false) String agent) { @@ -58,10 +59,10 @@ public void notFound( @RequestMapping(Url.INTERNAL_ERROR_PAGE) public void internalError( - // CheckStyle: ignore LineLength for next 2 lines - @RequestAttribute(name = "javax.servlet.error.exception_type", required = false) Class exceptionType, - @RequestAttribute(name = "javax.servlet.error.exception", required = false) Exception exception, - @RequestAttribute(name = "javax.servlet.error.request_uri", required = false) String page) { + // CheckStyle: ignore LineLength for next 3 lines + @RequestAttribute(name = RequestDispatcher.ERROR_EXCEPTION_TYPE, required = false) Class exceptionType, + @RequestAttribute(name = RequestDispatcher.ERROR_EXCEPTION, required = false) Exception exception, + @RequestAttribute(name = RequestDispatcher.ERROR_REQUEST_URI, required = false) String page) { // TODO: log to database (with *.status_code, *.message, *.servlet_name and user details) From b87c290e388f434fe18862e3aff4a98d752d3d22 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 4 Oct 2016 13:44:19 +0200 Subject: [PATCH 055/463] pom.xml: use htmlunit-driver 2.21 again. Correction for ef59044dd3beb746b22acc0fd476cc696fbf84de commit. No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e55ea8392c..65fc0ad9b6 100644 --- a/pom.xml +++ b/pom.xml @@ -381,7 +381,7 @@ 5.2.4.Final - 2.20 + 2.21 0.7.7.201606060606 2.2 From 5ff81f13d5e36689b8501ae1515d4e9b8dbbd233 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 4 Oct 2016 14:01:43 +0200 Subject: [PATCH 056/463] pom.xml: exclude duplicated dependency on tomcat-embed-el. We're already using org.mortbay.jasper:apache-el and dependency on org.apache.tomcat.embed:tomcat-embed-el is unnecessary. This also saves additional 235K. No functional changes. --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 65fc0ad9b6..2a2eb7d32a 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,13 @@ org.springframework.boot spring-boot-starter-validation + + + + org.apache.tomcat.embed + tomcat-embed-el + + @@ -642,6 +649,8 @@ commons-logging + + org.apache.tomcat.embed:tomcat-embed-el junit:*:*:*:compile org.yaml:snakeyaml From da2440f025d3547a3aaeefb5f7f9c688c903ba98 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 4 Oct 2016 14:28:59 +0200 Subject: [PATCH 057/463] Exclude Jackson. We don't use it. Also it saves ~1.5Mb. No functional changes. --- pom.xml | 12 ++++++++++++ src/main/resources/application-test.properties | 1 + src/main/resources/application-travis.properties | 1 + .../templates/application-prod.properties | 1 + 4 files changed, 15 insertions(+) diff --git a/pom.xml b/pom.xml index 2a2eb7d32a..73a23c5e0b 100644 --- a/pom.xml +++ b/pom.xml @@ -133,6 +133,18 @@ org.springframework.boot spring-boot-starter-tomcat + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 07e525446f..e6ca70bc30 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -70,6 +70,7 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration \ , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ + , org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration \ , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ , org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index f950ded0d4..72d10c1c9d 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -70,6 +70,7 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration \ , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ + , org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration \ , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ , org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ diff --git a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties index 9567876b3a..0cd5cb6174 100644 --- a/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties +++ b/vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties @@ -73,6 +73,7 @@ spring.autoconfigure.exclude: \ , org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration \ , org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration \ , org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration \ + , org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration \ , org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration \ , org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration \ , org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration \ From 4b8ba1336252c3ee8b76804486e43dd35d2e1063 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 4 Oct 2016 14:49:49 +0200 Subject: [PATCH 058/463] pom.xml: exclude jetty-xml artifact. No functional changes. --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 73a23c5e0b..7896275908 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,10 @@ org.eclipse.jetty.websocket javax-websocket-server-impl + + org.eclipse.jetty + jetty-xml + From 94f1d2cc2ba9bcd3f82385662c9d97d7683b8b02 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 3 Oct 2016 22:51:15 +0200 Subject: [PATCH 059/463] pom.xml: update Thymeleaf to 3.0.2.RELEASE. This also updates thymeleaf-extras-togglz to 2.0.0.SNAPSHOT @see http://forum.thymeleaf.org/Thymeleaf-3-0-is-here-td4029676.html @see http://www.thymeleaf.org/doc/articles/thymeleaf3migration.html @see http://forum.thymeleaf.org/Thymeleaf-3-0-1-JUST-PUBLISHED-td4029852.html @see http://forum.thymeleaf.org/Thymeleaf-3-0-2-JUST-PUBLISHED-td4029985.html Fix #406 No functional changes. --- pom.xml | 21 ++++++++++++++++--- .../resources/application-test.properties | 1 + .../resources/application-travis.properties | 1 + .../webapp/WEB-INF/views/collection/info.html | 3 --- .../templates/application-prod.properties | 1 + 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7896275908..3b86a63fcc 100644 --- a/pom.xml +++ b/pom.xml @@ -469,12 +469,12 @@ 6.8.8 - 2.1.2.RELEASE + 3.0.0.RELEASE - 1.1.0.RELEASE + 2.0.0-SNAPSHOT - 2.1.5.RELEASE + 3.0.2.RELEASE 2.3.0.Final 3.0.0 @@ -919,4 +919,19 @@ 3.2.1 + + + + false + + + true + fail + + oss-sonatype + oss-sonatype + https://oss.sonatype.org/content/repositories/snapshots/ + + + diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index e6ca70bc30..38ddac4400 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -23,6 +23,7 @@ spring.messages.basename: \ ru/mystamps/i18n/SpringSecurityMessages, \ ru/mystamps/i18n/MailTemplates +spring.thymeleaf.mode: HTML spring.thymeleaf.prefix: /WEB-INF/views/ spring.thymeleaf.suffix: .html spring.thymeleaf.cache: false diff --git a/src/main/resources/application-travis.properties b/src/main/resources/application-travis.properties index 72d10c1c9d..8c63246411 100644 --- a/src/main/resources/application-travis.properties +++ b/src/main/resources/application-travis.properties @@ -21,6 +21,7 @@ spring.messages.basename: \ ru/mystamps/i18n/SpringSecurityMessages, \ ru/mystamps/i18n/MailTemplates +spring.thymeleaf.mode: HTML spring.thymeleaf.prefix: /WEB-INF/views/ spring.thymeleaf.suffix: .html spring.thymeleaf.cache: true diff --git a/src/main/webapp/WEB-INF/views/collection/info.html b/src/main/webapp/WEB-INF/views/collection/info.html index 2b39776d2c..e15ec7bd63 100644 --- a/src/main/webapp/WEB-INF/views/collection/info.html +++ b/src/main/webapp/WEB-INF/views/collection/info.html @@ -210,7 +210,6 @@

    Stamps by categories 1.4 @@ -778,6 +780,24 @@ + + + org.codehaus.mojo + codenarc-maven-plugin + ${codenarc.plugin.version} + + ${codenarc.version} + ${groovy.version} + src/test/groovy + + rulesets/basic.xml,rulesets/braces.xml,rulesets/concurrency.xml,rulesets/convention.xml,rulesets/design.xml,rulesets/dry.xml,rulesets/enhanced.xml,rulesets/exceptions.xml,rulesets/formatting.xml,rulesets/generic.xml,rulesets/groovyism.xml,rulesets/imports.xml,rulesets/jdbc.xml,rulesets/logging.xml,rulesets/naming.xml,rulesets/security.xml,rulesets/serialization.xml,rulesets/unnecessary.xml,rulesets/unused.xml + + + + org.codehaus.mojo native2ascii-maven-plugin From 9a0f5ecbf76cf78629965a819894f2e20c6f58f8 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 27 Jul 2016 18:12:19 +0200 Subject: [PATCH 061/463] Fix UnnecessaryGString warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-unnecessary.html#UnnecessaryGString No functional changes. --- .../service/CategoryServiceImplTest.groovy | 2 +- .../web/service/CountryServiceImplTest.groovy | 2 +- .../web/service/CronServiceImplTest.groovy | 16 +++++++------- .../web/service/SeriesServiceImplTest.groovy | 10 ++++----- .../web/service/SiteServiceImplTest.groovy | 2 +- .../SuspiciousActivityServiceImplTest.groovy | 4 ++-- .../web/service/UserServiceImplTest.groovy | 2 +- .../UsersActivationServiceImplTest.groovy | 6 ++--- .../mystamps/web/util/LocaleUtilsTest.groovy | 6 ++--- .../ru/mystamps/web/util/SlugUtilsTest.groovy | 22 +++++++++---------- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index 9a7ddc4952..181e39ea4d 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -129,7 +129,7 @@ class CategoryServiceImplTest extends Specification { def "add() should pass slug to dao"() { given: - String name = "-foo123 test_" + String name = '-foo123 test_' and: String slug = SlugUtils.slugify(name) and: diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index 180ec3a714..6f57bea871 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -130,7 +130,7 @@ class CountryServiceImplTest extends Specification { def "add() should pass slug to dao"() { given: - String name = "-foo123 test_" + String name = '-foo123 test_' and: String slug = SlugUtils.slugify(name) and: diff --git a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy index f424c08cbf..11a99d2b06 100644 --- a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy @@ -99,19 +99,19 @@ class CronServiceImplTest extends Specification { assertMidnightOfYesterday(date) return true }) - 1 * suspiciousActivityService.countByTypeSince("PageNotFound", { Date date -> + 1 * suspiciousActivityService.countByTypeSince('PageNotFound', { Date date -> assertMidnightOfYesterday(date) return true }) - 1 * suspiciousActivityService.countByTypeSince("AuthenticationFailed", { Date date -> + 1 * suspiciousActivityService.countByTypeSince('AuthenticationFailed', { Date date -> assertMidnightOfYesterday(date) return true }) - 1 * suspiciousActivityService.countByTypeSince("MissingCsrfToken", { Date date -> + 1 * suspiciousActivityService.countByTypeSince('MissingCsrfToken', { Date date -> assertMidnightOfYesterday(date) return true }) - 1 * suspiciousActivityService.countByTypeSince("InvalidCsrfToken", { Date date -> + 1 * suspiciousActivityService.countByTypeSince('InvalidCsrfToken', { Date date -> assertMidnightOfYesterday(date) return true }) @@ -127,10 +127,10 @@ class CronServiceImplTest extends Specification { userService.countRegisteredSince(_ as Date) >> 6 and: long expectedEvents = 7 + 8 + 9 + 10 - suspiciousActivityService.countByTypeSince("PageNotFound", _ as Date) >> 7 - suspiciousActivityService.countByTypeSince("AuthenticationFailed", _ as Date) >> 8 - suspiciousActivityService.countByTypeSince("MissingCsrfToken", _ as Date) >> 9 - suspiciousActivityService.countByTypeSince("InvalidCsrfToken", _ as Date) >> 10 + suspiciousActivityService.countByTypeSince('PageNotFound', _ as Date) >> 7 + suspiciousActivityService.countByTypeSince('AuthenticationFailed', _ as Date) >> 8 + suspiciousActivityService.countByTypeSince('MissingCsrfToken', _ as Date) >> 9 + suspiciousActivityService.countByTypeSince('InvalidCsrfToken', _ as Date) >> 10 when: service.sendDailyStatistics() then: diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index 0081d40e28..820e99f3bc 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -34,7 +34,7 @@ import ru.mystamps.web.dao.dto.SitemapInfoDto import ru.mystamps.web.tests.DateUtils class SeriesServiceImplTest extends Specification { - private static final BigDecimal ANY_PRICE = new BigDecimal("17") + private static final BigDecimal ANY_PRICE = new BigDecimal('17') private static final Integer ANY_IMAGE_ID = 18 private ImageService imageService = Mock() @@ -415,7 +415,7 @@ class SeriesServiceImplTest extends Specification { 0 * michelCatalogService.addToSeries(_ as Integer, _ as Set) where: numbers | _ - "" | _ + '' | _ null | _ } @@ -457,7 +457,7 @@ class SeriesServiceImplTest extends Specification { 0 * scottCatalogService.addToSeries(_ as Integer, _ as Set) where: numbers | _ - "" | _ + '' | _ null | _ } @@ -499,7 +499,7 @@ class SeriesServiceImplTest extends Specification { 0 * yvertCatalogService.addToSeries(_ as Integer, _ as Set) where: numbers | _ - "" | _ + '' | _ null | _ } @@ -541,7 +541,7 @@ class SeriesServiceImplTest extends Specification { 0 * gibbonsCatalogService.addToSeries(_ as Integer, _ as Set) where: numbers | _ - "" | _ + '' | _ null | _ } diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index 88c942ec2d..dddd6c17c0 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -204,7 +204,7 @@ class SiteServiceImplTest extends Specification { def "logEvent() should pass abbreviated method when it's too long"() { given: - String method = "PROPFIND" + String method = 'PROPFIND' and: String exceptedMethod = method.take(Db.SuspiciousActivity.METHOD_LENGTH-3) + '...' when: diff --git a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy index 0913f4a488..8d960a82e2 100644 --- a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy @@ -63,14 +63,14 @@ class SuspiciousActivityServiceImplTest extends Specification { def "countByTypeSince() should throw exception when date is null"() { when: - service.countByTypeSince("AnyType", null) + service.countByTypeSince('AnyType', null) then: thrown IllegalArgumentException } def "countByTypeSince() should invoke dao, pass arguments and return result from dao"() { given: - String expectedType = "ExpectedType" + String expectedType = 'ExpectedType' Date expectedDate = new Date().plus(1) long expectedResult = 47 when: diff --git a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy index cbe4b2e6fb..6e020082b9 100644 --- a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy @@ -160,7 +160,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should use email from registration request"() { given: - UsersActivationDto activation = new UsersActivationDto("test@example.org", new Date()) + UsersActivationDto activation = new UsersActivationDto('test@example.org', new Date()) and: usersActivationService.findByActivationKey(_ as String) >> activation when: diff --git a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy index 7122517dff..d85b6e92e2 100644 --- a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy @@ -152,7 +152,7 @@ class UsersActivationServiceImplTest extends Specification { assert activation != null assert activation.activationKey != null assert activation.email == registrationForm.email - assert activation.locale == new Locale("fr") + assert activation.locale == new Locale('fr') return true; }) } @@ -226,9 +226,9 @@ class UsersActivationServiceImplTest extends Specification { given: UsersActivationDto expectedResult = TestObjects.createUsersActivationDto(); when: - UsersActivationDto result = service.findByActivationKey("0987654321") + UsersActivationDto result = service.findByActivationKey('0987654321') then: - 1 * usersActivationDao.findByActivationKey("0987654321") >> expectedResult + 1 * usersActivationDao.findByActivationKey('0987654321') >> expectedResult and: result == expectedResult } diff --git a/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy b/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy index 7cfd6653c7..1def2a0e7d 100644 --- a/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy @@ -52,9 +52,9 @@ class LocaleUtilsTest extends Specification { where: locale | value || expected null | null || null - null | "en" || "en" - Locale.ENGLISH | "ru" || "en" - Locale.ENGLISH | null || "en" + null | 'en' || 'en' + Locale.ENGLISH | 'ru' || 'en' + Locale.ENGLISH | null || 'en' } } diff --git a/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy b/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy index 84f07a5a07..f2f6da2564 100644 --- a/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy @@ -41,17 +41,17 @@ class SlugUtilsTest extends Specification { result == output where: input || output - "" || "" - "-_" || "" - "тест" || "" - "test" || "test" - "TEST" || "test" - "test!" || "test" - "_test_" || "test" - "foo3" || "foo3" - "one two" || "one-two" - "one+two" || "one-two" - "one||two" || "one-two" + '' || '' + '-_' || '' + 'тест' || '' + 'test' || 'test' + 'TEST' || 'test' + 'test!' || 'test' + '_test_' || 'test' + 'foo3' || 'foo3' + 'one two' || 'one-two' + 'one+two' || 'one-two' + 'one||two' || 'one-two' } } From 173c35b33005cd1553c70d92a58bb51979bfe8cf Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 28 Jul 2016 14:34:14 +0200 Subject: [PATCH 062/463] Fix UnnecessaryGetter warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-unnecessary.html#UnnecessaryGetter No functional changes. --- .../service/CollectionServiceImplTest.groovy | 2 +- ...atabaseImagePersistenceStrategyTest.groovy | 8 ++++---- .../web/service/ImageServiceImplTest.groovy | 12 +++++------ .../web/service/SeriesServiceImplTest.groovy | 4 ++-- .../web/service/UserServiceImplTest.groovy | 20 +++++++++---------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index 1a785fd2fa..adca8a15bf 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -157,7 +157,7 @@ class CollectionServiceImplTest extends Specification { and: UrlEntityDto url = TestObjects.createUrlEntityDto() and: - Integer expectedCollectionId = url.getId() + Integer expectedCollectionId = url.id and: collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> url when: diff --git a/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy index fd9ce75b07..60e4323568 100644 --- a/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy @@ -41,7 +41,7 @@ class DatabaseImagePersistenceStrategyTest extends Specification { def "save() should convert IOException to ImagePersistenceException"() { given: - multipartFile.getBytes() >> { throw new IOException() } + multipartFile.bytes >> { throw new IOException() } when: strategy.save(multipartFile, imageInfoDto) then: @@ -52,8 +52,8 @@ class DatabaseImagePersistenceStrategyTest extends Specification { def "save() should pass file content to image data dao"() { given: - byte[] expected = 'test'.getBytes() - multipartFile.getBytes() >> expected + byte[] expected = 'test'.bytes + multipartFile.bytes >> expected when: strategy.save(multipartFile, imageInfoDto) then: @@ -65,7 +65,7 @@ class DatabaseImagePersistenceStrategyTest extends Specification { def "save() should pass image to image data dao"() { given: - Integer expectedImageId = imageInfoDto.getId() + Integer expectedImageId = imageInfoDto.id when: strategy.save(multipartFile, imageInfoDto) then: diff --git a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy index 3e5cd200ee..aea675153f 100644 --- a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy @@ -36,8 +36,8 @@ class ImageServiceImplTest extends Specification { private ImageService service = new ImageServiceImpl(imagePersistenceStrategy, imageDao) def setup() { - multipartFile.getSize() >> 1024L - multipartFile.getContentType() >> 'image/png' + multipartFile.size >> 1024L + multipartFile.contentType >> 'image/png' imageDao.add(_ as String) >> 17 } @@ -56,7 +56,7 @@ class ImageServiceImplTest extends Specification { when: service.save(multipartFile) then: - multipartFile.getSize() >> 0L + multipartFile.size >> 0L and: thrown IllegalArgumentException } @@ -65,7 +65,7 @@ class ImageServiceImplTest extends Specification { when: service.save(multipartFile) then: - multipartFile.getContentType() >> null + multipartFile.contentType >> null and: thrown IllegalArgumentException } @@ -74,7 +74,7 @@ class ImageServiceImplTest extends Specification { when: service.save(multipartFile) then: - multipartFile.getContentType() >> 'image/tiff' + multipartFile.contentType >> 'image/tiff' and: thrown IllegalStateException } @@ -91,7 +91,7 @@ class ImageServiceImplTest extends Specification { when: service.save(multipartFile) then: - multipartFile.getContentType() >> contentType + multipartFile.contentType >> contentType and: 1 * imageDao.add({ String type -> assert type == expectedType diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index 820e99f3bc..f3dc0842bb 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -130,7 +130,7 @@ class SeriesServiceImplTest extends Specification { given: LinkEntityDto country = TestObjects.createLinkEntityDto() and: - Integer expectedCountryId = country.getId() + Integer expectedCountryId = country.id and: form.setCountry(country) when: @@ -176,7 +176,7 @@ class SeriesServiceImplTest extends Specification { given: LinkEntityDto category = TestObjects.createLinkEntityDto() and: - Integer expectedCategoryId = category.getId() + Integer expectedCategoryId = category.id and: form.setCategory(category) when: diff --git a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy index 6e020082b9..c2034c348b 100644 --- a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy @@ -43,15 +43,15 @@ class UserServiceImplTest extends Specification { def setup() { AddUserDbDto user = TestObjects.createAddUserDbDto() - encoder.encode(_ as String) >> user.getHash() + encoder.encode(_ as String) >> user.hash UsersActivationDto activation = TestObjects.createUsersActivationDto() usersActivationService.findByActivationKey(_ as String) >> activation activationForm = new ActivateAccountForm() - activationForm.setLogin(user.getLogin()) + activationForm.setLogin(user.login) activationForm.setPassword(TestObjects.TEST_PASSWORD) - activationForm.setName(user.getName()) + activationForm.setName(user.name) activationForm.setActivationKey(TestObjects.TEST_ACTIVATION_KEY) service = new UserServiceImpl(userDao, usersActivationService, collectionService, encoder) @@ -77,7 +77,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should delete registration request"() { given: - String expectedActivationKey = activationForm.getActivationKey() + String expectedActivationKey = activationForm.activationKey when: service.registerUser(activationForm) then: @@ -111,7 +111,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should pass name to dao"() { given: - String expectedUserName = activationForm.getName() + String expectedUserName = activationForm.name when: service.registerUser(activationForm) then: @@ -123,7 +123,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should pass login instead of name when name is null"() { given: - String expectedUserLogin = activationForm.getLogin() + String expectedUserLogin = activationForm.login activationForm.setName(null) when: service.registerUser(activationForm) @@ -136,7 +136,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should pass login instead of name when name is empty"() { given: - String expectedUserLogin = activationForm.getLogin() + String expectedUserLogin = activationForm.login and: activationForm.setName('') when: @@ -197,7 +197,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should gets hash from encoder"() { given: - String expectedHash = TestObjects.createAddUserDbDto().getHash() + String expectedHash = TestObjects.createAddUserDbDto().hash when: service.registerUser(activationForm) then: @@ -232,7 +232,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should pass login to dao"() { given: - String expectedUserLogin = activationForm.getLogin() + String expectedUserLogin = activationForm.login when: service.registerUser(activationForm) then: @@ -255,7 +255,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should create collection for user"() { given: Integer expectedId = 909; - String expectedLogin = activationForm.getLogin() + String expectedLogin = activationForm.login and: userDao.add(_ as AddUserDbDto) >> expectedId when: From b1a59b279df5e872dbaf20b12c7bf879b8d91fb6 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 28 Jul 2016 16:20:46 +0200 Subject: [PATCH 063/463] Fix UnnecessarySemicolon warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-unnecessary.html#UnnecessarySemicolon No functional changes. --- .../ru/mystamps/web/service/SiteServiceImplTest.groovy | 2 +- .../ru/mystamps/web/service/UserServiceImplTest.groovy | 2 +- .../web/service/UsersActivationServiceImplTest.groovy | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index dddd6c17c0..966dcc3840 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -144,7 +144,7 @@ class SiteServiceImplTest extends Specification { def "logEvent() should assign occurred at to specified date when date was provided"() { given: - Date expectedDate = new Date() - 100; + Date expectedDate = new Date() - 100 when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, null, expectedDate) then: diff --git a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy index c2034c348b..84ee535bb4 100644 --- a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy @@ -254,7 +254,7 @@ class UserServiceImplTest extends Specification { def "registerUser() should create collection for user"() { given: - Integer expectedId = 909; + Integer expectedId = 909 String expectedLogin = activationForm.login and: userDao.add(_ as AddUserDbDto) >> expectedId diff --git a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy index d85b6e92e2..8214dac7db 100644 --- a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy @@ -36,7 +36,7 @@ class UsersActivationServiceImplTest extends Specification { private UsersActivationService service private RegisterAccountForm registrationForm - private static final Locale ANY_LOCALE = Locale.ENGLISH; + private static final Locale ANY_LOCALE = Locale.ENGLISH def setup() { registrationForm = new RegisterAccountForm() @@ -153,7 +153,7 @@ class UsersActivationServiceImplTest extends Specification { assert activation.activationKey != null assert activation.email == registrationForm.email assert activation.locale == new Locale('fr') - return true; + return true }) } @@ -224,7 +224,7 @@ class UsersActivationServiceImplTest extends Specification { def "findByActivationKey() should call dao, pass argument to it and return result"() { given: - UsersActivationDto expectedResult = TestObjects.createUsersActivationDto(); + UsersActivationDto expectedResult = TestObjects.createUsersActivationDto() when: UsersActivationDto result = service.findByActivationKey('0987654321') then: From c5f6e6cde9a5aa4de5cee220095d63760b14b818 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 28 Jul 2016 16:23:02 +0200 Subject: [PATCH 064/463] Fix ExplicitCallToPlusMethod warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-groovyism.html#ExplicitCallToPlusMethod No functional changes. --- .../web/service/SuspiciousActivityServiceImplTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy index 8d960a82e2..0fb5cb0526 100644 --- a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy @@ -71,7 +71,7 @@ class SuspiciousActivityServiceImplTest extends Specification { def "countByTypeSince() should invoke dao, pass arguments and return result from dao"() { given: String expectedType = 'ExpectedType' - Date expectedDate = new Date().plus(1) + Date expectedDate = new Date() + 1 long expectedResult = 47 when: long result = service.countByTypeSince(expectedType, expectedDate) From 92b7f56aa7562b74f2034583f9b836cdc3fefb5e Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 28 Jul 2016 18:06:06 +0200 Subject: [PATCH 065/463] Fix UnnecessaryCast warnings from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-unnecessary.html#UnnecessaryCast No functional changes. --- .../service/GibbonsCatalogServiceImplTest.groovy | 2 +- .../web/service/ImageServiceImplTest.groovy | 2 +- .../service/MichelCatalogServiceImplTest.groovy | 2 +- .../service/ScottCatalogServiceImplTest.groovy | 2 +- .../web/service/SeriesServiceImplTest.groovy | 16 ++++++++-------- .../SuspiciousActivityServiceImplTest.groovy | 2 +- .../service/YvertCatalogServiceImplTest.groovy | 2 +- .../ru/mystamps/web/util/CatalogUtilsTest.groovy | 12 ++++++------ .../groovy/ru/mystamps/web/util/PagerTest.groovy | 16 ++++++++-------- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy index afdb6fd965..f5f65c41e8 100644 --- a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy @@ -42,7 +42,7 @@ class GibbonsCatalogServiceImplTest extends Specification { given: Integer expectedSeriesId = 53 and: - List expectedResult = [ '80', '81' ] as List + List expectedResult = [ '80', '81' ] when: List result = service.findBySeriesId(expectedSeriesId) then: diff --git a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy index aea675153f..24510f2383 100644 --- a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy @@ -262,7 +262,7 @@ class ImageServiceImplTest extends Specification { given: Integer expectedSeriesId = 14 and: - List expectedResult = [ 1, 2 ] as List + List expectedResult = [ 1, 2 ] when: List result = service.findBySeriesId(expectedSeriesId) then: diff --git a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy index 21a88ed062..a22fa0b8ce 100644 --- a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy @@ -42,7 +42,7 @@ class MichelCatalogServiceImplTest extends Specification { given: Integer expectedSeriesId = 50 and: - List expectedResult = [ '75', '76' ] as List + List expectedResult = [ '75', '76' ] when: List result = service.findBySeriesId(expectedSeriesId) then: diff --git a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy index e3e6c0f0ce..5a841fb6c5 100644 --- a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy @@ -42,7 +42,7 @@ class ScottCatalogServiceImplTest extends Specification { given: Integer expectedSeriesId = 52 and: - List expectedResult = [ '79', '80' ] as List + List expectedResult = [ '79', '80' ] when: List result = service.findBySeriesId(expectedSeriesId) then: diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index f3dc0842bb..6fd6ebe882 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -799,11 +799,11 @@ class SeriesServiceImplTest extends Specification { given: String expectedLang = 'en' and: - List expectedSeriesIds = [ 1 ] as List + List expectedSeriesIds = [ 1 ] and: seriesDao.findSeriesIdsByMichelNumberCode(_ as String) >> expectedSeriesIds and: - List expectedResult = [] as List + List expectedResult = [] when: List result = service.findByMichelNumber('5', expectedLang) then: @@ -862,11 +862,11 @@ class SeriesServiceImplTest extends Specification { given: String expectedLang = 'en' and: - List expectedSeriesIds = [ 1 ] as List + List expectedSeriesIds = [ 1 ] and: seriesDao.findSeriesIdsByScottNumberCode(_ as String) >> expectedSeriesIds and: - List expectedResult = [] as List + List expectedResult = [] when: List result = service.findByScottNumber('5', expectedLang) then: @@ -925,11 +925,11 @@ class SeriesServiceImplTest extends Specification { given: String expectedLang = 'en' and: - List expectedSeriesIds = [ 1 ] as List + List expectedSeriesIds = [ 1 ] and: seriesDao.findSeriesIdsByYvertNumberCode(_ as String) >> expectedSeriesIds and: - List expectedResult = [] as List + List expectedResult = [] when: List result = service.findByYvertNumber('5', expectedLang) then: @@ -988,11 +988,11 @@ class SeriesServiceImplTest extends Specification { given: String expectedLang = 'en' and: - List expectedSeriesIds = [ 1 ] as List + List expectedSeriesIds = [ 1 ] and: seriesDao.findSeriesIdsByGibbonsNumberCode(_ as String) >> expectedSeriesIds and: - List expectedResult = [] as List + List expectedResult = [] when: List result = service.findByGibbonsNumber('5', expectedLang) then: diff --git a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy index 0fb5cb0526..dffdc6f95e 100644 --- a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy @@ -119,7 +119,7 @@ class SuspiciousActivityServiceImplTest extends Specification { given: int expectedPage = 5 int expectedRecordsPerPage = 10 - List expectedResult = [ TestObjects.createSuspiciousActivityDto() ] as List + List expectedResult = [ TestObjects.createSuspiciousActivityDto() ] when: List result = service.findSuspiciousActivities(expectedPage, expectedRecordsPerPage) diff --git a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy index ccf8b8f665..d638ecf0ed 100644 --- a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy @@ -42,7 +42,7 @@ class YvertCatalogServiceImplTest extends Specification { given: Integer expectedSeriesId = 51 and: - List expectedResult = [ '77', '78' ] as List + List expectedResult = [ '77', '78' ] when: List result = service.findBySeriesId(expectedSeriesId) then: diff --git a/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy b/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy index ea83ce695b..13d0668660 100644 --- a/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy @@ -34,7 +34,7 @@ class CatalogUtilsTest extends Specification { def "toShortForm() should return empty string for empty numbers"() { given: - List empty = [] as List + List empty = [] when: String numbers = CatalogUtils.toShortForm(empty) then: @@ -43,7 +43,7 @@ class CatalogUtilsTest extends Specification { def "toShortForm() should return single number as is"() { given: - List singleNumber = [ '1' ] as List + List singleNumber = [ '1' ] when: String numbers = CatalogUtils.toShortForm(singleNumber) then: @@ -52,7 +52,7 @@ class CatalogUtilsTest extends Specification { def "toShortForm() should return pair of numbers as comma separated"() { given: - List setOfNumbers = [ '1', '2' ] as List + List setOfNumbers = [ '1', '2' ] when: String numbers = CatalogUtils.toShortForm(setOfNumbers) then: @@ -61,7 +61,7 @@ class CatalogUtilsTest extends Specification { def "toShortForm() should produce range for sequence"() { given: - List setOfNumbers = [ '1', '2', '3' ] as List + List setOfNumbers = [ '1', '2', '3' ] when: String numbers = CatalogUtils.toShortForm(setOfNumbers) then: @@ -70,7 +70,7 @@ class CatalogUtilsTest extends Specification { def "toShortForm() should return comma separated numbers if they are not a sequence"() { given: - List setOfNumbers = [ '1', '2', '4', '5' ] as List + List setOfNumbers = [ '1', '2', '4', '5' ] when: String numbers = CatalogUtils.toShortForm(setOfNumbers) then: @@ -79,7 +79,7 @@ class CatalogUtilsTest extends Specification { def "toShortForm() should produce two ranges for two sequences"() { given: - List setOfNumbers = [ '1', '2', '3', '10', '19', '20', '21' ] as List + List setOfNumbers = [ '1', '2', '3', '10', '19', '20', '21' ] when: String numbers = CatalogUtils.toShortForm(setOfNumbers) then: diff --git a/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy b/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy index a73165743f..3f3d10dc67 100644 --- a/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy @@ -89,7 +89,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(totalRecords, 10, 1) then: - pager.items == [ 1 ] as List + pager.items == [ 1 ] where: totalRecords | _ 0 | _ @@ -103,7 +103,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(20, 10, currentPage) then: - pager.items == [ 1, 2 ] as List + pager.items == [ 1, 2 ] where: currentPage | _ 1 | _ @@ -115,7 +115,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(30, 10, currentPage) then: - pager.items == [ 1, 2, 3 ] as List + pager.items == [ 1, 2, 3 ] where: currentPage | _ 1 | _ @@ -128,7 +128,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(40, 10, currentPage) then: - pager.items == [ 1, 2, 3, 4 ] as List + pager.items == [ 1, 2, 3, 4 ] where: currentPage | _ 1 | _ @@ -142,7 +142,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(50, 10, currentPage) then: - pager.items == [ 1, 2, 3, 4, 5 ] as List + pager.items == [ 1, 2, 3, 4, 5 ] where: currentPage | _ 1 | _ @@ -157,7 +157,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(51, 10, currentPage) then: - pager.items == [ 1, 2, 3, 4, 5 ] as List + pager.items == [ 1, 2, 3, 4, 5 ] where: currentPage | _ 1 | _ @@ -169,7 +169,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(90, 10, 4) then: - pager.items == [ 2, 3, 4, 5, 6 ] as List + pager.items == [ 2, 3, 4, 5, 6 ] } @Unroll @@ -177,7 +177,7 @@ class PagerTest extends Specification { when: Pager pager = new Pager(60, 10, currentPage) then: - pager.items == [ 2, 3, 4, 5, 6 ] as List + pager.items == [ 2, 3, 4, 5, 6 ] where: currentPage | _ 6 | _ From a5ce998f7083a706b85a4502789ee384cfb4ad48 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 1 Aug 2016 19:55:05 +0200 Subject: [PATCH 066/463] Fix UnnecessaryDefInMethodDeclaration warnings from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-unnecessary.html#UnnecessaryDefInMethodDeclaration No functional changes. --- .../ru/mystamps/web/service/CronServiceImplTest.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy index 11a99d2b06..cd31838f3c 100644 --- a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy @@ -42,26 +42,26 @@ class CronServiceImplTest extends Specification { mailService ) - private static def assertMidnight(Date date) { + private static void assertMidnight(Date date) { assert date[Calendar.HOUR_OF_DAY] == 0 assert date[Calendar.MINUTE] == 0 assert date[Calendar.SECOND] == 0 assert date[Calendar.MILLISECOND] == 0 } - private static def assertDatesEqual(Date first, Date second) { + private static void assertDatesEqual(Date first, Date second) { assert first[Calendar.YEAR] == second[Calendar.YEAR] assert first[Calendar.MONTH] == second[Calendar.MONTH] assert first[Calendar.DAY_OF_MONTH] == second[Calendar.DAY_OF_MONTH] } - private static def assertMidnightOfYesterday(Date date) { + private static void assertMidnightOfYesterday(Date date) { assert date != null assertDatesEqual(date, new Date().previous()) assertMidnight(date) } - private static def assertMidnightOfToday(Date date) { + private static void assertMidnightOfToday(Date date) { assert date != null assertDatesEqual(date, new Date()) assertMidnight(date) From 8820f3134e4d1b88ee232ca29aeaa876dd2c770a Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 1 Aug 2016 19:58:45 +0200 Subject: [PATCH 067/463] Fix ConsecutiveBlankLines warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-formatting.html#ConsecutiveBlankLines No functional changes. --- .../ru/mystamps/web/service/CollectionServiceImplTest.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index adca8a15bf..5918f6d415 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -138,7 +138,6 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } - def "removeFromCollection() should find collection by user id"() { given: Integer expectedUserId = 123 From 36289ab99dc00e14183e0092a78b8b60ac7a3a51 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 1 Aug 2016 20:04:51 +0200 Subject: [PATCH 068/463] Fix UnusedVariable warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-unused.html#UnusedVariable No functional changes. --- .../groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy index 24510f2383..b4a6482435 100644 --- a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy @@ -120,7 +120,7 @@ class ImageServiceImplTest extends Specification { given: ImageInfoDto image = TestObjects.createImageInfoDto() when: - String url = service.save(multipartFile) + service.save(multipartFile) then: imageDao.add(_ as String) >> image.id and: From b19a1d59790e8ec6c0ca737d543cfa92ddb47977 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 15:15:29 +0200 Subject: [PATCH 069/463] Suppress violations that I won't fix. --- .../service/CategoryServiceImplTest.groovy | 15 ++++ .../service/CollectionServiceImplTest.groovy | 12 ++++ .../web/service/CountryServiceImplTest.groovy | 15 ++++ .../web/service/CronServiceImplTest.groovy | 4 ++ ...atabaseImagePersistenceStrategyTest.groovy | 4 ++ ...esystemImagePersistenceStrategyTest.groovy | 3 + .../GibbonsCatalogServiceImplTest.groovy | 2 + .../web/service/ImageServiceImplTest.groovy | 11 +++ .../MichelCatalogServiceImplTest.groovy | 2 + .../ScottCatalogServiceImplTest.groovy | 2 + .../web/service/SeriesServiceImplTest.groovy | 68 +++++++++++++++++++ .../web/service/SiteServiceImplTest.groovy | 19 ++++++ .../SuspiciousActivityServiceImplTest.groovy | 3 + .../web/service/UserServiceImplTest.groovy | 13 ++++ .../UsersActivationServiceImplTest.groovy | 12 ++++ .../YvertCatalogServiceImplTest.groovy | 2 + .../mystamps/web/util/CatalogUtilsTest.groovy | 1 + .../mystamps/web/util/LocaleUtilsTest.groovy | 5 +- .../ru/mystamps/web/util/PagerTest.groovy | 3 + .../ru/mystamps/web/util/SlugUtilsTest.groovy | 2 + 20 files changed, 197 insertions(+), 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index 181e39ea4d..fef3a599a6 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -27,6 +27,7 @@ import ru.mystamps.web.dao.dto.LinkEntityDto import ru.mystamps.web.tests.DateUtils import ru.mystamps.web.util.SlugUtils +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CategoryServiceImplTest extends Specification { private AddCategoryForm form @@ -92,6 +93,7 @@ class CategoryServiceImplTest extends Specification { actualSlug == expectedSlug } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass English category name to dao"() { given: String expectedCategoryName = 'Animals' @@ -105,6 +107,7 @@ class CategoryServiceImplTest extends Specification { }) >> 20 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass Russian category name to dao"() { given: String expectedCategoryName = 'Животные' @@ -127,6 +130,7 @@ class CategoryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass slug to dao"() { given: String name = '-foo123 test_' @@ -143,6 +147,7 @@ class CategoryServiceImplTest extends Specification { }) >> 40 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created at to current date"() { when: service.add(form, userId) @@ -153,6 +158,7 @@ class CategoryServiceImplTest extends Specification { }) >> 50 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated at to current date"() { when: service.add(form, userId) @@ -163,6 +169,7 @@ class CategoryServiceImplTest extends Specification { }) >> 60 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created by to user"() { given: Integer expectedUserId = 10 @@ -175,6 +182,7 @@ class CategoryServiceImplTest extends Specification { }) >> 70 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated by to user"() { given: Integer expectedUserId = 20 @@ -207,6 +215,7 @@ class CategoryServiceImplTest extends Specification { } @Unroll + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findAllAsLinkEntities(String) should pass language '#expectedLanguage' to dao"(String expectedLanguage) { when: service.findAllAsLinkEntities(expectedLanguage) @@ -238,6 +247,7 @@ class CategoryServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findOneAsLinkEntity() should pass arguments to dao"() { given: String expectedSlug = 'people' @@ -288,6 +298,7 @@ class CategoryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countCategoriesOf() should pass arguments to dao"() { given: Integer expectedCollectionId = 10 @@ -320,6 +331,7 @@ class CategoryServiceImplTest extends Specification { result == 2L } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countByName() should pass category name to dao in lowercase"() { when: service.countByName('Sport') @@ -350,6 +362,7 @@ class CategoryServiceImplTest extends Specification { result == 2L } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countByNameRu() should pass category name to dao in lowercase"() { when: service.countByNameRu('Спорт') @@ -371,6 +384,7 @@ class CategoryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countAddedSince() should invoke dao, pass argument and return result from dao"() { given: Date expectedDate = new Date() @@ -398,6 +412,7 @@ class CategoryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "getStatisticsOf() should pass arguments to dao"() { given: Integer expectedCollectionId = 15 diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index 5918f6d415..136ea126db 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -26,6 +26,7 @@ import ru.mystamps.web.dao.dto.CollectionInfoDto import ru.mystamps.web.dao.dto.UrlEntityDto import ru.mystamps.web.util.SlugUtils +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CollectionServiceImplTest extends Specification { private CollectionDao collectionDao = Mock() @@ -39,6 +40,7 @@ class CollectionServiceImplTest extends Specification { // Tests for createCollection() // + @SuppressWarnings('FactoryMethodName') def "createCollection() should throw exception when owner id is null"() { when: service.createCollection(null, 'test-owner-login') @@ -46,6 +48,7 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings('FactoryMethodName') def "createCollection() should throw exception when owner login is null"() { when: service.createCollection(123, null) @@ -53,6 +56,7 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings('FactoryMethodName') def "createCollection() should throw exception when owner login can't be converted to slug"() { when: service.createCollection(123, '') @@ -60,6 +64,7 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'FactoryMethodName', 'UnnecessaryReturnKeyword']) def "createCollection() should pass owner id to dao"() { given: Integer expectedOwnerId = 123 @@ -72,6 +77,7 @@ class CollectionServiceImplTest extends Specification { }) >> 100 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'FactoryMethodName', 'UnnecessaryReturnKeyword']) def "createCollection() should pass slugified owner login to dao"() { given: String ownerLogin = 'Test User' @@ -104,6 +110,7 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "addToCollection() should pass arguments to dao"() { given: Integer expectedUserId = 123 @@ -138,6 +145,7 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "removeFromCollection() should find collection by user id"() { given: Integer expectedUserId = 123 @@ -150,6 +158,7 @@ class CollectionServiceImplTest extends Specification { }) >> TestObjects.createUrlEntityDto() } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "removeFromCollection() should remove series from collection"() { given: Integer expectedSeriesId = 456 @@ -204,6 +213,7 @@ class CollectionServiceImplTest extends Specification { 0 * collectionDao.isSeriesInUserCollection(_ as Integer, _ as Integer) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "isSeriesInCollection() should pass arguments to dao"() { given: Integer expectedUserId = 123 @@ -256,6 +266,7 @@ class CollectionServiceImplTest extends Specification { 0 | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findRecentlyCreated() should pass arguments to dao"() { given: int expectedQuantity = 4 @@ -279,6 +290,7 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findBySlug() should invoke dao, pass argument and return result from dao"() { given: String expectedSlug = 'cuba' diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index 6f57bea871..fd786c7b91 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -28,6 +28,7 @@ import ru.mystamps.web.dao.dto.UrlEntityDto import ru.mystamps.web.tests.DateUtils import ru.mystamps.web.util.SlugUtils +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CountryServiceImplTest extends Specification { private AddCountryForm form @@ -93,6 +94,7 @@ class CountryServiceImplTest extends Specification { actualSlug == expectedSlug } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass country name in English to dao"() { given: String expectedCountryName = 'Italy' @@ -106,6 +108,7 @@ class CountryServiceImplTest extends Specification { }) >> 20 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass country name in Russian to dao"() { given: String expectedCountryName = 'Италия' @@ -128,6 +131,7 @@ class CountryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass slug to dao"() { given: String name = '-foo123 test_' @@ -144,6 +148,7 @@ class CountryServiceImplTest extends Specification { }) >> 40 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created at to current date"() { when: service.add(form, userId) @@ -154,6 +159,7 @@ class CountryServiceImplTest extends Specification { }) >> 50 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated at to current date"() { when: service.add(form, userId) @@ -164,6 +170,7 @@ class CountryServiceImplTest extends Specification { }) >> 60 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created by to user"() { given: Integer expectedUserId = 10 @@ -176,6 +183,7 @@ class CountryServiceImplTest extends Specification { }) >> 70 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated by to user"() { given: Integer expectedUserId = 10 @@ -208,6 +216,7 @@ class CountryServiceImplTest extends Specification { } @Unroll + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findAllAsLinkEntities(String) should pass language '#expectedLanguage' to dao"(String expectedLanguage) { when: service.findAllAsLinkEntities(expectedLanguage) @@ -238,6 +247,7 @@ class CountryServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findOneAsLinkEntity() should pass arguments to dao"() { given: String expectedSlug = 'france' @@ -288,6 +298,7 @@ class CountryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countCountriesOf() should pass arguments to dao"() { given: Integer expectedCollectionId = 9 @@ -320,6 +331,7 @@ class CountryServiceImplTest extends Specification { result == 2L } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countByName() should pass country name to dao in lowercase"() { when: service.countByName('Canada') @@ -350,6 +362,7 @@ class CountryServiceImplTest extends Specification { result == 2L } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countByNameRu() should pass category name to dao in lowercase"() { when: service.countByNameRu('Канада') @@ -371,6 +384,7 @@ class CountryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countAddedSince() should invoke dao, pass argument and return result from dao"() { given: Date expectedDate = new Date() @@ -398,6 +412,7 @@ class CountryServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "getStatisticsOf() should pass arguments to dao"() { given: Integer expectedCollectionId = 17 diff --git a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy index cd31838f3c..9eeed6933c 100644 --- a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy @@ -22,6 +22,7 @@ import spock.lang.Specification import ru.mystamps.web.dao.dto.UsersActivationFullDto import ru.mystamps.web.service.dto.AdminDailyReport +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CronServiceImplTest extends Specification { private CategoryService categoryService = Mock() @@ -71,6 +72,7 @@ class CronServiceImplTest extends Specification { // Tests for sendDailyStatistics() // + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "sendDailyStatistics() should invoke services and pass start date to them"() { when: service.sendDailyStatistics() @@ -117,6 +119,7 @@ class CronServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "sendDailyStatistics() should prepare report and pass it to mail service"() { given: categoryService.countAddedSince(_ as Date) >> 1 @@ -164,6 +167,7 @@ class CronServiceImplTest extends Specification { 1 * usersActivationService.findOlderThan(_ as Integer) >> [] } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "purgeUsersActivations() should pass days to service"() { given: int expectedDays = CronService.PURGE_AFTER_DAYS diff --git a/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy index 60e4323568..49f2b8e6ab 100644 --- a/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy @@ -27,6 +27,7 @@ import ru.mystamps.web.dao.dto.ImageDto import ru.mystamps.web.dao.dto.ImageInfoDto import ru.mystamps.web.service.exception.ImagePersistenceException +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class DatabaseImagePersistenceStrategyTest extends Specification { private ImageDataDao imageDataDao = Mock() @@ -50,6 +51,7 @@ class DatabaseImagePersistenceStrategyTest extends Specification { ex.cause instanceof IOException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "save() should pass file content to image data dao"() { given: byte[] expected = 'test'.bytes @@ -63,6 +65,7 @@ class DatabaseImagePersistenceStrategyTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "save() should pass image to image data dao"() { given: Integer expectedImageId = imageInfoDto.id @@ -79,6 +82,7 @@ class DatabaseImagePersistenceStrategyTest extends Specification { // Tests for get() // + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "get() should pass image to image data dao"() { given: Integer expectedImageId = imageInfoDto.id diff --git a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy index 8cdd2a74df..507f145e80 100644 --- a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy @@ -27,6 +27,7 @@ import ru.mystamps.web.service.exception.ImagePersistenceException import java.nio.file.Path +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class FilesystemImagePersistenceStrategyTest extends Specification { private static final STORAGE_DIR = File.separator + 'tmp' @@ -47,6 +48,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification { 1 * strategy.writeToFile(_ as MultipartFile, _ as Path) >> {} } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "save() should saves file onto the configured directory"() { given: String expectedDirectoryName = STORAGE_DIR @@ -59,6 +61,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification { }) >> {} } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "save() should gives proper name to the file"() { given: String expectedExtension = imageInfoDto.type.toLowerCase() diff --git a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy index f5f65c41e8..6ef55bfae7 100644 --- a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy @@ -21,6 +21,7 @@ import spock.lang.Specification import ru.mystamps.web.dao.StampsCatalogDao +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class GibbonsCatalogServiceImplTest extends Specification { private StampsCatalogDao gibbonsCatalogDao = Mock() @@ -38,6 +39,7 @@ class GibbonsCatalogServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 53 diff --git a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy index b4a6482435..e8dde74a31 100644 --- a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy @@ -27,6 +27,7 @@ import ru.mystamps.web.dao.dto.ImageDto import ru.mystamps.web.dao.dto.ImageInfoDto import ru.mystamps.web.service.exception.ImagePersistenceException +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class ImageServiceImplTest extends Specification { private ImageDao imageDao = Mock() @@ -87,6 +88,11 @@ class ImageServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'UnnecessaryReturnKeyword', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "save() should pass content type '#contentType' to image dao"(String contentType, String expectedType) { when: service.save(multipartFile) @@ -116,6 +122,7 @@ class ImageServiceImplTest extends Specification { thrown ImagePersistenceException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "save() should call strategy"() { given: ImageInfoDto image = TestObjects.createImageInfoDto() @@ -162,6 +169,7 @@ class ImageServiceImplTest extends Specification { 0 | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "get() should pass argument to image dao"() { when: service.get(7) @@ -183,6 +191,7 @@ class ImageServiceImplTest extends Specification { image == null } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "get() should pass argument to strategy and return result from it"() { given: ImageInfoDto expectedImage = TestObjects.createImageInfoDto() @@ -231,6 +240,7 @@ class ImageServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "addToSeries() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 14 @@ -258,6 +268,7 @@ class ImageServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 14 diff --git a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy index a22fa0b8ce..372a64e26d 100644 --- a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy @@ -21,6 +21,7 @@ import spock.lang.Specification import ru.mystamps.web.dao.StampsCatalogDao +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class MichelCatalogServiceImplTest extends Specification { private StampsCatalogDao michelCatalogDao = Mock() @@ -38,6 +39,7 @@ class MichelCatalogServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 50 diff --git a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy index 5a841fb6c5..480050ad31 100644 --- a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy @@ -21,6 +21,7 @@ import spock.lang.Specification import ru.mystamps.web.dao.StampsCatalogDao +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class ScottCatalogServiceImplTest extends Specification { private StampsCatalogDao scottCatalogDao = Mock() @@ -38,6 +39,7 @@ class ScottCatalogServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 52 diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index 6fd6ebe882..bc7d4c9bfa 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -33,6 +33,7 @@ import ru.mystamps.web.dao.dto.SeriesInfoDto import ru.mystamps.web.dao.dto.SitemapInfoDto import ru.mystamps.web.tests.DateUtils +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class SeriesServiceImplTest extends Specification { private static final BigDecimal ANY_PRICE = new BigDecimal('17') private static final Integer ANY_IMAGE_ID = 18 @@ -126,6 +127,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should load and pass country to series dao if country present"() { given: LinkEntityDto country = TestObjects.createLinkEntityDto() @@ -143,6 +145,7 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass date of release (#expectedDay/#expectedMonth/#expectedYear) when it's #day/#month/#year"( Integer day, Integer month, Integer year, Integer expectedDay, Integer expectedMonth, Integer expectedYear) { @@ -172,6 +175,7 @@ class SeriesServiceImplTest extends Specification { null | 6 | null || null | null | null } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass category to series dao"() { given: LinkEntityDto category = TestObjects.createLinkEntityDto() @@ -188,6 +192,7 @@ class SeriesServiceImplTest extends Specification { }) >> 123 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass quantity to series dao"() { given: Integer expectedQuantity = 3 @@ -201,6 +206,7 @@ class SeriesServiceImplTest extends Specification { }) >> 123 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass perforated to series dao"() { given: Boolean expectedResult = true @@ -215,6 +221,12 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'UnnecessaryReturnKeyword', + 'LineLength', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "add() should pass michel price and currency to series dao"(BigDecimal price, BigDecimal expectedPrice, String expectedCurrency) { given: form.setMichelPrice(price) @@ -233,6 +245,12 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'LineLength', + 'UnnecessaryReturnKeyword', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "add() should pass scott price and currency to series dao"(BigDecimal price, BigDecimal expectedPrice, String expectedCurrency) { given: form.setScottPrice(price) @@ -251,6 +269,12 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'LineLength', + 'UnnecessaryReturnKeyword', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "add() should pass yvert price and currency to series dao"(BigDecimal price, BigDecimal expectedPrice, String expectedCurrency) { given: form.setYvertPrice(price) @@ -269,6 +293,12 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'LineLength', + 'UnnecessaryReturnKeyword', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "add() should pass gibbons price and currency to series dao"(BigDecimal price, BigDecimal expectedPrice, String expectedCurrency) { given: form.setGibbonsPrice(price) @@ -296,6 +326,12 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'LineLength', + 'UnnecessaryReturnKeyword', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "add() should pass '#expectedComment' as comment to series dao if user can add comment is #canAddComment"(boolean canAddComment, String comment, String expectedComment) { given: form.setComment(comment) @@ -314,6 +350,7 @@ class SeriesServiceImplTest extends Specification { true | 'Some text' || 'Some text' } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created at to current date"() { when: service.add(form, userId, false) @@ -324,6 +361,7 @@ class SeriesServiceImplTest extends Specification { }) >> 123 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated at to current date"() { when: service.add(form, userId, false) @@ -334,6 +372,7 @@ class SeriesServiceImplTest extends Specification { }) >> 123 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created by to user"() { given: Integer expectedUserId = 456 @@ -346,6 +385,7 @@ class SeriesServiceImplTest extends Specification { }) >> 123 } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated by to user"() { given: Integer expectedUserId = 789 @@ -369,6 +409,7 @@ class SeriesServiceImplTest extends Specification { actual == expected } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass image to image service"() { given: form.setImage(multipartFile) @@ -381,6 +422,7 @@ class SeriesServiceImplTest extends Specification { }) >> ANY_IMAGE_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should add image to the series"() { given: Integer expectedSeriesId = 123 @@ -419,6 +461,7 @@ class SeriesServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should add michel numbers to series"() { given: Set expectedNumbers = [ '1', '2' ] as Set @@ -461,6 +504,7 @@ class SeriesServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should add scott numbers to series"() { given: Set expectedNumbers = [ '1', '2' ] as Set @@ -503,6 +547,7 @@ class SeriesServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should add yvert numbers to series"() { given: Set expectedNumbers = [ '1', '2' ] as Set @@ -545,6 +590,7 @@ class SeriesServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should add gibbons numbers to series"() { given: Set expectedNumbers = [ '1', '2' ] as Set @@ -575,6 +621,7 @@ class SeriesServiceImplTest extends Specification { // Tests for addImageToSeries() // + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "addImageToSeries() should call dao and pass series id, current date and user id to it"() { given: Integer expectedSeriesId = 123 @@ -636,6 +683,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countSeriesOf() should pass argument to dao"() { given: Integer expectedCollectionId = 7 @@ -659,6 +707,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countStampsOf() should pass arguments to dao"() { given: Integer expectedCollectionId = 8 @@ -682,6 +731,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countAddedSince() should invoke dao, pass argument and return result from dao"() { given: Date expectedDate = new Date() @@ -709,6 +759,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countUpdatedSince() should invoke dao, pass argument and return result from dao"() { given: Date expectedDate = new Date() @@ -737,6 +788,12 @@ class SeriesServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'UnnecessaryReturnKeyword', + 'LineLength', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "isSeriesExist() should invoke dao, pass argument and return result from dao"(Integer daoReturnValue, boolean expectedResult) { given: Integer expectedSeriesId = 13 @@ -772,6 +829,7 @@ class SeriesServiceImplTest extends Specification { ' ' | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByMichelNumber() should find series ids"() { given: String expectedMichelNumber = '5' @@ -795,6 +853,7 @@ class SeriesServiceImplTest extends Specification { result.empty } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByMichelNumber() should find and return series info"() { given: String expectedLang = 'en' @@ -835,6 +894,7 @@ class SeriesServiceImplTest extends Specification { ' ' | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByScottNumber() should find series ids"() { given: String expectedScottNumber = '5' @@ -858,6 +918,7 @@ class SeriesServiceImplTest extends Specification { result.empty } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByScottNumber() should find and return series info"() { given: String expectedLang = 'en' @@ -898,6 +959,7 @@ class SeriesServiceImplTest extends Specification { ' ' | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByYvertNumber() should find series ids"() { given: String expectedYvertNumber = '5' @@ -921,6 +983,7 @@ class SeriesServiceImplTest extends Specification { result.empty } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByYvertNumber() should find and return series info"() { given: String expectedLang = 'en' @@ -961,6 +1024,7 @@ class SeriesServiceImplTest extends Specification { ' ' | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByGibbonsNumber() should find series ids"() { given: String expectedGibbonsNumber = '5' @@ -984,6 +1048,7 @@ class SeriesServiceImplTest extends Specification { result.empty } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByGibbonsNumber() should find and return series info"() { given: String expectedLang = 'en' @@ -1066,6 +1131,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findByCollectionId() should pass arguments to dao"() { given: Integer expectedCollectionId = 16 @@ -1102,6 +1168,7 @@ class SeriesServiceImplTest extends Specification { 0 | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findRecentlyAdded should pass arguments to dao"() { given: int expectedQuantity = 3 @@ -1149,6 +1216,7 @@ class SeriesServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findPurchasesAndSales() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 88 diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index 966dcc3840..d86ec22100 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -25,6 +25,7 @@ import ru.mystamps.web.dao.SuspiciousActivityDao import ru.mystamps.web.dao.dto.AddSuspiciousActivityDbDto import ru.mystamps.web.tests.DateUtils +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class SiteServiceImplTest extends Specification { private static final String TEST_TYPE = TestObjects.TEST_ACTIVITY_TYPE private static final String TEST_PAGE = TestObjects.TEST_ACTIVITY_PAGE @@ -46,6 +47,7 @@ class SiteServiceImplTest extends Specification { // Tests for logAboutAbsentPage() // + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logAboutAbsentPage() should pass arguments to logEvent()"() { given: Integer expectedUserId = 17 @@ -130,6 +132,7 @@ class SiteServiceImplTest extends Specification { 1 * suspiciousActivityDao.add(_ as AddSuspiciousActivityDbDto) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass activity type to dao"() { given: String expectedType = 'expectedType' @@ -142,6 +145,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should assign occurred at to specified date when date was provided"() { given: Date expectedDate = new Date() - 100 @@ -154,6 +158,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should assign occurred at to current date when date wasn't provided"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, null, null) @@ -164,6 +169,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass page to dao"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, null, null) @@ -174,6 +180,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logAboutAbsentPage() should pass abbreviated page when it's too long"() { given: String longPageUrl = '/long/url/' + ('x' * Db.SuspiciousActivity.PAGE_URL_LENGTH) @@ -189,6 +196,7 @@ class SiteServiceImplTest extends Specification { } @Unroll + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass method to dao"(String expectedMethod) { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, expectedMethod, null, null, null, null, null) @@ -202,6 +210,7 @@ class SiteServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass abbreviated method when it's too long"() { given: String method = 'PROPFIND' @@ -216,6 +225,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass null to dao for unknown user id"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, null, null) @@ -226,6 +236,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass user id to dao"() { given: Integer expectedUserId = 20 @@ -238,6 +249,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass ip to dao"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, TEST_IP, null, null, null) @@ -248,6 +260,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass empty string to dao for unknown ip"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, null, null) @@ -258,6 +271,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass referer to dao"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, TEST_REFERER_PAGE, null, null) @@ -268,6 +282,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass abbreviated referer when it's too long"() { given: String longRefererUrl = '/long/url/' + ('x' * Db.SuspiciousActivity.REFERER_PAGE_LENGTH) @@ -282,6 +297,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass null to dao for unknown referer"(String refererPage) { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, refererPage, null, null) @@ -296,6 +312,7 @@ class SiteServiceImplTest extends Specification { null | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass user agent to dao"() { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, TEST_USER_AGENT, null) @@ -306,6 +323,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass abbreviated user agent when it's too long"() { given: String longUserAgent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/' + ('x' * Db.SuspiciousActivity.USER_AGENT_LENGTH) @@ -320,6 +338,7 @@ class SiteServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "logEvent() should pass null to dao for unknown user agent"(String userAgent) { when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, TEST_METHOD, null, null, null, userAgent, null) diff --git a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy index dffdc6f95e..571b2340ec 100644 --- a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy @@ -23,6 +23,7 @@ import spock.lang.Unroll import ru.mystamps.web.dao.SuspiciousActivityDao import ru.mystamps.web.dao.dto.SuspiciousActivityDto +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class SuspiciousActivityServiceImplTest extends Specification { private SuspiciousActivityDao suspiciousActivityDao = Mock() @@ -68,6 +69,7 @@ class SuspiciousActivityServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countByTypeSince() should invoke dao, pass arguments and return result from dao"() { given: String expectedType = 'ExpectedType' @@ -115,6 +117,7 @@ class SuspiciousActivityServiceImplTest extends Specification { 0 | _ } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findSuspiciousActivities() should invoke dao and return result from dao"() { given: int expectedPage = 5 diff --git a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy index 84ee535bb4..f13a18d9bf 100644 --- a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy @@ -28,6 +28,7 @@ import ru.mystamps.web.dao.dto.UsersActivationDto import ru.mystamps.web.model.ActivateAccountForm import ru.mystamps.web.tests.DateUtils +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class UserServiceImplTest extends Specification { private static Integer ANY_USER_ID = TestObjects.TEST_USER_ID @@ -75,6 +76,7 @@ class UserServiceImplTest extends Specification { 1 * userDao.add(_ as AddUserDbDto) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should delete registration request"() { given: String expectedActivationKey = activationForm.activationKey @@ -109,6 +111,7 @@ class UserServiceImplTest extends Specification { 0 * usersActivationService.remove(_ as String) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should pass name to dao"() { given: String expectedUserName = activationForm.name @@ -121,6 +124,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should pass login instead of name when name is null"() { given: String expectedUserLogin = activationForm.login @@ -134,6 +138,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should pass login instead of name when name is empty"() { given: String expectedUserLogin = activationForm.login @@ -148,6 +153,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should fill role field"() { when: service.registerUser(activationForm) @@ -158,6 +164,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should use email from registration request"() { given: UsersActivationDto activation = new UsersActivationDto('test@example.org', new Date()) @@ -172,6 +179,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should use registration date from registration request"() { given: UsersActivationDto activation = new UsersActivationDto(TestObjects.TEST_EMAIL, new Date(86, 8, 12)) @@ -195,6 +203,7 @@ class UserServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should gets hash from encoder"() { given: String expectedHash = TestObjects.createAddUserDbDto().hash @@ -230,6 +239,7 @@ class UserServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should pass login to dao"() { given: String expectedUserLogin = activationForm.login @@ -242,6 +252,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should assign activated at to current date"() { when: service.registerUser(activationForm) @@ -252,6 +263,7 @@ class UserServiceImplTest extends Specification { }) >> ANY_USER_ID } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "registerUser() should create collection for user"() { given: Integer expectedId = 909 @@ -336,6 +348,7 @@ class UserServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countRegisteredSince() should invoke dao, pass argument and return result from dao"() { given: Date expectedDate = new Date() diff --git a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy index 8214dac7db..d689424777 100644 --- a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy @@ -28,6 +28,7 @@ import ru.mystamps.web.service.dto.SendUsersActivationDto import ru.mystamps.web.tests.DateUtils import ru.mystamps.web.validation.ValidationRules +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class UsersActivationServiceImplTest extends Specification { private UsersActivationDao usersActivationDao = Mock() @@ -63,6 +64,7 @@ class UsersActivationServiceImplTest extends Specification { 1 * usersActivationDao.add(_ as AddUsersActivationDbDto) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should generate activation key"() { when: service.add(registrationForm, ANY_LOCALE) @@ -74,6 +76,7 @@ class UsersActivationServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should generate unique activation key"() { given: List passedArguments = [] @@ -106,6 +109,7 @@ class UsersActivationServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass email to dao"() { given: String expectedEmail = 'somename@example.org' @@ -120,6 +124,11 @@ class UsersActivationServiceImplTest extends Specification { } @Unroll + @SuppressWarnings([ + 'ClosureAsLastMethodParameter', + 'UnnecessaryReturnKeyword', + /* false positive: */ 'UnnecessaryBooleanExpression', + ]) def "add() should pass language '#expectedLang' to dao"(Locale lang, String expectedLang) { when: service.add(registrationForm, lang) @@ -134,6 +143,7 @@ class UsersActivationServiceImplTest extends Specification { Locale.FRENCH || 'fr' } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created at to current date"() { when: service.add(registrationForm, ANY_LOCALE) @@ -144,6 +154,7 @@ class UsersActivationServiceImplTest extends Specification { }) } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should pass user's activation request to mail service"() { when: service.add(registrationForm, Locale.FRANCE) @@ -195,6 +206,7 @@ class UsersActivationServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "countCreatedSince() should invoke dao, pass argument and return result from dao"() { given: Date expectedDate = new Date() diff --git a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy index d638ecf0ed..3b8b9d7df4 100644 --- a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy @@ -21,6 +21,7 @@ import spock.lang.Specification import ru.mystamps.web.dao.StampsCatalogDao +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class YvertCatalogServiceImplTest extends Specification { private StampsCatalogDao yvertCatalogDao = Mock() @@ -38,6 +39,7 @@ class YvertCatalogServiceImplTest extends Specification { thrown IllegalArgumentException } + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { given: Integer expectedSeriesId = 51 diff --git a/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy b/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy index 13d0668660..fdcaf7fb8c 100644 --- a/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/CatalogUtilsTest.groovy @@ -19,6 +19,7 @@ package ru.mystamps.web.util import spock.lang.Specification +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CatalogUtilsTest extends Specification { // diff --git a/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy b/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy index 1def2a0e7d..8764105509 100644 --- a/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/LocaleUtilsTest.groovy @@ -20,6 +20,7 @@ package ru.mystamps.web.util import spock.lang.Specification import spock.lang.Unroll +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class LocaleUtilsTest extends Specification { // @@ -27,6 +28,7 @@ class LocaleUtilsTest extends Specification { // @Unroll + @SuppressWarnings('UnnecessaryBooleanExpression') // false positive def "getLanguageOrNull() should extract language '#language' from locale '#locale'"(Locale locale, String language) { when: String result = LocaleUtils.getLanguageOrNull(locale) @@ -44,7 +46,8 @@ class LocaleUtilsTest extends Specification { // @Unroll - def "getLanguageOrDefault() should returns '#expected' for #locale/#value"(Locale locale, String value, String expected) { + @SuppressWarnings(['LineLength', /* false positive: */ 'UnnecessaryBooleanExpression']) + def "getLanguageOrDefault() should return '#expected' for #locale/#value"(Locale locale, String value, String expected) { when: String result = LocaleUtils.getLanguageOrDefault(locale, value) then: diff --git a/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy b/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy index 3f3d10dc67..ffb74b3df2 100644 --- a/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/PagerTest.groovy @@ -20,6 +20,7 @@ package ru.mystamps.web.util import spock.lang.Specification import spock.lang.Unroll +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class PagerTest extends Specification { // @@ -190,6 +191,7 @@ class PagerTest extends Specification { // @Unroll + @SuppressWarnings('UnnecessaryBooleanExpression') // false positive def "getPrev() should return #prev for when page = #currentPage"(int currentPage, Integer prev) { when: Pager pager = new Pager(3, 1, currentPage) @@ -207,6 +209,7 @@ class PagerTest extends Specification { // @Unroll + @SuppressWarnings('UnnecessaryBooleanExpression') // false positive def "getNext() should return #next for when page = #currentPage"(int currentPage, Integer next) { when: Pager pager = new Pager(3, 1, currentPage) diff --git a/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy b/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy index f2f6da2564..cccdde955e 100644 --- a/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy +++ b/src/test/groovy/ru/mystamps/web/util/SlugUtilsTest.groovy @@ -20,6 +20,7 @@ package ru.mystamps.web.util import spock.lang.Specification import spock.lang.Unroll +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class SlugUtilsTest extends Specification { // @@ -34,6 +35,7 @@ class SlugUtilsTest extends Specification { } @Unroll + @SuppressWarnings('UnnecessaryBooleanExpression') // false positive def "slugify() should transform text '#input' to '#output'"(String input, String output) { when: String result = SlugUtils.slugify(input) From 29d92fb0f0479a6d2a2c44c53d6629ed5e043298 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 15:45:25 +0200 Subject: [PATCH 070/463] SeriesServiceImplTest: fix LineLength warning from CodeNarc. No functional changes. --- .../web/service/SeriesServiceImplTest.groovy | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index bc7d4c9bfa..c52708ceb4 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -817,16 +817,16 @@ class SeriesServiceImplTest extends Specification { // @Unroll - def "findByMichelNumber() should throw exception for invalid argument '#michelNumberCode'"(String michelNumberCode) { + def "findByMichelNumber() should throw exception for invalid argument '#catalogNumber'"(String catalogNumber) { when: - service.findByMichelNumber(michelNumberCode, 'en') + service.findByMichelNumber(catalogNumber, 'en') then: thrown IllegalArgumentException where: - michelNumberCode | _ - null | _ - '' | _ - ' ' | _ + catalogNumber | _ + null | _ + '' | _ + ' ' | _ } @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) @@ -882,16 +882,16 @@ class SeriesServiceImplTest extends Specification { // @Unroll - def "findByScottNumber() should throw exception for invalid argument '#scottNumberCode'"(String scottNumberCode) { + def "findByScottNumber() should throw exception for invalid argument '#catalogNumber'"(String catalogNumber) { when: - service.findByScottNumber(scottNumberCode, 'en') + service.findByScottNumber(catalogNumber, 'en') then: thrown IllegalArgumentException where: - scottNumberCode | _ - null | _ - '' | _ - ' ' | _ + catalogNumber | _ + null | _ + '' | _ + ' ' | _ } @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) @@ -947,16 +947,16 @@ class SeriesServiceImplTest extends Specification { // @Unroll - def "findByYvertNumber() should throw exception for invalid argument '#yvertNumberCode'"(String yvertNumberCode) { + def "findByYvertNumber() should throw exception for invalid argument '#catalogNumber'"(String catalogNumber) { when: - service.findByYvertNumber(yvertNumberCode, 'en') + service.findByYvertNumber(catalogNumber, 'en') then: thrown IllegalArgumentException where: - yvertNumberCode | _ - null | _ - '' | _ - ' ' | _ + catalogNumber | _ + null | _ + '' | _ + ' ' | _ } @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) @@ -1012,16 +1012,16 @@ class SeriesServiceImplTest extends Specification { // @Unroll - def "findByGibbonsNumber() should throw exception for invalid argument '#gibbonsNumberCode'"(String gibbonsNumberCode) { + def "findByGibbonsNumber() should throw exception for invalid argument '#catalogNumber'"(String catalogNumber) { when: - service.findByGibbonsNumber(gibbonsNumberCode, 'en') + service.findByGibbonsNumber(catalogNumber, 'en') then: thrown IllegalArgumentException where: - gibbonsNumberCode | _ - null | _ - '' | _ - ' ' | _ + catalogNumber | _ + null | _ + '' | _ + ' ' | _ } @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) From 93f0c421ad307ec9b998d80c7a37c2b42b46f624 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 16:23:28 +0200 Subject: [PATCH 071/463] CountryServiceImplTest: remove unused import. Reported by CodeNarc. Should be in e174bec6ad25868c37f3cda4e5ffd31f1a803db1 commit. No functional changes. --- .../groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index fd786c7b91..4253a93dff 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -24,7 +24,6 @@ import ru.mystamps.web.dao.CountryDao import ru.mystamps.web.dao.dto.AddCountryDbDto import ru.mystamps.web.model.AddCountryForm import ru.mystamps.web.dao.dto.LinkEntityDto -import ru.mystamps.web.dao.dto.UrlEntityDto import ru.mystamps.web.tests.DateUtils import ru.mystamps.web.util.SlugUtils From 319f309b313eab1d6341989b2ec675a2421bb69f Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 17:09:41 +0200 Subject: [PATCH 072/463] Fix SpaceAroundOperator warning from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-formatting.html#SpaceAroundOperator No functional changes. --- .../groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index d86ec22100..74652febf7 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -215,7 +215,7 @@ class SiteServiceImplTest extends Specification { given: String method = 'PROPFIND' and: - String exceptedMethod = method.take(Db.SuspiciousActivity.METHOD_LENGTH-3) + '...' + String exceptedMethod = method.take(Db.SuspiciousActivity.METHOD_LENGTH - 3) + '...' when: serviceImpl.logEvent(TEST_TYPE, TEST_PAGE, method, null, null, null, TEST_USER_AGENT, null) then: From 8934430c9cd001a41a96222f6971ff09210e8bf5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 17:14:43 +0200 Subject: [PATCH 073/463] Fix SpaceBeforeClosingBrace warnings from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-formatting.html#SpaceBeforeClosingBrace No functional changes. --- .../service/FilesystemImagePersistenceStrategyTest.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy index 507f145e80..50a0ec3da9 100644 --- a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy @@ -45,7 +45,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification { when: strategy.save(multipartFile, imageInfoDto) then: - 1 * strategy.writeToFile(_ as MultipartFile, _ as Path) >> {} + 1 * strategy.writeToFile(_ as MultipartFile, _ as Path) >> { } } @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) @@ -58,7 +58,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification { 1 * strategy.writeToFile(_ as MultipartFile, { Path path -> assert path.parent.toString() == expectedDirectoryName return true - }) >> {} + }) >> { } } @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) @@ -73,7 +73,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification { 1 * strategy.writeToFile(_ as MultipartFile, { Path path -> assert path.fileName.toString() == expectedFileName return true - }) >> {} + }) >> { } } def "save() should converts IOException to ImagePersistenceException"() { From 8ad211ff5409af400dd09aaceeea898a3ed5a8ca Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 17:17:14 +0200 Subject: [PATCH 074/463] Fix SpaceAroundMapEntryColon warnings from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-formatting.html#SpaceAroundMapEntryColon No functional changes. --- .../web/service/FilesystemImagePersistenceStrategyTest.groovy | 2 +- .../groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy index 50a0ec3da9..8451fd49a1 100644 --- a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy @@ -35,7 +35,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification { private ImageInfoDto imageInfoDto = TestObjects.createImageInfoDto() private Path mockFile = Mock(Path) - private ImagePersistenceStrategy strategy = Spy(FilesystemImagePersistenceStrategy, constructorArgs: [STORAGE_DIR]) + private ImagePersistenceStrategy strategy = Spy(FilesystemImagePersistenceStrategy, constructorArgs:[STORAGE_DIR]) // // Tests for save() diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index 74652febf7..6bfcfa5383 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -40,7 +40,7 @@ class SiteServiceImplTest extends Specification { def setup() { service = new SiteServiceImpl(suspiciousActivityDao) - serviceImpl = Spy(SiteServiceImpl, constructorArgs: [suspiciousActivityDao]) + serviceImpl = Spy(SiteServiceImpl, constructorArgs:[suspiciousActivityDao]) } // From adfa5ead0f3d2fd61fed4b4fdf58baa72669120a Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 19:13:04 +0200 Subject: [PATCH 075/463] check-build-and-verify.sh: run CodeNarc. --- src/main/scripts/ci/check-build-and-verify.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/scripts/ci/check-build-and-verify.sh b/src/main/scripts/ci/check-build-and-verify.sh index 5b2459b2ec..acd2c36563 100755 --- a/src/main/scripts/ci/check-build-and-verify.sh +++ b/src/main/scripts/ci/check-build-and-verify.sh @@ -9,6 +9,7 @@ fi CS_FAIL= PMD_FAIL= +CODENARC_FAIL= LICENSE_FAIL= POM_FAIL= BOOTLINT_FAIL= @@ -20,6 +21,11 @@ VERIFY_FAIL= if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then mvn --batch-mode checkstyle:check -Dcheckstyle.violationSeverity=warning >cs.log 2>&1 || CS_FAIL=yes mvn --batch-mode pmd:check >pmd.log 2>&1 || PMD_FAIL=yes + mvn --batch-mode codenarc:codenarc \ + -Dcodenarc.maxPriority1Violations=0 \ + -Dcodenarc.maxPriority2Violations=0 \ + -Dcodenarc.maxPriority3Violations=0 \ + >codenarc.log 2>&1 || CODENARC_FAIL=yes mvn --batch-mode license:check >license.log 2>&1 || LICENSE_FAIL=yes mvn --batch-mode sortpom:verify -Dsort.verifyFail=stop >pom.log || POM_FAIL=yes find src -type f -name '*.html' | xargs bootlint >bootlint.log 2>&1 || BOOTLINT_FAIL=yes @@ -46,6 +52,7 @@ echo if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then print_status "$CS_FAIL" 'Run CheckStyle' print_status "$PMD_FAIL" 'Run PMD' + print_status "$CODENARC_FAIL" 'Run CodeNarc' print_status "$LICENSE_FAIL" 'Check license headers' print_status "$POM_FAIL" 'Check sorting of pom.xml' print_status "$BOOTLINT_FAIL" 'Run bootlint' @@ -61,6 +68,7 @@ echo if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then print_log cs.log 'Run CheckStyle' print_log pmd.log 'Run PMD' + print_log codenarc.log 'Run CodeNarc' print_log license.log 'Check license headers' print_log pom.log 'Check sorting of pom.xml' print_log bootlint.log 'Run bootlint' @@ -71,8 +79,8 @@ fi print_log verify.log 'Run integration tests' -rm -f cs.log pmd.log license.log bootlint.log jasmine.log validator.log test.log verify.log +rm -f cs.log pmd.log codenarc.log license.log bootlint.log jasmine.log validator.log test.log verify.log -if [ -n "$CS_FAIL$PMD_FAIL$LICENSE_FAIL$POM_FAIL$BOOTLINT_FAIL$JASMINE_FAIL$HTML_FAIL$TEST_FAIL$VERIFY_FAIL" ]; then +if [ -n "$CS_FAIL$PMD_FAIL$CODENARC_FAIL$LICENSE_FAIL$POM_FAIL$BOOTLINT_FAIL$JASMINE_FAIL$HTML_FAIL$TEST_FAIL$VERIFY_FAIL" ]; then exit 1 fi From db150965e87b7ad688c76769de695ce8c86f240a Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 22:53:02 +0200 Subject: [PATCH 076/463] SiteServiceImplTest: remove unused member. Should be in b23db3101ac652695ef0816721f384fe2abc71f4 commit. No functional changes. --- .../groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index 6bfcfa5383..380d6e1f67 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -35,11 +35,9 @@ class SiteServiceImplTest extends Specification { private static final String TEST_USER_AGENT = TestObjects.TEST_ACTIVITY_AGENT private SuspiciousActivityDao suspiciousActivityDao = Mock() - private SiteService service private SiteServiceImpl serviceImpl def setup() { - service = new SiteServiceImpl(suspiciousActivityDao) serviceImpl = Spy(SiteServiceImpl, constructorArgs:[suspiciousActivityDao]) } From 2b3d2a9cbc9302b5da7a4c50898a33bdab270a19 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 23:05:19 +0200 Subject: [PATCH 077/463] Fix PrivateFieldCouldBeFinal warnings from CodeNarc. @see http://codenarc.sourceforge.net/codenarc-rules-design.html#PrivateFieldCouldBeFinal No functional changes. --- .../web/service/CategoryServiceImplTest.groovy | 8 ++++---- .../service/CollectionServiceImplTest.groovy | 3 ++- .../web/service/CountryServiceImplTest.groovy | 8 ++++---- .../web/service/CronServiceImplTest.groovy | 18 +++++++++--------- ...DatabaseImagePersistenceStrategyTest.groovy | 8 ++++---- ...lesystemImagePersistenceStrategyTest.groovy | 9 +++++---- .../GibbonsCatalogServiceImplTest.groovy | 4 ++-- .../web/service/ImageServiceImplTest.groovy | 8 ++++---- .../MichelCatalogServiceImplTest.groovy | 4 ++-- .../service/ScottCatalogServiceImplTest.groovy | 4 ++-- .../web/service/SeriesServiceImplTest.groovy | 14 +++++++------- .../web/service/SiteServiceImplTest.groovy | 3 ++- .../SuspiciousActivityServiceImplTest.groovy | 4 ++-- .../web/service/UserServiceImplTest.groovy | 10 +++++----- .../UsersActivationServiceImplTest.groovy | 4 ++-- .../service/YvertCatalogServiceImplTest.groovy | 5 ++--- 16 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index fef3a599a6..9b3491b918 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -30,11 +30,11 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CategoryServiceImplTest extends Specification { - private AddCategoryForm form - private Integer userId = 123 + private final Integer userId = 123 + private final CategoryDao categoryDao = Mock() + private final CategoryService service = new CategoryServiceImpl(categoryDao) - private CategoryDao categoryDao = Mock() - private CategoryService service = new CategoryServiceImpl(categoryDao) + private AddCategoryForm form def setup() { form = new AddCategoryForm() diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index 136ea126db..ea9d4e93eb 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -28,7 +28,8 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CollectionServiceImplTest extends Specification { - private CollectionDao collectionDao = Mock() + + private final CollectionDao collectionDao = Mock() private CollectionService service diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index 4253a93dff..ef2f23b1c8 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -30,11 +30,11 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CountryServiceImplTest extends Specification { - private AddCountryForm form - private Integer userId = 321 + private final Integer userId = 321 + private final CountryDao countryDao = Mock() + private final CountryService service = new CountryServiceImpl(countryDao) - private CountryDao countryDao = Mock() - private CountryService service = new CountryServiceImpl(countryDao) + private AddCountryForm form def setup() { form = new AddCountryForm() diff --git a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy index 9eeed6933c..f9b064dd5b 100644 --- a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy @@ -25,15 +25,15 @@ import ru.mystamps.web.service.dto.AdminDailyReport @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CronServiceImplTest extends Specification { - private CategoryService categoryService = Mock() - private CountryService countryService = Mock() - private SeriesService seriesService = Mock() - private SuspiciousActivityService suspiciousActivityService = Mock() - private MailService mailService = Mock() - private UserService userService = Mock() - private UsersActivationService usersActivationService = Mock() - - private CronService service = new CronServiceImpl( + private final CategoryService categoryService = Mock() + private final CountryService countryService = Mock() + private final SeriesService seriesService = Mock() + private final SuspiciousActivityService suspiciousActivityService = Mock() + private final MailService mailService = Mock() + private final UserService userService = Mock() + private final UsersActivationService usersActivationService = Mock() + + private final CronService service = new CronServiceImpl( categoryService, countryService, seriesService, diff --git a/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy index 49f2b8e6ab..d1bc746bb2 100644 --- a/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/DatabaseImagePersistenceStrategyTest.groovy @@ -30,11 +30,11 @@ import ru.mystamps.web.service.exception.ImagePersistenceException @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class DatabaseImagePersistenceStrategyTest extends Specification { - private ImageDataDao imageDataDao = Mock() - private MultipartFile multipartFile = Mock() - private ImageInfoDto imageInfoDto = TestObjects.createImageInfoDto() + private final ImageDataDao imageDataDao = Mock() + private final MultipartFile multipartFile = Mock() + private final ImageInfoDto imageInfoDto = TestObjects.createImageInfoDto() - private ImagePersistenceStrategy strategy = new DatabaseImagePersistenceStrategy(imageDataDao) + private final ImagePersistenceStrategy strategy = new DatabaseImagePersistenceStrategy(imageDataDao) // // Tests for save() diff --git a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy index 8451fd49a1..a8479c3d30 100644 --- a/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/FilesystemImagePersistenceStrategyTest.groovy @@ -31,11 +31,12 @@ import java.nio.file.Path class FilesystemImagePersistenceStrategyTest extends Specification { private static final STORAGE_DIR = File.separator + 'tmp' - private MultipartFile multipartFile = Mock() - private ImageInfoDto imageInfoDto = TestObjects.createImageInfoDto() - private Path mockFile = Mock(Path) + private final MultipartFile multipartFile = Mock() + private final ImageInfoDto imageInfoDto = TestObjects.createImageInfoDto() + private final Path mockFile = Mock(Path) - private ImagePersistenceStrategy strategy = Spy(FilesystemImagePersistenceStrategy, constructorArgs:[STORAGE_DIR]) + private final ImagePersistenceStrategy strategy = + Spy(FilesystemImagePersistenceStrategy, constructorArgs:[STORAGE_DIR]) // // Tests for save() diff --git a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy index 6ef55bfae7..11b92fdb14 100644 --- a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy @@ -24,9 +24,9 @@ import ru.mystamps.web.dao.StampsCatalogDao @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class GibbonsCatalogServiceImplTest extends Specification { - private StampsCatalogDao gibbonsCatalogDao = Mock() + private final StampsCatalogDao gibbonsCatalogDao = Mock() - private StampsCatalogService service = new GibbonsCatalogServiceImpl(gibbonsCatalogDao) + private final StampsCatalogService service = new GibbonsCatalogServiceImpl(gibbonsCatalogDao) // // Tests for findBySeriesId() diff --git a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy index e8dde74a31..fd5675a376 100644 --- a/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ImageServiceImplTest.groovy @@ -30,11 +30,11 @@ import ru.mystamps.web.service.exception.ImagePersistenceException @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class ImageServiceImplTest extends Specification { - private ImageDao imageDao = Mock() - private MultipartFile multipartFile = Mock() - private ImagePersistenceStrategy imagePersistenceStrategy = Mock() + private final ImageDao imageDao = Mock() + private final MultipartFile multipartFile = Mock() + private final ImagePersistenceStrategy imagePersistenceStrategy = Mock() - private ImageService service = new ImageServiceImpl(imagePersistenceStrategy, imageDao) + private final ImageService service = new ImageServiceImpl(imagePersistenceStrategy, imageDao) def setup() { multipartFile.size >> 1024L diff --git a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy index 372a64e26d..06f6e9f610 100644 --- a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy @@ -24,9 +24,9 @@ import ru.mystamps.web.dao.StampsCatalogDao @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class MichelCatalogServiceImplTest extends Specification { - private StampsCatalogDao michelCatalogDao = Mock() + private final StampsCatalogDao michelCatalogDao = Mock() - private StampsCatalogService service = new MichelCatalogServiceImpl(michelCatalogDao) + private final StampsCatalogService service = new MichelCatalogServiceImpl(michelCatalogDao) // // Tests for findBySeriesId() diff --git a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy index 480050ad31..3c52b915c4 100644 --- a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy @@ -24,9 +24,9 @@ import ru.mystamps.web.dao.StampsCatalogDao @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class ScottCatalogServiceImplTest extends Specification { - private StampsCatalogDao scottCatalogDao = Mock() + private final StampsCatalogDao scottCatalogDao = Mock() - private StampsCatalogService service = new ScottCatalogServiceImpl(scottCatalogDao) + private final StampsCatalogService service = new ScottCatalogServiceImpl(scottCatalogDao) // // Tests for findBySeriesId() diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index c52708ceb4..c1ee589f37 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -38,13 +38,13 @@ class SeriesServiceImplTest extends Specification { private static final BigDecimal ANY_PRICE = new BigDecimal('17') private static final Integer ANY_IMAGE_ID = 18 - private ImageService imageService = Mock() - private SeriesDao seriesDao = Mock() - private StampsCatalogService michelCatalogService = Mock() - private StampsCatalogService scottCatalogService = Mock() - private StampsCatalogService yvertCatalogService = Mock() - private StampsCatalogService gibbonsCatalogService = Mock() - private MultipartFile multipartFile = Mock() + private final ImageService imageService = Mock() + private final SeriesDao seriesDao = Mock() + private final StampsCatalogService michelCatalogService = Mock() + private final StampsCatalogService scottCatalogService = Mock() + private final StampsCatalogService yvertCatalogService = Mock() + private final StampsCatalogService gibbonsCatalogService = Mock() + private final MultipartFile multipartFile = Mock() private SeriesService service private AddSeriesForm form diff --git a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy index 380d6e1f67..f4f2318a01 100644 --- a/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy @@ -34,7 +34,8 @@ class SiteServiceImplTest extends Specification { private static final String TEST_REFERER_PAGE = TestObjects.TEST_ACTIVITY_REFERER private static final String TEST_USER_AGENT = TestObjects.TEST_ACTIVITY_AGENT - private SuspiciousActivityDao suspiciousActivityDao = Mock() + private final SuspiciousActivityDao suspiciousActivityDao = Mock() + private SiteServiceImpl serviceImpl def setup() { diff --git a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy index 571b2340ec..a4ae480108 100644 --- a/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SuspiciousActivityServiceImplTest.groovy @@ -26,9 +26,9 @@ import ru.mystamps.web.dao.dto.SuspiciousActivityDto @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class SuspiciousActivityServiceImplTest extends Specification { - private SuspiciousActivityDao suspiciousActivityDao = Mock() + private final SuspiciousActivityDao suspiciousActivityDao = Mock() - private SuspiciousActivityService service = new SuspiciousActivityServiceImpl(suspiciousActivityDao) + private final SuspiciousActivityService service = new SuspiciousActivityServiceImpl(suspiciousActivityDao) // // Tests for countAll() diff --git a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy index f13a18d9bf..20985da2d7 100644 --- a/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UserServiceImplTest.groovy @@ -31,12 +31,12 @@ import ru.mystamps.web.tests.DateUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class UserServiceImplTest extends Specification { - private static Integer ANY_USER_ID = TestObjects.TEST_USER_ID + private static final Integer ANY_USER_ID = TestObjects.TEST_USER_ID - private UserDao userDao = Mock() - private UsersActivationService usersActivationService = Mock() - private CollectionService collectionService = Mock() - private PasswordEncoder encoder = Mock() + private final UserDao userDao = Mock() + private final UsersActivationService usersActivationService = Mock() + private final CollectionService collectionService = Mock() + private final PasswordEncoder encoder = Mock() private UserService service private ActivateAccountForm activationForm diff --git a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy index d689424777..797ac19665 100644 --- a/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/UsersActivationServiceImplTest.groovy @@ -31,8 +31,8 @@ import ru.mystamps.web.validation.ValidationRules @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class UsersActivationServiceImplTest extends Specification { - private UsersActivationDao usersActivationDao = Mock() - private MailService mailService = Mock() + private final UsersActivationDao usersActivationDao = Mock() + private final MailService mailService = Mock() private UsersActivationService service private RegisterAccountForm registrationForm diff --git a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy index 3b8b9d7df4..18bcda2c1a 100644 --- a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy @@ -24,9 +24,8 @@ import ru.mystamps.web.dao.StampsCatalogDao @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class YvertCatalogServiceImplTest extends Specification { - private StampsCatalogDao yvertCatalogDao = Mock() - - private StampsCatalogService service = new YvertCatalogServiceImpl(yvertCatalogDao) + private final StampsCatalogDao yvertCatalogDao = Mock() + private final StampsCatalogService service = new YvertCatalogServiceImpl(yvertCatalogDao) // // Tests for findBySeriesId() From 15d6be9a9657579a36b15035cc81eebf9556c96e Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 7 Oct 2016 18:13:04 +0200 Subject: [PATCH 078/463] series/add.html: fix indentation. No code changes. [ci skip] --- src/main/webapp/WEB-INF/views/series/add.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/add.html b/src/main/webapp/WEB-INF/views/series/add.html index 30e030a104..418be84282 100644 --- a/src/main/webapp/WEB-INF/views/series/add.html +++ b/src/main/webapp/WEB-INF/views/series/add.html @@ -117,9 +117,9 @@

    From 90b7c990cfc235f65288c4541acc1a95d65c961e Mon Sep 17 00:00:00 2001 From: Sergey Chechenev Date: Mon, 29 Aug 2016 00:44:58 +0300 Subject: [PATCH 079/463] Fix "No TaskExecutor bean found for async processing" message. Despite this is just an informational message, we're defining SimpleAsyncTaskExecutor explicitly as recommended by Juergen Hoeller. @see https://jira.spring.io/browse/SPR-14271 Fix #472 --- .../web/config/ApplicationContext.java | 1 + .../web/config/TaskExecutorConfig.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java diff --git a/src/main/java/ru/mystamps/web/config/ApplicationContext.java b/src/main/java/ru/mystamps/web/config/ApplicationContext.java index 3bfdb7b486..80a328ebab 100755 --- a/src/main/java/ru/mystamps/web/config/ApplicationContext.java +++ b/src/main/java/ru/mystamps/web/config/ApplicationContext.java @@ -33,6 +33,7 @@ DaoConfig.class, ServicesConfig.class, StrategiesConfig.class, + TaskExecutorConfig.class, TogglzConfig.class }) @SuppressWarnings({"checkstyle:hideutilityclassconstructor", "PMD.UseUtilityClass"}) diff --git a/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java b/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java new file mode 100644 index 0000000000..d16e6a642a --- /dev/null +++ b/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.config; + +import java.util.concurrent.Executor; + +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.scheduling.annotation.AsyncConfigurerSupport; + +/** + * @author Sergey Chechenev + */ +@Configuration +public class TaskExecutorConfig extends AsyncConfigurerSupport { + + @Override + public Executor getAsyncExecutor() { + return new SimpleAsyncTaskExecutor(); + } + +} From 7a4e2a985e9b5e1e30a69459f23f159be5ab367f Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 10 Oct 2016 16:33:28 +0200 Subject: [PATCH 080/463] Move @EnableAsync to TaskExecutorConfig. Follow-up to 08448311d35afd7cf4941c95eb7dc85d15831c81 commmit (see #472). No functional changes. --- src/main/java/ru/mystamps/web/config/ServicesConfig.java | 2 -- src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/mystamps/web/config/ServicesConfig.java b/src/main/java/ru/mystamps/web/config/ServicesConfig.java index fac9963555..600f02a8ce 100644 --- a/src/main/java/ru/mystamps/web/config/ServicesConfig.java +++ b/src/main/java/ru/mystamps/web/config/ServicesConfig.java @@ -24,7 +24,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.scheduling.annotation.EnableAsync; import lombok.RequiredArgsConstructor; @@ -33,7 +32,6 @@ import ru.mystamps.web.support.spring.security.SecurityConfig; @Configuration -@EnableAsync @RequiredArgsConstructor public class ServicesConfig { diff --git a/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java b/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java index d16e6a642a..ce36a7e880 100644 --- a/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java +++ b/src/main/java/ru/mystamps/web/config/TaskExecutorConfig.java @@ -22,11 +22,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.scheduling.annotation.AsyncConfigurerSupport; +import org.springframework.scheduling.annotation.EnableAsync; /** * @author Sergey Chechenev + * @author Slava Semushin */ @Configuration +@EnableAsync public class TaskExecutorConfig extends AsyncConfigurerSupport { @Override From 5823b41102182b4226f31640fef7218c1331b196 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 5 Oct 2016 23:25:35 +0200 Subject: [PATCH 081/463] {Category,Country}ServiceImpl: add static modified. No functional changes. --- .../ru/mystamps/web/service/CategoryServiceImplTest.groovy | 3 ++- .../ru/mystamps/web/service/CountryServiceImplTest.groovy | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index 9b3491b918..28c2ea1ddf 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -30,7 +30,8 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CategoryServiceImplTest extends Specification { - private final Integer userId = 123 + private static final Integer userId = 123 + private final CategoryDao categoryDao = Mock() private final CategoryService service = new CategoryServiceImpl(categoryDao) diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index ef2f23b1c8..b0ed7e4f82 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -30,7 +30,8 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CountryServiceImplTest extends Specification { - private final Integer userId = 321 + private static final Integer userId = 321 + private final CountryDao countryDao = Mock() private final CountryService service = new CountryServiceImpl(countryDao) From 096dbac30e4bee7ac42ae18f925e60cd33ffb30e Mon Sep 17 00:00:00 2001 From: Sergey Chechenev Date: Wed, 28 Sep 2016 15:47:10 +0300 Subject: [PATCH 082/463] series_sales: add created_at/created_by fields. Fix #469 No functional changes. --- src/main/resources/liquibase/version/0.4.xml | 1 + ...9-28--add_creator_data_to_series_sales.xml | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/resources/liquibase/version/0.4/2016-09-28--add_creator_data_to_series_sales.xml diff --git a/src/main/resources/liquibase/version/0.4.xml b/src/main/resources/liquibase/version/0.4.xml index 2c80f155e5..5e1a4d8894 100644 --- a/src/main/resources/liquibase/version/0.4.xml +++ b/src/main/resources/liquibase/version/0.4.xml @@ -18,5 +18,6 @@ + diff --git a/src/main/resources/liquibase/version/0.4/2016-09-28--add_creator_data_to_series_sales.xml b/src/main/resources/liquibase/version/0.4/2016-09-28--add_creator_data_to_series_sales.xml new file mode 100644 index 0000000000..5f8493d69d --- /dev/null +++ b/src/main/resources/liquibase/version/0.4/2016-09-28--add_creator_data_to_series_sales.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + From a28159cc73ceac3270ec5ce7050394fb35231dbc Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 10 Oct 2016 22:53:39 +0200 Subject: [PATCH 083/463] {Category,Country}ServiceImplTest: uppercase final variable. Should be in 52498c7aa309ae6487931f989c8724b961f1e610 commit. No functional changes. --- .../service/CategoryServiceImplTest.groovy | 22 +++++++++---------- .../web/service/CountryServiceImplTest.groovy | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index 28c2ea1ddf..6e91519dc5 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -30,7 +30,7 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CategoryServiceImplTest extends Specification { - private static final Integer userId = 123 + private static final Integer USER_ID = 123 private final CategoryDao categoryDao = Mock() private final CategoryService service = new CategoryServiceImpl(categoryDao) @@ -49,7 +49,7 @@ class CategoryServiceImplTest extends Specification { def "add() should throw exception when dto is null"() { when: - service.add(null, userId) + service.add(null, USER_ID) then: thrown IllegalArgumentException } @@ -58,7 +58,7 @@ class CategoryServiceImplTest extends Specification { given: form.setName(null) when: - service.add(form, userId) + service.add(form, USER_ID) then: thrown IllegalArgumentException } @@ -67,7 +67,7 @@ class CategoryServiceImplTest extends Specification { given: form.setNameRu(null) when: - service.add(form, userId) + service.add(form, USER_ID) then: thrown IllegalArgumentException } @@ -89,7 +89,7 @@ class CategoryServiceImplTest extends Specification { and: categoryDao.add(_ as AddCategoryDbDto) >> expectedId when: - String actualSlug = service.add(form, userId) + String actualSlug = service.add(form, USER_ID) then: actualSlug == expectedSlug } @@ -100,7 +100,7 @@ class CategoryServiceImplTest extends Specification { String expectedCategoryName = 'Animals' form.setName(expectedCategoryName) when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * categoryDao.add({ AddCategoryDbDto category -> assert category?.name == expectedCategoryName @@ -114,7 +114,7 @@ class CategoryServiceImplTest extends Specification { String expectedCategoryName = 'Животные' form.setNameRu(expectedCategoryName) when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * categoryDao.add({ AddCategoryDbDto category -> assert category?.nameRu == expectedCategoryName @@ -126,7 +126,7 @@ class CategoryServiceImplTest extends Specification { given: form.setName(null) when: - service.add(form, userId) + service.add(form, USER_ID) then: thrown IllegalArgumentException } @@ -140,7 +140,7 @@ class CategoryServiceImplTest extends Specification { and: form.setName(name) when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * categoryDao.add({ AddCategoryDbDto category -> assert category?.slug == slug @@ -151,7 +151,7 @@ class CategoryServiceImplTest extends Specification { @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created at to current date"() { when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * categoryDao.add({ AddCategoryDbDto category -> assert DateUtils.roughlyEqual(category?.createdAt, new Date()) @@ -162,7 +162,7 @@ class CategoryServiceImplTest extends Specification { @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated at to current date"() { when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * categoryDao.add({ AddCategoryDbDto category -> assert DateUtils.roughlyEqual(category?.updatedAt, new Date()) diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index b0ed7e4f82..05b541e9e3 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -30,7 +30,7 @@ import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) class CountryServiceImplTest extends Specification { - private static final Integer userId = 321 + private static final Integer USER_ID = 321 private final CountryDao countryDao = Mock() private final CountryService service = new CountryServiceImpl(countryDao) @@ -49,7 +49,7 @@ class CountryServiceImplTest extends Specification { def "add() should throw exception when dto is null"() { when: - service.add(null, userId) + service.add(null, USER_ID) then: thrown IllegalArgumentException } @@ -58,7 +58,7 @@ class CountryServiceImplTest extends Specification { given: form.setName(null) when: - service.add(form, userId) + service.add(form, USER_ID) then: thrown IllegalArgumentException } @@ -67,7 +67,7 @@ class CountryServiceImplTest extends Specification { given: form.setNameRu(null) when: - service.add(form, userId) + service.add(form, USER_ID) then: thrown IllegalArgumentException } @@ -89,7 +89,7 @@ class CountryServiceImplTest extends Specification { and: countryDao.add(_ as AddCountryDbDto) >> expectedId when: - String actualSlug = service.add(form, userId) + String actualSlug = service.add(form, USER_ID) then: actualSlug == expectedSlug } @@ -100,7 +100,7 @@ class CountryServiceImplTest extends Specification { String expectedCountryName = 'Italy' form.setName(expectedCountryName) when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * countryDao.add({ AddCountryDbDto country -> assert country?.name == expectedCountryName @@ -114,7 +114,7 @@ class CountryServiceImplTest extends Specification { String expectedCountryName = 'Италия' form.setNameRu(expectedCountryName) when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * countryDao.add({ AddCountryDbDto country -> assert country?.nameRu == expectedCountryName @@ -126,7 +126,7 @@ class CountryServiceImplTest extends Specification { given: form.setName(null) when: - service.add(form, userId) + service.add(form, USER_ID) then: thrown IllegalArgumentException } @@ -140,7 +140,7 @@ class CountryServiceImplTest extends Specification { and: form.setName(name) when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * countryDao.add({ AddCountryDbDto country -> assert country?.slug == slug @@ -151,7 +151,7 @@ class CountryServiceImplTest extends Specification { @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign created at to current date"() { when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * countryDao.add({ AddCountryDbDto country -> assert DateUtils.roughlyEqual(country?.createdAt, new Date()) @@ -162,7 +162,7 @@ class CountryServiceImplTest extends Specification { @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "add() should assign updated at to current date"() { when: - service.add(form, userId) + service.add(form, USER_ID) then: 1 * countryDao.add({ AddCountryDbDto country -> assert DateUtils.roughlyEqual(country?.updatedAt, new Date()) From 9e445959728af3fb0be0ef74a34f0c2e64bbb2dc Mon Sep 17 00:00:00 2001 From: Sergey Chechenev Date: Wed, 28 Sep 2016 13:27:22 +0300 Subject: [PATCH 084/463] /series/info: fix TemplateProcessingException when transaction doesn't have a price. Mark first_price and first_currency fields in series_sales table as non-nullable. Fix #467 --- src/main/resources/liquibase/version/0.4.xml | 1 + ...-add_constraints_to_series-first-price.xml | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/main/resources/liquibase/version/0.4/2016-09-28--add_constraints_to_series-first-price.xml diff --git a/src/main/resources/liquibase/version/0.4.xml b/src/main/resources/liquibase/version/0.4.xml index 5e1a4d8894..e0c9f876f4 100644 --- a/src/main/resources/liquibase/version/0.4.xml +++ b/src/main/resources/liquibase/version/0.4.xml @@ -19,5 +19,6 @@ + diff --git a/src/main/resources/liquibase/version/0.4/2016-09-28--add_constraints_to_series-first-price.xml b/src/main/resources/liquibase/version/0.4/2016-09-28--add_constraints_to_series-first-price.xml new file mode 100644 index 0000000000..df497f521a --- /dev/null +++ b/src/main/resources/liquibase/version/0.4/2016-09-28--add_constraints_to_series-first-price.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + From c32717008d797925d4cd438df21aa1f78e325ff9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 00:16:30 +0200 Subject: [PATCH 085/463] ScottCatalogServiceImpl: fix typo in log message. Should be in 5d148c02c42df18c5346a2facb31a604526764e5 commit. No functional changes. --- .../java/ru/mystamps/web/service/ScottCatalogServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java b/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java index 6b2d407662..6c5ed9dfa7 100644 --- a/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java @@ -64,7 +64,7 @@ public void addToSeries(Integer seriesId, Set scottNumbers) { scottCatalogDao.addToSeries(seriesId, scottNumbers); - LOG.info("Series #{}: scoot numbers {} were added", seriesId, scottNumbers); + LOG.info("Series #{}: scott numbers {} were added", seriesId, scottNumbers); } @Override From 1c6a8c13afc4bb06a277e5d2e4347cb9d12304d5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 00:17:48 +0200 Subject: [PATCH 086/463] SeriesServiceImpl: fix typo in variable name. Should be in 4fad9f7cc0326daaf0242baa5b5363ad782ab00f commit. No functional changes. --- src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java b/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java index 8cd9d0d35f..c62617eb50 100644 --- a/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java @@ -240,7 +240,7 @@ public SeriesDto findFullInfoById(Integer seriesId, String lang) { } List michelNumbers = michelCatalogService.findBySeriesId(seriesId); - List scootNumbers = scottCatalogService.findBySeriesId(seriesId); + List scottNumbers = scottCatalogService.findBySeriesId(seriesId); List yvertNumbers = yvertCatalogService.findBySeriesId(seriesId); List gibbonsNumbers = gibbonsCatalogService.findBySeriesId(seriesId); @@ -249,7 +249,7 @@ public SeriesDto findFullInfoById(Integer seriesId, String lang) { return new SeriesDto( seriesBaseInfo, michelNumbers, - scootNumbers, + scottNumbers, yvertNumbers, gibbonsNumbers, imageIds From 09f91a82ed99d1ed8df6f6428619f4e448f0cc22 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 00:37:57 +0200 Subject: [PATCH 087/463] StampsCatalogServiceImpl: introduce and replace MichelCatalogServiceImpl. Addressed to #491 No functional changes. --- .../mystamps/web/config/ServicesConfig.java | 2 +- ...mpl.java => StampsCatalogServiceImpl.java} | 29 ++++++++++--------- ...vy => StampsCatalogServiceImplTest.groovy} | 8 ++--- 3 files changed, 20 insertions(+), 19 deletions(-) rename src/main/java/ru/mystamps/web/service/{MichelCatalogServiceImpl.java => StampsCatalogServiceImpl.java} (62%) rename src/test/groovy/ru/mystamps/web/service/{MichelCatalogServiceImplTest.groovy => StampsCatalogServiceImplTest.groovy} (85%) diff --git a/src/main/java/ru/mystamps/web/config/ServicesConfig.java b/src/main/java/ru/mystamps/web/config/ServicesConfig.java index 600f02a8ce..6c864e7a96 100644 --- a/src/main/java/ru/mystamps/web/config/ServicesConfig.java +++ b/src/main/java/ru/mystamps/web/config/ServicesConfig.java @@ -131,7 +131,7 @@ public UserService getUserService() { @Bean public StampsCatalogService getMichelCatalogService() { - return new MichelCatalogServiceImpl(daoConfig.getMichelCatalogDao()); + return new StampsCatalogServiceImpl("Michel", daoConfig.getMichelCatalogDao()); } @Bean diff --git a/src/main/java/ru/mystamps/web/service/MichelCatalogServiceImpl.java b/src/main/java/ru/mystamps/web/service/StampsCatalogServiceImpl.java similarity index 62% rename from src/main/java/ru/mystamps/web/service/MichelCatalogServiceImpl.java rename to src/main/java/ru/mystamps/web/service/StampsCatalogServiceImpl.java index 439b39e436..e8a81b456c 100644 --- a/src/main/java/ru/mystamps/web/service/MichelCatalogServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/StampsCatalogServiceImpl.java @@ -35,36 +35,37 @@ import ru.mystamps.web.support.spring.security.HasAuthority; @RequiredArgsConstructor -public class MichelCatalogServiceImpl implements StampsCatalogService { - private static final Logger LOG = LoggerFactory.getLogger(MichelCatalogServiceImpl.class); +public class StampsCatalogServiceImpl implements StampsCatalogService { + private static final Logger LOG = LoggerFactory.getLogger(StampsCatalogServiceImpl.class); - private final StampsCatalogDao michelCatalogDao; + private final String catalogName; + private final StampsCatalogDao stampsCatalogDao; @Override @Transactional @PreAuthorize(HasAuthority.CREATE_SERIES) - public void add(Set michelNumbers) { - Validate.isTrue(michelNumbers != null, "Michel numbers must be non null"); - Validate.isTrue(!michelNumbers.isEmpty(), "Michel numbers must be non empty"); + public void add(Set catalogNumbers) { + Validate.isTrue(catalogNumbers != null, "%s numbers must be non null", catalogName); + Validate.isTrue(!catalogNumbers.isEmpty(), "%s numbers must be non empty", catalogName); - List insertedNumbers = michelCatalogDao.add(michelNumbers); + List insertedNumbers = stampsCatalogDao.add(catalogNumbers); if (!insertedNumbers.isEmpty()) { - LOG.info("Michel numbers {} were created", insertedNumbers); + LOG.info("{} numbers {} were created", catalogName, insertedNumbers); } } @Override @Transactional @PreAuthorize(HasAuthority.CREATE_SERIES) - public void addToSeries(Integer seriesId, Set michelNumbers) { + public void addToSeries(Integer seriesId, Set catalogNumbers) { Validate.isTrue(seriesId != null, "Series id must be non null"); - Validate.isTrue(michelNumbers != null, "Michel numbers must be non null"); - Validate.isTrue(!michelNumbers.isEmpty(), "Michel numbers must be non empty"); + Validate.isTrue(catalogNumbers != null, "%s numbers must be non null", catalogName); + Validate.isTrue(!catalogNumbers.isEmpty(), "%s numbers must be non empty", catalogName); - michelCatalogDao.addToSeries(seriesId, michelNumbers); + stampsCatalogDao.addToSeries(seriesId, catalogNumbers); - LOG.info("Series #{}: michel numbers {} were added", seriesId, michelNumbers); + LOG.info("Series #{}: {} numbers {} were added", seriesId, catalogName, catalogNumbers); } @Override @@ -72,7 +73,7 @@ public void addToSeries(Integer seriesId, Set michelNumbers) { public List findBySeriesId(Integer seriesId) { Validate.isTrue(seriesId != null, "Series id must be non null"); - return michelCatalogDao.findBySeriesId(seriesId); + return stampsCatalogDao.findBySeriesId(seriesId); } } diff --git a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy similarity index 85% rename from src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy rename to src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy index 06f6e9f610..0e91b9f4d0 100644 --- a/src/test/groovy/ru/mystamps/web/service/MichelCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy @@ -22,11 +22,11 @@ import spock.lang.Specification import ru.mystamps.web.dao.StampsCatalogDao @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) -class MichelCatalogServiceImplTest extends Specification { +class StampsCatalogServiceImplTest extends Specification { - private final StampsCatalogDao michelCatalogDao = Mock() + private final StampsCatalogDao stampsCatalogDao = Mock() - private final StampsCatalogService service = new MichelCatalogServiceImpl(michelCatalogDao) + private final StampsCatalogService service = new StampsCatalogServiceImpl("TestCatalog", stampsCatalogDao) // // Tests for findBySeriesId() @@ -48,7 +48,7 @@ class MichelCatalogServiceImplTest extends Specification { when: List result = service.findBySeriesId(expectedSeriesId) then: - 1 * michelCatalogDao.findBySeriesId({ Integer seriesId -> + 1 * stampsCatalogDao.findBySeriesId({ Integer seriesId -> assert seriesId == expectedSeriesId return true }) >> expectedResult From f1ddab8f8da423e0cc3079b2521dc77c7b2c761c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 00:44:28 +0200 Subject: [PATCH 088/463] ScottCatalogServiceImpl: replace by StampsCatalogServiceImpl. Addressed to #491 No functional changes. --- .../mystamps/web/config/ServicesConfig.java | 2 +- .../web/service/ScottCatalogServiceImpl.java | 78 ------------------- .../ScottCatalogServiceImplTest.groovy | 59 -------------- 3 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java delete mode 100644 src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy diff --git a/src/main/java/ru/mystamps/web/config/ServicesConfig.java b/src/main/java/ru/mystamps/web/config/ServicesConfig.java index 6c864e7a96..c555071d3b 100644 --- a/src/main/java/ru/mystamps/web/config/ServicesConfig.java +++ b/src/main/java/ru/mystamps/web/config/ServicesConfig.java @@ -136,7 +136,7 @@ public StampsCatalogService getMichelCatalogService() { @Bean public StampsCatalogService getScottCatalogService() { - return new ScottCatalogServiceImpl(daoConfig.getScottCatalogDao()); + return new StampsCatalogServiceImpl("Scott", daoConfig.getScottCatalogDao()); } @Bean diff --git a/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java b/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java deleted file mode 100644 index 6c5ed9dfa7..0000000000 --- a/src/main/java/ru/mystamps/web/service/ScottCatalogServiceImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009-2016 Slava Semushin - * - * 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.List; -import java.util.Set; - -import org.apache.commons.lang3.Validate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.transaction.annotation.Transactional; - -import org.springframework.security.access.prepost.PreAuthorize; - -import lombok.RequiredArgsConstructor; - -import ru.mystamps.web.dao.StampsCatalogDao; -import ru.mystamps.web.support.spring.security.HasAuthority; - -@RequiredArgsConstructor -public class ScottCatalogServiceImpl implements StampsCatalogService { - private static final Logger LOG = LoggerFactory.getLogger(ScottCatalogServiceImpl.class); - - private final StampsCatalogDao scottCatalogDao; - - @Override - @Transactional - @PreAuthorize(HasAuthority.CREATE_SERIES) - public void add(Set scottNumbers) { - Validate.isTrue(scottNumbers != null, "Scott numbers must be non null"); - Validate.isTrue(!scottNumbers.isEmpty(), "Scott numbers must be non empty"); - - List insertedNumbers = scottCatalogDao.add(scottNumbers); - - if (!insertedNumbers.isEmpty()) { - LOG.info("Scott numbers {} were created", insertedNumbers); - } - } - - @Override - @Transactional - @PreAuthorize(HasAuthority.CREATE_SERIES) - public void addToSeries(Integer seriesId, Set scottNumbers) { - Validate.isTrue(seriesId != null, "Series id must be non null"); - Validate.isTrue(scottNumbers != null, "Scott numbers must be non null"); - Validate.isTrue(!scottNumbers.isEmpty(), "Scott numbers must be non empty"); - - scottCatalogDao.addToSeries(seriesId, scottNumbers); - - LOG.info("Series #{}: scott numbers {} were added", seriesId, scottNumbers); - } - - @Override - @Transactional(readOnly = true) - public List findBySeriesId(Integer seriesId) { - Validate.isTrue(seriesId != null, "Series id must be non null"); - - return scottCatalogDao.findBySeriesId(seriesId); - } - -} diff --git a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy deleted file mode 100644 index 3c52b915c4..0000000000 --- a/src/test/groovy/ru/mystamps/web/service/ScottCatalogServiceImplTest.groovy +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2009-2016 Slava Semushin - * - * 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 spock.lang.Specification - -import ru.mystamps.web.dao.StampsCatalogDao - -@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) -class ScottCatalogServiceImplTest extends Specification { - - private final StampsCatalogDao scottCatalogDao = Mock() - - private final StampsCatalogService service = new ScottCatalogServiceImpl(scottCatalogDao) - - // - // Tests for findBySeriesId() - // - - def "findBySeriesId() should throw exception when series id is null"() { - when: - service.findBySeriesId(null) - then: - thrown IllegalArgumentException - } - - @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) - def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { - given: - Integer expectedSeriesId = 52 - and: - List expectedResult = [ '79', '80' ] - when: - List result = service.findBySeriesId(expectedSeriesId) - then: - 1 * scottCatalogDao.findBySeriesId({ Integer seriesId -> - assert seriesId == expectedSeriesId - return true - }) >> expectedResult - and: - result == expectedResult - } - -} From b754cd5efd5093d6bfe87ebe99275251cd2ab98e Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 00:46:41 +0200 Subject: [PATCH 089/463] YvertCatalogServiceImpl: replace by StampsCatalogServiceImpl. Addressed to #491 No functional changes. --- .../mystamps/web/config/ServicesConfig.java | 2 +- .../web/service/YvertCatalogServiceImpl.java | 78 ------------------- .../YvertCatalogServiceImplTest.groovy | 58 -------------- 3 files changed, 1 insertion(+), 137 deletions(-) delete mode 100644 src/main/java/ru/mystamps/web/service/YvertCatalogServiceImpl.java delete mode 100644 src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy diff --git a/src/main/java/ru/mystamps/web/config/ServicesConfig.java b/src/main/java/ru/mystamps/web/config/ServicesConfig.java index c555071d3b..c3c3ba6a37 100644 --- a/src/main/java/ru/mystamps/web/config/ServicesConfig.java +++ b/src/main/java/ru/mystamps/web/config/ServicesConfig.java @@ -141,7 +141,7 @@ public StampsCatalogService getScottCatalogService() { @Bean public StampsCatalogService getYvertCatalogService() { - return new YvertCatalogServiceImpl(daoConfig.getYvertCatalogDao()); + return new StampsCatalogServiceImpl("Yvert", daoConfig.getYvertCatalogDao()); } @Bean diff --git a/src/main/java/ru/mystamps/web/service/YvertCatalogServiceImpl.java b/src/main/java/ru/mystamps/web/service/YvertCatalogServiceImpl.java deleted file mode 100644 index 2a8f5e5413..0000000000 --- a/src/main/java/ru/mystamps/web/service/YvertCatalogServiceImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009-2016 Slava Semushin - * - * 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.List; -import java.util.Set; - -import org.apache.commons.lang3.Validate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.transaction.annotation.Transactional; - -import org.springframework.security.access.prepost.PreAuthorize; - -import lombok.RequiredArgsConstructor; - -import ru.mystamps.web.dao.StampsCatalogDao; -import ru.mystamps.web.support.spring.security.HasAuthority; - -@RequiredArgsConstructor -public class YvertCatalogServiceImpl implements StampsCatalogService { - private static final Logger LOG = LoggerFactory.getLogger(YvertCatalogServiceImpl.class); - - private final StampsCatalogDao yvertCatalogDao; - - @Override - @Transactional - @PreAuthorize(HasAuthority.CREATE_SERIES) - public void add(Set yvertNumbers) { - Validate.isTrue(yvertNumbers != null, "Yvert numbers must be non null"); - Validate.isTrue(!yvertNumbers.isEmpty(), "Yvert numbers must be non empty"); - - List insertedNumbers = yvertCatalogDao.add(yvertNumbers); - - if (!insertedNumbers.isEmpty()) { - LOG.info("Yvert numbers {} were created", insertedNumbers); - } - } - - @Override - @Transactional - @PreAuthorize(HasAuthority.CREATE_SERIES) - public void addToSeries(Integer seriesId, Set yvertNumbers) { - Validate.isTrue(seriesId != null, "Series id must be non null"); - Validate.isTrue(yvertNumbers != null, "Yvert numbers must be non null"); - Validate.isTrue(!yvertNumbers.isEmpty(), "Yvert numbers must be non empty"); - - yvertCatalogDao.addToSeries(seriesId, yvertNumbers); - - LOG.info("Series #{}: yvert numbers {} were added", seriesId, yvertNumbers); - } - - @Override - @Transactional(readOnly = true) - public List findBySeriesId(Integer seriesId) { - Validate.isTrue(seriesId != null, "Series id must be non null"); - - return yvertCatalogDao.findBySeriesId(seriesId); - } - -} diff --git a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy deleted file mode 100644 index 18bcda2c1a..0000000000 --- a/src/test/groovy/ru/mystamps/web/service/YvertCatalogServiceImplTest.groovy +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2009-2016 Slava Semushin - * - * 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 spock.lang.Specification - -import ru.mystamps.web.dao.StampsCatalogDao - -@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) -class YvertCatalogServiceImplTest extends Specification { - - private final StampsCatalogDao yvertCatalogDao = Mock() - private final StampsCatalogService service = new YvertCatalogServiceImpl(yvertCatalogDao) - - // - // Tests for findBySeriesId() - // - - def "findBySeriesId() should throw exception when series id is null"() { - when: - service.findBySeriesId(null) - then: - thrown IllegalArgumentException - } - - @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) - def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { - given: - Integer expectedSeriesId = 51 - and: - List expectedResult = [ '77', '78' ] - when: - List result = service.findBySeriesId(expectedSeriesId) - then: - 1 * yvertCatalogDao.findBySeriesId({ Integer seriesId -> - assert seriesId == expectedSeriesId - return true - }) >> expectedResult - and: - result == expectedResult - } - -} From 83e1015cc73d1b9bf0cac88f36cba99242be0874 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 00:48:52 +0200 Subject: [PATCH 090/463] GibbonsCatalogServiceImpl: replace by StampsCatalogServiceImpl. Addressed to #491 No functional changes. --- .../mystamps/web/config/ServicesConfig.java | 2 +- .../service/GibbonsCatalogServiceImpl.java | 78 ------------------- .../GibbonsCatalogServiceImplTest.groovy | 59 -------------- 3 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 src/main/java/ru/mystamps/web/service/GibbonsCatalogServiceImpl.java delete mode 100644 src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy diff --git a/src/main/java/ru/mystamps/web/config/ServicesConfig.java b/src/main/java/ru/mystamps/web/config/ServicesConfig.java index c3c3ba6a37..1331cf0efa 100644 --- a/src/main/java/ru/mystamps/web/config/ServicesConfig.java +++ b/src/main/java/ru/mystamps/web/config/ServicesConfig.java @@ -146,7 +146,7 @@ public StampsCatalogService getYvertCatalogService() { @Bean public StampsCatalogService getGibbonsCatalogService() { - return new GibbonsCatalogServiceImpl(daoConfig.getGibbonsCatalogDao()); + return new StampsCatalogServiceImpl("Gibbons", daoConfig.getGibbonsCatalogDao()); } } diff --git a/src/main/java/ru/mystamps/web/service/GibbonsCatalogServiceImpl.java b/src/main/java/ru/mystamps/web/service/GibbonsCatalogServiceImpl.java deleted file mode 100644 index 3ef90f6453..0000000000 --- a/src/main/java/ru/mystamps/web/service/GibbonsCatalogServiceImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009-2016 Slava Semushin - * - * 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.List; -import java.util.Set; - -import org.apache.commons.lang3.Validate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.transaction.annotation.Transactional; - -import org.springframework.security.access.prepost.PreAuthorize; - -import lombok.RequiredArgsConstructor; - -import ru.mystamps.web.dao.StampsCatalogDao; -import ru.mystamps.web.support.spring.security.HasAuthority; - -@RequiredArgsConstructor -public class GibbonsCatalogServiceImpl implements StampsCatalogService { - private static final Logger LOG = LoggerFactory.getLogger(GibbonsCatalogServiceImpl.class); - - private final StampsCatalogDao gibbonsCatalogDao; - - @Override - @Transactional - @PreAuthorize(HasAuthority.CREATE_SERIES) - public void add(Set gibbonsNumbers) { - Validate.isTrue(gibbonsNumbers != null, "Gibbons numbers must be non null"); - Validate.isTrue(!gibbonsNumbers.isEmpty(), "Gibbons numbers must be non empty"); - - List insertedNumbers = gibbonsCatalogDao.add(gibbonsNumbers); - - if (!insertedNumbers.isEmpty()) { - LOG.info("Gibbons numbers {} were created", insertedNumbers); - } - } - - @Override - @Transactional - @PreAuthorize(HasAuthority.CREATE_SERIES) - public void addToSeries(Integer seriesId, Set gibbonsNumbers) { - Validate.isTrue(seriesId != null, "Series id must be non null"); - Validate.isTrue(gibbonsNumbers != null, "Gibbons numbers must be non null"); - Validate.isTrue(!gibbonsNumbers.isEmpty(), "Gibbons numbers must be non empty"); - - gibbonsCatalogDao.addToSeries(seriesId, gibbonsNumbers); - - LOG.info("Series #{}: gibbons numbers {} were added", seriesId, gibbonsNumbers); - } - - @Override - @Transactional(readOnly = true) - public List findBySeriesId(Integer seriesId) { - Validate.isTrue(seriesId != null, "Series id must be non null"); - - return gibbonsCatalogDao.findBySeriesId(seriesId); - } - -} diff --git a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy deleted file mode 100644 index 11b92fdb14..0000000000 --- a/src/test/groovy/ru/mystamps/web/service/GibbonsCatalogServiceImplTest.groovy +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2009-2016 Slava Semushin - * - * 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 spock.lang.Specification - -import ru.mystamps.web.dao.StampsCatalogDao - -@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) -class GibbonsCatalogServiceImplTest extends Specification { - - private final StampsCatalogDao gibbonsCatalogDao = Mock() - - private final StampsCatalogService service = new GibbonsCatalogServiceImpl(gibbonsCatalogDao) - - // - // Tests for findBySeriesId() - // - - def "findBySeriesId() should throw exception when series id is null"() { - when: - service.findBySeriesId(null) - then: - thrown IllegalArgumentException - } - - @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) - def "findBySeriesId() should invoke dao, pass argument and return result from dao"() { - given: - Integer expectedSeriesId = 53 - and: - List expectedResult = [ '80', '81' ] - when: - List result = service.findBySeriesId(expectedSeriesId) - then: - 1 * gibbonsCatalogDao.findBySeriesId({ Integer seriesId -> - assert seriesId == expectedSeriesId - return true - }) >> expectedResult - and: - result == expectedResult - } - -} From 1c8fe4fe16cd397193bcd044503e308475a85d0b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 01:02:25 +0200 Subject: [PATCH 091/463] StampsCatalogServiceImpl: fix UnnecessaryGString warning from CodeNarc. Should be in 1b31696c52136f08c80fb6738f57df0fde2fd3b5 commit. No functional changes. --- .../ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy index 0e91b9f4d0..25b2e28a41 100644 --- a/src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/StampsCatalogServiceImplTest.groovy @@ -26,7 +26,7 @@ class StampsCatalogServiceImplTest extends Specification { private final StampsCatalogDao stampsCatalogDao = Mock() - private final StampsCatalogService service = new StampsCatalogServiceImpl("TestCatalog", stampsCatalogDao) + private final StampsCatalogService service = new StampsCatalogServiceImpl('TestCatalog', stampsCatalogDao) // // Tests for findBySeriesId() From 7536067cda887921550639692b8540e69e9d2d8f Mon Sep 17 00:00:00 2001 From: Sergey Chechenev Date: Tue, 11 Oct 2016 00:53:19 +0300 Subject: [PATCH 092/463] Change type of series_sales.date to DATE. Fix #471 No functional changes. --- src/main/resources/liquibase/version/0.4.xml | 1 + .../2016-10-10--change_series_sales_date_type.xml | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/main/resources/liquibase/version/0.4/2016-10-10--change_series_sales_date_type.xml diff --git a/src/main/resources/liquibase/version/0.4.xml b/src/main/resources/liquibase/version/0.4.xml index e0c9f876f4..6b563e3d10 100644 --- a/src/main/resources/liquibase/version/0.4.xml +++ b/src/main/resources/liquibase/version/0.4.xml @@ -20,5 +20,6 @@ + diff --git a/src/main/resources/liquibase/version/0.4/2016-10-10--change_series_sales_date_type.xml b/src/main/resources/liquibase/version/0.4/2016-10-10--change_series_sales_date_type.xml new file mode 100644 index 0000000000..4912b2ff74 --- /dev/null +++ b/src/main/resources/liquibase/version/0.4/2016-10-10--change_series_sales_date_type.xml @@ -0,0 +1,14 @@ + + + + + + + + + + From c935ace858651f4434184e9d9cb9f494173245c9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 17:25:45 +0200 Subject: [PATCH 093/463] pom.xml: add missing bracket to comment. Should be in febc72c5097500cd18847154f2e8c81002366177 commit. No code changes. [ci skip] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5c15da29b8..481c296a86 100644 --- a/pom.xml +++ b/pom.xml @@ -782,7 +782,7 @@ org.codehaus.mojo From 7e21bc7d2d11e1ad07948930a0a8fa6d84170853 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 12:31:08 +0200 Subject: [PATCH 094/463] pom.xml(findbugs-maven-plugin): add. Use `mvn findbugs:check` to scan and generate report. @see https://github.com/gleclaire/findbugs-maven-plugin @see http://findbugs.sourceforge.net/ No functional changes. --- pom.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pom.xml b/pom.xml index 481c296a86..1c6f737d4f 100644 --- a/pom.xml +++ b/pom.xml @@ -393,6 +393,7 @@ 1.4.1 2.19.1 2.0M8 + 3.0.4 1.4 1.5 @@ -756,6 +757,19 @@ + + + org.codehaus.gmaven + findbugs-maven-plugin + ${findbugs.plugin.version} + + true + + + org.codehaus.gmaven gmaven-plugin From 78cc13171e02c54deae9252879b9f2222418cfa8 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 12:33:44 +0200 Subject: [PATCH 095/463] check-build-and-verify.sh: run FindBugs. --- src/main/scripts/ci/check-build-and-verify.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/scripts/ci/check-build-and-verify.sh b/src/main/scripts/ci/check-build-and-verify.sh index acd2c36563..2579dbe212 100755 --- a/src/main/scripts/ci/check-build-and-verify.sh +++ b/src/main/scripts/ci/check-build-and-verify.sh @@ -16,6 +16,7 @@ BOOTLINT_FAIL= JASMINE_FAIL= HTML_FAIL= TEST_FAIL= +FINDBUGS_FAIL= VERIFY_FAIL= if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then @@ -41,6 +42,8 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then --show-warnings \ >validator.log 2>&1 || HTML_FAIL=yes mvn --batch-mode test -Denforcer.skip=true -DskipMinify=true >test.log 2>&1 || TEST_FAIL=yes + # run after tests for getting compiled sources + mvn --batch-mode findbugs:check >findbugs.log 2>&1 || FINDBUGS_FAIL=yes fi mvn --batch-mode verify -Denforcer.skip=true -DskipUnitTests=true >verify.log 2>&1 || VERIFY_FAIL=yes @@ -59,6 +62,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then print_status "$JASMINE_FAIL" 'Run JavaScript unit tests' print_status "$HTML_FAIL" 'Run html5validator' print_status "$TEST_FAIL" 'Run unit tests' + print_status "$FINDBUGS_FAIL" 'Run FindBugs' fi print_status "$VERIFY_FAIL" 'Run integration tests' @@ -75,12 +79,13 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then print_log jasmine.log 'Run JavaScript unit tests' print_log validator.log 'Run html5validator' print_log test.log 'Run unit tests' + print_log findbugs.log 'Run FindBugs' fi print_log verify.log 'Run integration tests' -rm -f cs.log pmd.log codenarc.log license.log bootlint.log jasmine.log validator.log test.log verify.log +rm -f cs.log pmd.log codenarc.log license.log bootlint.log jasmine.log validator.log test.log findbugs.log verify.log -if [ -n "$CS_FAIL$PMD_FAIL$CODENARC_FAIL$LICENSE_FAIL$POM_FAIL$BOOTLINT_FAIL$JASMINE_FAIL$HTML_FAIL$TEST_FAIL$VERIFY_FAIL" ]; then +if [ -n "$CS_FAIL$PMD_FAIL$CODENARC_FAIL$LICENSE_FAIL$POM_FAIL$BOOTLINT_FAIL$JASMINE_FAIL$HTML_FAIL$TEST_FAIL$FINDBUGS_FAIL$VERIFY_FAIL" ]; then exit 1 fi From fb90f9edd6030381cfa789e1408bf42b4e6f6fc1 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 14:30:54 +0200 Subject: [PATCH 096/463] Configure FindBugs to ignore EI_EXPOSE_REP and EI_EXPOSE_REP2 violations. For some very strange reason, using in plugin's doesn't work. That's why I'm using findbugs.excludeFilterFile property. --- pom.xml | 1 + src/main/config/findbugs-filter.xml | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/main/config/findbugs-filter.xml diff --git a/pom.xml b/pom.xml index 1c6f737d4f..4cc5e3c37a 100644 --- a/pom.xml +++ b/pom.xml @@ -393,6 +393,7 @@ 1.4.1 2.19.1 2.0M8 + src/main/config/findbugs-filter.xml 3.0.4 1.4 1.5 diff --git a/src/main/config/findbugs-filter.xml b/src/main/config/findbugs-filter.xml new file mode 100644 index 0000000000..1dd522e814 --- /dev/null +++ b/src/main/config/findbugs-filter.xml @@ -0,0 +1,11 @@ + + + + + + + From cba95566241d9b8c8a77d43ca1f59652d053ff4c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 11 Oct 2016 17:20:21 +0200 Subject: [PATCH 097/463] Configure FindBugs to ignore EQ_DOESNT_OVERRIDE_EQUALS. --- src/main/config/findbugs-filter.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/config/findbugs-filter.xml b/src/main/config/findbugs-filter.xml index 1dd522e814..8d3ed998a8 100644 --- a/src/main/config/findbugs-filter.xml +++ b/src/main/config/findbugs-filter.xml @@ -8,4 +8,11 @@ + + + + + From da1942a60f9746d3ff08cad167c96987ab80e036 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 14 Oct 2016 12:29:48 +0200 Subject: [PATCH 098/463] .gitignore: ignore IDEA project file by extension. No functional changes. [ci skip] --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 022f288abd..e2272b6be4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ target/ # IDEA related files .idea -mystamps.iml +*.iml # jasmine-maven-plugin uses phantomjs-maven-plugin. # phantomjs-maven-plugin creates this log file. From 76535dd3359cb32d69a3a602c424a0b64e5c5ca6 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 14 Oct 2016 19:36:18 +0200 Subject: [PATCH 099/463] pom.xml: remove dependency on spring-boot-starter-validation. All we need from this starter is a hibernate-validator but we're including it by ourselves already. No functional changes. --- pom.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pom.xml b/pom.xml index 4cc5e3c37a..e4ff721dc8 100644 --- a/pom.xml +++ b/pom.xml @@ -114,19 +114,6 @@ - - - org.springframework.boot - spring-boot-starter-validation - - - - org.apache.tomcat.embed - tomcat-embed-el - - - - org.springframework.boot From 873bb36123bc688deff0c22a2e2e0eb3c604c824 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 16 Oct 2016 12:55:19 +0200 Subject: [PATCH 100/463] AddCountryForm: put different checks to different groups. Should be in 5a125e17fd095a5316757921423969f0ed653ec4 commit. No functional changes. --- src/main/java/ru/mystamps/web/model/AddCountryForm.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/mystamps/web/model/AddCountryForm.java b/src/main/java/ru/mystamps/web/model/AddCountryForm.java index baf9e39405..fa7d2a4185 100644 --- a/src/main/java/ru/mystamps/web/model/AddCountryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCountryForm.java @@ -45,7 +45,8 @@ Group.Level2.class, Group.Level3.class, Group.Level4.class, - Group.Level5.class + Group.Level5.class, + Group.Level6.class }) public class AddCountryForm implements AddCountryDto { @@ -79,7 +80,7 @@ public class AddCountryForm implements AddCountryDto { groups = Group.Level5.class ) }) - @UniqueCountryName(lang = Lang.EN, groups = Group.Level5.class) + @UniqueCountryName(lang = Lang.EN, groups = Group.Level6.class) private String name; @NotEmpty(groups = Group.Level1.class) From 9122493036722afd598a807da2dcd2e78f0dafc4 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 16 Oct 2016 13:15:47 +0200 Subject: [PATCH 101/463] /category/add: add validation for unique slug. This fixes DuplicateKeyException when name contains mix of spaces and hyphens. Fix #486 --- .../java/ru/mystamps/web/dao/CategoryDao.java | 1 + .../web/dao/impl/JdbcCategoryDao.java | 12 +++++ .../mystamps/web/model/AddCategoryForm.java | 5 +- .../java/ru/mystamps/web/model/Group.java | 3 ++ .../mystamps/web/service/CategoryService.java | 1 + .../web/service/CategoryServiceImpl.java | 8 +++ .../validation/jsr303/UniqueCategorySlug.java | 40 +++++++++++++++ .../jsr303/UniqueCategorySlugValidator.java | 51 +++++++++++++++++++ .../i18n/ValidationMessages.properties | 1 + .../i18n/ValidationMessages_ru.properties | 1 + .../sql/category_dao_queries.properties | 5 ++ .../service/CategoryServiceImplTest.groovy | 20 ++++++++ 12 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlug.java create mode 100644 src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlugValidator.java diff --git a/src/main/java/ru/mystamps/web/dao/CategoryDao.java b/src/main/java/ru/mystamps/web/dao/CategoryDao.java index 9ec991db3f..d4439f81af 100644 --- a/src/main/java/ru/mystamps/web/dao/CategoryDao.java +++ b/src/main/java/ru/mystamps/web/dao/CategoryDao.java @@ -26,6 +26,7 @@ public interface CategoryDao { Integer add(AddCategoryDbDto category); long countAll(); + long countBySlug(String slug); long countByName(String name); long countByNameRu(String name); long countCategoriesOfCollection(Integer collectionId); diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java index 9f21187f02..407d4641bc 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java @@ -50,6 +50,9 @@ public class JdbcCategoryDao implements CategoryDao { @Value("${category.count_all_categories}") private String countAllSql; + @Value("${category.count_categories_by_slug}") + private String countBySlugSql; + @Value("${category.count_categories_by_name}") private String countByNameSql; @@ -108,6 +111,15 @@ public long countAll() { ); } + @Override + public long countBySlug(String slug) { + return jdbcTemplate.queryForObject( + countBySlugSql, + Collections.singletonMap("slug", slug), + Long.class + ); + } + @Override public long countByName(String name) { return jdbcTemplate.queryForObject( diff --git a/src/main/java/ru/mystamps/web/model/AddCategoryForm.java b/src/main/java/ru/mystamps/web/model/AddCategoryForm.java index c32ef08e8f..b704d03d47 100644 --- a/src/main/java/ru/mystamps/web/model/AddCategoryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCategoryForm.java @@ -29,6 +29,7 @@ import ru.mystamps.web.service.dto.AddCategoryDto; import ru.mystamps.web.validation.jsr303.UniqueCategoryName; import ru.mystamps.web.validation.jsr303.UniqueCategoryName.Lang; +import ru.mystamps.web.validation.jsr303.UniqueCategorySlug; import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_EN_REGEXP; import static ru.mystamps.web.validation.ValidationRules.CATEGORY_NAME_MAX_LENGTH; @@ -46,7 +47,8 @@ Group.Level3.class, Group.Level4.class, Group.Level5.class, - Group.Level6.class + Group.Level6.class, + Group.Level7.class }) public class AddCategoryForm implements AddCategoryDto { @@ -81,6 +83,7 @@ public class AddCategoryForm implements AddCategoryDto { ) }) @UniqueCategoryName(lang = Lang.EN, groups = Group.Level6.class) + @UniqueCategorySlug(groups = Group.Level7.class) private String name; @NotEmpty(groups = Group.Level1.class) diff --git a/src/main/java/ru/mystamps/web/model/Group.java b/src/main/java/ru/mystamps/web/model/Group.java index fb8f92b750..70880bcd7c 100644 --- a/src/main/java/ru/mystamps/web/model/Group.java +++ b/src/main/java/ru/mystamps/web/model/Group.java @@ -37,4 +37,7 @@ interface Level5 { interface Level6 { } + interface Level7 { + } + } diff --git a/src/main/java/ru/mystamps/web/service/CategoryService.java b/src/main/java/ru/mystamps/web/service/CategoryService.java index 39502d0a37..bc2977b3ca 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryService.java +++ b/src/main/java/ru/mystamps/web/service/CategoryService.java @@ -29,6 +29,7 @@ public interface CategoryService { LinkEntityDto findOneAsLinkEntity(String slug, String lang); long countAll(); long countCategoriesOf(Integer collectionId); + long countBySlug(String slug); long countByName(String name); long countByNameRu(String name); long countAddedSince(Date date); diff --git a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java index 47bc2a7604..e6717da9b0 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java @@ -109,6 +109,14 @@ public long countCategoriesOf(Integer collectionId) { return categoryDao.countCategoriesOfCollection(collectionId); } + @Override + @Transactional(readOnly = true) + public long countBySlug(String slug) { + Validate.isTrue(slug != null, "Category slug must be non null"); + + return categoryDao.countBySlug(slug); + } + @Override @Transactional(readOnly = true) public long countByName(String name) { diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlug.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlug.java new file mode 100644 index 0000000000..32ad1fe081 --- /dev/null +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlug.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.validation.jsr303; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({ METHOD, FIELD, ANNOTATION_TYPE }) +@Retention(RUNTIME) +@Constraint(validatedBy = UniqueCategorySlugValidator.class) +@Documented +public @interface UniqueCategorySlug { + String message() default "{ru.mystamps.web.validation.jsr303.UniqueCategorySlug.message}"; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlugValidator.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlugValidator.java new file mode 100644 index 0000000000..6a39206ffb --- /dev/null +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCategorySlugValidator.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.validation.jsr303; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import lombok.RequiredArgsConstructor; + +import ru.mystamps.web.service.CategoryService; +import ru.mystamps.web.util.SlugUtils; + +@RequiredArgsConstructor +public class UniqueCategorySlugValidator + implements ConstraintValidator { + + private final CategoryService categoryService; + + @Override + public void initialize(UniqueCategorySlug annotation) { + // Intentionally empty: nothing to initialize + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext ctx) { + + if (value == null) { + return true; + } + + String slug = SlugUtils.slugify(value); + + return categoryService.countBySlug(slug) == 0; + } + +} diff --git a/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties b/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties index c56d33a980..3765e34598 100644 --- a/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties +++ b/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties @@ -9,6 +9,7 @@ ru.mystamps.web.validation.jsr303.FieldsMatch.message = Field '{second}' must ma ru.mystamps.web.validation.jsr303.UniqueLogin.message = Login already exists ru.mystamps.web.validation.jsr303.UniqueCountryName.message = Country already exists ru.mystamps.web.validation.jsr303.UniqueCategoryName.message = Category already exists +ru.mystamps.web.validation.jsr303.UniqueCategorySlug.message = Category with similar name already exists ru.mystamps.web.validation.jsr303.ExistingActivationKey.message = Wrong activation key ru.mystamps.web.validation.jsr303.Email.message = Wrong e-mail address ru.mystamps.web.validation.jsr303.NotEmptyFilename.message = Value must not be empty diff --git a/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties b/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties index ce55e644c3..ce82f6c51b 100644 --- a/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties @@ -9,6 +9,7 @@ ru.mystamps.web.validation.jsr303.FieldsMatch.message = Поле '{second}' до ru.mystamps.web.validation.jsr303.UniqueLogin.message = Логин уже существует ru.mystamps.web.validation.jsr303.UniqueCountryName.message = Страна уже есть в базе ru.mystamps.web.validation.jsr303.UniqueCategoryName.message = Категория уже есть в базе +ru.mystamps.web.validation.jsr303.UniqueCategorySlug.message = Категория с похожим названием уже есть в базе ru.mystamps.web.validation.jsr303.ExistingActivationKey.message = Неправильный код активации ru.mystamps.web.validation.jsr303.Email.message = Неправильный адрес электронной почты ru.mystamps.web.validation.jsr303.ReleaseDateIsNotInFuture.message = Дата выпуска не может быть в будущем diff --git a/src/main/resources/sql/category_dao_queries.properties b/src/main/resources/sql/category_dao_queries.properties index 4e62ea713f..f9c351a7b4 100644 --- a/src/main/resources/sql/category_dao_queries.properties +++ b/src/main/resources/sql/category_dao_queries.properties @@ -23,6 +23,11 @@ category.count_all_categories = \ SELECT COUNT(*) \ FROM categories +category.count_categories_by_slug = \ +SELECT COUNT(*) \ + FROM categories \ + WHERE slug = :slug + category.count_categories_by_name = \ SELECT COUNT(*) \ FROM categories \ diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index 6e91519dc5..ef2ccbfe91 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -312,6 +312,26 @@ class CategoryServiceImplTest extends Specification { }) >> 0L } + // + // Tests for countBySlug() + // + + def "countBySlug() should throw exception when slug is null"() { + when: + service.countBySlug(null) + then: + thrown IllegalArgumentException + } + + def "countBySlug() should call dao"() { + given: + categoryDao.countBySlug(_ as String) >> 3L + when: + long result = service.countBySlug('any-slug') + then: + result == 3L + } + // // Tests for countByName() // From 28a94d1f850ed6caed4135c5fa8454542988580c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 16 Oct 2016 13:18:47 +0200 Subject: [PATCH 102/463] /country/add: add validation for unique slug. This fixes DuplicateKeyException when name contains mix of spaces and hyphens. Fix #487 --- .../java/ru/mystamps/web/dao/CountryDao.java | 1 + .../mystamps/web/dao/impl/JdbcCountryDao.java | 12 +++++ .../ru/mystamps/web/model/AddCountryForm.java | 5 +- .../mystamps/web/service/CountryService.java | 1 + .../web/service/CountryServiceImpl.java | 8 +++ .../validation/jsr303/UniqueCountrySlug.java | 40 +++++++++++++++ .../jsr303/UniqueCountrySlugValidator.java | 50 +++++++++++++++++++ .../i18n/ValidationMessages.properties | 1 + .../i18n/ValidationMessages_ru.properties | 1 + .../sql/country_dao_queries.properties | 5 ++ .../web/service/CountryServiceImplTest.groovy | 20 ++++++++ 11 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlug.java create mode 100644 src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlugValidator.java diff --git a/src/main/java/ru/mystamps/web/dao/CountryDao.java b/src/main/java/ru/mystamps/web/dao/CountryDao.java index 1b90902c0a..8edf9836f5 100644 --- a/src/main/java/ru/mystamps/web/dao/CountryDao.java +++ b/src/main/java/ru/mystamps/web/dao/CountryDao.java @@ -26,6 +26,7 @@ public interface CountryDao { Integer add(AddCountryDbDto country); long countAll(); + long countBySlug(String slug); long countByName(String name); long countByNameRu(String name); long countCountriesOfCollection(Integer collectionId); diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java index 66e7099b71..ed585b18fb 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java @@ -50,6 +50,9 @@ public class JdbcCountryDao implements CountryDao { @Value("${country.count_all_countries}") private String countAllSql; + @Value("${country.count_countries_by_slug}") + private String countBySlugSql; + @Value("${country.count_countries_by_name}") private String countByNameSql; @@ -108,6 +111,15 @@ public long countAll() { ); } + @Override + public long countBySlug(String slug) { + return jdbcTemplate.queryForObject( + countBySlugSql, + Collections.singletonMap("slug", slug), + Long.class + ); + } + @Override public long countByName(String name) { return jdbcTemplate.queryForObject( diff --git a/src/main/java/ru/mystamps/web/model/AddCountryForm.java b/src/main/java/ru/mystamps/web/model/AddCountryForm.java index fa7d2a4185..077c1a093b 100644 --- a/src/main/java/ru/mystamps/web/model/AddCountryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCountryForm.java @@ -29,6 +29,7 @@ import ru.mystamps.web.service.dto.AddCountryDto; import ru.mystamps.web.validation.jsr303.UniqueCountryName; import ru.mystamps.web.validation.jsr303.UniqueCountryName.Lang; +import ru.mystamps.web.validation.jsr303.UniqueCountrySlug; import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_EN_REGEXP; import static ru.mystamps.web.validation.ValidationRules.COUNTRY_NAME_MAX_LENGTH; @@ -46,7 +47,8 @@ Group.Level3.class, Group.Level4.class, Group.Level5.class, - Group.Level6.class + Group.Level6.class, + Group.Level7.class }) public class AddCountryForm implements AddCountryDto { @@ -81,6 +83,7 @@ public class AddCountryForm implements AddCountryDto { ) }) @UniqueCountryName(lang = Lang.EN, groups = Group.Level6.class) + @UniqueCountrySlug(groups = Group.Level7.class) private String name; @NotEmpty(groups = Group.Level1.class) diff --git a/src/main/java/ru/mystamps/web/service/CountryService.java b/src/main/java/ru/mystamps/web/service/CountryService.java index 80b0d2bda2..5423887660 100644 --- a/src/main/java/ru/mystamps/web/service/CountryService.java +++ b/src/main/java/ru/mystamps/web/service/CountryService.java @@ -29,6 +29,7 @@ public interface CountryService { LinkEntityDto findOneAsLinkEntity(String slug, String lang); long countAll(); long countCountriesOf(Integer collectionId); + long countBySlug(String slug); long countByName(String name); long countByNameRu(String name); long countAddedSince(Date date); diff --git a/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java index 12100b1ae9..85ca8a4df8 100644 --- a/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java @@ -110,6 +110,14 @@ public long countCountriesOf(Integer collectionId) { return countryDao.countCountriesOfCollection(collectionId); } + @Override + @Transactional(readOnly = true) + public long countBySlug(String slug) { + Validate.isTrue(slug != null, "Country slug must be non null"); + + return countryDao.countBySlug(slug); + } + @Override @Transactional(readOnly = true) public long countByName(String name) { diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlug.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlug.java new file mode 100644 index 0000000000..6943fa12b7 --- /dev/null +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlug.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.validation.jsr303; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({ METHOD, FIELD, ANNOTATION_TYPE }) +@Retention(RUNTIME) +@Constraint(validatedBy = UniqueCountrySlugValidator.class) +@Documented +public @interface UniqueCountrySlug { + String message() default "{ru.mystamps.web.validation.jsr303.UniqueCountrySlug.message}"; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlugValidator.java b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlugValidator.java new file mode 100644 index 0000000000..bbaeb7028b --- /dev/null +++ b/src/main/java/ru/mystamps/web/validation/jsr303/UniqueCountrySlugValidator.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009-2016 Slava Semushin + * + * 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.validation.jsr303; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import lombok.RequiredArgsConstructor; + +import ru.mystamps.web.service.CountryService; +import ru.mystamps.web.util.SlugUtils; + +@RequiredArgsConstructor +public class UniqueCountrySlugValidator implements ConstraintValidator { + + private final CountryService countryService; + + @Override + public void initialize(UniqueCountrySlug annotation) { + // Intentionally empty: nothing to initialize + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext ctx) { + + if (value == null) { + return true; + } + + String slug = SlugUtils.slugify(value); + + return countryService.countBySlug(slug) == 0; + } + +} diff --git a/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties b/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties index 3765e34598..cddd075dc6 100644 --- a/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties +++ b/src/main/resources/ru/mystamps/i18n/ValidationMessages.properties @@ -9,6 +9,7 @@ ru.mystamps.web.validation.jsr303.FieldsMatch.message = Field '{second}' must ma ru.mystamps.web.validation.jsr303.UniqueLogin.message = Login already exists ru.mystamps.web.validation.jsr303.UniqueCountryName.message = Country already exists ru.mystamps.web.validation.jsr303.UniqueCategoryName.message = Category already exists +ru.mystamps.web.validation.jsr303.UniqueCountrySlug.message = Country with similar name already exists ru.mystamps.web.validation.jsr303.UniqueCategorySlug.message = Category with similar name already exists ru.mystamps.web.validation.jsr303.ExistingActivationKey.message = Wrong activation key ru.mystamps.web.validation.jsr303.Email.message = Wrong e-mail address diff --git a/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties b/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties index ce82f6c51b..00d9a545e8 100644 --- a/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties @@ -9,6 +9,7 @@ ru.mystamps.web.validation.jsr303.FieldsMatch.message = Поле '{second}' до ru.mystamps.web.validation.jsr303.UniqueLogin.message = Логин уже существует ru.mystamps.web.validation.jsr303.UniqueCountryName.message = Страна уже есть в базе ru.mystamps.web.validation.jsr303.UniqueCategoryName.message = Категория уже есть в базе +ru.mystamps.web.validation.jsr303.UniqueCountrySlug.message = Страна с похожим названием уже есть в базе ru.mystamps.web.validation.jsr303.UniqueCategorySlug.message = Категория с похожим названием уже есть в базе ru.mystamps.web.validation.jsr303.ExistingActivationKey.message = Неправильный код активации ru.mystamps.web.validation.jsr303.Email.message = Неправильный адрес электронной почты diff --git a/src/main/resources/sql/country_dao_queries.properties b/src/main/resources/sql/country_dao_queries.properties index 8dd8621089..46a653ee23 100644 --- a/src/main/resources/sql/country_dao_queries.properties +++ b/src/main/resources/sql/country_dao_queries.properties @@ -23,6 +23,11 @@ country.count_all_countries = \ SELECT COUNT(*) \ FROM countries +country.count_countries_by_slug = \ +SELECT COUNT(*) \ + FROM countries \ + WHERE slug = :slug + country.count_countries_by_name = \ SELECT COUNT(*) \ FROM countries \ diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index 05b541e9e3..4a56fd8fa7 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -311,6 +311,26 @@ class CountryServiceImplTest extends Specification { }) >> 0L } + // + // Tests for countBySlug() + // + + def "countBySlug() should throw exception when slug is null"() { + when: + service.countBySlug(null) + then: + thrown IllegalArgumentException + } + + def "countBySlug() should call dao"() { + given: + countryDao.countBySlug(_ as String) >> 3L + when: + long result = service.countBySlug('any-slug') + then: + result == 3L + } + // // Tests for countByName() // From 871a2dcc47129088ab17aa79153c1a1dacf3f819 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 13:00:55 +0200 Subject: [PATCH 103/463] series/info: move block with sellers info into separate row. No functional changes. --- .../webapp/WEB-INF/views/series/info.html | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 96496d0513..ccd8bd51c2 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -256,45 +256,49 @@
    -
    -
    Who was selling/buying this series:
    - +
    +
    +
    +
    Who was selling/buying this series:
    + +
    +
    - +
    From fceade5b4046ae18e153f7de6c5b112f2d819918 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 13:13:23 +0200 Subject: [PATCH 104/463] series/info: move block with series in collection info into separate row. No functional changes. --- .../webapp/WEB-INF/views/series/info.html | 67 +++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index ccd8bd51c2..765273c891 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -299,44 +299,43 @@
    Who was selling/buying this series:
    -

    - - -
    -
    -

    - Series isn't part of your collection -

    -

    - - -

    -
    -
    - -
    -

    - In order to add this series to your collection you should register - or pass authentication. -

    -
    - - /*/--> + From 8b11981a9a7ad49bad350d68645ac34903e9a279 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 13:32:51 +0200 Subject: [PATCH 105/463] series/info: move block with adding image form into the column with images. No functional changes. --- .../webapp/WEB-INF/views/series/info.html | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 765273c891..25d92df8a1 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -105,6 +105,21 @@ + +
    +
    +
    +
    + + +
    +
    + +
    +
    +
    +
    +
    @@ -339,23 +354,6 @@
    Who was selling/buying this series:
    -
    -
    -
    -
    -
    -
    - - -
    -
    - -
    -
    -
    -
    -
    -
    From a28d71c6d87aae32c898e25ce0a4e0a54a561f0c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 18:42:10 +0200 Subject: [PATCH 106/463] main.css: add commented CSS-rules for highlighting blocks. No functional changes. [ci skip] --- src/main/webapp/WEB-INF/static/styles/main.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/webapp/WEB-INF/static/styles/main.css b/src/main/webapp/WEB-INF/static/styles/main.css index ab46a12068..35f18361f3 100644 --- a/src/main/webapp/WEB-INF/static/styles/main.css +++ b/src/main/webapp/WEB-INF/static/styles/main.css @@ -1,3 +1,14 @@ +/* Only for debug: highlight borders of rows and columns */ +/* +.row { + border: solid 1px red; +} +.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, +.col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 { + border: solid 1px green; +} +*/ + body, #user_bar ul { margin: 0; From 8900e197e2748d131b42584f2b4a6d4c90d747ff Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 19:26:57 +0200 Subject: [PATCH 107/463] Enable resource versioning for CSS/JS files. See also: http://www.mscharhag.com/spring/resource-versioning-with-spring-mvc While it's also possible to configure resource versioning by using spring.resources.chain.strategy.fixed.* properties, I decided to configure it in the Url class. The first approach requires to modify application-prod.properties file each time when resources got changed. This means that in our setup we will have to modify this file on the server on each deploy because we have application-prod.properties file that resides in the separate directory on the filesystem. Fix #235 --- src/main/java/ru/mystamps/web/Url.java | 13 ++++++++----- .../java/ru/mystamps/web/config/MvcConfig.java | 18 ++++++++++++++++-- src/main/javascript/CatalogUtils.js | 4 ++++ src/main/javascript/collection/info.js | 4 ++++ src/main/javascript/series/add.js | 4 ++++ src/main/webapp/WEB-INF/static/styles/main.css | 5 +++++ 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/mystamps/web/Url.java b/src/main/java/ru/mystamps/web/Url.java index 1b8e075ddf..3a42de77fa 100644 --- a/src/main/java/ru/mystamps/web/Url.java +++ b/src/main/java/ru/mystamps/web/Url.java @@ -81,12 +81,15 @@ public final class Url { public static final String NOT_FOUND_PAGE = "/error/404"; public static final String INTERNAL_ERROR_PAGE = "/error/500"; - // resources + // MUST be updated when any of our resources were modified + public static final String RESOURCES_VERSION = "v0.3.0"; + + // CheckStyle: ignore LineLength for next 4 lines + public static final String MAIN_CSS = "/static/" + RESOURCES_VERSION + "/styles/main.min.css"; + public static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js"; + public static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js"; + public static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js"; public static final String FAVICON_ICO = "/favicon.ico"; - public static final String MAIN_CSS = "/static/styles/main.min.css"; - public static final String CATALOG_UTILS_JS = "/public/js/CatalogUtils.min.js"; - public static final String SERIES_ADD_JS = "/public/js/series/add.min.js"; - public static final String COLLECTION_INFO_JS = "/public/js/collection/info.min.js"; // CheckStyle: ignore LineLength for next 4 lines public static final String BOOTSTRAP_CSS = "/public/bootstrap/3.3.6/css/bootstrap.min.css"; diff --git a/src/main/java/ru/mystamps/web/config/MvcConfig.java b/src/main/java/ru/mystamps/web/config/MvcConfig.java index a23d019768..6d91a6d821 100755 --- a/src/main/java/ru/mystamps/web/config/MvcConfig.java +++ b/src/main/java/ru/mystamps/web/config/MvcConfig.java @@ -19,12 +19,14 @@ import java.util.List; import java.util.Locale; +import java.util.concurrent.TimeUnit; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.springframework.format.FormatterRegistry; +import org.springframework.http.CacheControl; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.validation.Validator; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; @@ -38,6 +40,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.servlet.i18n.SessionLocaleResolver; +import org.springframework.web.servlet.resource.VersionResourceResolver; import lombok.RequiredArgsConstructor; @@ -77,10 +80,21 @@ public void addViewControllers(ViewControllerRegistry registry) { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { + VersionResourceResolver resourceResolver = new VersionResourceResolver() + .addFixedVersionStrategy(Url.RESOURCES_VERSION, "/**"); + + @SuppressWarnings("checkstyle:magicnumber") + CacheControl cacheControl = CacheControl.maxAge(7, TimeUnit.DAYS); + registry.addResourceHandler("/static/**") - .addResourceLocations("/WEB-INF/static/"); + .addResourceLocations("/WEB-INF/static/") + .setCacheControl(cacheControl) + .resourceChain(true) + .addResolver(resourceResolver); registry.addResourceHandler("/public/js/**") - .addResourceLocations("classpath:/js/"); + .addResourceLocations("classpath:/js/") + .resourceChain(true) + .addResolver(resourceResolver); // For WebJars: registry.addResourceHandler("/public/bootstrap/**") diff --git a/src/main/javascript/CatalogUtils.js b/src/main/javascript/CatalogUtils.js index e196fa030c..335219a040 100644 --- a/src/main/javascript/CatalogUtils.js +++ b/src/main/javascript/CatalogUtils.js @@ -1,3 +1,7 @@ +// +// IMPORTANT: +// You have to update Url.RESOURCES_VERSION each time whenever you're modified this file! +// var CatalogUtils = { /** @public */ diff --git a/src/main/javascript/collection/info.js b/src/main/javascript/collection/info.js index a9fa3ede4f..948f36ac66 100644 --- a/src/main/javascript/collection/info.js +++ b/src/main/javascript/collection/info.js @@ -1,3 +1,7 @@ +// +// IMPORTANT: +// You have to update Url.RESOURCES_VERSION each time whenever you're modified this file! +// function initPage(statByCategories, statByCountries) { var chartsVersion = '44'; google.charts.load(chartsVersion, {'packages':['corechart']}); diff --git a/src/main/javascript/series/add.js b/src/main/javascript/series/add.js index 61cddb63d1..c0c504d022 100644 --- a/src/main/javascript/series/add.js +++ b/src/main/javascript/series/add.js @@ -1,3 +1,7 @@ +// +// IMPORTANT: +// You have to update Url.RESOURCES_VERSION each time whenever you're modified this file! +// function initPage() { $('#country').selectize(); diff --git a/src/main/webapp/WEB-INF/static/styles/main.css b/src/main/webapp/WEB-INF/static/styles/main.css index 35f18361f3..65c04aa88d 100644 --- a/src/main/webapp/WEB-INF/static/styles/main.css +++ b/src/main/webapp/WEB-INF/static/styles/main.css @@ -1,3 +1,8 @@ +/* + * IMPORTANT: + * You have to update Url.RESOURCES_VERSION each time whenever you're modified this file! + */ + /* Only for debug: highlight borders of rows and columns */ /* .row { From 74e368c187f4cf930f6796ecd99f8723354bde03 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 23:12:43 +0200 Subject: [PATCH 108/463] CollectionService.removeFromCollection(): don't return UrlEntityDto. Addressed to #440 No functional changes. --- .../web/controller/SeriesController.java | 9 +++-- .../ru/mystamps/web/dao/CollectionDao.java | 4 +- .../ru/mystamps/web/dao/dto/UrlEntityDto.java | 32 ---------------- .../web/dao/impl/JdbcCollectionDao.java | 22 ++--------- .../ru/mystamps/web/dao/impl/RowMappers.java | 8 ---- .../web/service/CollectionService.java | 3 +- .../web/service/CollectionServiceImpl.java | 16 ++------ .../sql/collection_dao_queries.properties | 7 +--- .../service/CollectionServiceImplTest.groovy | 38 ++----------------- .../ru/mystamps/web/service/TestObjects.java | 5 --- 10 files changed, 19 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/ru/mystamps/web/dao/dto/UrlEntityDto.java diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 5da8943efc..3c8ec66aa3 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -59,7 +59,6 @@ import ru.mystamps.web.dao.dto.LinkEntityDto; import ru.mystamps.web.dao.dto.PurchaseAndSaleDto; import ru.mystamps.web.dao.dto.SeriesInfoDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.model.AddImageForm; import ru.mystamps.web.model.AddSeriesForm; import ru.mystamps.web.service.CategoryService; @@ -288,7 +287,7 @@ public String addToCollection( @PostMapping(path = Url.INFO_SERIES_PAGE, params = "action=REMOVE") public String removeFromCollection( @PathVariable("id") Integer seriesId, - @CurrentUser Integer currentUserId, + @AuthenticationPrincipal CustomUserDetails currentUserDetails, RedirectAttributes redirectAttributes, HttpServletResponse response) throws IOException { @@ -304,11 +303,13 @@ public String removeFromCollection( return null; } - UrlEntityDto collection = collectionService.removeFromCollection(currentUserId, seriesId); + Integer userId = currentUserDetails.getUserId(); + collectionService.removeFromCollection(userId, seriesId); redirectAttributes.addFlashAttribute("justRemovedSeries", true); - return redirectTo(Url.INFO_COLLECTION_PAGE, collection.getSlug()); + String collectionSlug = currentUserDetails.getUserCollectionSlug(); + return redirectTo(Url.INFO_COLLECTION_PAGE, collectionSlug); } @PostMapping(Url.SEARCH_SERIES_BY_CATALOG) diff --git a/src/main/java/ru/mystamps/web/dao/CollectionDao.java b/src/main/java/ru/mystamps/web/dao/CollectionDao.java index 8efcc042b6..a9e50f79fa 100644 --- a/src/main/java/ru/mystamps/web/dao/CollectionDao.java +++ b/src/main/java/ru/mystamps/web/dao/CollectionDao.java @@ -22,15 +22,13 @@ import ru.mystamps.web.dao.dto.AddCollectionDbDto; import ru.mystamps.web.dao.dto.CollectionInfoDto; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; public interface CollectionDao { List findLastCreated(int quantity); long countCollectionsOfUsers(); Integer add(AddCollectionDbDto collection); boolean isSeriesInUserCollection(Integer userId, Integer seriesId); - UrlEntityDto findCollectionUrlEntityByUserId(Integer userId); void addSeriesToUserCollection(Integer userId, Integer seriesId); - void removeSeriesFromCollection(Integer collectionId, Integer seriesId); + void removeSeriesFromUserCollection(Integer userId, Integer seriesId); CollectionInfoDto findCollectionInfoBySlug(String slug); } diff --git a/src/main/java/ru/mystamps/web/dao/dto/UrlEntityDto.java b/src/main/java/ru/mystamps/web/dao/dto/UrlEntityDto.java deleted file mode 100644 index 2705caaa69..0000000000 --- a/src/main/java/ru/mystamps/web/dao/dto/UrlEntityDto.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2009-2016 Slava Semushin - * - * 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.dao.dto; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.ToString; - -@Getter -@ToString -@EqualsAndHashCode -@RequiredArgsConstructor -public class UrlEntityDto { - private final Integer id; - private final String slug; -} diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java index 9378831fe8..868c9453a1 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java @@ -40,7 +40,6 @@ import ru.mystamps.web.dao.dto.AddCollectionDbDto; import ru.mystamps.web.dao.dto.CollectionInfoDto; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; @RequiredArgsConstructor @SuppressWarnings("PMD.AvoidDuplicateLiterals") @@ -61,10 +60,6 @@ public class JdbcCollectionDao implements CollectionDao { @Value("${collection.is_series_in_collection}") private String isSeriesInUserCollectionSql; - @SuppressWarnings("PMD.LongVariable") - @Value("${collection.find_id_and_slug_by_user_id}") - private String findCollectionIdAndSlugByUserIdSql; - @Value("${collection.add_series_to_collection}") private String addSeriesToCollectionSql; @@ -128,15 +123,6 @@ public boolean isSeriesInUserCollection(Integer userId, Integer seriesId) { return result > 0; } - @Override - public UrlEntityDto findCollectionUrlEntityByUserId(Integer userId) { - return jdbcTemplate.queryForObject( - findCollectionIdAndSlugByUserIdSql, - Collections.singletonMap("user_id", userId), - RowMappers::forUrlEntityDto - ); - } - @Override public void addSeriesToUserCollection(Integer userId, Integer seriesId) { Map params = new HashMap<>(); @@ -157,18 +143,18 @@ public void addSeriesToUserCollection(Integer userId, Integer seriesId) { @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") @Override - public void removeSeriesFromCollection(Integer collectionId, Integer seriesId) { + public void removeSeriesFromUserCollection(Integer userId, Integer seriesId) { Map params = new HashMap<>(); - params.put("collection_id", collectionId); + params.put("user_id", userId); params.put("series_id", seriesId); int affected = jdbcTemplate.update(removeSeriesFromCollectionSql, params); if (affected != 1) { // CheckStyle: ignore LineLength for next 2 lines LOG.warn( - "Unexpected number of affected rows after removing series #{} from collection #{}: %{}", + "Unexpected number of affected rows after removing series #{} from collection of user #{}: %{}", seriesId, - collectionId, + userId, affected ); } diff --git a/src/main/java/ru/mystamps/web/dao/impl/RowMappers.java b/src/main/java/ru/mystamps/web/dao/impl/RowMappers.java index 8bd92ec94f..e0a45b6443 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/RowMappers.java +++ b/src/main/java/ru/mystamps/web/dao/impl/RowMappers.java @@ -32,7 +32,6 @@ import ru.mystamps.web.dao.dto.SeriesInfoDto; import ru.mystamps.web.dao.dto.SitemapInfoDto; import ru.mystamps.web.dao.dto.SuspiciousActivityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.dao.dto.UserDetails; import ru.mystamps.web.dao.dto.UsersActivationDto; import ru.mystamps.web.dao.dto.UsersActivationFullDto; @@ -51,13 +50,6 @@ public static LinkEntityDto forLinkEntityDto(ResultSet rs, int i) throws SQLExce ); } - public static UrlEntityDto forUrlEntityDto(ResultSet rs, int i) throws SQLException { - return new UrlEntityDto( - rs.getInt("id"), - rs.getString("slug") - ); - } - public static Object[] forNameAndCounter(ResultSet rs, int i) throws SQLException { return new Object[]{ rs.getString("name"), diff --git a/src/main/java/ru/mystamps/web/service/CollectionService.java b/src/main/java/ru/mystamps/web/service/CollectionService.java index 5e58811de4..809c0c2044 100644 --- a/src/main/java/ru/mystamps/web/service/CollectionService.java +++ b/src/main/java/ru/mystamps/web/service/CollectionService.java @@ -21,12 +21,11 @@ import ru.mystamps.web.dao.dto.CollectionInfoDto; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; public interface CollectionService { void createCollection(Integer ownerId, String ownerLogin); void addToCollection(Integer userId, Integer seriesId); - UrlEntityDto removeFromCollection(Integer userId, Integer seriesId); + void removeFromCollection(Integer userId, Integer seriesId); boolean isSeriesInCollection(Integer userId, Integer seriesId); long countCollectionsOfUsers(); List findRecentlyCreated(int quantity); diff --git a/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java b/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java index cea18c9267..80a187a259 100644 --- a/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java @@ -35,7 +35,6 @@ import ru.mystamps.web.dao.dto.AddCollectionDbDto; import ru.mystamps.web.dao.dto.CollectionInfoDto; import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.support.spring.security.HasAuthority; import ru.mystamps.web.util.SlugUtils; @@ -81,22 +80,13 @@ public void addToCollection(Integer userId, Integer seriesId) { @Override @Transactional @PreAuthorize(HasAuthority.UPDATE_COLLECTION) - public UrlEntityDto removeFromCollection(Integer userId, Integer seriesId) { + public void removeFromCollection(Integer userId, Integer seriesId) { Validate.isTrue(userId != null, "User id must be non null"); Validate.isTrue(seriesId != null, "Series id must be non null"); - UrlEntityDto url = collectionDao.findCollectionUrlEntityByUserId(userId); - Integer collectionId = url.getId(); + collectionDao.removeSeriesFromUserCollection(userId, seriesId); - collectionDao.removeSeriesFromCollection(collectionId, seriesId); - - LOG.info( - "Series #{} has been removed from collection of user #{}", - seriesId, - userId - ); - - return url; + LOG.info("Series #{} has been removed from collection of user #{}", seriesId, userId); } @Override diff --git a/src/main/resources/sql/collection_dao_queries.properties b/src/main/resources/sql/collection_dao_queries.properties index a95457eb79..140dcaee6a 100644 --- a/src/main/resources/sql/collection_dao_queries.properties +++ b/src/main/resources/sql/collection_dao_queries.properties @@ -38,11 +38,6 @@ SELECT COUNT(*) \ WHERE c.user_id = :user_id \ AND cs.series_id = :series_id -collection.find_id_and_slug_by_user_id = \ -SELECT id, slug \ - FROM collections c \ - WHERE c.user_id = :user_id - collection.add_series_to_collection = \ INSERT \ INTO collections_series(collection_id, series_id) \ @@ -54,7 +49,7 @@ SELECT c.id AS collection_id \ collection.remove_series_from_collection = \ DELETE \ FROM collections_series \ - WHERE collection_id = :collection_id \ + WHERE user_id = :user_id \ AND series_id = :series_id collection.find_info_by_slug = \ diff --git a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy index ea9d4e93eb..bb7d910e15 100644 --- a/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy @@ -23,7 +23,6 @@ import spock.lang.Unroll import ru.mystamps.web.dao.CollectionDao import ru.mystamps.web.dao.dto.AddCollectionDbDto import ru.mystamps.web.dao.dto.CollectionInfoDto -import ru.mystamps.web.dao.dto.UrlEntityDto import ru.mystamps.web.util.SlugUtils @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) @@ -146,34 +145,16 @@ class CollectionServiceImplTest extends Specification { thrown IllegalArgumentException } - @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) - def "removeFromCollection() should find collection by user id"() { - given: - Integer expectedUserId = 123 - when: - service.removeFromCollection(expectedUserId, 321) - then: - 1 * collectionDao.findCollectionUrlEntityByUserId({ Integer userId -> - assert userId == expectedUserId - return true - }) >> TestObjects.createUrlEntityDto() - } - @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) def "removeFromCollection() should remove series from collection"() { given: + Integer expectedUserId = 123 Integer expectedSeriesId = 456 - and: - UrlEntityDto url = TestObjects.createUrlEntityDto() - and: - Integer expectedCollectionId = url.id - and: - collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> url when: - service.removeFromCollection(123, expectedSeriesId) + service.removeFromCollection(expectedUserId, expectedSeriesId) then: - 1 * collectionDao.removeSeriesFromCollection({ Integer collectionId -> - assert collectionId == expectedCollectionId + 1 * collectionDao.removeSeriesFromUserCollection({ Integer userId -> + assert userId == expectedUserId return true }, { Integer seriesId -> assert seriesId == expectedSeriesId @@ -181,17 +162,6 @@ class CollectionServiceImplTest extends Specification { }) } - def "removeFromCollection() should return result from dao"() { - given: - UrlEntityDto expectedResult = TestObjects.createUrlEntityDto() - and: - collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> expectedResult - when: - UrlEntityDto serviceResult = service.removeFromCollection(123, 456) - then: - serviceResult == expectedResult - } - // // Tests for isSeriesInCollection() // diff --git a/src/test/java/ru/mystamps/web/service/TestObjects.java b/src/test/java/ru/mystamps/web/service/TestObjects.java index e767bf7797..151f7853d9 100644 --- a/src/test/java/ru/mystamps/web/service/TestObjects.java +++ b/src/test/java/ru/mystamps/web/service/TestObjects.java @@ -30,7 +30,6 @@ import ru.mystamps.web.dao.dto.SeriesInfoDto; import ru.mystamps.web.dao.dto.SitemapInfoDto; import ru.mystamps.web.dao.dto.SuspiciousActivityDto; -import ru.mystamps.web.dao.dto.UrlEntityDto; import ru.mystamps.web.dao.dto.UserDetails; import ru.mystamps.web.dao.dto.UsersActivationDto; import ru.mystamps.web.dao.dto.UsersActivationFullDto; @@ -79,10 +78,6 @@ public static UsersActivationDto createUsersActivationDto() { return new UsersActivationDto(TEST_EMAIL, new Date()); } - public static UrlEntityDto createUrlEntityDto() { - return new UrlEntityDto(TEST_ENTITY_ID, TEST_ENTITY_SLUG); - } - public static LinkEntityDto createLinkEntityDto() { return new LinkEntityDto(TEST_ENTITY_ID, TEST_ENTITY_SLUG, TEST_ENTITY_NAME); } From 3fac29f2371b39ac6664c0d9ec03b2d71459cea9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 23:39:52 +0200 Subject: [PATCH 109/463] Unbreak removing series from collection. Correction for ff8fff521f6d92fb97d8b40410265b8cce281505 commit. Addressed to #440 --- src/main/resources/sql/collection_dao_queries.properties | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/resources/sql/collection_dao_queries.properties b/src/main/resources/sql/collection_dao_queries.properties index 140dcaee6a..fa52b27689 100644 --- a/src/main/resources/sql/collection_dao_queries.properties +++ b/src/main/resources/sql/collection_dao_queries.properties @@ -49,8 +49,13 @@ SELECT c.id AS collection_id \ collection.remove_series_from_collection = \ DELETE \ FROM collections_series \ - WHERE user_id = :user_id \ - AND series_id = :series_id + WHERE series_id = :series_id \ + AND collection_id = ( \ + SELECT id \ + FROM collections \ + WHERE user_id = :user_id \ + ) + collection.find_info_by_slug = \ SELECT c.id \ From 70fd55c7a2d82f38eb9309fc42492bcd3b36e507 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 21 Oct 2016 17:38:26 +0200 Subject: [PATCH 110/463] Move colon from translation to Thymeleaf expression. Should be in c5e733b6e06fd5f73fb59f85754479c8f52ffba3 commit. No functional changes. --- src/main/resources/ru/mystamps/i18n/Messages.properties | 2 +- src/main/resources/ru/mystamps/i18n/Messages_ru.properties | 2 +- src/main/webapp/WEB-INF/views/series/info.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/ru/mystamps/i18n/Messages.properties b/src/main/resources/ru/mystamps/i18n/Messages.properties index c4544b24a1..68097e00bd 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages.properties @@ -139,7 +139,7 @@ t_need_authentication_to_add_series_to_collection = \ In order to add this series to your collection you should register or pass authentication. t_add_image = Add image t_add_image_error = This series has enough images. Please, contact with admin if you want to add more images -t_who_selling_series = Who was selling/buying this series: +t_who_selling_series = Who was selling/buying this series t_was_selling_for = was selling for t_sold_to = sold to t_sold_for = for diff --git a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties index 6d933b12ab..c2b5888ca5 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties @@ -139,7 +139,7 @@ t_need_authentication_to_add_series_to_collection = \ Для того, чтобы добавить эту серию в свою коллекцию вы должны зарегистрироваться или пройти идентификацию. t_add_image = Добавить изображение t_add_image_error = Эта серия содержит все необходимые изображения. Пожалуйста, свяжитесь с администратором, если вы хотите добавить больше изображений -t_who_selling_series = Покупки и продажи этой серии: +t_who_selling_series = Покупки и продажи этой серии t_was_selling_for = продавал за t_sold_to = продал t_sold_for = за diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 25d92df8a1..b2ba40274f 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -274,7 +274,7 @@
    -
    Who was selling/buying this series:
    +
    Who was selling/buying this series:
    • -
      +
      Who was selling/buying this series:
        From 6dee2022b88d217f23ee51e121229e97c5beb33b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 21 Oct 2016 18:06:11 +0200 Subject: [PATCH 112/463] Check not only user's permissions but also whether feature is active or not. Should be in c5e733b6e06fd5f73fb59f85754479c8f52ffba3 commit. No functional changes. --- .../java/ru/mystamps/web/controller/SeriesController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 3c8ec66aa3..ae40b837f5 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -69,6 +69,7 @@ import ru.mystamps.web.support.spring.security.Authority; import ru.mystamps.web.support.spring.security.CustomUserDetails; import ru.mystamps.web.support.spring.security.SecurityContextUtils; +import ru.mystamps.web.support.togglz.Features; import ru.mystamps.web.util.CatalogUtils; import ru.mystamps.web.util.LocaleUtils; @@ -374,7 +375,9 @@ public String searchSeriesByCatalog( model.put("isSeriesInCollection", isSeriesInCollection); model.put("allowAddingImages", userCanAddImagesToSeries); - if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) { + if (Features.SHOW_PURCHASES_AND_SALES.isActive() + && SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) { + List purchasesAndSales = seriesService.findPurchasesAndSales(series.getId()); model.put("purchasesAndSales", purchasesAndSales); From 34e369b8a31ba76e3475e927c6c3b0d685870321 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 19 Oct 2016 23:52:09 +0200 Subject: [PATCH 113/463] series/info: move block with series in collection info to the top. No functional changes. --- .../webapp/WEB-INF/views/series/info.html | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 91428c2654..4a6c045646 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -272,6 +272,42 @@
      + +
      +
      +
      +

      + Series isn't part of your collection +

      +

      + + +

      +
      +
      + + +
      +
      Who was selling/buying this series:
      @@ -315,41 +351,6 @@
      Who was selling/buying this series:
      -
      -
      -
      -

      - Series isn't part of your collection -

      -

      - - -

      -
      -
      - - -
      -
      From be5139515d436490d4a7a52c1b0277f7acb43efd Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 4 Nov 2016 17:32:08 +0100 Subject: [PATCH 114/463] .travis.yml: clone repository with a depth of 1 commit. No functional changes. --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 14989e98aa..fc508ccfa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,3 +54,8 @@ notifications: # We don't want to run `mvn install -DskipTests=true` for downloading project's dependencies install: true + +# Clone repository with a depth of 1 commit. +# https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth +git: + depth: 1 # default: 50 From e9985985ac1663406ac0abb2ac3a1a95175b5cd1 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 12:09:42 +0100 Subject: [PATCH 115/463] pom.xml: update Spring Boot to 1.4.2.RELEASE. This also updates Spring Framework to 4.3.4.RELEASE. See also: - https://spring.io/blog/2016/11/08/spring-boot-1-4-2-available-now - https://github.com/spring-projects/spring-boot/milestone/73?closed=1 - https://spring.io/blog/2016/11/08/spring-framework-4-3-4-available-now - https://jira.spring.io/jira/secure/ReleaseNote.jspa?projectId=10000&version=15722 No functional changes. --- pom.xml | 60 +++++++++++------------ src/main/resources/application.properties | 2 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index e4ff721dc8..666c6f68a5 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ ${slf4j.version} - + org.springframework.boot spring-boot-starter @@ -52,7 +52,7 @@ - + org.springframework.boot spring-boot-starter-jdbc @@ -64,7 +64,7 @@ - + org.springframework.boot spring-boot-starter-jetty @@ -84,25 +84,25 @@ - + org.springframework.boot spring-boot-starter-logging - + org.springframework.boot spring-boot-starter-mail - + org.springframework.boot spring-boot-starter-security - + org.springframework.boot spring-boot-starter-thymeleaf @@ -114,7 +114,7 @@ - + org.springframework.boot spring-boot-starter-web @@ -320,7 +320,7 @@ org.springframework.boot @@ -352,10 +352,10 @@ - + org.springframework.boot spring-boot-starter-parent - 1.4.1.RELEASE + 1.4.2.RELEASE @@ -368,10 +368,10 @@ 0.22-1 0.25.2 - + 1.4 - + 1.5.4 3.4 @@ -385,32 +385,32 @@ 1.4 1.5 - + 2.0.8 - + 1.4.192 - + 5.2.4.Final - + 2.21 0.7.7.201606060606 2.2 - + 1.8 2.10.4 - + 1.5.4 1.1.0.Final - + 9.2.18.v20160721 @@ -418,15 +418,15 @@ 1.9.0 - + 3.5.1 - + 1.16.10 1.7.4 - + 5.1.39 1.0-beta-1 @@ -436,35 +436,35 @@ 0.12.3 - + 2.53.1 - + 3.1.0 false - + 1.7.21 2.5.0 - + 1.0-groovy-2.0 - + ru.mystamps.web.support.spring.boot.ApplicationBootstrap 3.1.7 2.19.1 6.8.8 - + 3.0.0.RELEASE 2.0.0-SNAPSHOT - + 3.0.2.RELEASE 2.3.0.Final diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 174d549c79..c4201b1aab 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -15,7 +15,7 @@ spring.mvc.favicon.enabled: false spring.cache.type: none -# See for details: http://docs.spring.io/autorepo/docs/spring-boot/1.4.1.RELEASE/api/org/springframework/boot/autoconfigure/web/MultipartProperties.html +# See for details: http://docs.spring.io/autorepo/docs/spring-boot/1.4.2.RELEASE/api/org/springframework/boot/autoconfigure/web/MultipartProperties.html spring.http.multipart.location: /tmp spring.http.multipart.max-request-size: 10Mb spring.http.multipart.max-file-size: 5Mb From cb7ccf4622affa309910b03cc798c2370f5d13ff Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 12:35:34 +0100 Subject: [PATCH 116/463] pom.xml: update H2 to 1.4.193 See http://www.h2database.com/html/changelog.html No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 666c6f68a5..d60b7c8266 100644 --- a/pom.xml +++ b/pom.xml @@ -389,7 +389,7 @@ 2.0.8 - 1.4.192 + 1.4.193 5.2.4.Final From 9f816720027bf6a6647c55e1ceb29fdc5a544a39 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 12:56:04 +0100 Subject: [PATCH 117/463] pom.xml: remove exclusion of commons-logging. Spring Boot 1.4.2 already did it for us. See Spring Boot GH 7067 No functional changes. --- pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pom.xml b/pom.xml index d60b7c8266..794b1bc0f8 100644 --- a/pom.xml +++ b/pom.xml @@ -283,13 +283,6 @@ htmlunit-driver ${htmlunit.version} test - - - - commons-logging - commons-logging - - From f7141f91355265dcd698c8ac7e65381c0add83de Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 15:15:05 +0100 Subject: [PATCH 118/463] pom.xml: update Liquibase to 3.5.3 See: - http://www.liquibase.org/2016/09/liquibase-3-5-2-released.html - http://www.liquibase.org/2016/10/liquibase-3-5-3-released.html No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 794b1bc0f8..d71c4c02e7 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ 1.9.0 - 3.5.1 + 3.5.3 1.16.10 From 5e3d395a7485188b424e897c1e09e858d81f5418 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 15:23:59 +0100 Subject: [PATCH 119/463] pom.xml(mysql-connector-java): update to 5.1.40 See http://dev.mysql.com/doc/relnotes/connector-j/5.1/en/news-5-1-40.html No functional changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d71c4c02e7..ed7c8f2d7c 100644 --- a/pom.xml +++ b/pom.xml @@ -420,7 +420,7 @@ 1.7.4 - 5.1.39 + 5.1.40 1.0-beta-1 3.6 From d4ed74ded0cda96abb98507a32d2efd3b1956512 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 15:46:40 +0100 Subject: [PATCH 120/463] pom.xml(maven-compiler-plugin): update to 3.6.0 See https://mail-archives.apache.org/mod_mbox/maven-announce/201610.mbox/%3Cop.yp5p3mm2kdkhrr%40desktop-2khsk44.dynamic.ziggo.nl%3E Also activate new failOnWarning option. No functional changes. --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ed7c8f2d7c..99b55464c2 100644 --- a/pom.xml +++ b/pom.xml @@ -368,7 +368,7 @@ 1.5.4 3.4 - 3.5.1 + 3.6.0 2.2.0 1.4.1 2.19.1 @@ -630,6 +630,7 @@ true true false + true From 1d2a7f2eaec3ab892f45ea1ee0d0301195ba2592 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 9 Nov 2016 15:53:22 +0100 Subject: [PATCH 121/463] pom.xml(maven-resources-plugin): update to 3.0.1 See: - http://osdir.com/ml/announce.maven.apache.org/2016-05/msg00003.html - http://osdir.com/ml/announce.maven.apache.org/2016-06/msg00003.html Also disable resources processing when we're running unit test, they don't use resources and executing this plugin were useless. No functional changes. --- pom.xml | 2 +- src/main/scripts/ci/check-build-and-verify.sh | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 99b55464c2..023b9fb66b 100644 --- a/pom.xml +++ b/pom.xml @@ -424,7 +424,7 @@ 1.0-beta-1 3.6 - 2.7 + 3.0.1 0.12.3 diff --git a/src/main/scripts/ci/check-build-and-verify.sh b/src/main/scripts/ci/check-build-and-verify.sh index 2579dbe212..b1dd7bc253 100755 --- a/src/main/scripts/ci/check-build-and-verify.sh +++ b/src/main/scripts/ci/check-build-and-verify.sh @@ -41,7 +41,11 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then 'An "img" element must have an "alt" attribute' \ --show-warnings \ >validator.log 2>&1 || HTML_FAIL=yes - mvn --batch-mode test -Denforcer.skip=true -DskipMinify=true >test.log 2>&1 || TEST_FAIL=yes + mvn --batch-mode test \ + -Denforcer.skip=true \ + -Dmaven.resources.skip=true \ + -DskipMinify=true \ + >test.log 2>&1 || TEST_FAIL=yes # run after tests for getting compiled sources mvn --batch-mode findbugs:check >findbugs.log 2>&1 || FINDBUGS_FAIL=yes fi From b3be19453ff0889fba9bef815f8ce8f0b040e87b Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 12 Nov 2016 15:29:00 +0100 Subject: [PATCH 122/463] pom.xml: use release version of thymeleaf-extras-togglz. Follow-up to 976c4373913965b2ef4cb1f134b2148e6d5f8f44 commit. No functional changes. --- pom.xml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 023b9fb66b..2255d91768 100644 --- a/pom.xml +++ b/pom.xml @@ -455,7 +455,7 @@ 3.0.0.RELEASE - 2.0.0-SNAPSHOT + 2.0.0.RELEASE 3.0.2.RELEASE @@ -935,19 +935,4 @@ 3.2.1 - - - - false - - - true - fail - - oss-sonatype - oss-sonatype - https://oss.sonatype.org/content/repositories/snapshots/ - - - From d639da6689ea40c157aabf2d57b8a78485181fe9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 12 Nov 2016 12:42:02 +0100 Subject: [PATCH 123/463] Fix markup in prototype to look the same as real page. No functional changes. --- .../WEB-INF/views/account/activate.html | 10 ++++++ .../WEB-INF/views/account/register.html | 2 ++ .../webapp/WEB-INF/views/category/add.html | 4 +++ .../webapp/WEB-INF/views/country/add.html | 4 +++ src/main/webapp/WEB-INF/views/series/add.html | 34 ++++++++++++++----- .../webapp/WEB-INF/views/series/info.html | 2 ++ 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/account/activate.html b/src/main/webapp/WEB-INF/views/account/activate.html index 309503161b..0f96ff0cf2 100644 --- a/src/main/webapp/WEB-INF/views/account/activate.html +++ b/src/main/webapp/WEB-INF/views/account/activate.html @@ -116,7 +116,9 @@

      +

      @@ -126,7 +128,9 @@

      +

      @@ -137,7 +141,9 @@

      +

      @@ -148,7 +154,9 @@

      +

    @@ -159,7 +167,9 @@

    +

    diff --git a/src/main/webapp/WEB-INF/views/account/register.html b/src/main/webapp/WEB-INF/views/account/register.html index 81163d34f0..cae4a52619 100644 --- a/src/main/webapp/WEB-INF/views/account/register.html +++ b/src/main/webapp/WEB-INF/views/account/register.html @@ -119,7 +119,9 @@

    To this address we will send activation code +

    diff --git a/src/main/webapp/WEB-INF/views/category/add.html b/src/main/webapp/WEB-INF/views/category/add.html index d23d2a1b36..396154e290 100644 --- a/src/main/webapp/WEB-INF/views/category/add.html +++ b/src/main/webapp/WEB-INF/views/category/add.html @@ -110,7 +110,9 @@

    +
    @@ -123,7 +125,9 @@

    +
    diff --git a/src/main/webapp/WEB-INF/views/country/add.html b/src/main/webapp/WEB-INF/views/country/add.html index 53fa91900e..e1f904852f 100644 --- a/src/main/webapp/WEB-INF/views/country/add.html +++ b/src/main/webapp/WEB-INF/views/country/add.html @@ -110,7 +110,9 @@

    +
    @@ -123,7 +125,9 @@

    +
    diff --git a/src/main/webapp/WEB-INF/views/series/add.html b/src/main/webapp/WEB-INF/views/series/add.html index 418be84282..e38a5a9aca 100644 --- a/src/main/webapp/WEB-INF/views/series/add.html +++ b/src/main/webapp/WEB-INF/views/series/add.html @@ -143,7 +143,9 @@

    You can also add a new category + @@ -174,7 +176,9 @@

    You can also add a new country + @@ -195,7 +199,9 @@

    min="1" max="50" th:field="*{quantity}" /> + @@ -207,7 +213,9 @@

    +
    @@ -225,15 +233,15 @@

    You will be able to add additional images on the series page + @@ -315,17 +323,17 @@

    + @@ -347,8 +355,10 @@

    + @@ -370,8 +380,10 @@

    + @@ -393,8 +405,10 @@

    + @@ -416,16 +430,16 @@

    + @@ -437,7 +451,9 @@

    +
    diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 4a6c045646..f02fde71dc 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -111,7 +111,9 @@
    +
    From 707964f74c273af306b1385606ddd486a1c5f70d Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 12 Nov 2016 19:22:23 +0100 Subject: [PATCH 124/463] /series/add: sync help message in prototype and reality. Should be in 27d12040eae17214378a8594b59dfb397723e2a2 commit. No functional changes. --- src/main/webapp/WEB-INF/views/series/add.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/WEB-INF/views/series/add.html b/src/main/webapp/WEB-INF/views/series/add.html index e38a5a9aca..aa469bd265 100644 --- a/src/main/webapp/WEB-INF/views/series/add.html +++ b/src/main/webapp/WEB-INF/views/series/add.html @@ -230,7 +230,7 @@

    - You will be able to add additional images on the series page + Later you will be able to add additional images + + + diff --git a/src/main/config/findbugs-filter.xml b/src/main/config/findbugs-filter.xml index 8d3ed998a8..ccfab53f98 100644 --- a/src/main/config/findbugs-filter.xml +++ b/src/main/config/findbugs-filter.xml @@ -8,6 +8,15 @@ + + + + + +

    + + +
    + +
    + + +
    +
    + +
    + +
    + + +
    +
    + +
    + +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    + +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    + +
    + + +
    +
    + +
    +
    + +
    +
    + +
    + + + diff --git a/src/test/groovy/ru/mystamps/web/service/TransactionParticipantServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/TransactionParticipantServiceImplTest.groovy new file mode 100644 index 0000000000..53ee70f2e1 --- /dev/null +++ b/src/test/groovy/ru/mystamps/web/service/TransactionParticipantServiceImplTest.groovy @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2009-2016 Slava Semushin + * + * 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 spock.lang.Specification + +import ru.mystamps.web.dao.TransactionParticipantDao +import ru.mystamps.web.dao.dto.EntityWithIdDto + +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) +class TransactionParticipantServiceImplTest extends Specification { + + private final TransactionParticipantDao transactionParticipantDao = Mock() + private final TransactionParticipantService service = + new TransactionParticipantServiceImpl(transactionParticipantDao) + + // + // Tests for findAllBuyers() + // + + def "findAllBuyers() should call dao and return result"() { + given: + List expectedResult = [ TestObjects.createEntityWithIdDto() ] + when: + List result = service.findAllBuyers() + then: + 1 * transactionParticipantDao.findAllAsEntityWithIdDto() >> expectedResult + and: + result == expectedResult + } + + // + // Tests for findAllSellers() + // + + def "findAllSellers() should call dao and return result"() { + given: + List expectedResult = [ TestObjects.createEntityWithIdDto() ] + when: + List result = service.findAllSellers() + then: + 1 * transactionParticipantDao.findAllAsEntityWithIdDto() >> expectedResult + and: + result == expectedResult + } + +} diff --git a/src/test/java/ru/mystamps/web/service/TestObjects.java b/src/test/java/ru/mystamps/web/service/TestObjects.java index 151f7853d9..2340178efb 100644 --- a/src/test/java/ru/mystamps/web/service/TestObjects.java +++ b/src/test/java/ru/mystamps/web/service/TestObjects.java @@ -20,19 +20,8 @@ import java.math.BigDecimal; import java.util.Date; -import ru.mystamps.web.dao.dto.AddUserDbDto; -import ru.mystamps.web.dao.dto.CollectionInfoDto; -import ru.mystamps.web.dao.dto.Currency; -import ru.mystamps.web.dao.dto.DbImageDto; -import ru.mystamps.web.dao.dto.ImageInfoDto; -import ru.mystamps.web.dao.dto.LinkEntityDto; -import ru.mystamps.web.dao.dto.PurchaseAndSaleDto; -import ru.mystamps.web.dao.dto.SeriesInfoDto; -import ru.mystamps.web.dao.dto.SitemapInfoDto; -import ru.mystamps.web.dao.dto.SuspiciousActivityDto; -import ru.mystamps.web.dao.dto.UserDetails; -import ru.mystamps.web.dao.dto.UsersActivationDto; -import ru.mystamps.web.dao.dto.UsersActivationFullDto; +// CheckStyle: ignore AvoidStarImportCheck for next 1 line +import ru.mystamps.web.dao.dto.*; final class TestObjects { public static final String TEST_ACTIVITY_TYPE = "EventType"; @@ -169,4 +158,8 @@ public static PurchaseAndSaleDto createPurchaseAndSaleDto() { ); } + public static EntityWithIdDto createEntityWithIdDto() { + return new EntityWithIdDto(TEST_ENTITY_ID, TEST_ENTITY_NAME); + } + } From b8e77785b8ff3628af0ca0bba85f15a7cf96d7ca Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 19 Nov 2016 13:48:55 +0100 Subject: [PATCH 127/463] SeriesController.addImageFormToModel(): extract method. No functional changes. --- .../mystamps/web/controller/SeriesController.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index ef396f6fae..bb91e6a709 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -215,9 +215,7 @@ public String showInfo( model.addAllAttributes(commonAttrs); addSeriesSalesFormToModel(model); - - AddImageForm form = new AddImageForm(); - model.addAttribute("addImageForm", form); + addImageFormToModel(model); model.addAttribute("maxQuantityOfImagesExceeded", false); @@ -350,14 +348,12 @@ public String processAskForm( boolean maxQuantityOfImagesExceeded = !isAdmin() && !isAllowedToAddingImages(series); model.addAttribute("maxQuantityOfImagesExceeded", maxQuantityOfImagesExceeded); - AddImageForm addImageForm = new AddImageForm(); - model.addAttribute("addImageForm", addImageForm); - if (result.hasErrors() || maxQuantityOfImagesExceeded) { Map commonAttrs = prepareCommonAttrsForSeriesInfo(series, currentUserId); model.addAllAttributes(commonAttrs); addSeriesSalesFormToModel(model); + addImageFormToModel(model); return "series/info"; } @@ -459,6 +455,11 @@ private void addSeriesSalesFormToModel(Model model) { model.addAttribute("buyers", buyers); } + private static void addImageFormToModel(Model model) { + AddImageForm form = new AddImageForm(); + model.addAttribute("addImageForm", form); + } + private static boolean isAllowedToAddingImages(SeriesDto series) { return series.getImageIds().size() <= series.getQuantity(); } From 98aa9825d36c4ff7657582a82edaf129bd1c662c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 20 Nov 2016 13:11:13 +0100 Subject: [PATCH 128/463] Features: mention page in description and group by page. No functional changes. --- .../mystamps/web/support/togglz/Features.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/ru/mystamps/web/support/togglz/Features.java b/src/main/java/ru/mystamps/web/support/togglz/Features.java index a4ea7d3241..417b09937f 100644 --- a/src/main/java/ru/mystamps/web/support/togglz/Features.java +++ b/src/main/java/ru/mystamps/web/support/togglz/Features.java @@ -24,57 +24,57 @@ public enum Features implements Feature { - @Label("Send mail with activation key to user") - @EnabledByDefault - SEND_ACTIVATION_MAIL, - - @Label("Show list of recently added series on index page") + @Label("/site/index: show list of recently added series") @EnabledByDefault SHOW_RECENT_SERIES_ON_INDEX_PAGE, - @Label("Show list of recently created collections on index page") + @Label("/site/index: show list of recently created collections") @EnabledByDefault SHOW_RECENT_COLLECTIONS_ON_INDEX_PAGE, - @Label("Show search panel on index page") + @Label("/site/index: show search panel") @EnabledByDefault SHOW_SEARCH_PANEL_ON_INDEX_PAGE, - @Label("View site events") - @EnabledByDefault - VIEW_SITE_EVENTS, - - @Label("Show statistics of collection on collection page") + @Label("/site/index: show link to list of categories") @EnabledByDefault - SHOW_COLLECTION_STATISTICS, + LIST_CATEGORIES, - @Label("Show charts on collection page") + @Label("/site/index: show link to list of countries") @EnabledByDefault - SHOW_COLLECTION_CHARTS, + LIST_COUNTRIES, - @Label("Possibility to user to add series to collection") + @Label("/series/{id}: possibility to user to add series to collection") @EnabledByDefault ADD_SERIES_TO_COLLECTION, - @Label("Possibility of user to add additional images to series") + @Label("/series/{id}: possibility of user to add additional images to series") @EnabledByDefault ADD_ADDITIONAL_IMAGES_TO_SERIES, - @Label("Show link to list of categories on index page") + @Label("/series/{id}: show series purchases and sales") @EnabledByDefault - LIST_CATEGORIES, + SHOW_PURCHASES_AND_SALES, - @Label("Show link to list of countries on index page") + @Label("/series/{id}: possibility of user to add series purchases and sales") @EnabledByDefault - LIST_COUNTRIES, + ADD_PURCHASES_AND_SALES, - @Label("Show series purchases and sales on series info page") + @Label("/collection/{slug}: show statistics of collection") @EnabledByDefault - SHOW_PURCHASES_AND_SALES, + SHOW_COLLECTION_STATISTICS, - @Label("/series/{id}: possibility of user to add series purchases and sales") + @Label("/collection/{slug}: show charts on collection page") + @EnabledByDefault + SHOW_COLLECTION_CHARTS, + + @Label("Send mail with activation key to user") + @EnabledByDefault + SEND_ACTIVATION_MAIL, + + @Label("View site events") @EnabledByDefault - ADD_PURCHASES_AND_SALES; + VIEW_SITE_EVENTS; public boolean isActive() { return FeatureContext.getFeatureManager().isActive(this); From 699e1478b5c563c8076ee146bbbca3d9b4d0902c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 20 Nov 2016 13:33:03 +0100 Subject: [PATCH 129/463] Ignore warnings from htmlvalidator about empty option. WARNING:html5validator.validator:"file:src/main/webapp/WEB-INF/views/series/info.html":428.16-428.35: error: The first child "option" element of a "select" element with a "required" attribute, and without a "multiple" attribute, and without a "size" attribute whose value is greater than "1", must have either an empty "value" attribute, or must have no text content. Consider either adding a placeholder option label, or adding a "size" attribute with a value equal to the number of "option" elements. When I'm adding empty option then there is no way to set a default value. In Safari and Firefox "selected" attribute doesn't work. Should be in fe9f30daefe5ce0f76cd817c433062600676c404 commit. No functional changes. --- src/main/scripts/ci/check-build-and-verify.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/scripts/ci/check-build-and-verify.sh b/src/main/scripts/ci/check-build-and-verify.sh index b1dd7bc253..ea7095cd64 100755 --- a/src/main/scripts/ci/check-build-and-verify.sh +++ b/src/main/scripts/ci/check-build-and-verify.sh @@ -39,6 +39,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then 'Attribute “(th|sec|togglz):[a-z]+” is not serializable' \ 'Attribute with the local name “xmlns:[a-z]+” is not serializable' \ 'An "img" element must have an "alt" attribute' \ + 'The first child "option" element of a "select" element with a "required" attribute' \ --show-warnings \ >validator.log 2>&1 || HTML_FAIL=yes mvn --batch-mode test \ From 901a2b76545bc68564a0e91ab71ae0abe136adca Mon Sep 17 00:00:00 2001 From: John Shkarin Date: Sun, 27 Nov 2016 23:26:33 +0500 Subject: [PATCH 130/463] transaction_participants: name and url should be unique. Fix #476 --- src/main/resources/liquibase/version/0.4.xml | 1 + ...unique-key-transaction_participants-table.xml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/main/resources/liquibase/version/0.4/2016-11-29--add-unique-key-transaction_participants-table.xml diff --git a/src/main/resources/liquibase/version/0.4.xml b/src/main/resources/liquibase/version/0.4.xml index 6b563e3d10..91b073cc4b 100644 --- a/src/main/resources/liquibase/version/0.4.xml +++ b/src/main/resources/liquibase/version/0.4.xml @@ -21,5 +21,6 @@ + diff --git a/src/main/resources/liquibase/version/0.4/2016-11-29--add-unique-key-transaction_participants-table.xml b/src/main/resources/liquibase/version/0.4/2016-11-29--add-unique-key-transaction_participants-table.xml new file mode 100644 index 0000000000..58baed3dd3 --- /dev/null +++ b/src/main/resources/liquibase/version/0.4/2016-11-29--add-unique-key-transaction_participants-table.xml @@ -0,0 +1,16 @@ + + + + + + + + + From 09443f985988224317833b1b2295c96c057c9f86 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 4 Dec 2016 15:47:55 +0100 Subject: [PATCH 131/463] AddCountryForm: put different checks to different groups. Should be in 5a125e17fd095a5316757921423969f0ed653ec4 commit. No functional changes. --- src/main/java/ru/mystamps/web/model/AddCountryForm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/mystamps/web/model/AddCountryForm.java b/src/main/java/ru/mystamps/web/model/AddCountryForm.java index 077c1a093b..470b5ac99b 100644 --- a/src/main/java/ru/mystamps/web/model/AddCountryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCountryForm.java @@ -116,7 +116,7 @@ public class AddCountryForm implements AddCountryDto { groups = Group.Level5.class ) }) - @UniqueCountryName(lang = Lang.RU, groups = Group.Level5.class) + @UniqueCountryName(lang = Lang.RU, groups = Group.Level6.class) private String nameRu; } From f1bb2368f3014cf4a16ccbbaa76718bc29f40949 Mon Sep 17 00:00:00 2001 From: Aleksandr Zorin Date: Fri, 7 Oct 2016 01:13:19 +0300 Subject: [PATCH 132/463] Daily report: include overal counter to the subject. --- .../mystamps/web/service/MailServiceImpl.java | 19 +++++++++++++++++-- .../ru/mystamps/i18n/MailTemplates.properties | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java index ce4628d442..b3b1109daa 100644 --- a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java @@ -17,7 +17,6 @@ */ package ru.mystamps.web.service; -import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -171,11 +170,27 @@ public String getSubjectOfDailyStatisticsMail(AdminDailyReport report) { String template = messageSource.getMessage("daily_stat.subject", null, adminLang); String fromDate = shortDatePrinter.format(report.getStartDate()); - Map ctx = Collections.singletonMap("date", fromDate); + Map ctx = new HashMap<>(); + ctx.put("date", fromDate); + ctx.put("total_changes", calculateTotalChanges(report)); StrSubstitutor substitutor = new StrSubstitutor(ctx); return substitutor.replace(template); } + + private String calculateTotalChanges(AdminDailyReport report) { + long totalChanges = report.getAddedCategoriesCounter(); + totalChanges += report.getAddedCountriesCounter(); + totalChanges += report.getAddedSeriesCounter(); + totalChanges += report.getFailedAuthCounter(); + totalChanges += report.getInvalidCsrfCounter(); + totalChanges += report.getMissingCsrfCounter(); + totalChanges += report.getNotFoundCounter(); + totalChanges += report.getRegisteredUsersCounter(); + totalChanges += report.getRegistrationRequestsCounter(); + totalChanges += report.getUpdatedSeriesCounter(); + return totalChanges == 0 ? "no" : String.valueOf(totalChanges); + } public String getTextOfDailyStatisticsMail(AdminDailyReport report) { String template = messageSource.getMessage("daily_stat.text", null, adminLang); diff --git a/src/main/resources/ru/mystamps/i18n/MailTemplates.properties b/src/main/resources/ru/mystamps/i18n/MailTemplates.properties index ed6dfd42dd..da44f1f023 100644 --- a/src/main/resources/ru/mystamps/i18n/MailTemplates.properties +++ b/src/main/resources/ru/mystamps/i18n/MailTemplates.properties @@ -16,7 +16,7 @@ This letter has been sent by system and you don't need to reply on it.\n\ -- \n\ MyStamps.Ru -daily_stat.subject = [my-stamps.ru] Daily statistics for ${date} +daily_stat.subject = [my-stamps.ru] Daily statistics for ${date} (${total_changes} changes) daily_stat.text = Hello, \n\ \n\ The following updates have been made on site from ${from_date} to ${to_date}:\n\ From 535d87cdb4b2a04a8c859b3ac229117aa764d444 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 6 Dec 2016 23:08:59 +0100 Subject: [PATCH 133/463] Daily report: follow-up improvements. Should be in cb2890b5fba4395ca672dd602d655734609fbad4 commit. --- .../ru/mystamps/web/service/MailServiceImpl.java | 16 +--------------- .../web/service/dto/AdminDailyReport.java | 12 ++++++++++++ .../ru/mystamps/i18n/MailTemplates_ru.properties | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java index b3b1109daa..c0a4ea8a45 100644 --- a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java @@ -172,26 +172,12 @@ public String getSubjectOfDailyStatisticsMail(AdminDailyReport report) { String fromDate = shortDatePrinter.format(report.getStartDate()); Map ctx = new HashMap<>(); ctx.put("date", fromDate); - ctx.put("total_changes", calculateTotalChanges(report)); + put(ctx, "total_changes", report.countTotalChanges()); StrSubstitutor substitutor = new StrSubstitutor(ctx); return substitutor.replace(template); } - private String calculateTotalChanges(AdminDailyReport report) { - long totalChanges = report.getAddedCategoriesCounter(); - totalChanges += report.getAddedCountriesCounter(); - totalChanges += report.getAddedSeriesCounter(); - totalChanges += report.getFailedAuthCounter(); - totalChanges += report.getInvalidCsrfCounter(); - totalChanges += report.getMissingCsrfCounter(); - totalChanges += report.getNotFoundCounter(); - totalChanges += report.getRegisteredUsersCounter(); - totalChanges += report.getRegistrationRequestsCounter(); - totalChanges += report.getUpdatedSeriesCounter(); - return totalChanges == 0 ? "no" : String.valueOf(totalChanges); - } - public String getTextOfDailyStatisticsMail(AdminDailyReport report) { String template = messageSource.getMessage("daily_stat.text", null, adminLang); String fromDate = shortDatePrinter.format(report.getStartDate()); diff --git a/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java b/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java index 5186b0bdb5..06dd8e457a 100644 --- a/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java +++ b/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java @@ -47,4 +47,16 @@ public long countEvents() { return eventsCounter; } + public long countTotalChanges() { + long totalChanges = 0L; + totalChanges = Math.addExact(totalChanges, addedCategoriesCounter); + totalChanges = Math.addExact(totalChanges, addedCountriesCounter); + totalChanges = Math.addExact(totalChanges, addedSeriesCounter); + totalChanges = Math.addExact(totalChanges, updatedSeriesCounter); + totalChanges = Math.addExact(totalChanges, registrationRequestsCounter); + totalChanges = Math.addExact(totalChanges, registeredUsersCounter); + totalChanges = Math.addExact(totalChanges, countEvents()); + return totalChanges; + } + } diff --git a/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties b/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties index 7c686112ce..ab4284cfc1 100644 --- a/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties @@ -16,7 +16,7 @@ ${site_url}${activation_url_with_key}\n\ -- \n\ MyStamps.Ru -daily_stat.subject = [my-stamps.ru] Ежедневная статистика за ${date} +daily_stat.subject = [my-stamps.ru] Ежедневная статистика за ${date} (${total_changes} изменений) daily_stat.text = Здравствуйте, \n\ \n\ Изменения на сайте с ${from_date} по ${to_date}:\n\ From 2edbac34be08f057bf25450bf2839046ebaaba65 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 6 Dec 2016 23:19:26 +0100 Subject: [PATCH 134/463] MailServiceImpl: mark 2 methods as private. No functional changes. --- src/main/java/ru/mystamps/web/service/MailServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java index c0a4ea8a45..9d1454e73a 100644 --- a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java @@ -166,7 +166,7 @@ private String getSubjectOfActivationMail(SendUsersActivationDto activation) { return messageSource.getMessage("activation.subject", null, activation.getLocale()); } - public String getSubjectOfDailyStatisticsMail(AdminDailyReport report) { + private String getSubjectOfDailyStatisticsMail(AdminDailyReport report) { String template = messageSource.getMessage("daily_stat.subject", null, adminLang); String fromDate = shortDatePrinter.format(report.getStartDate()); @@ -178,7 +178,7 @@ public String getSubjectOfDailyStatisticsMail(AdminDailyReport report) { return substitutor.replace(template); } - public String getTextOfDailyStatisticsMail(AdminDailyReport report) { + private String getTextOfDailyStatisticsMail(AdminDailyReport report) { String template = messageSource.getMessage("daily_stat.text", null, adminLang); String fromDate = shortDatePrinter.format(report.getStartDate()); String tillDate = shortDatePrinter.format(report.getEndDate()); From 907f8da58cbdbc3ab49153b7e43b6498f067667c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 6 Dec 2016 23:21:46 +0100 Subject: [PATCH 135/463] MailServiceImpl: simplify code and remove a method. No functional changes. --- .../java/ru/mystamps/web/service/MailServiceImpl.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java index 9d1454e73a..46a43b959a 100644 --- a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java @@ -191,7 +191,7 @@ private String getTextOfDailyStatisticsMail(AdminDailyReport report) { put(ctx, "added_categories_cnt", report.getAddedCategoriesCounter()); put(ctx, "added_series_cnt", report.getAddedSeriesCounter()); put(ctx, "updated_series_cnt", report.getUpdatedSeriesCounter()); - put(ctx, "updated_collections_cnt", "-1"); // TODO: #357 + put(ctx, "updated_collections_cnt", -1L); // TODO: #357 put(ctx, "registration_requests_cnt", report.getRegistrationRequestsCounter()); put(ctx, "registered_users_cnt", report.getRegisteredUsersCounter()); put(ctx, "events_cnt", report.countEvents()); @@ -199,15 +199,11 @@ private String getTextOfDailyStatisticsMail(AdminDailyReport report) { 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", "-1"); // TODO: #122 + put(ctx, "bad_request_cnt", -1L); // TODO: #122 return new StrSubstitutor(ctx).replace(template); } - private static void put(Map ctx, String key, String value) { - ctx.put(key, value); - } - private static void put(Map ctx, String key, long value) { ctx.put(key, String.valueOf(value)); } From 80c532ca9aaee965ef3d508c002cf2955b6aeb33 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 5 Dec 2016 00:40:50 +0100 Subject: [PATCH 136/463] Name of category/country in Russian now are optional fields. Fix #363 --- NEWS.txt | 1 + .../editor/ReplaceRepeatingSpacesEditor.java | 11 ++++-- .../java/ru/mystamps/web/dao/CategoryDao.java | 1 + .../java/ru/mystamps/web/dao/CountryDao.java | 1 + .../web/dao/impl/JdbcCategoryDao.java | 12 ++++++ .../mystamps/web/dao/impl/JdbcCountryDao.java | 12 ++++++ .../mystamps/web/model/AddCategoryForm.java | 1 - .../ru/mystamps/web/model/AddCountryForm.java | 1 - .../mystamps/web/service/CategoryService.java | 1 + .../web/service/CategoryServiceImpl.java | 9 ++++- .../mystamps/web/service/CountryService.java | 1 + .../web/service/CountryServiceImpl.java | 9 ++++- .../mystamps/web/service/CronServiceImpl.java | 7 ++++ .../mystamps/web/service/MailServiceImpl.java | 2 + .../web/service/dto/AdminDailyReport.java | 4 ++ src/main/resources/liquibase/version/0.4.xml | 1 + .../0.4/2016-12-05--make_name_ru_optional.xml | 23 ++++++++++++ .../ru/mystamps/i18n/MailTemplates.properties | 2 + .../mystamps/i18n/MailTemplates_ru.properties | 2 + .../sql/category_dao_queries.properties | 16 +++++--- .../sql/country_dao_queries.properties | 16 +++++--- .../sql/series_dao_queries.properties | 24 ++++++------ .../webapp/WEB-INF/views/category/add.html | 3 +- .../webapp/WEB-INF/views/country/add.html | 3 +- .../service/CategoryServiceImplTest.groovy | 37 ++++++++++++++----- .../web/service/CountryServiceImplTest.groovy | 37 ++++++++++++++----- .../web/service/CronServiceImplTest.groovy | 12 ++++++ .../web/tests/cases/WhenAdminAddCategory.java | 17 ++++++--- .../web/tests/cases/WhenAdminAddCountry.java | 17 ++++++--- .../web/tests/page/AddCategoryPage.java | 3 +- .../web/tests/page/AddCountryPage.java | 3 +- 31 files changed, 223 insertions(+), 66 deletions(-) create mode 100644 src/main/resources/liquibase/version/0.4/2016-12-05--make_name_ru_optional.xml diff --git a/NEWS.txt b/NEWS.txt index e13e56662d..34c3da4e80 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -12,6 +12,7 @@ - (infrastructure) use logback (instead of log4j) for logging - (functionality) add possibility for adding series sales - (functionality) add interface for viewing series sales (contributed by Sergey Chechenev) +- (functionality) name of category/country in Russian now are optional fields 0.3 - (functionality) implemented possibility to user to add series to his collection diff --git a/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java b/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java index 2d450e6ca5..5b6ff57a07 100644 --- a/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java +++ b/src/main/java/ru/mystamps/web/controller/editor/ReplaceRepeatingSpacesEditor.java @@ -24,24 +24,27 @@ /** * @author Maxim Shestakov + * @author Slava Semushin */ @RequiredArgsConstructor public class ReplaceRepeatingSpacesEditor extends PropertyEditorSupport { private static final Pattern REPEATING_SPACES = Pattern.compile("[ ]{2,}"); - private final boolean performTrimming; + private final boolean emptyAsNull; @Override public void setAsText(String name) throws IllegalArgumentException { String text = name; - if (performTrimming) { - text = name.trim(); - } + text = name.trim(); if (text.contains(" ")) { text = REPEATING_SPACES.matcher(text).replaceAll(" "); } + if (emptyAsNull && "".equals(text)) { // NOPMD: AvoidLiteralsInIfCondition (it's ok for me) + text = null; // NOPMD: NullAssignment (we need it) + } + setValue(text); } diff --git a/src/main/java/ru/mystamps/web/dao/CategoryDao.java b/src/main/java/ru/mystamps/web/dao/CategoryDao.java index d4439f81af..f61c4a8187 100644 --- a/src/main/java/ru/mystamps/web/dao/CategoryDao.java +++ b/src/main/java/ru/mystamps/web/dao/CategoryDao.java @@ -31,6 +31,7 @@ public interface CategoryDao { long countByNameRu(String name); long countCategoriesOfCollection(Integer collectionId); long countAddedSince(Date date); + long countUntranslatedNamesSince(Date date); List getStatisticsOf(Integer collectionId, String lang); List findAllAsLinkEntities(String lang); LinkEntityDto findOneAsLinkEntity(String slug, String lang); diff --git a/src/main/java/ru/mystamps/web/dao/CountryDao.java b/src/main/java/ru/mystamps/web/dao/CountryDao.java index 8edf9836f5..afce09503f 100644 --- a/src/main/java/ru/mystamps/web/dao/CountryDao.java +++ b/src/main/java/ru/mystamps/web/dao/CountryDao.java @@ -31,6 +31,7 @@ public interface CountryDao { long countByNameRu(String name); long countCountriesOfCollection(Integer collectionId); long countAddedSince(Date date); + long countUntranslatedNamesSince(Date date); List getStatisticsOf(Integer collectionId, String lang); List findAllAsLinkEntities(String lang); LinkEntityDto findOneAsLinkEntity(String slug, String lang); diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java index 407d4641bc..72b31e10c8 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCategoryDao.java @@ -65,6 +65,9 @@ public class JdbcCategoryDao implements CategoryDao { @Value("${category.count_categories_added_since}") private String countCategoriesAddedSinceSql; + @Value("${category.count_untranslated_names_since}") + private String countUntranslatedNamesSinceSql; + @Value("${category.count_stamps_by_categories}") private String countStampsByCategoriesSql; @@ -156,6 +159,15 @@ public long countAddedSince(Date date) { ); } + @Override + public long countUntranslatedNamesSince(Date date) { + return jdbcTemplate.queryForObject( + countUntranslatedNamesSinceSql, + Collections.singletonMap("date", date), + Long.class + ); + } + @Override public List getStatisticsOf(Integer collectionId, String lang) { Map params = new HashMap<>(); diff --git a/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java b/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java index ed585b18fb..fdfd68033e 100644 --- a/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java +++ b/src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java @@ -65,6 +65,9 @@ public class JdbcCountryDao implements CountryDao { @Value("${country.count_countries_added_since}") private String countCountriesAddedSinceSql; + @Value("${country.count_untranslated_names_since}") + private String countUntranslatedNamesSinceSql; + @Value("${country.count_stamps_by_countries}") private String countStampsByCountriesSql; @@ -156,6 +159,15 @@ public long countAddedSince(Date date) { ); } + @Override + public long countUntranslatedNamesSince(Date date) { + return jdbcTemplate.queryForObject( + countUntranslatedNamesSinceSql, + Collections.singletonMap("date", date), + Long.class + ); + } + @Override public List getStatisticsOf(Integer collectionId, String lang) { Map params = new HashMap<>(); diff --git a/src/main/java/ru/mystamps/web/model/AddCategoryForm.java b/src/main/java/ru/mystamps/web/model/AddCategoryForm.java index b704d03d47..e1d034ad95 100644 --- a/src/main/java/ru/mystamps/web/model/AddCategoryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCategoryForm.java @@ -86,7 +86,6 @@ public class AddCategoryForm implements AddCategoryDto { @UniqueCategorySlug(groups = Group.Level7.class) private String name; - @NotEmpty(groups = Group.Level1.class) @Size.List({ @Size( min = CATEGORY_NAME_MIN_LENGTH, diff --git a/src/main/java/ru/mystamps/web/model/AddCountryForm.java b/src/main/java/ru/mystamps/web/model/AddCountryForm.java index 470b5ac99b..ebd6fc1d8c 100644 --- a/src/main/java/ru/mystamps/web/model/AddCountryForm.java +++ b/src/main/java/ru/mystamps/web/model/AddCountryForm.java @@ -86,7 +86,6 @@ public class AddCountryForm implements AddCountryDto { @UniqueCountrySlug(groups = Group.Level7.class) private String name; - @NotEmpty(groups = Group.Level1.class) @Size.List({ @Size( min = COUNTRY_NAME_MIN_LENGTH, diff --git a/src/main/java/ru/mystamps/web/service/CategoryService.java b/src/main/java/ru/mystamps/web/service/CategoryService.java index bc2977b3ca..6279012f6f 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryService.java +++ b/src/main/java/ru/mystamps/web/service/CategoryService.java @@ -33,5 +33,6 @@ public interface CategoryService { long countByName(String name); long countByNameRu(String name); long countAddedSince(Date date); + long countUntranslatedNamesSince(Date date); List getStatisticsOf(Integer collectionId, String lang); } diff --git a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java index e6717da9b0..51eea7d8ff 100644 --- a/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CategoryServiceImpl.java @@ -53,7 +53,6 @@ public class CategoryServiceImpl implements CategoryService { public String add(AddCategoryDto dto, Integer userId) { Validate.isTrue(dto != null, "DTO must be non null"); Validate.isTrue(dto.getName() != null, "Category name in English must be non null"); - Validate.isTrue(dto.getNameRu() != null, "Category name in Russian must be non null"); Validate.isTrue(userId != null, "User id must be non null"); AddCategoryDbDto category = new AddCategoryDbDto(); @@ -147,6 +146,14 @@ public long countAddedSince(Date date) { return categoryDao.countAddedSince(date); } + @Override + @Transactional(readOnly = true) + public long countUntranslatedNamesSince(Date date) { + Validate.isTrue(date != null, "Date must be non null"); + + return categoryDao.countUntranslatedNamesSince(date); + } + @Override @Transactional(readOnly = true) public List getStatisticsOf(Integer collectionId, String lang) { diff --git a/src/main/java/ru/mystamps/web/service/CountryService.java b/src/main/java/ru/mystamps/web/service/CountryService.java index 5423887660..13d43b27ba 100644 --- a/src/main/java/ru/mystamps/web/service/CountryService.java +++ b/src/main/java/ru/mystamps/web/service/CountryService.java @@ -33,5 +33,6 @@ public interface CountryService { long countByName(String name); long countByNameRu(String name); long countAddedSince(Date date); + long countUntranslatedNamesSince(Date date); List getStatisticsOf(Integer collectionId, String lang); } diff --git a/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java b/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java index 85ca8a4df8..679bbd5de3 100644 --- a/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CountryServiceImpl.java @@ -53,7 +53,6 @@ public class CountryServiceImpl implements CountryService { public String add(AddCountryDto dto, Integer userId) { Validate.isTrue(dto != null, "DTO must be non null"); Validate.isTrue(dto.getName() != null, "Country name in English must be non null"); - Validate.isTrue(dto.getNameRu() != null, "Country name in Russian must be non null"); Validate.isTrue(userId != null, "User id must be non null"); AddCountryDbDto country = new AddCountryDbDto(); @@ -148,6 +147,14 @@ public long countAddedSince(Date date) { return countryDao.countAddedSince(date); } + @Override + @Transactional(readOnly = true) + public long countUntranslatedNamesSince(Date date) { + Validate.isTrue(date != null, "Date must be non null"); + + return countryDao.countUntranslatedNamesSince(date); + } + @Override @Transactional(readOnly = true) public List getStatisticsOf(Integer collectionId, String lang) { diff --git a/src/main/java/ru/mystamps/web/service/CronServiceImpl.java b/src/main/java/ru/mystamps/web/service/CronServiceImpl.java index 65399e5e80..2bbd6f3dc8 100644 --- a/src/main/java/ru/mystamps/web/service/CronServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/CronServiceImpl.java @@ -69,6 +69,13 @@ public AdminDailyReport getDailyStatistics() { report.setEndDate(today); report.setAddedCategoriesCounter(categoryService.countAddedSince(yesterday)); report.setAddedCountriesCounter(countryService.countAddedSince(yesterday)); + + long untranslatedCategories = categoryService.countUntranslatedNamesSince(yesterday); + report.setUntranslatedCategoriesCounter(untranslatedCategories); + + long untranslatedCountries = countryService.countUntranslatedNamesSince(yesterday); + report.setUntranslatedCountriesCounter(untranslatedCountries); + report.setAddedSeriesCounter(seriesService.countAddedSince(yesterday)); report.setUpdatedSeriesCounter(seriesService.countUpdatedSince(yesterday)); report.setRegistrationRequestsCounter(usersActivationService.countCreatedSince(yesterday)); diff --git a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java index 46a43b959a..4079cdbf05 100644 --- a/src/main/java/ru/mystamps/web/service/MailServiceImpl.java +++ b/src/main/java/ru/mystamps/web/service/MailServiceImpl.java @@ -188,7 +188,9 @@ private String getTextOfDailyStatisticsMail(AdminDailyReport report) { 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", -1L); // TODO: #357 diff --git a/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java b/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java index 06dd8e457a..fe9cca2115 100644 --- a/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java +++ b/src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java @@ -28,7 +28,9 @@ public class AdminDailyReport { private Date startDate; private Date endDate; private long addedCategoriesCounter; + private long untranslatedCategoriesCounter; private long addedCountriesCounter; + private long untranslatedCountriesCounter; private long addedSeriesCounter; private long updatedSeriesCounter; private long registrationRequestsCounter; @@ -50,7 +52,9 @@ public long countEvents() { public long countTotalChanges() { long totalChanges = 0L; totalChanges = Math.addExact(totalChanges, addedCategoriesCounter); + totalChanges = Math.addExact(totalChanges, untranslatedCategoriesCounter); totalChanges = Math.addExact(totalChanges, addedCountriesCounter); + totalChanges = Math.addExact(totalChanges, untranslatedCountriesCounter); totalChanges = Math.addExact(totalChanges, addedSeriesCounter); totalChanges = Math.addExact(totalChanges, updatedSeriesCounter); totalChanges = Math.addExact(totalChanges, registrationRequestsCounter); diff --git a/src/main/resources/liquibase/version/0.4.xml b/src/main/resources/liquibase/version/0.4.xml index 91b073cc4b..074938b38f 100644 --- a/src/main/resources/liquibase/version/0.4.xml +++ b/src/main/resources/liquibase/version/0.4.xml @@ -22,5 +22,6 @@ + diff --git a/src/main/resources/liquibase/version/0.4/2016-12-05--make_name_ru_optional.xml b/src/main/resources/liquibase/version/0.4/2016-12-05--make_name_ru_optional.xml new file mode 100644 index 0000000000..b4e5b1a8cf --- /dev/null +++ b/src/main/resources/liquibase/version/0.4/2016-12-05--make_name_ru_optional.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/ru/mystamps/i18n/MailTemplates.properties b/src/main/resources/ru/mystamps/i18n/MailTemplates.properties index da44f1f023..760fbcfc52 100644 --- a/src/main/resources/ru/mystamps/i18n/MailTemplates.properties +++ b/src/main/resources/ru/mystamps/i18n/MailTemplates.properties @@ -22,7 +22,9 @@ daily_stat.text = Hello, \n\ The following updates have been made on site from ${from_date} to ${to_date}:\n\ \n\ * ${added_countries_cnt} countries have been added\n\ +* ${untranslated_countries_cnt} countries have untranslated names\n\ * ${added_categories_cnt} categories have been created\n\ +* ${untranslated_categories_cnt} categories have untranslated names\n\ * ${added_series_cnt} series have been added\n\ * ${updated_series_cnt} series have been updated\n\ * ${updated_collections_cnt} collections have been updated\n\ diff --git a/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties b/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties index ab4284cfc1..7be25c4c3d 100644 --- a/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/MailTemplates_ru.properties @@ -22,7 +22,9 @@ daily_stat.text = Здравствуйте, \n\ Изменения на сайте с ${from_date} по ${to_date}:\n\ \n\ * Добавлено ${added_countries_cnt} стран\n\ +* Непереведены названия ${untranslated_countries_cnt} стран\n\ * Создано ${added_categories_cnt} категорий\n\ +* Непереведены названия ${untranslated_categories_cnt} категорий\n\ * Добавлено ${added_series_cnt} серий\n\ * Обновлено ${updated_series_cnt} серий\n\ * Обновлено ${updated_collections_cnt} коллекций\n\ diff --git a/src/main/resources/sql/category_dao_queries.properties b/src/main/resources/sql/category_dao_queries.properties index f9c351a7b4..4e94f91455 100644 --- a/src/main/resources/sql/category_dao_queries.properties +++ b/src/main/resources/sql/category_dao_queries.properties @@ -50,8 +50,14 @@ SELECT COUNT(*) \ FROM categories \ WHERE created_at >= :date +category.count_untranslated_names_since = \ +SELECT COUNT(*) \ + FROM categories \ + WHERE name_ru IS NULL \ + AND (created_at >= :date OR updated_at >= :date) + category.count_stamps_by_categories = \ - SELECT CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END AS name \ + SELECT CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END AS name \ , SUM(s.quantity) AS counter \ FROM collections_series cs \ JOIN series s \ @@ -62,16 +68,16 @@ category.count_stamps_by_categories = \ GROUP BY s.category_id category.find_all_categories_names_with_slug = \ - SELECT CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END AS name \ + SELECT CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END AS name \ , c.slug \ , c.id \ FROM categories c \ -ORDER BY CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END +ORDER BY CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END category.find_category_link_info_by_slug = \ - SELECT CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END AS name \ + SELECT CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END AS name \ , c.slug \ , c.id \ FROM categories c \ WHERE c.slug = :slug \ -ORDER BY CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END +ORDER BY CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END diff --git a/src/main/resources/sql/country_dao_queries.properties b/src/main/resources/sql/country_dao_queries.properties index 46a653ee23..c80cacdf84 100644 --- a/src/main/resources/sql/country_dao_queries.properties +++ b/src/main/resources/sql/country_dao_queries.properties @@ -50,8 +50,14 @@ SELECT COUNT(*) \ FROM countries \ WHERE created_at >= :date +country.count_untranslated_names_since = \ +SELECT COUNT(*) \ + FROM countries \ + WHERE name_ru IS NULL \ + AND (created_at >= :date OR updated_at >= :date) + country.count_stamps_by_countries = \ - SELECT COALESCE(CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END, 'Unknown') AS name \ + SELECT COALESCE(CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END, 'Unknown') AS name \ , SUM(s.quantity) AS counter \ FROM collections_series cs \ JOIN series s \ @@ -62,16 +68,16 @@ LEFT JOIN countries c \ GROUP BY s.country_id country.find_all_countries_names_with_slug = \ - SELECT CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END AS name \ + SELECT CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END AS name \ , c.slug \ , c.id \ FROM countries c \ -ORDER BY CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END +ORDER BY CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END country.find_country_link_info_by_slug = \ - SELECT CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END AS name \ + SELECT CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END AS name \ , c.slug \ , c.id \ FROM countries c \ WHERE c.slug = :slug \ -ORDER BY CASE WHEN 'ru' = :lang THEN c.name_ru ELSE c.name END +ORDER BY CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END diff --git a/src/main/resources/sql/series_dao_queries.properties b/src/main/resources/sql/series_dao_queries.properties index 5c5c382cf1..67259ab666 100644 --- a/src/main/resources/sql/series_dao_queries.properties +++ b/src/main/resources/sql/series_dao_queries.properties @@ -64,10 +64,10 @@ series.find_last_added = \ , s.perforated \ , cat.id AS category_id \ , cat.slug AS category_slug \ - , CASE WHEN 'ru' = :lang THEN cat.name_ru ELSE cat.name END AS category_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \ , count.id AS country_id \ , count.slug AS country_slug \ - , CASE WHEN 'ru' = :lang THEN count.name_ru ELSE count.name END AS country_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \ FROM series s \ JOIN categories cat \ ON cat.id = s.category_id \ @@ -80,10 +80,10 @@ series.find_full_info_by_id = \ SELECT s.id \ , cat.id AS category_id \ , cat.slug AS category_slug \ - , CASE WHEN 'ru' = :lang THEN cat.name_ru ELSE cat.name END AS category_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \ , count.id AS country_id \ , count.slug AS country_slug \ - , CASE WHEN 'ru' = :lang THEN count.name_ru ELSE count.name END AS country_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \ , s.release_day \ , s.release_month \ , s.release_year \ @@ -110,10 +110,10 @@ series.find_by_ids = \ SELECT s.id \ , cat.id AS category_id \ , cat.slug AS category_slug \ - , CASE WHEN 'ru' = :lang THEN cat.name_ru ELSE cat.name END AS category_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \ , count.id AS country_id \ , count.slug AS country_slug \ - , CASE WHEN 'ru' = :lang THEN count.name_ru ELSE count.name END AS country_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \ , s.release_day \ , s.release_month \ , s.release_year \ @@ -130,10 +130,10 @@ series.find_by_category_slug = \ SELECT s.id \ , cat.id AS category_id \ , cat.slug AS category_slug \ - , CASE WHEN 'ru' = :lang THEN cat.name_ru ELSE cat.name END AS category_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \ , count.id AS country_id \ , count.slug AS country_slug \ - , CASE WHEN 'ru' = :lang THEN count.name_ru ELSE count.name END AS country_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \ , s.release_day \ , s.release_month \ , s.release_year \ @@ -150,10 +150,10 @@ series.find_by_country_slug = \ SELECT s.id \ , cat.id AS category_id \ , cat.slug AS category_slug \ - , CASE WHEN 'ru' = :lang THEN cat.name_ru ELSE cat.name END AS category_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \ , count.id AS country_id \ , count.slug AS country_slug \ - , CASE WHEN 'ru' = :lang THEN count.name_ru ELSE count.name END AS country_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \ , s.release_day \ , s.release_month \ , s.release_year \ @@ -170,10 +170,10 @@ series.find_by_collection_id = \ SELECT s.id \ , cat.id AS category_id \ , cat.slug AS category_slug \ - , CASE WHEN 'ru' = :lang THEN cat.name_ru ELSE cat.name END AS category_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \ , count.id AS country_id \ , count.slug AS country_slug \ - , CASE WHEN 'ru' = :lang THEN count.name_ru ELSE count.name END AS country_name \ + , CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \ , s.release_day \ , s.release_month \ , s.release_year \ diff --git a/src/main/webapp/WEB-INF/views/category/add.html b/src/main/webapp/WEB-INF/views/category/add.html index 396154e290..0d18e1d820 100644 --- a/src/main/webapp/WEB-INF/views/category/add.html +++ b/src/main/webapp/WEB-INF/views/category/add.html @@ -121,10 +121,9 @@

    Name (in Russian) - *
    - + diff --git a/src/main/webapp/WEB-INF/views/country/add.html b/src/main/webapp/WEB-INF/views/country/add.html index e1f904852f..967ee62a8e 100644 --- a/src/main/webapp/WEB-INF/views/country/add.html +++ b/src/main/webapp/WEB-INF/views/country/add.html @@ -121,10 +121,9 @@

    Name (in Russian) - *
    - + diff --git a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy index ef2ccbfe91..421b678996 100644 --- a/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CategoryServiceImplTest.groovy @@ -63,15 +63,6 @@ class CategoryServiceImplTest extends Specification { thrown IllegalArgumentException } - def "add() should throw exception when Russian category name is null"() { - given: - form.setNameRu(null) - when: - service.add(form, USER_ID) - then: - thrown IllegalArgumentException - } - def "add() should throw exception when user is null"() { when: service.add(form, null) @@ -422,6 +413,34 @@ class CategoryServiceImplTest extends Specification { result == expectedResult } + // + // Tests for countUntranslatedNamesSince() + // + + def "countUntranslatedNamesSince() should throw exception when date is null"() { + when: + service.countUntranslatedNamesSince(null) + then: + thrown IllegalArgumentException + } + + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) + def "countUntranslatedNamesSince() should invoke dao, pass argument and return result from dao"() { + given: + Date expectedDate = new Date() + and: + long expectedResult = 17 + when: + long result = service.countUntranslatedNamesSince(expectedDate) + then: + 1 * categoryDao.countUntranslatedNamesSince({ Date date -> + assert date == expectedDate + return true + }) >> expectedResult + and: + result == expectedResult + } + // // Tests for getStatisticsOf() // diff --git a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy index 4a56fd8fa7..99346e8638 100644 --- a/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy @@ -63,15 +63,6 @@ class CountryServiceImplTest extends Specification { thrown IllegalArgumentException } - def "add() should throw exception when country name in Russian is null"() { - given: - form.setNameRu(null) - when: - service.add(form, USER_ID) - then: - thrown IllegalArgumentException - } - def "add() should throw exception when user is null"() { when: service.add(form, null) @@ -421,6 +412,34 @@ class CountryServiceImplTest extends Specification { result == expectedResult } + // + // Tests for countUntranslatedNamesSince() + // + + def "countUntranslatedNamesSince() should throw exception when date is null"() { + when: + service.countUntranslatedNamesSince(null) + then: + thrown IllegalArgumentException + } + + @SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) + def "countUntranslatedNamesSince() should invoke dao, pass argument and return result from dao"() { + given: + Date expectedDate = new Date() + and: + long expectedResult = 18 + when: + long result = service.countUntranslatedNamesSince(expectedDate) + then: + 1 * countryDao.countUntranslatedNamesSince({ Date date -> + assert date == expectedDate + return true + }) >> expectedResult + and: + result == expectedResult + } + // // Tests for getStatisticsOf() // diff --git a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy index f9b064dd5b..3471965335 100644 --- a/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy @@ -81,10 +81,18 @@ class CronServiceImplTest extends Specification { assertMidnightOfYesterday(date) return true }) + 1 * categoryService.countUntranslatedNamesSince({ Date date -> + assertMidnightOfYesterday(date) + return true + }) 1 * countryService.countAddedSince( { Date date -> assertMidnightOfYesterday(date) return true }) + 1 * countryService.countUntranslatedNamesSince( { Date date -> + assertMidnightOfYesterday(date) + return true + }) 1 * seriesService.countAddedSince({ Date date -> assertMidnightOfYesterday(date) return true @@ -123,7 +131,9 @@ class CronServiceImplTest extends Specification { def "sendDailyStatistics() should prepare report and pass it to mail service"() { given: categoryService.countAddedSince(_ as Date) >> 1 + categoryService.countUntranslatedNamesSince(_ as Date) >> 11 countryService.countAddedSince(_ as Date) >> 2 + countryService.countUntranslatedNamesSince(_ as Date) >> 12 seriesService.countAddedSince(_ as Date) >> 3 seriesService.countUpdatedSince(_ as Date) >> 4 usersActivationService.countCreatedSince(_ as Date) >> 5 @@ -142,7 +152,9 @@ class CronServiceImplTest extends Specification { assertMidnightOfYesterday(report.startDate) assertMidnightOfToday(report.endDate) assert report.addedCategoriesCounter == 1 + assert report.untranslatedCategoriesCounter == 11 assert report.addedCountriesCounter == 2 + assert report.untranslatedCountriesCounter == 12 assert report.addedSeriesCounter == 3 assert report.updatedSeriesCounter == 4 assert report.registrationRequestsCounter == 5 diff --git a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java index d5086f62cd..0b06322a31 100644 --- a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java +++ b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCategory.java @@ -228,7 +228,17 @@ public void categoryNameRuShouldReplaceRepeatedSpacesByOne() { } @Test(groups = "logic", dependsOnGroups = { "std", "invalid", "valid", "misc" }) - public void shouldBeRedirectedToPageWithInfoAboutCategoryAfterCreation() { + public void shouldCreateCategoryWithNameInEnglishOnly() { + page.addCategory("Cars", null); + + String expectedUrl = Url.INFO_CATEGORY_PAGE.replace("{slug}", "cars"); + + assertThat(page.getCurrentUrl()).isEqualTo(expectedUrl); + assertThat(page.getHeader()).isEqualTo("Cars"); + } + + @Test(groups = "logic", dependsOnGroups = { "std", "invalid", "valid", "misc" }) + public void shouldCreateCategoryWithNameInTwoLanguages() { page.addCategory(TEST_CATEGORY_NAME_EN, TEST_CATEGORY_NAME_RU); String expectedUrl = Url.INFO_CATEGORY_PAGE @@ -238,10 +248,7 @@ public void shouldBeRedirectedToPageWithInfoAboutCategoryAfterCreation() { assertThat(page.getHeader()).isEqualTo(TEST_CATEGORY_NAME_EN); } - @Test( - groups = "logic", - dependsOnMethods = "shouldBeRedirectedToPageWithInfoAboutCategoryAfterCreation" - ) + @Test(groups = "logic", dependsOnMethods = "shouldCreateCategoryWithNameInTwoLanguages") public void categoryShouldBeAvailableForChoosingAtPageWithSeries() { page.open(Url.ADD_SERIES_PAGE); diff --git a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java index f726924b18..1e0a469495 100644 --- a/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java +++ b/src/test/java/ru/mystamps/web/tests/cases/WhenAdminAddCountry.java @@ -251,7 +251,17 @@ public void countryNameRuShouldReplaceRepeatedSpacesByOne() { } @Test(groups = "logic", dependsOnGroups = { "std", "invalid", "valid", "misc" }) - public void shouldBeRedirectedToPageWithInfoAboutCountryAfterCreation() { + public void shouldCreateCountryWithNameInEnglishOnly() { + page.addCountry("Germany", null); + + String expectedUrl = Url.INFO_COUNTRY_PAGE.replace("{slug}", "germany"); + + assertThat(page.getCurrentUrl()).matches(expectedUrl); + assertThat(page.getHeader()).isEqualTo("Stamps of Germany"); + } + + @Test(groups = "logic", dependsOnGroups = { "std", "invalid", "valid", "misc" }) + public void shouldCreateCountryWithNameInTwoLanguages() { page.addCountry(TEST_COUNTRY_NAME_EN, TEST_COUNTRY_NAME_RU); String expectedUrl = Url.INFO_COUNTRY_PAGE @@ -261,10 +271,7 @@ public void shouldBeRedirectedToPageWithInfoAboutCountryAfterCreation() { assertThat(page.getHeader()).isEqualTo("Stamps of " + TEST_COUNTRY_NAME_EN); } - @Test( - groups = "logic", - dependsOnMethods = "shouldBeRedirectedToPageWithInfoAboutCountryAfterCreation" - ) + @Test(groups = "logic", dependsOnMethods = "shouldCreateCountryWithNameInTwoLanguages") public void countryShouldBeAvailableForChoosingAtPageWithSeries() { page.open(Url.ADD_SERIES_PAGE); diff --git a/src/test/java/ru/mystamps/web/tests/page/AddCategoryPage.java b/src/test/java/ru/mystamps/web/tests/page/AddCategoryPage.java index 380ce517ac..034e4fe2c4 100644 --- a/src/test/java/ru/mystamps/web/tests/page/AddCategoryPage.java +++ b/src/test/java/ru/mystamps/web/tests/page/AddCategoryPage.java @@ -37,7 +37,7 @@ public AddCategoryPage(WebDriver driver) { hasForm( with( required(inputField("name")).withLabel(tr("t_category_on_english")), - required(inputField("nameRu")).withLabel(tr("t_category_on_russian")) + inputField("nameRu").withLabel(tr("t_category_on_russian")) ) .and() .with(submitButton(tr("t_add"))) @@ -46,7 +46,6 @@ public AddCategoryPage(WebDriver driver) { public void addCategory(String nameEn, String nameRu) { Validate.validState(nameEn != null, "Category name in English must be non null"); - Validate.validState(nameRu != null, "Category name in Russian must be non null"); fillNameEn(nameEn); fillNameRu(nameRu); diff --git a/src/test/java/ru/mystamps/web/tests/page/AddCountryPage.java b/src/test/java/ru/mystamps/web/tests/page/AddCountryPage.java index ebac41a4b7..bb7a0a7655 100644 --- a/src/test/java/ru/mystamps/web/tests/page/AddCountryPage.java +++ b/src/test/java/ru/mystamps/web/tests/page/AddCountryPage.java @@ -37,7 +37,7 @@ public AddCountryPage(WebDriver driver) { hasForm( with( required(inputField("name")).withLabel(tr("t_country_on_english")), - required(inputField("nameRu")).withLabel(tr("t_country_on_russian")) + inputField("nameRu").withLabel(tr("t_country_on_russian")) ) .and() .with(submitButton(tr("t_add"))) @@ -46,7 +46,6 @@ public AddCountryPage(WebDriver driver) { public void addCountry(String nameEn, String nameRu) { Validate.validState(nameEn != null, "Country name in English must be non null"); - Validate.validState(nameRu != null, "Country name in Russian must be non null"); fillNameEn(nameEn); fillNameRu(nameRu); From b15079acc90a5fcf69e0cbfd41c810d7e9a1d517 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 6 Dec 2016 23:49:50 +0100 Subject: [PATCH 137/463] CountryController: add comment. Should be in 5a125e17fd095a5316757921423969f0ed653ec4 commit. No code changes. --- src/main/java/ru/mystamps/web/controller/CountryController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ru/mystamps/web/controller/CountryController.java b/src/main/java/ru/mystamps/web/controller/CountryController.java index c0f1706b96..acf60eb26e 100644 --- a/src/main/java/ru/mystamps/web/controller/CountryController.java +++ b/src/main/java/ru/mystamps/web/controller/CountryController.java @@ -61,6 +61,8 @@ public class CountryController { @InitBinder("addCountryForm") protected void initBinder(WebDataBinder binder) { + // We can't use StringTrimmerEditor here because "only one single registered custom + // editor per property path is supported". ReplaceRepeatingSpacesEditor editor = new ReplaceRepeatingSpacesEditor(true); binder.registerCustomEditor(String.class, "name", editor); binder.registerCustomEditor(String.class, "nameRu", editor); From fa6a8d3f48cb623e3cdf361fb595277265416234 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Wed, 7 Dec 2016 14:20:48 +0100 Subject: [PATCH 138/463] Messages(t_name_on_english,t_name_on_russian): sync keys with content. Should be in f4d8d90086d6b5d712aadbfc2a68cec8b0eef581 commit. No functional changes. --- src/main/resources/ru/mystamps/i18n/Messages.properties | 4 ++-- src/main/resources/ru/mystamps/i18n/Messages_ru.properties | 4 ++-- src/main/webapp/WEB-INF/views/category/add.html | 4 ++-- src/main/webapp/WEB-INF/views/country/add.html | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/resources/ru/mystamps/i18n/Messages.properties b/src/main/resources/ru/mystamps/i18n/Messages.properties index 835022f4f0..1cbf55eec6 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages.properties @@ -18,8 +18,8 @@ t_issue_date = Date of release t_items = item(s) t_wo_perforation_short = without perforation t_open_my_collection = Open my collection -t_name_on_english = Name (in English) -t_name_on_russian = Name (in Russian) +t_name_in_english = Name (in English) +t_name_in_russian = Name (in Russian) # header t_my_stamps = My stamps diff --git a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties index 05ea481bad..05f9d70f9a 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties @@ -18,8 +18,8 @@ t_issue_date = Дата выпуска t_wo_perforation_short = б/з t_items = шт. t_open_my_collection = Открыть мою коллекцию -t_name_on_english = Название (на английском) -t_name_on_russian = Название (на русском) +t_name_in_english = Название (на английском) +t_name_in_russian = Название (на русском) # шапка t_my_stamps = Мои марки diff --git a/src/main/webapp/WEB-INF/views/category/add.html b/src/main/webapp/WEB-INF/views/category/add.html index 0d18e1d820..24b6dab0f2 100644 --- a/src/main/webapp/WEB-INF/views/category/add.html +++ b/src/main/webapp/WEB-INF/views/category/add.html @@ -103,7 +103,7 @@