Skip to content

Commit 3199d98

Browse files
committed
Daily report: include stat with updated collections.
1 parent a3f3704 commit 3199d98

11 files changed

+69
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public CronService getCronService() {
6767
return new CronServiceImpl(
6868
getCategoryService(),
6969
getCountryService(),
70+
getCollectionService(),
7071
getSeriesService(),
7172
getSuspiciousActivityService(),
7273
getUserService(),

src/main/java/ru/mystamps/web/dao/CollectionDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
public interface CollectionDao {
2828
List<LinkEntityDto> findLastCreated(int quantity);
2929
long countCollectionsOfUsers();
30+
long countUpdatedSince(Date date);
3031
Integer add(AddCollectionDbDto collection);
3132
void markAsModified(Integer userId, Date updatedAt);
3233
boolean isSeriesInUserCollection(Integer userId, Integer seriesId);

src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class JdbcCollectionDao implements CollectionDao {
5555
@Value("${collection.count_collections_of_users}")
5656
private String countCollectionsOfUsersSql;
5757

58+
@Value("${collection.count_updated_since}")
59+
private String countUpdatedSinceSql;
60+
5861
@Value("${collection.create}")
5962
private String addCollectionSql;
6063

@@ -91,6 +94,15 @@ public long countCollectionsOfUsers() {
9194
);
9295
}
9396

97+
@Override
98+
public long countUpdatedSince(Date date) {
99+
return jdbcTemplate.queryForObject(
100+
countUpdatedSinceSql,
101+
Collections.singletonMap("date", date),
102+
Long.class
103+
);
104+
}
105+
94106
@Override
95107
public Integer add(AddCollectionDbDto collection) {
96108
Map<String, Object> params = new HashMap<>();

src/main/java/ru/mystamps/web/service/CollectionService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package ru.mystamps.web.service;
1919

20+
import java.util.Date;
2021
import java.util.List;
2122

2223
import ru.mystamps.web.dao.dto.CollectionInfoDto;
@@ -28,6 +29,7 @@ public interface CollectionService {
2829
void removeFromCollection(Integer userId, Integer seriesId);
2930
boolean isSeriesInCollection(Integer userId, Integer seriesId);
3031
long countCollectionsOfUsers();
32+
long countUpdatedSince(Date date);
3133
List<LinkEntityDto> findRecentlyCreated(int quantity);
3234
CollectionInfoDto findBySlug(String slug);
3335
}

src/main/java/ru/mystamps/web/service/CollectionServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public long countCollectionsOfUsers() {
121121
return collectionDao.countCollectionsOfUsers();
122122
}
123123

124+
@Override
125+
@Transactional(readOnly = true)
126+
public long countUpdatedSince(Date date) {
127+
Validate.isTrue(date != null, "Date must be non null");
128+
129+
return collectionDao.countUpdatedSince(date);
130+
}
131+
124132
@Override
125133
@Transactional(readOnly = true)
126134
public List<LinkEntityDto> findRecentlyCreated(int quantity) {

src/main/java/ru/mystamps/web/service/CronServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class CronServiceImpl implements CronService {
4444

4545
private final CategoryService categoryService;
4646
private final CountryService countryService;
47+
private final CollectionService collectionService;
4748
private final SeriesService seriesService;
4849
private final SuspiciousActivityService suspiciousActivityService;
4950
private final UserService userService;
@@ -71,6 +72,7 @@ public void sendDailyStatistics() {
7172

7273
report.setAddedSeriesCounter(seriesService.countAddedSince(yesterday));
7374
report.setUpdatedSeriesCounter(seriesService.countUpdatedSince(yesterday));
75+
report.setUpdatedCollectionsCounter(collectionService.countUpdatedSince(yesterday));
7476
report.setRegistrationRequestsCounter(usersActivationService.countCreatedSince(yesterday));
7577
report.setRegisteredUsersCounter(userService.countRegisteredSince(yesterday));
7678

src/main/java/ru/mystamps/web/service/MailServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private String getTextOfDailyStatisticsMail(AdminDailyReport report) {
197197
put(ctx, "untranslated_categories_cnt", report.getUntranslatedCategoriesCounter());
198198
put(ctx, "added_series_cnt", report.getAddedSeriesCounter());
199199
put(ctx, "updated_series_cnt", report.getUpdatedSeriesCounter());
200-
put(ctx, "updated_collections_cnt", -1L); // TODO: #357
200+
put(ctx, "updated_collections_cnt", report.getUpdatedCollectionsCounter());
201201
put(ctx, "registration_requests_cnt", report.getRegistrationRequestsCounter());
202202
put(ctx, "registered_users_cnt", report.getRegisteredUsersCounter());
203203
put(ctx, "events_cnt", report.countEvents());

src/main/java/ru/mystamps/web/service/dto/AdminDailyReport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AdminDailyReport {
3333
private long untranslatedCountriesCounter;
3434
private long addedSeriesCounter;
3535
private long updatedSeriesCounter;
36+
private long updatedCollectionsCounter;
3637
private long registrationRequestsCounter;
3738
private long registeredUsersCounter;
3839
private long notFoundCounter;
@@ -57,6 +58,7 @@ public long countTotalChanges() {
5758
totalChanges = Math.addExact(totalChanges, untranslatedCountriesCounter);
5859
totalChanges = Math.addExact(totalChanges, addedSeriesCounter);
5960
totalChanges = Math.addExact(totalChanges, updatedSeriesCounter);
61+
totalChanges = Math.addExact(totalChanges, updatedCollectionsCounter);
6062
totalChanges = Math.addExact(totalChanges, registrationRequestsCounter);
6163
totalChanges = Math.addExact(totalChanges, registeredUsersCounter);
6264
totalChanges = Math.addExact(totalChanges, countEvents());

src/main/resources/sql/collection_dao_queries.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ LEFT JOIN series s \
1919
ON s.id = cs.series_id \
2020
WHERE s.id IS NOT NULL
2121

22+
collection.count_updated_since = \
23+
SELECT COUNT(*) \
24+
FROM collections \
25+
WHERE updated_at >= :date
26+
2227
collection.create = \
2328
INSERT \
2429
INTO collections \

src/test/groovy/ru/mystamps/web/service/CollectionServiceImplTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,33 @@ class CollectionServiceImplTest extends Specification {
249249
serviceResult == expectedResult
250250
}
251251

252+
//
253+
// Tests for countUpdatedSince()
254+
//
255+
256+
def "countUpdatedSince() should throw exception when date is null"() {
257+
when:
258+
service.countUpdatedSince(null)
259+
then:
260+
thrown IllegalArgumentException
261+
}
262+
263+
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])
264+
def "countUpdatedSince() should invoke dao, pass argument and return result from dao"() {
265+
given:
266+
Date expectedDate = new Date()
267+
long expectedResult = 47
268+
when:
269+
long result = service.countUpdatedSince(expectedDate)
270+
then:
271+
1 * collectionDao.countUpdatedSince({ Date date ->
272+
assert date == expectedDate
273+
return true
274+
}) >> expectedResult
275+
and:
276+
result == expectedResult
277+
}
278+
252279
//
253280
// Tests for findRecentlyCreated()
254281
//

src/test/groovy/ru/mystamps/web/service/CronServiceImplTest.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CronServiceImplTest extends Specification {
2727

2828
private final CategoryService categoryService = Mock()
2929
private final CountryService countryService = Mock()
30+
private final CollectionService collectionService = Mock()
3031
private final SeriesService seriesService = Mock()
3132
private final SuspiciousActivityService suspiciousActivityService = Mock()
3233
private final MailService mailService = Mock()
@@ -36,6 +37,7 @@ class CronServiceImplTest extends Specification {
3637
private final CronService service = new CronServiceImpl(
3738
categoryService,
3839
countryService,
40+
collectionService,
3941
seriesService,
4042
suspiciousActivityService,
4143
userService,
@@ -101,6 +103,10 @@ class CronServiceImplTest extends Specification {
101103
assertMidnightOfYesterday(date)
102104
return true
103105
})
106+
1 * collectionService.countUpdatedSince({ Date date ->
107+
assertMidnightOfYesterday(date)
108+
return true
109+
})
104110
1 * usersActivationService.countCreatedSince({ Date date ->
105111
assertMidnightOfYesterday(date)
106112
return true
@@ -136,6 +142,7 @@ class CronServiceImplTest extends Specification {
136142
countryService.countUntranslatedNamesSince(_ as Date) >> 12
137143
seriesService.countAddedSince(_ as Date) >> 3
138144
seriesService.countUpdatedSince(_ as Date) >> 4
145+
collectionService.countUpdatedSince(_ as Date) >> 13
139146
usersActivationService.countCreatedSince(_ as Date) >> 5
140147
userService.countRegisteredSince(_ as Date) >> 6
141148
and:
@@ -157,6 +164,7 @@ class CronServiceImplTest extends Specification {
157164
assert report.untranslatedCountriesCounter == 12
158165
assert report.addedSeriesCounter == 3
159166
assert report.updatedSeriesCounter == 4
167+
assert report.updatedCollectionsCounter == 13
160168
assert report.registrationRequestsCounter == 5
161169
assert report.registeredUsersCounter == 6
162170
assert report.notFoundCounter == 7

0 commit comments

Comments
 (0)